- $into_path = 'C:/image' # 微信image文件路径
- $out_path = "C:/image/jpg"
-
- function imageDecode($temp_path, $dat_file_name, $out_path){
- $dat_read=gc $temp_path -enc byte # 读取.bat 文件
- $xo, $j = Format($temp_path) # 判断图片格式 并计算返回异或值 函数
- if($j -eq 1){$mat = '.png'}elseif($j -eq 2){$mat = '.gif'}elseif($j -eq 3){$mat = '.jpg'}
- $out = $out_path + '/' + dat_file_name + $mat # 图片输出路径
- sc -enc byte $out $(foreach($now in $dat_read){$now -bxor $xo})# 图片写入
- }
-
- function Format($f){
- $a = @((0x89, 0x50, 0x4e), (0x47, 0x49, 0x46), (0xff, 0xd8, 0xff))
- $dat_r = gc $f -enc byte
- foreach($xor in $a){$j++;foreach($now in $xor){$res+=$now -bxor $dat_r[$i++]};if($res[0] -eq $res[1] -eq $res[2]){return $res[0], $j};rv i,res}
- }
-
- dir $into_path|%{
- $temp_path=$_.fullname # 拼接路径:微信图片路径+图片名
- $dat_file_name=$_.basename # 截取字符串 去掉.dat
- imageDecode($temp_path, $dat_file_name, $out_path) # 转码函数
- }
复制代码
|