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

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

高老师10个月前 (12-04)PHP272

根据文件头进制特征识别文件类型,识别为图片进行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批量插入的2种方法速度对比

PHP批量插入的2种方法速度对比

代码1:for循环批量插入100W数据<?php set_time_limit(0); $servername = "localhost"; $username = "root"; $password ...

PHP对象转数组

PHP对象转数组

function objtoarr($obj){ $ret = array(); foreach($obj as $key =>$value){ if(gettype($value) == 'arr...

php 地址转换经纬度

php 地址转换经纬度

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

PHP二维数组排序,PHP多维数组排序, array_multisort()

PHP二维数组排序,PHP多维数组排序, array_multisort()

使用php函数array_multisort()即可实现和SQL一样的order by排序. 例如我们需要对会员表按照主键降序排列,年龄升序排列://会员表数据 $list = []; $list[] = ['mid' =>&n...

PHP yield  PHP协程,PHP协程用法学习

PHP yield PHP协程,PHP协程用法学习

【一】.迭代器迭代是指反复执行一个过程,每执行一次叫做一次迭代。比如下面的代码就叫做迭代:1.  <?php   2.  $data = ['1', '2', &...

 php命令行中文乱码,php cli中文乱码

php命令行中文乱码,php cli中文乱码

<?php //如果支持exec函数,可以使用的方式 exec('chcp 65001'); //如果exec函数因安全问题禁用,可以使用的方式 pclose(popen('chcp 65001', 'r'));...