capacitor-dex-editor 0.0.35 → 0.0.36

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.
@@ -2661,7 +2661,7 @@ public class DexManager {
2661
2661
  }
2662
2662
 
2663
2663
  /**
2664
- * 精准替换 AndroidManifest.xml 中的字符串(使用 ARSCLib,无长度限制)
2664
+ * 精准替换 AndroidManifest.xml 中的字符串(使用 ARSCLib
2665
2665
  */
2666
2666
  public JSObject replaceInManifest(String apkPath, org.json.JSONArray replacements) throws Exception {
2667
2667
  JSObject result = new JSObject();
@@ -2674,28 +2674,30 @@ public class DexManager {
2674
2674
  com.reandroid.arsc.chunk.xml.AndroidManifestBlock manifest = apkModule.getAndroidManifest();
2675
2675
 
2676
2676
  if (manifest == null) {
2677
+ apkModule.close();
2677
2678
  throw new Exception("AndroidManifest.xml not found in APK");
2678
2679
  }
2679
2680
 
2680
- // 获取 XML 字符串进行替换
2681
- String xmlContent = manifest.serializeToXml();
2682
- String originalContent = xmlContent;
2681
+ // 遍历所有字符串并替换
2682
+ com.reandroid.arsc.pool.ResXmlStringPool stringPool = manifest.getStringPool();
2683
2683
 
2684
- // 执行替换
2685
2684
  for (int i = 0; i < replacements.length(); i++) {
2686
2685
  org.json.JSONObject replacement = replacements.getJSONObject(i);
2687
2686
  String oldValue = replacement.getString("oldValue");
2688
2687
  String newValue = replacement.getString("newValue");
2689
2688
 
2690
2689
  int count = 0;
2691
- String before = xmlContent;
2692
- xmlContent = xmlContent.replace(oldValue, newValue);
2693
2690
 
2694
- // 计算替换次数
2695
- int idx = 0;
2696
- while ((idx = before.indexOf(oldValue, idx)) != -1) {
2697
- count++;
2698
- idx += oldValue.length();
2691
+ // 遍历字符串池中的所有字符串
2692
+ for (com.reandroid.arsc.item.StringItem stringItem : stringPool.listItems()) {
2693
+ if (stringItem != null) {
2694
+ String str = stringItem.get();
2695
+ if (str != null && str.contains(oldValue)) {
2696
+ String newStr = str.replace(oldValue, newValue);
2697
+ stringItem.set(newStr);
2698
+ count++;
2699
+ }
2700
+ }
2699
2701
  }
2700
2702
 
2701
2703
  JSObject detail = new JSObject();
@@ -2716,8 +2718,7 @@ public class DexManager {
2716
2718
  return result;
2717
2719
  }
2718
2720
 
2719
- // 解析修改后的 XML 并更新 Manifest
2720
- manifest.parseXmlString(xmlContent);
2721
+ // 刷新并保存
2721
2722
  manifest.refresh();
2722
2723
 
2723
2724
  // 保存 APK
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-dex-editor",
3
- "version": "0.0.35",
3
+ "version": "0.0.36",
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",