capacitor-dex-editor 0.0.61 → 0.0.62
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,12 +621,6 @@ 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
|
-
|
|
630
624
|
// ==================== XML/资源操作 ====================
|
|
631
625
|
case "getManifest":
|
|
632
626
|
result.put("data", dexManager.getManifestFromApk(
|
|
@@ -151,8 +151,13 @@ public class DexManager {
|
|
|
151
151
|
String apkPath;
|
|
152
152
|
Map<String, DexBackedDexFile> dexFiles;
|
|
153
153
|
Map<String, ClassDef> modifiedClasses;
|
|
154
|
-
|
|
155
|
-
|
|
154
|
+
// 使用 LRU 缓存限制内存,最多缓存 200 个类
|
|
155
|
+
Map<String, String> smaliCache = new java.util.LinkedHashMap<String, String>(200, 0.75f, true) {
|
|
156
|
+
@Override
|
|
157
|
+
protected boolean removeEldestEntry(Map.Entry<String, String> eldest) {
|
|
158
|
+
return size() > 200;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
156
161
|
boolean modified = false;
|
|
157
162
|
|
|
158
163
|
MultiDexSession(String sessionId, String apkPath) {
|
|
@@ -160,7 +165,6 @@ public class DexManager {
|
|
|
160
165
|
this.apkPath = apkPath;
|
|
161
166
|
this.dexFiles = new HashMap<>();
|
|
162
167
|
this.modifiedClasses = new HashMap<>();
|
|
163
|
-
this.smaliCache = new HashMap<>();
|
|
164
168
|
}
|
|
165
169
|
|
|
166
170
|
void addDex(String dexName, DexBackedDexFile dexFile) {
|
|
@@ -1911,47 +1915,6 @@ public class DexManager {
|
|
|
1911
1915
|
return smali;
|
|
1912
1916
|
}
|
|
1913
1917
|
|
|
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
|
-
|
|
1955
1918
|
/**
|
|
1956
1919
|
* 从多 DEX 会话获取类的 Smali 代码
|
|
1957
1920
|
*/
|