capacitor-dex-editor 0.0.22 → 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
- // 2. MT 风格:使用 ZipInputStream 流式处理替换 DEX
1741
+ // MT 风格:只保存 DEX 文件,不修改 APK
1742
+ // 将修改后的 DEX 保存到 APK 同目录下
1742
1743
  java.io.File apkFile = new java.io.File(apkPath);
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 stream)...");
1747
-
1748
- java.util.zip.ZipInputStream zis = new java.util.zip.ZipInputStream(
1749
- new java.io.BufferedInputStream(new java.io.FileInputStream(apkFile)));
1750
- java.util.zip.ZipOutputStream zos = new java.util.zip.ZipOutputStream(
1751
- new java.io.BufferedOutputStream(new java.io.FileOutputStream(tempApkFile)));
1752
-
1753
- java.util.zip.ZipEntry entry;
1754
- while ((entry = zis.getNextEntry()) != null) {
1755
- if (entry.getName().equals(dexPath)) {
1756
- // 替换 DEX:写入新数据
1757
- java.util.zip.ZipEntry newEntry = new java.util.zip.ZipEntry(dexPath);
1758
- newEntry.setMethod(java.util.zip.ZipEntry.DEFLATED);
1759
- zos.putNextEntry(newEntry);
1760
- zos.write(newDexBytes);
1761
- zos.closeEntry();
1762
- // 跳过原 DEX 数据
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();
1744
+ java.io.File outputDir = apkFile.getParentFile();
1745
+ java.io.File outputDexFile = new java.io.File(outputDir, dexPath);
1789
1746
 
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
- }
1747
+ // 复制合并后的 DEX 到输出目录
1748
+ copyFile(mergedDexFile, outputDexFile);
1799
1749
 
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 保存成功!APK 已更新");
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-dex-editor",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
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",