capacitor-dex-editor 0.0.76 → 0.0.77
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -938,13 +938,51 @@ public class DexManager {
|
|
|
938
938
|
}
|
|
939
939
|
|
|
940
940
|
/**
|
|
941
|
-
* 反汇编整个 DEX
|
|
941
|
+
* 反汇编整个 DEX 到目录(优先使用 C++ 实现)
|
|
942
942
|
*/
|
|
943
943
|
public void disassemble(String sessionId, String outputDir) throws Exception {
|
|
944
944
|
DexSession session = getSession(sessionId);
|
|
945
945
|
File outDir = new File(outputDir);
|
|
946
946
|
outDir.mkdirs();
|
|
947
947
|
|
|
948
|
+
// 优先使用 C++ 实现 - 逐个类反汇编
|
|
949
|
+
if (CppDex.isAvailable() && session.dexBytes != null) {
|
|
950
|
+
try {
|
|
951
|
+
// 获取所有类
|
|
952
|
+
String classesJson = CppDex.listClasses(session.dexBytes, "", 0, 10000);
|
|
953
|
+
if (classesJson != null && !classesJson.contains("\"error\"")) {
|
|
954
|
+
org.json.JSONObject result = new org.json.JSONObject(classesJson);
|
|
955
|
+
org.json.JSONArray classes = result.optJSONArray("classes");
|
|
956
|
+
if (classes != null) {
|
|
957
|
+
for (int i = 0; i < classes.length(); i++) {
|
|
958
|
+
String className = classes.getString(i);
|
|
959
|
+
try {
|
|
960
|
+
String smaliJson = CppDex.getClassSmali(session.dexBytes, className);
|
|
961
|
+
if (smaliJson != null && !smaliJson.contains("\"error\"")) {
|
|
962
|
+
org.json.JSONObject smaliResult = new org.json.JSONObject(smaliJson);
|
|
963
|
+
String smali = smaliResult.optString("smali", "");
|
|
964
|
+
if (!smali.isEmpty()) {
|
|
965
|
+
// 保存到文件
|
|
966
|
+
String filePath = className.substring(1, className.length() - 1) + ".smali";
|
|
967
|
+
File smaliFile = new File(outDir, filePath);
|
|
968
|
+
smaliFile.getParentFile().mkdirs();
|
|
969
|
+
writeFileContent(smaliFile, smali);
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
} catch (Exception e) {
|
|
973
|
+
Log.w(TAG, "Failed to disassemble class: " + className, e);
|
|
974
|
+
}
|
|
975
|
+
}
|
|
976
|
+
Log.d(TAG, "Disassembled to (C++): " + outputDir);
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
} catch (Exception e) {
|
|
981
|
+
Log.w(TAG, "C++ disassemble failed, fallback to Java", e);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
// Java 回退实现
|
|
948
986
|
BaksmaliOptions options = new BaksmaliOptions();
|
|
949
987
|
Baksmali.disassembleDexFile(session.originalDexFile, outDir, 4, options);
|
|
950
988
|
|
|
@@ -1652,6 +1690,12 @@ public class DexManager {
|
|
|
1652
1690
|
return content.toString();
|
|
1653
1691
|
}
|
|
1654
1692
|
|
|
1693
|
+
private void writeFileContent(File file, String content) throws IOException {
|
|
1694
|
+
try (java.io.BufferedWriter writer = new java.io.BufferedWriter(new java.io.FileWriter(file))) {
|
|
1695
|
+
writer.write(content);
|
|
1696
|
+
}
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1655
1699
|
private byte[] readFileBytes(File file) throws IOException {
|
|
1656
1700
|
byte[] bytes = new byte[(int) file.length()];
|
|
1657
1701
|
try (FileInputStream fis = new FileInputStream(file)) {
|