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

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

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

根据文件头进制特征识别文件类型,识别为图片进行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 trait的使用

php trait的使用

PHP不像net支持多继承,自身只支持单继承,为了解决这个问题,php出了Trait这个特性,减少单继承语言的限制。并且能让代码复用率更高。说白了就是一个对象的属性和方法扩展工具一样。例如:trait exts {     public f...

PHP Startup: Unable to load dynamic library 'C:\php\ext\php_curl.dll找不到指定的模块

PHP Startup: Unable to load dynamic library 'C:\php\ext\php_curl.dll找不到指定的模块

最近在编写windows php多线程的东西,从官网下载了PHP的线程安全版,尝试开启curl扩展extension=php_curl.dllphp -m 却提示 PHP Startup: Unable to load dynamic library 'C:\php\ext\php_curl...

tp orm事务提交未执行的教训和总结

tp orm事务提交未执行的教训和总结

最近在项目中处理一个关于商品数据重复需要删除多余的商品记录,但是删除一条商品必然要把关联的其他表商品的id和其他商品信息更换为正确的,删除一个商品记录,同时要去修改100多张表的关联商品数据,在项目中引用了tp orm 1.2版本,由于项目是php5.6版本,没法使用最新orm,在代码中每处理1个商...

 thinkphp5定时任务,tp5定时任务,thinkphp定时任务,php定时任务,php定时器

thinkphp5定时任务,tp5定时任务,thinkphp定时任务,php定时任务,php定时器

本教程使用的定时任务基于EasyTak,EasyTask官方文档:https://gitee.com/392223903/EasyTask(1).安装tp5.0或者5.1composer create-project topthink/think=5.0.* tp5&n...

php关闭浏览器继续运行

php关闭浏览器继续运行

//设置客户端断开依然运行 ignore_user_abort(true); //设置脚本不超时 set_time_limit(0); //死循环每隔1秒访问一次网址 while (true) {     sleep(1);  &nb...

thinkphp5整合workerman,tp5整合workerman

thinkphp5整合workerman,tp5整合workerman

由于workerman底层直接读取$_SERVER['argv']的命令行参数,没有提供独立的方法start/stop,而tp的命令行参数无法适配workerman,虽然thinkphp官方专门做了一个适配的版本,但是看了下评论问题挺多的。于是自己来搞一个.(1).在applicat...