capacitor-dex-editor 0.0.23 → 0.0.24

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,21 +1738,70 @@ public class DexManager {
1738
1738
 
1739
1739
  zipFile.close();
1740
1740
 
1741
- // MT 风格:只保存 DEX 文件,不修改 APK
1742
- // 将修改后的 DEX 保存到 APK 同目录下
1741
+ // MT 风格:直接替换 APK 内的 DEX
1743
1742
  java.io.File apkFile = new java.io.File(apkPath);
1744
- java.io.File outputDir = apkFile.getParentFile();
1745
- java.io.File outputDexFile = new java.io.File(outputDir, dexPath);
1743
+ java.io.File tempApkFile = new java.io.File(apkPath + ".tmp");
1744
+ byte[] newDexBytes = readFileBytes(mergedDexFile);
1745
+
1746
+ Log.d(TAG, "Replacing DEX in APK (MT style)...");
1747
+
1748
+ // 使用 ZipInputStream 流式处理替换 DEX
1749
+ java.util.zip.ZipInputStream zis = new java.util.zip.ZipInputStream(
1750
+ new java.io.BufferedInputStream(new java.io.FileInputStream(apkFile)));
1751
+ java.util.zip.ZipOutputStream zos = new java.util.zip.ZipOutputStream(
1752
+ new java.io.BufferedOutputStream(new java.io.FileOutputStream(tempApkFile)));
1753
+
1754
+ java.util.zip.ZipEntry entry;
1755
+ while ((entry = zis.getNextEntry()) != null) {
1756
+ if (entry.getName().equals(dexPath)) {
1757
+ // 替换 DEX:写入新数据
1758
+ java.util.zip.ZipEntry newEntry = new java.util.zip.ZipEntry(dexPath);
1759
+ newEntry.setMethod(java.util.zip.ZipEntry.DEFLATED);
1760
+ zos.putNextEntry(newEntry);
1761
+ zos.write(newDexBytes);
1762
+ zos.closeEntry();
1763
+ zis.closeEntry();
1764
+ } else {
1765
+ // 直接复制其他条目
1766
+ java.util.zip.ZipEntry newEntry = new java.util.zip.ZipEntry(entry.getName());
1767
+ newEntry.setTime(entry.getTime());
1768
+ if (entry.getMethod() == java.util.zip.ZipEntry.STORED) {
1769
+ newEntry.setMethod(java.util.zip.ZipEntry.STORED);
1770
+ newEntry.setSize(entry.getSize());
1771
+ newEntry.setCrc(entry.getCrc());
1772
+ } else {
1773
+ newEntry.setMethod(java.util.zip.ZipEntry.DEFLATED);
1774
+ }
1775
+ zos.putNextEntry(newEntry);
1776
+ if (!entry.isDirectory()) {
1777
+ byte[] buf = new byte[8192];
1778
+ int n;
1779
+ while ((n = zis.read(buf)) != -1) {
1780
+ zos.write(buf, 0, n);
1781
+ }
1782
+ }
1783
+ zos.closeEntry();
1784
+ }
1785
+ }
1786
+
1787
+ zis.close();
1788
+ zos.close();
1746
1789
 
1747
- // 复制合并后的 DEX 到输出目录
1748
- copyFile(mergedDexFile, outputDexFile);
1790
+ // 用临时文件替换原文件
1791
+ if (!apkFile.delete()) {
1792
+ Log.e(TAG, "Failed to delete original APK");
1793
+ }
1794
+ if (!tempApkFile.renameTo(apkFile)) {
1795
+ copyFile(tempApkFile, apkFile);
1796
+ tempApkFile.delete();
1797
+ }
1749
1798
 
1750
- Log.d(TAG, "DEX saved to: " + outputDexFile.getAbsolutePath());
1799
+ Log.d(TAG, "APK updated successfully: " + apkPath);
1751
1800
 
1752
1801
  result.put("success", true);
1753
- result.put("message", "Smali 编译成功!DEX 已保存");
1754
- result.put("dexPath", outputDexFile.getAbsolutePath());
1755
- result.put("note", "请使用 MT 管理器将修改后的 DEX 替换到 APK 中");
1802
+ result.put("message", "Smali 编译成功!APK 已更新");
1803
+ result.put("apkPath", apkPath);
1804
+ result.put("needSign", true);
1756
1805
 
1757
1806
  // 清理临时文件
1758
1807
  cleanupTempDir(tempDir);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-dex-editor",
3
- "version": "0.0.23",
3
+ "version": "0.0.24",
4
4
  "description": "Capacitor-plugin-for-editing-DEX-files-in-APK",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",