capacitor-dex-editor 0.0.63 → 0.0.65
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.
package/android/build.gradle
CHANGED
|
@@ -9,16 +9,13 @@ buildscript {
|
|
|
9
9
|
repositories {
|
|
10
10
|
google()
|
|
11
11
|
mavenCentral()
|
|
12
|
-
maven { url "https://plugins.gradle.org/m2/" }
|
|
13
12
|
}
|
|
14
13
|
dependencies {
|
|
15
14
|
classpath 'com.android.tools.build:gradle:8.7.2'
|
|
16
|
-
classpath 'org.mozilla.rust-android-gradle:plugin:0.9.6'
|
|
17
15
|
}
|
|
18
16
|
}
|
|
19
17
|
|
|
20
18
|
apply plugin: 'com.android.library'
|
|
21
|
-
apply plugin: 'org.mozilla.rust-android-gradle.rust-android'
|
|
22
19
|
|
|
23
20
|
android {
|
|
24
21
|
namespace "com.aetherlink.dexeditor"
|
|
@@ -75,18 +72,3 @@ dependencies {
|
|
|
75
72
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
76
73
|
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
77
74
|
}
|
|
78
|
-
|
|
79
|
-
// Rust 编译配置
|
|
80
|
-
cargo {
|
|
81
|
-
module = "../rust"
|
|
82
|
-
libname = "dex_rust"
|
|
83
|
-
targets = ["arm", "arm64", "x86", "x86_64"]
|
|
84
|
-
profile = "release"
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// 将 Rust 编译任务添加到构建流程
|
|
88
|
-
tasks.configureEach { task ->
|
|
89
|
-
if ((task.name == 'javaPreCompileDebug' || task.name == 'javaPreCompileRelease')) {
|
|
90
|
-
task.dependsOn 'cargoBuild'
|
|
91
|
-
}
|
|
92
|
-
}
|
|
@@ -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(),
|
|
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
|
|
1772
|
-
|
|
1773
|
-
|
|
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
|
*/
|