capacitor-dex-editor 0.0.18 → 0.0.19
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.
|
@@ -44,7 +44,7 @@ public class DexEditorPluginPlugin extends Plugin {
|
|
|
44
44
|
Log.d(TAG, "Executing action: " + action);
|
|
45
45
|
|
|
46
46
|
// 在后台线程执行,避免阻塞UI
|
|
47
|
-
|
|
47
|
+
new Thread(() -> {
|
|
48
48
|
try {
|
|
49
49
|
JSObject result = dispatchAction(action, params);
|
|
50
50
|
call.resolve(result);
|
|
@@ -55,7 +55,7 @@ public class DexEditorPluginPlugin extends Plugin {
|
|
|
55
55
|
error.put("error", e.getMessage());
|
|
56
56
|
call.resolve(error);
|
|
57
57
|
}
|
|
58
|
-
});
|
|
58
|
+
}).start();
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
/**
|
|
@@ -1736,67 +1736,25 @@ public class DexManager {
|
|
|
1736
1736
|
|
|
1737
1737
|
Log.d(TAG, "Merged DEX written to: " + mergedDexFile.getAbsolutePath());
|
|
1738
1738
|
|
|
1739
|
-
// 2.
|
|
1740
|
-
|
|
1741
|
-
java.
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
// 复制原 APK 中的所有条目(除了要替换的 DEX)
|
|
1745
|
-
java.util.Enumeration<? extends java.util.zip.ZipEntry> entries = zipFile.entries();
|
|
1746
|
-
while (entries.hasMoreElements()) {
|
|
1747
|
-
java.util.zip.ZipEntry entry = entries.nextElement();
|
|
1748
|
-
if (entry.getName().equals(dexPath)) {
|
|
1749
|
-
// 跳过原 DEX,稍后添加新的
|
|
1750
|
-
continue;
|
|
1751
|
-
}
|
|
1752
|
-
|
|
1753
|
-
// 复制其他条目
|
|
1754
|
-
java.util.zip.ZipEntry newEntry = new java.util.zip.ZipEntry(entry.getName());
|
|
1755
|
-
zos.putNextEntry(newEntry);
|
|
1756
|
-
|
|
1757
|
-
if (!entry.isDirectory()) {
|
|
1758
|
-
java.io.InputStream is = zipFile.getInputStream(entry);
|
|
1759
|
-
while ((len = is.read(buffer)) != -1) {
|
|
1760
|
-
zos.write(buffer, 0, len);
|
|
1761
|
-
}
|
|
1762
|
-
is.close();
|
|
1763
|
-
}
|
|
1764
|
-
zos.closeEntry();
|
|
1739
|
+
// 2. 直接替换 APK 中的 DEX(使用 RandomAccessFile 原地修改,避免复制整个 APK)
|
|
1740
|
+
// 简化方案:只保存修改后的 DEX 到输出目录,让用户手动替换或使用其他工具
|
|
1741
|
+
java.io.File outputDir = new java.io.File(new java.io.File(apkPath).getParent(), "dex_modified");
|
|
1742
|
+
if (!outputDir.exists()) {
|
|
1743
|
+
outputDir.mkdirs();
|
|
1765
1744
|
}
|
|
1766
1745
|
|
|
1767
|
-
//
|
|
1768
|
-
java.
|
|
1769
|
-
|
|
1770
|
-
java.io.FileInputStream fis = new java.io.FileInputStream(mergedDexFile);
|
|
1771
|
-
while ((len = fis.read(buffer)) != -1) {
|
|
1772
|
-
zos.write(buffer, 0, len);
|
|
1773
|
-
}
|
|
1774
|
-
fis.close();
|
|
1775
|
-
zos.closeEntry();
|
|
1746
|
+
// 复制修改后的 DEX 到输出目录
|
|
1747
|
+
java.io.File outputDexFile = new java.io.File(outputDir, dexPath);
|
|
1748
|
+
copyFile(mergedDexFile, outputDexFile);
|
|
1776
1749
|
|
|
1777
|
-
|
|
1778
|
-
zipFile.close();
|
|
1750
|
+
Log.d(TAG, "Modified DEX saved to: " + outputDexFile.getAbsolutePath());
|
|
1779
1751
|
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
// 3. 替换原 APK(先备份)
|
|
1783
|
-
java.io.File backupApk = new java.io.File(apkPath + ".backup");
|
|
1784
|
-
java.io.File originalApkFile = new java.io.File(apkPath);
|
|
1785
|
-
|
|
1786
|
-
// 复制原 APK 作为备份
|
|
1787
|
-
copyFile(originalApkFile, backupApk);
|
|
1788
|
-
|
|
1789
|
-
// 用修改后的 APK 替换原 APK
|
|
1790
|
-
copyFile(outputApk, originalApkFile);
|
|
1791
|
-
|
|
1792
|
-
// 删除临时修改的 APK
|
|
1793
|
-
outputApk.delete();
|
|
1794
|
-
|
|
1795
|
-
Log.d(TAG, "APK updated successfully. Backup at: " + backupApk.getAbsolutePath());
|
|
1752
|
+
zipFile.close();
|
|
1796
1753
|
|
|
1797
1754
|
result.put("success", true);
|
|
1798
|
-
result.put("message", "Smali
|
|
1799
|
-
result.put("
|
|
1755
|
+
result.put("message", "Smali 编译成功!修改后的 DEX 已保存");
|
|
1756
|
+
result.put("modifiedDexPath", outputDexFile.getAbsolutePath());
|
|
1757
|
+
result.put("note", "请使用 MT 管理器或其他工具将修改后的 DEX 替换到 APK 中");
|
|
1800
1758
|
|
|
1801
1759
|
// 清理临时文件
|
|
1802
1760
|
cleanupTempDir(tempDir);
|