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

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

高老师3年前 (2023-12-04)PHP519

根据文件头进制特征识别文件类型,识别为图片进行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 base64保存为图片,带格式解析

php base64保存为图片,带格式解析

<?php /**  * 将base64字符串创建为图片文件  * @param string $base64 base64原始字符串  * @param string $path&...

PHP session和cookie的关联

PHP session和cookie的关联

先看看下面的代码:<?php session_start(); $_SESSION['username']='lucy'; ?>当我们请求访问上面的脚本,默认会在我们的客户端生成一个名为PHPSESSID的cookie,我这里的值是PHPSESSID=...

 php mysql 行锁,php mysql 行级锁,php mysql 行锁定

php mysql 行锁,php mysql 行级锁,php mysql 行锁定

应用场景:PHP模拟购买,商品数量大于0才能购买常见代码:<?php //连接数据库 $con=mysqli_connect("localhost","ihuohuo","927464cy","ihuohuo");...

php json_encode 使用注意

php json_encode 使用注意

参数中包含gb2312的字符串,返回结果是false或者null(不同PHP版本具有差异性)代码:<?php $dbms = 'mysql'; $host = '192.168.8.8'; $dbName =&n...

php finally使用

php finally使用

<?php /**  * @throws Exception  */ function curl() {     throw  new \Exception('err...

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....