Skip to content

Commit e02b942

Browse files
committed
添加微信小程序反编译工具。
1 parent 24414a8 commit e02b942

10 files changed

Lines changed: 305 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ xJavaFxTool是使用javaFx开发的实用小工具集,目前项目刚刚建立
107107

108108
38、ImageAnalysisTool:图片解析工具(1、.atlas文件反解析;2、图片快速拆分工具);
109109

110+
39、DecompilerWxApkgTool:微信小程序反编译工具(一键反编译微信小程序包);
111+
110112
项目开发中,以后会陆续添加新工具,欢迎大家参与其中,多提提意见,谢谢。
111113

112114

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>com.xwintop</groupId>
66
<artifactId>xJavaFxTool</artifactId>
7-
<version>0.1.4-SNAPSHOT</version>
7+
<version>0.1.5-SNAPSHOT</version>
88
<packaging>jar</packaging>
99
<name>xJavaFxTool</name>
1010
<description>基于JavaFx搭建的实用小工具集合</description>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package com.xwintop.xJavaFxTool.controller.assistTools;
2+
3+
import com.xwintop.xJavaFxTool.view.assistTools.DecompilerWxApkgToolView;
4+
import com.xwintop.xJavaFxTool.services.assistTools.DecompilerWxApkgToolService;
5+
import com.xwintop.xcore.util.javafx.FileChooserUtil;
6+
import lombok.Getter;
7+
import lombok.Setter;
8+
import lombok.extern.slf4j.Slf4j;
9+
10+
import java.io.File;
11+
import java.net.URL;
12+
import java.util.ResourceBundle;
13+
14+
import javafx.event.ActionEvent;
15+
import javafx.fxml.FXML;
16+
17+
/**
18+
* @ClassName: DecompilerWxApkgToolController
19+
* @Description: 微信小程序反编译工具
20+
* @author: xufeng
21+
* @date: 2018/7/4 14:44
22+
*/
23+
@Getter
24+
@Setter
25+
@Slf4j
26+
public class DecompilerWxApkgToolController extends DecompilerWxApkgToolView {
27+
private DecompilerWxApkgToolService decompilerWxApkgToolService = new DecompilerWxApkgToolService(this);
28+
29+
@Override
30+
public void initialize(URL location, ResourceBundle resources) {
31+
initView();
32+
initEvent();
33+
initService();
34+
}
35+
36+
private void initView() {
37+
}
38+
39+
private void initEvent() {
40+
FileChooserUtil.setOnDrag(packageFileTextField, FileChooserUtil.FileType.FILE);
41+
FileChooserUtil.setOnDrag(decompilePathTextField, FileChooserUtil.FileType.FOLDER);
42+
}
43+
44+
private void initService() {
45+
}
46+
47+
@FXML
48+
private void packageFileButtonAction(ActionEvent event) {
49+
File file = FileChooserUtil.chooseFile();
50+
if (file != null) {
51+
packageFileTextField.setText(file.getPath());
52+
}
53+
}
54+
55+
@FXML
56+
private void decompilePathButtonAction(ActionEvent event) {
57+
File file = FileChooserUtil.chooseDirectory();
58+
if (file != null) {
59+
decompilePathTextField.setText(file.getPath());
60+
}
61+
}
62+
63+
@FXML
64+
private void decompileButtonAction(ActionEvent event) throws Exception {
65+
decompilerWxApkgToolService.decompileButtonAction();
66+
}
67+
}
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package com.xwintop.xJavaFxTool.services.assistTools;
2+
3+
import com.xwintop.xJavaFxTool.controller.assistTools.DecompilerWxApkgToolController;
4+
import com.xwintop.xcore.util.javafx.TooltipUtil;
5+
import lombok.Data;
6+
import lombok.Getter;
7+
import lombok.Setter;
8+
import lombok.extern.slf4j.Slf4j;
9+
import org.apache.commons.io.FileUtils;
10+
import org.apache.commons.io.FilenameUtils;
11+
import org.apache.commons.lang3.StringUtils;
12+
13+
import java.io.*;
14+
15+
/**
16+
* @ClassName: DecompilerWxApkgToolService
17+
* @Description: 微信小程序反编译工具
18+
* @author: xufeng
19+
* @date: 2018/7/4 14:44
20+
*/
21+
22+
@Getter
23+
@Setter
24+
@Slf4j
25+
public class DecompilerWxApkgToolService {
26+
private DecompilerWxApkgToolController decompilerWxApkgToolController;
27+
28+
private DataInputStream in;//in 流
29+
private WxFile wxFile;//当前文件
30+
private WxFile currentWxFile;//当前文件
31+
private int count;//当前文件
32+
33+
public void decompileButtonAction() throws Exception {
34+
String filePath = decompilerWxApkgToolController.getPackageFileTextField().getText();
35+
if (StringUtils.isBlank(filePath)) {
36+
TooltipUtil.showToast("原包路径未填写。");
37+
return;
38+
}
39+
String decompilePath = decompilerWxApkgToolController.getDecompilePathTextField().getText();
40+
if (StringUtils.isBlank(decompilePath)) {
41+
decompilePath = FilenameUtils.getFullPath(filePath) + FilenameUtils.getBaseName(filePath);
42+
FileUtils.forceMkdir(new File(decompilePath + "\\"));
43+
}
44+
decompilePath = StringUtils.appendIfMissing(decompilePath, "/", "/", "\\");
45+
this.in = new DataInputStream(new FileInputStream(filePath));
46+
decodeWxFile(this.in);
47+
while (currentWxFile != null) {
48+
String name = currentWxFile.getName();
49+
File file = new File(decompilePath, name);
50+
if (!file.getParentFile().exists()) {
51+
file.getParentFile().mkdirs();
52+
}
53+
OutputStream o = new FileOutputStream(file);
54+
this.readWxFile(o);
55+
o.close();
56+
}
57+
if (in != null) {
58+
in.close();
59+
}
60+
TooltipUtil.showToast("反编译成功,文件保存在:" + decompilePath + "目录下。");
61+
}
62+
63+
public DecompilerWxApkgToolService(DecompilerWxApkgToolController decompilerWxApkgToolController) {
64+
this.decompilerWxApkgToolController = decompilerWxApkgToolController;
65+
}
66+
67+
/**
68+
* 解码文件名区域
69+
*
70+
* @param in in
71+
*/
72+
private void decodeWxFile(DataInputStream in) throws IOException {
73+
in.readByte(); //标识
74+
in.readInt(); //未知
75+
in.readInt(); //文件名域长度
76+
in.readInt(); //内容域长度
77+
in.readByte(); //未知
78+
count = in.readInt(); //文件数量
79+
if (count > 0) {
80+
WxFile nextWxFile = null;
81+
for (int i = 0; i < count; i++) {
82+
byte[] name = new byte[in.readInt()]; //文件名长度
83+
int j = in.read(name);
84+
int offset = in.readInt(); //偏移
85+
int length = in.readInt(); //内容长度
86+
WxFile currentWxFile = new WxFile();
87+
currentWxFile.setName(new String(name, "UTF-8"));
88+
currentWxFile.setOffset(offset);
89+
currentWxFile.setLength(length);
90+
if (nextWxFile == null) {
91+
nextWxFile = currentWxFile;
92+
wxFile = nextWxFile;
93+
} else {
94+
nextWxFile.setNext(currentWxFile);
95+
nextWxFile = currentWxFile;
96+
}
97+
}
98+
}
99+
currentWxFile = wxFile; //当前处理的文件
100+
}
101+
102+
/**
103+
* @param out 输出流
104+
*/
105+
public void readWxFile(OutputStream out) throws IOException {
106+
if (currentWxFile == null) {
107+
throw new IOException("no more files");
108+
}
109+
int length = currentWxFile.getLength();
110+
byte[] buffer = new byte[length];
111+
int readSize;
112+
while (length > 0 && (readSize = in.read(buffer)) != -1) {
113+
length -= readSize;
114+
out.write(buffer, 0, readSize);
115+
}
116+
currentWxFile = currentWxFile.getNext();
117+
}
118+
119+
@Data
120+
public class WxFile {
121+
private String name;//文件名称
122+
private int offset;//偏移量
123+
private int length;//文件长度
124+
private WxFile next;//文件长度
125+
}
126+
}

src/main/java/com/xwintop/xJavaFxTool/utils/Config.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88
public class Config {
99
public static Locale defaultLocale = Locale.getDefault();// 设置系统语言
1010

11-
public static final String xJavaFxToolVersions = "V0.1.4";// xJavaFxTool版本信息
12-
public static final int xJavaFxToolVersionsInteger = 5;// xJavaFxTool更新信息
11+
public static final String xJavaFxToolVersions = "V0.1.5";// xJavaFxTool版本信息
12+
public static final int xJavaFxToolVersionsInteger = 6;// xJavaFxTool更新信息
1313
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package com.xwintop.xJavaFxTool.view.assistTools;
2+
3+
import javafx.fxml.FXML;
4+
import javafx.fxml.Initializable;
5+
import javafx.scene.control.Button;
6+
import javafx.scene.control.TextField;
7+
import lombok.Getter;
8+
import lombok.Setter;
9+
10+
/**
11+
* @ClassName: DecompilerWxApkgToolView
12+
* @Description: 微信小程序反编译工具
13+
* @author: xufeng
14+
* @date: 2018/7/4 14:44
15+
*/
16+
17+
@Getter
18+
@Setter
19+
public abstract class DecompilerWxApkgToolView implements Initializable {
20+
@FXML
21+
protected TextField packageFileTextField;
22+
@FXML
23+
protected Button packageFileButton;
24+
@FXML
25+
protected TextField decompilePathTextField;
26+
@FXML
27+
protected Button decompilePathButton;
28+
@FXML
29+
protected Button decompileButton;
30+
31+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?import javafx.geometry.Insets?>
4+
<?import javafx.scene.control.Button?>
5+
<?import javafx.scene.control.Label?>
6+
<?import javafx.scene.control.TextField?>
7+
<?import javafx.scene.layout.AnchorPane?>
8+
<?import javafx.scene.layout.BorderPane?>
9+
<?import javafx.scene.layout.HBox?>
10+
<?import javafx.scene.layout.VBox?>
11+
12+
13+
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.xwintop.xJavaFxTool.controller.assistTools.DecompilerWxApkgToolController">
14+
<children>
15+
<BorderPane layoutX="128.0" layoutY="39.0" AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0">
16+
<center>
17+
<VBox alignment="CENTER" spacing="20.0" BorderPane.alignment="CENTER">
18+
<children>
19+
<HBox alignment="CENTER" spacing="10.0">
20+
<children>
21+
<Label text="包路径:" />
22+
<TextField fx:id="packageFileTextField" promptText="选择或者拖拽包至此" HBox.hgrow="ALWAYS" />
23+
<Button fx:id="packageFileButton" mnemonicParsing="false" onAction="#packageFileButtonAction" text="选择" />
24+
</children>
25+
</HBox>
26+
<HBox alignment="CENTER" spacing="10.0">
27+
<children>
28+
<Label text="反编译后保存路径:" />
29+
<TextField fx:id="decompilePathTextField" promptText="默认为包原路径" HBox.hgrow="ALWAYS" />
30+
<Button fx:id="decompilePathButton" mnemonicParsing="false" onAction="#decompilePathButtonAction" text="选择" />
31+
</children>
32+
</HBox>
33+
<HBox alignment="CENTER" spacing="10.0">
34+
<children>
35+
<Button fx:id="decompileButton" mnemonicParsing="false" onAction="#decompileButtonAction" text="反编译" />
36+
</children>
37+
</HBox>
38+
</children>
39+
</VBox>
40+
</center>
41+
<top>
42+
<VBox spacing="10.0" BorderPane.alignment="CENTER">
43+
<children>
44+
<Label alignment="CENTER" contentDisplay="CENTER" lineSpacing="10.0" text="1、一部已经 root 的 Android 手机;" textAlignment="CENTER" wrapText="true">
45+
<padding>
46+
<Insets left="20.0" right="20.0" />
47+
</padding>
48+
</Label>
49+
<Label alignment="CENTER" contentDisplay="CENTER" lineSpacing="10.0" text="2、获取到该目录下文件包/data/data/com.tencent.mm/MicroMsg/{User}/appbrand/pkg;" textAlignment="CENTER" wrapText="true">
50+
<padding>
51+
<Insets left="20.0" right="20.0" />
52+
</padding>
53+
</Label>
54+
<Label alignment="CENTER" contentDisplay="CENTER" lineSpacing="10.0" text="3、拖动需要破解的包至该工具中进行反编译。" textAlignment="CENTER" wrapText="true">
55+
<padding>
56+
<Insets left="20.0" right="20.0" />
57+
</padding>
58+
</Label>
59+
</children>
60+
<BorderPane.margin>
61+
<Insets top="10.0" />
62+
</BorderPane.margin>
63+
</VBox>
64+
</top>
65+
</BorderPane>
66+
</children>
67+
</AnchorPane>

src/main/resources/config/toolFxmlLoaderConfiguration.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,11 @@
233233
<url>/com/xwintop/xJavaFxTool/fxmlView/littleTools/ImageAnalysisTool.fxml</url>
234234
<title>ImageAnalysisTool</title>
235235
<menuParentId>littleTools</menuParentId>
236+
</ToolFxmlLoaderConfiguration>
237+
<ToolFxmlLoaderConfiguration>
238+
<url>/com/xwintop/xJavaFxTool/fxmlView/assistTools/DecompilerWxApkgTool.fxml</url>
239+
<title>DecompilerWxApkgTool</title>
240+
<menuParentId>assistTools</menuParentId>
236241
<isDefaultShow></isDefaultShow>
237242
</ToolFxmlLoaderConfiguration>
238243

src/main/resources/locale/Menu.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@ WechatJumpGameTool=\u5FAE\u4FE1\u8DF3\u4E00\u8DF3\u52A9\u624B
7575
TextToSpeechTool=\u8BED\u97F3\u8F6C\u6362\u5DE5\u5177
7676
x2048=2048
7777
SocketTool=Socket\u8C03\u8BD5\u5DE5\u5177
78-
ImageAnalysisTool=\u56FE\u7247\u62C6\u5206\u5DE5\u5177
78+
ImageAnalysisTool=\u56FE\u7247\u62C6\u5206\u5DE5\u5177
79+
DecompilerWxApkgTool=\u53CD\u7F16\u8BD1\u5FAE\u4FE1\u5C0F\u7A0B\u5E8F\u5305\u5DE5\u5177

src/main/resources/locale/Menu_en_US.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,5 @@ WechatJumpGameTool=WechatJumpGameTool
7575
TextToSpeechTool=TextToSpeechTool
7676
x2048=2048
7777
SocketTool=SocketTool
78-
ImageAnalysisTool=ImageAnalysisTool
78+
ImageAnalysisTool=ImageAnalysisTool
79+
DecompilerWxApkgTool=DecompilerWxApkgTool

0 commit comments

Comments
 (0)