capacitor-dex-editor 0.0.21 → 0.0.23
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.
|
@@ -1738,69 +1738,21 @@ public class DexManager {
|
|
|
1738
1738
|
|
|
1739
1739
|
zipFile.close();
|
|
1740
1740
|
|
|
1741
|
-
//
|
|
1742
|
-
//
|
|
1741
|
+
// MT 风格:只保存 DEX 文件,不修改 APK
|
|
1742
|
+
// 将修改后的 DEX 保存到 APK 同目录下
|
|
1743
1743
|
java.io.File apkFile = new java.io.File(apkPath);
|
|
1744
|
-
java.io.File
|
|
1744
|
+
java.io.File outputDir = apkFile.getParentFile();
|
|
1745
|
+
java.io.File outputDexFile = new java.io.File(outputDir, dexPath);
|
|
1745
1746
|
|
|
1746
|
-
|
|
1747
|
+
// 复制合并后的 DEX 到输出目录
|
|
1748
|
+
copyFile(mergedDexFile, outputDexFile);
|
|
1747
1749
|
|
|
1748
|
-
|
|
1749
|
-
java.util.zip.ZipOutputStream zos = new java.util.zip.ZipOutputStream(
|
|
1750
|
-
new java.io.BufferedOutputStream(new java.io.FileOutputStream(tempApkFile)));
|
|
1751
|
-
|
|
1752
|
-
// 设置不压缩,加快速度
|
|
1753
|
-
zos.setMethod(java.util.zip.ZipOutputStream.STORED);
|
|
1754
|
-
|
|
1755
|
-
java.util.Enumeration<? extends java.util.zip.ZipEntry> entries = originalZip.entries();
|
|
1756
|
-
while (entries.hasMoreElements()) {
|
|
1757
|
-
java.util.zip.ZipEntry entry = entries.nextElement();
|
|
1758
|
-
|
|
1759
|
-
if (entry.getName().equals(dexPath)) {
|
|
1760
|
-
// 替换 DEX 文件
|
|
1761
|
-
byte[] dexBytes = readFileBytes(mergedDexFile);
|
|
1762
|
-
java.util.zip.ZipEntry newEntry = new java.util.zip.ZipEntry(dexPath);
|
|
1763
|
-
newEntry.setMethod(java.util.zip.ZipEntry.STORED);
|
|
1764
|
-
newEntry.setSize(dexBytes.length);
|
|
1765
|
-
newEntry.setCompressedSize(dexBytes.length);
|
|
1766
|
-
newEntry.setCrc(calculateCrc32(dexBytes));
|
|
1767
|
-
zos.putNextEntry(newEntry);
|
|
1768
|
-
zos.write(dexBytes);
|
|
1769
|
-
zos.closeEntry();
|
|
1770
|
-
} else {
|
|
1771
|
-
// 复制原条目(保持原压缩方式)
|
|
1772
|
-
java.util.zip.ZipEntry newEntry = new java.util.zip.ZipEntry(entry);
|
|
1773
|
-
zos.putNextEntry(newEntry);
|
|
1774
|
-
if (!entry.isDirectory()) {
|
|
1775
|
-
java.io.InputStream is = originalZip.getInputStream(entry);
|
|
1776
|
-
byte[] buf = new byte[8192];
|
|
1777
|
-
int n;
|
|
1778
|
-
while ((n = is.read(buf)) != -1) {
|
|
1779
|
-
zos.write(buf, 0, n);
|
|
1780
|
-
}
|
|
1781
|
-
is.close();
|
|
1782
|
-
}
|
|
1783
|
-
zos.closeEntry();
|
|
1784
|
-
}
|
|
1785
|
-
}
|
|
1786
|
-
|
|
1787
|
-
zos.close();
|
|
1788
|
-
originalZip.close();
|
|
1789
|
-
|
|
1790
|
-
// 用临时文件替换原文件
|
|
1791
|
-
if (!apkFile.delete()) {
|
|
1792
|
-
Log.e(TAG, "Failed to delete original APK");
|
|
1793
|
-
}
|
|
1794
|
-
if (!tempApkFile.renameTo(apkFile)) {
|
|
1795
|
-
// 如果 rename 失败,尝试复制
|
|
1796
|
-
copyFile(tempApkFile, apkFile);
|
|
1797
|
-
tempApkFile.delete();
|
|
1798
|
-
}
|
|
1799
|
-
|
|
1800
|
-
Log.d(TAG, "APK updated successfully: " + apkPath);
|
|
1750
|
+
Log.d(TAG, "DEX saved to: " + outputDexFile.getAbsolutePath());
|
|
1801
1751
|
|
|
1802
1752
|
result.put("success", true);
|
|
1803
|
-
result.put("message", "Smali
|
|
1753
|
+
result.put("message", "Smali 编译成功!DEX 已保存");
|
|
1754
|
+
result.put("dexPath", outputDexFile.getAbsolutePath());
|
|
1755
|
+
result.put("note", "请使用 MT 管理器将修改后的 DEX 替换到 APK 中");
|
|
1804
1756
|
|
|
1805
1757
|
// 清理临时文件
|
|
1806
1758
|
cleanupTempDir(tempDir);
|