capacitor-dex-editor 0.0.63 → 0.0.64

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.
@@ -150,6 +150,7 @@ public class DexManager {
150
150
  String sessionId;
151
151
  String apkPath;
152
152
  Map<String, DexBackedDexFile> dexFiles;
153
+ Map<String, byte[]> dexBytes; // DEX 字节数据,用于 Rust 搜索
153
154
  Map<String, ClassDef> modifiedClasses;
154
155
  // 使用 LRU 缓存限制内存,最多缓存 200 个类
155
156
  Map<String, String> smaliCache = new java.util.LinkedHashMap<String, String>(200, 0.75f, true) {
@@ -164,11 +165,15 @@ public class DexManager {
164
165
  this.sessionId = sessionId;
165
166
  this.apkPath = apkPath;
166
167
  this.dexFiles = new HashMap<>();
168
+ this.dexBytes = new HashMap<>();
167
169
  this.modifiedClasses = new HashMap<>();
168
170
  }
169
171
 
170
- void addDex(String dexName, DexBackedDexFile dexFile) {
172
+ void addDex(String dexName, DexBackedDexFile dexFile, byte[] bytes) {
171
173
  this.dexFiles.put(dexName, dexFile);
174
+ if (bytes != null) {
175
+ this.dexBytes.put(dexName, bytes);
176
+ }
172
177
  }
173
178
  }
174
179
 
@@ -1638,10 +1643,11 @@ public class DexManager {
1638
1643
  baos.write(buffer, 0, len);
1639
1644
  }
1640
1645
  is.close();
1646
+ byte[] dexData = baos.toByteArray();
1641
1647
 
1642
1648
  // 解析 DEX
1643
- DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), baos.toByteArray());
1644
- multiSession.addDex(dexName, dexFile);
1649
+ DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dexData);
1650
+ multiSession.addDex(dexName, dexFile, dexData);
1645
1651
  totalClasses += dexFile.getClasses().size();
1646
1652
 
1647
1653
  Log.d(TAG, "Loaded DEX: " + dexName + " with " + dexFile.getClasses().size() + " classes");
@@ -1768,10 +1774,16 @@ public class DexManager {
1768
1774
  throw new IllegalArgumentException("Session not found: " + sessionId);
1769
1775
  }
1770
1776
 
1771
- // 尝试使用 Rust 实现(仅对 string/code 搜索有显著提升)
1772
- // 目前 Rust 实现需要 DEX 字节数据,暂时禁用
1773
- // TODO: 实现 Rust 加速搜索
1777
+ // 尝试使用 Rust 实现进行搜索
1778
+ if (RustDex.isAvailable() && !session.dexBytes.isEmpty()) {
1779
+ try {
1780
+ return searchWithRust(session, query, searchType, caseSensitive, maxResults);
1781
+ } catch (Exception e) {
1782
+ Log.w(TAG, "Rust search failed, falling back to Java: " + e.getMessage());
1783
+ }
1784
+ }
1774
1785
 
1786
+ // Java 回退实现
1775
1787
  JSObject result = new JSObject();
1776
1788
  JSArray results = new JSArray();
1777
1789
  String queryMatch = caseSensitive ? query : query.toLowerCase();
@@ -1888,6 +1900,56 @@ public class DexManager {
1888
1900
  return result;
1889
1901
  }
1890
1902
 
1903
+ /**
1904
+ * 使用 Rust 实现搜索(高性能)
1905
+ */
1906
+ private JSObject searchWithRust(MultiDexSession session, String query, String searchType,
1907
+ boolean caseSensitive, int maxResults) throws Exception {
1908
+ JSObject result = new JSObject();
1909
+ JSArray allResults = new JSArray();
1910
+
1911
+ for (Map.Entry<String, byte[]> entry : session.dexBytes.entrySet()) {
1912
+ String dexName = entry.getKey();
1913
+ byte[] dexData = entry.getValue();
1914
+
1915
+ // 调用 Rust 搜索
1916
+ String jsonResult = RustDex.searchInDex(dexData, query, searchType, caseSensitive, maxResults);
1917
+
1918
+ if (jsonResult != null && !jsonResult.contains("\"error\"")) {
1919
+ // 解析 Rust 返回的 JSON
1920
+ org.json.JSONObject rustResult = new org.json.JSONObject(jsonResult);
1921
+ org.json.JSONArray rustResults = rustResult.optJSONArray("results");
1922
+
1923
+ if (rustResults != null) {
1924
+ for (int i = 0; i < rustResults.length() && allResults.length() < maxResults; i++) {
1925
+ org.json.JSONObject item = rustResults.getJSONObject(i);
1926
+ JSObject jsItem = new JSObject();
1927
+ jsItem.put("type", item.optString("type", searchType));
1928
+ jsItem.put("className", item.optString("className", ""));
1929
+ jsItem.put("dexFile", dexName);
1930
+ if (item.has("methodName")) {
1931
+ jsItem.put("methodName", item.getString("methodName"));
1932
+ }
1933
+ if (item.has("fieldName")) {
1934
+ jsItem.put("fieldName", item.getString("fieldName"));
1935
+ }
1936
+ allResults.put(jsItem);
1937
+ }
1938
+ }
1939
+ }
1940
+
1941
+ if (allResults.length() >= maxResults) break;
1942
+ }
1943
+
1944
+ result.put("query", query);
1945
+ result.put("searchType", searchType);
1946
+ result.put("total", allResults.length());
1947
+ result.put("results", allResults);
1948
+ result.put("engine", "rust");
1949
+
1950
+ return result;
1951
+ }
1952
+
1891
1953
  /**
1892
1954
  * 获取类的 Smali 代码(内部方法)
1893
1955
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-dex-editor",
3
- "version": "0.0.63",
3
+ "version": "0.0.64",
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",