在線還原工具
福利在線微信dat文件還原工具 微信dat在線還原
引言
經常使用電腦端微信聊天的朋友,查看自己的微信安裝路徑,一般存儲路徑爲C:\Users\weixindata\WeChat Files\微信號\FileStorage\Image 會存在大量的dat格式的文件,沒錯,那就是你聊天記錄中圖片數據
你會發現微信的小夥伴們已經將數據進行了加密,明明是自己的圖片可是沒法看,真是愁壞了少年頭,空悲切!
查閱資料發現,dat文件的祕密在於將數據圖片(16進制),與特定的數據進行了異或加密,先來聊聊加解密的原理及代碼。
微信dat格式文件是將原來的圖片文件,以16進制數據讀取,然後根據圖片格式的不同(如jpg/PNG等等)異或不同單位16進制數值,然後將異或以後的數據保存成dat格式。
碼上碼上
package com;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
public class WxChatImgRevert2 {
/**
* @param path 圖片目錄地址
* @param targetPath 轉換後目錄
*/
private static void convert(String path, String targetPath) {
File[] file = new File(path).listFiles();
if (file == null) {
return;
}
int size = file.length;
System.out.println("總共" + size + "個文件");
AtomicReference<Integer> integer = new AtomicReference<>(0);
AtomicInteger x = new AtomicInteger();
for (File file1 : file) {
if (file1.isFile()) {
Object[] xori = getXor(file1);
if (xori != null && xori[1] != null){
x.set((int)xori[1]);
}
break;
}
}
Arrays.stream(file).parallel().forEach(file1 -> {
if (file1.isDirectory()) {
String[] newTargetPath = file1.getPath().split("/|\\\\");
File targetFile = new File(targetPath+File.separator+newTargetPath[newTargetPath.length - 1]);
if (!targetFile.exists()) {
targetFile.mkdirs();
}
convert(file1.getPath(),targetPath+File.separator+newTargetPath[newTargetPath.length - 1]);
return;
}
Object[] xor = getXor(file1);
if (x.get() == 0 && xor[1] != null && (int) xor[1] != 0) {
x.set((int) xor[1]);
}
xor[1] = xor[1] == null ? x.get() : xor[1];
try (InputStream reader = new FileInputStream(file1);
OutputStream writer =
new FileOutputStream(targetPath + File.separator + file1.getName().split("\\.")[0] + (xor[0] != null ?
"." + xor[0] : ""))) {
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] ^ (int) xor[1]);
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,異或值:" + xor[1] + ")," +
"進度:" + integer.get() +
"/" + size);
} catch (Exception e) {
e.printStackTrace();
}
});
System.out.println("解析完畢!");
}
/**
* 判斷圖片異或值
*
* @param file
* @return
*/
private static Object[] getXor(File file) {
Object[] xor = null;
if (file != null) {
byte[] bytes = new byte[4];
try (InputStream reader = new FileInputStream(file)) {
reader.read(bytes, 0, bytes.length);
} catch (Exception e) {
e.printStackTrace();
}
xor = getXor(bytes);
}
return xor;
}
/**
* @param bytes
* @return
*/
private static Object[] getXor(byte[] bytes) {
Object[] xorType = new Object[2];
int[] xors = new int[3];
for (Map.Entry<String, String> type : FILE_TYPE_MAP.entrySet()) {
String[] hex = {
String.valueOf(type.getKey().charAt(0)) + type.getKey().charAt(1),
String.valueOf(type.getKey().charAt(2)) + type.getKey().charAt(3),
String.valueOf(type.getKey().charAt(4)) + type.getKey().charAt(5)
};
xors[0] = bytes[0] & 0xFF ^ Integer.parseInt(hex[0], 16);
xors[1] = bytes[1] & 0xFF ^ Integer.parseInt(hex[1], 16);
xors[2] = bytes[2] & 0xFF ^ Integer.parseInt(hex[2], 16);
if (xors[0] == xors[1] && xors[1] == xors[2]) {
xorType[0] = type.getValue();
xorType[1] = xors[0];
break;
}
}
return xorType;
}
private final static Map<String, String> FILE_TYPE_MAP = new HashMap<String, String>();
}
代碼親測可用,喜歡動手的小夥伴們碼起來。
歡迎關注我的同名博客站 熊貓卓Sunhttps://9035shop.cn