capacitor-dex-editor 0.0.60 → 0.0.61

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.
@@ -621,6 +621,12 @@ public class DexEditorPluginPlugin extends Plugin {
621
621
  result.put("data", dexManager.listAllSessions());
622
622
  break;
623
623
 
624
+ case "precompileSmaliCache":
625
+ result.put("data", dexManager.precompileSmaliCache(
626
+ params.getString("sessionId")
627
+ ));
628
+ break;
629
+
624
630
  // ==================== XML/资源操作 ====================
625
631
  case "getManifest":
626
632
  result.put("data", dexManager.getManifestFromApk(
@@ -151,6 +151,8 @@ public class DexManager {
151
151
  String apkPath;
152
152
  Map<String, DexBackedDexFile> dexFiles;
153
153
  Map<String, ClassDef> modifiedClasses;
154
+ Map<String, String> smaliCache; // className -> smali 代码缓存
155
+ boolean smaliCacheReady = false;
154
156
  boolean modified = false;
155
157
 
156
158
  MultiDexSession(String sessionId, String apkPath) {
@@ -158,6 +160,7 @@ public class DexManager {
158
160
  this.apkPath = apkPath;
159
161
  this.dexFiles = new HashMap<>();
160
162
  this.modifiedClasses = new HashMap<>();
163
+ this.smaliCache = new HashMap<>();
161
164
  }
162
165
 
163
166
  void addDex(String dexName, DexBackedDexFile dexFile) {
@@ -1830,8 +1833,8 @@ public class DexManager {
1830
1833
 
1831
1834
  case "string":
1832
1835
  case "code":
1833
- // 需要反编译 smali 搜索
1834
- String smali = getSmaliForClass(dexFile, classDef);
1836
+ // 使用缓存的 smali 搜索
1837
+ String smali = getCachedSmali(session, className, dexFile, classDef);
1835
1838
  String smaliMatch = caseSensitive ? smali : smali.toLowerCase();
1836
1839
  if (smaliMatch.contains(queryMatch)) {
1837
1840
  JSObject item = new JSObject();
@@ -1853,8 +1856,8 @@ public class DexManager {
1853
1856
  break;
1854
1857
 
1855
1858
  case "int":
1856
- // 搜索整数常量
1857
- String smaliForInt = getSmaliForClass(dexFile, classDef);
1859
+ // 搜索整数常量(使用缓存)
1860
+ String smaliForInt = getCachedSmali(session, className, dexFile, classDef);
1858
1861
  if (smaliForInt.contains("0x" + query) || smaliForInt.contains(" " + query + "\n") ||
1859
1862
  smaliForInt.contains(" " + query + " ")) {
1860
1863
  JSObject item = new JSObject();
@@ -1893,6 +1896,62 @@ public class DexManager {
1893
1896
  }
1894
1897
  }
1895
1898
 
1899
+ /**
1900
+ * 获取缓存的 Smali 代码(用于搜索优化)
1901
+ */
1902
+ private String getCachedSmali(MultiDexSession session, String className, DexBackedDexFile dexFile, ClassDef classDef) {
1903
+ // 先查缓存
1904
+ String cached = session.smaliCache.get(className);
1905
+ if (cached != null) {
1906
+ return cached;
1907
+ }
1908
+ // 缓存未命中,反编译并缓存
1909
+ String smali = getSmaliForClass(dexFile, classDef);
1910
+ session.smaliCache.put(className, smali);
1911
+ return smali;
1912
+ }
1913
+
1914
+ /**
1915
+ * 预编译会话中所有类的 Smali(用于加速搜索)
1916
+ */
1917
+ public JSObject precompileSmaliCache(String sessionId) throws Exception {
1918
+ MultiDexSession session = multiDexSessions.get(sessionId);
1919
+ if (session == null) {
1920
+ throw new IllegalArgumentException("Session not found: " + sessionId);
1921
+ }
1922
+
1923
+ if (session.smaliCacheReady) {
1924
+ JSObject result = new JSObject();
1925
+ result.put("cached", true);
1926
+ result.put("count", session.smaliCache.size());
1927
+ return result;
1928
+ }
1929
+
1930
+ int count = 0;
1931
+ long startTime = System.currentTimeMillis();
1932
+
1933
+ for (Map.Entry<String, DexBackedDexFile> entry : session.dexFiles.entrySet()) {
1934
+ DexBackedDexFile dexFile = entry.getValue();
1935
+ for (ClassDef classDef : dexFile.getClasses()) {
1936
+ String className = convertTypeToClassName(classDef.getType());
1937
+ if (!session.smaliCache.containsKey(className)) {
1938
+ String smali = getSmaliForClass(dexFile, classDef);
1939
+ session.smaliCache.put(className, smali);
1940
+ count++;
1941
+ }
1942
+ }
1943
+ }
1944
+
1945
+ session.smaliCacheReady = true;
1946
+ long elapsed = System.currentTimeMillis() - startTime;
1947
+
1948
+ JSObject result = new JSObject();
1949
+ result.put("success", true);
1950
+ result.put("count", count);
1951
+ result.put("elapsedMs", elapsed);
1952
+ return result;
1953
+ }
1954
+
1896
1955
  /**
1897
1956
  * 从多 DEX 会话获取类的 Smali 代码
1898
1957
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-dex-editor",
3
- "version": "0.0.60",
3
+ "version": "0.0.61",
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",