当前位置:首页 > PHP > 正文内容

通过PHP代码解析微信电脑版加密的聊天文件代码开源

高老师2年前 (2023-12-04)PHP351

根据文件头进制特征识别文件类型,识别为图片进行OCR识别,懂得都懂,禁止用于违法行为。

<?php

// 16进制特征码
$checkMap = [
    ".jpeg" => hex2bin("FFD8FF"),
    ".png" => hex2bin("89504E47"),
    ".gif" => hex2bin("47494638"),
    ".tif" => hex2bin("49492A00"),
    ".bmp" => hex2bin("424D")
];

// 传递微信加密文件
$file = './be27b0c8911ffd7294b7febc16a9cb91_t.dat';
if (!file_exists($file)) {
    throw new Exception('文件' . $file . '不存在');
}

// 读取文件内容
$content = file_get_contents($file);
if (!$content) {
    throw new Exception('未获取到文件内容');
}

// 读取文件前10个字节内容作为特征码
$bytesToRead = 10;
$feature = substr($content, 0, 10);
if (!$feature || strlen($feature) != 10) {
    throw new Exception('未获取到文件特征码');
}

// 检查特征
$feature_array = str_split($feature, 1);
$fileRes = checkImage($feature_array);
if (empty($fileRes['0'])) {
    throw new Exception('不支持的文件类型');
}

// 生成新的文件
$newFile = 'test' . $fileRes['0'];

// 将文件内容转换
$newChar = '';
for ($i = 0; $i < strlen($content); $i++) {
    $newChar .= $content[$i] ^ $fileRes['1'];
}
file_put_contents($newFile, $newChar);


// 检查特征
function checkImage($in_feature)
{
    global $checkMap;
    foreach ($checkMap as $key => $check_feature) {
        $isConform = checkConformRule($check_feature, $in_feature);
        if ($isConform) {
            return [$key, $isConform];
        }
    }
    return [null, null];
}

// 检查规则
function checkConformRule($check_feature, $in_feature)
{
    $initDecodeByte = $check_feature[0] ^ $in_feature[0];
    for ($i = 0; $i < strlen($check_feature); $i++) {
        $b = $check_feature[$i] ^ $in_feature[$i];
        if ($b !== $initDecodeByte) {
            return false;
        }
    }
    return $initDecodeByte;
}


扫描二维码推送至手机访问。

版权声明:本文由高久峰个人博客发布,如需转载请注明出处。

本文链接:https://blog.20230611.cn/post/682.html

分享给朋友:

“通过PHP代码解析微信电脑版加密的聊天文件代码开源” 的相关文章

PHP浮点数乘以整数还是浮点型

PHP浮点数乘以整数还是浮点型

<?PHP     $a=0.5*100;     if(is_int($a)){   echo'int'; } else{ echo'not int';   }    ...

php 地址转换经纬度

php 地址转换经纬度

//$ak开发密钥,$cityname城市名称(支持省县乡详细地址) public  function   getposition($ak,$cityname){ $callback=array('lng'=>0,'l...

php scoket,php webscoket,php webscoket 服务器

php scoket,php webscoket,php webscoket 服务器

项目需要使用websocket推送最新订单,客户服务器非linux不支持swoole,因此使用原生,直接上代码(1).PHP服务端<?php ini_set('error_reporting', E_ALL ^ E_NOTICE); ini_set...

php多进程实现任务管理器,定时执行任务,支持守护

php多进程实现任务管理器,定时执行任务,支持守护

主要原理是通过PHP创建多个子进程,在子进程中发送进程闹钟信号,然后再监听闹钟信号中继续发送闹钟信号。同时通过父进程设置非阻塞运行。代码如下:<?php /**  * 订单任务  */ class Order {    &n...

PHP Warning:  ftok(): Project identifier is invalid

PHP Warning: ftok(): Project identifier is invalid

在使用ftok生成ipc进程通信key尝试将第二个参数项目标识符传入字符串报错:PHP Warning:  ftok(): Project identifier is invalid,查阅资料发现第二个字符串只能是1个字符串,长度为1....

packagist包发布稳定版

packagist包发布稳定版

自己的composer已经发布到packagist,但是无法使用composer require easy-task/easy-task来安装,只能在配置文件使用如下方式安装:"require": {     "easy...