關於異或值怎么計算


首先使用十六進制器打開微信dat文件,顯示如下

jpg圖片文件頭一般為FF D8 開頭的,所以此處使用科學計算器,計算異或值


計算后的值

所以此處異或值就是0x9D

代碼
以下是java代碼,創建一個weChatImgRevert .class后復制進去就好啦。
此處的jdk版本需要1.8以上…,另外三個參數需要改成自己的哦~

package main.java.com.example.demo;

import java.io.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicReference;

public class weChatImgRevert {

public static void main(String[] args) {
String path = "C:\\Users\\Administrator\\Documents\\WeChat Files\\xxx\\FileStorage\\Image\\2019-07";
String targetPath = "D:\\weChat\\2019-07\\";
int xor = 0xCB;
convert(path, targetPath, xor);
}

/**
* @param path 圖片地址
* @param targetPath 轉換后目錄
*/
private static void convert(String path, String targetPath, int xor) {
File[] file = new File(path).listFiles();
if (file == null) {
return;
}
int size = file.length;
System.out.println("總共" + size + "個文件");
AtomicReference<Integer> integer = new AtomicReference<>(0);
Arrays.stream(file).parallel().forEach(file1 -> {
try (InputStream reader = new FileInputStream(file1);
OutputStream writer =
new FileOutputStream(targetPath + file1.getName().split("\\.")[0] + ".jpg")) {
byte[] bytes = new byte[1024 * 10];
int b;
while ((b = reader.read(bytes)) != -1) {//這里的in.read(bytes);就是把輸入流中的東西,寫入到內存中(bytes)。
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) (int) (bytes[i] ^ xor);
if (i == (b - 1)) {
break;
}
}
writer.write(bytes, 0, b);
writer.flush();
}
integer.set(integer.get() + 1);
System.out.println(file1.getName() + "(大小:" + ((double) file1.length() / 1000) + "kb),進度:" + integer.get() +
"/" + size);
} catch (Exception e) {
e.printStackTrace();
}
});
System.out.println("解析完畢!");
}

/**
* 獲取異或值,不一定准確,當解析不出來的時候,換一張圖片的異或值來解析
*
* @param PhotoPath
* @return
*/
private static int getXor(String PhotoPath) {
File file = new File(PhotoPath);
try (InputStream reader = new FileInputStream(file)) {
int[] xors = new int[4];
xors[0] = reader.read() & 0xFF ^ 0xFF;
xors[1] = reader.read() & 0xFF ^ 0xD8;
reader.skip(file.length() - 1);
xors[2] = reader.read() & 0xFF ^ 0xFF;
xors[3] = reader.read() & 0xFF ^ 0xD9;
Map<Integer, Integer> map = new HashMap<>();
for (int xor : xors) {
if (map.containsKey(xor)) {
map.put(xor, map.get(xor) + 1);
} else {
map.put(xor, 1);
}
}
return map.values().stream().max(Integer::compareTo).get();
} catch (Exception e) {
e.printStackTrace();
}
return 0;
}

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
執行main方法后就可以在目標文件夾中去看轉換后的圖片了
以下是轉換后的效果圖片:


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM