Advertisement

Java开发微信dat文件解析工具,android原生开发笔记应用

阅读量:

//保存路径(输出)

String savePath=“C:\Users\Administrator\Desktop”;

//开始解析

convert(wxPath, savePath);

/**

@param path 图片目录地址

@param targetPath 转换后目录

*/

private void convert(String path, String targetPath) {

File[] file = new File(path).listFiles();

if (file == null) {

return;

}

int size = file.length;

txtArea_log.append(“总共” + size + “个文件\r\n”);

AtomicReference integer = new AtomicReference<>(0);

AtomicInteger x

《Android学习笔记总结+最新移动架构视频+大厂安卓面试真题+项目实战源码讲义》

docs.qq.com/doc/DSkNLaERkbnFoS0ZF】 完整内容开源分享

= 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);

txtArea_log.append(file1.getName() + “(大小:” + ((double) file1.length() / 1000) + “kb,异或值:” + xor[1] + “),” +“进度:” + integer.get() + “/” + size+"\r\n");

} catch (Exception e) {

e.printStackTrace();

}

});

txtArea_log.append(“解析完毕!\r\n”);

}

/**

判断图片异或值

@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>();

private JButton btn_open_wxpath;

private final JButton btn_open_savepath = new JButton("");

static {

getAllFileType();

}

private static void getAllFileType() {

FILE_TYPE_MAP.put(“ffd8ffe000104a464946”, “jpg”); //JPEG (jpg)

FILE_TYPE_MAP.put(“89504e470d0a1a0a0000”, “png”); //PNG (png)

FILE_TYPE_MAP.put(“47494638396126026f01”, “gif”); //GIF (gif)

FILE_TYPE_MAP.put(“49492a00227105008037”, “tif”); //TIFF (tif)

FILE_TYPE_MAP.put(“424d228c010000000000”, “bmp”); //16色位图(bmp)

FILE_TYPE_MAP.put(“424d8240090000000000”, “bmp”); //24位位图(bmp)

FILE_TYPE_MAP.put(“424d8e1b030000000000”, “bmp”); //256色位图(bmp)

FILE_TYPE_MAP.put(“41433130313500000000”, “dwg”); //CAD (dwg)

FILE_TYPE_MAP.put(“3c21444f435459504520”, “html”); //HTML (html)

FILE_TYPE_MAP.put(“3c21646f637479706520”, “htm”); //HTM (htm)

FILE_TYPE_MAP.put(“48544d4c207b0d0a0942”, “css”); //css

FILE_TYPE_MAP.put(“696b2e71623d696b2e71”, “js”); //js

FILE_TYPE_MAP.put(“7b5c727466315c616e73”, “rtf”); //Rich Text Format (rtf)

FILE_TYPE_MAP.put(“38425053000100000000”, “psd”); //Photoshop (psd)

FILE_TYPE_MAP.put(“46726f6d3a203d3f6762”, “eml”); //Email [Outlook Express 6] (eml)

全部评论 (0)

还没有任何评论哟~