capacitor-dex-editor 0.0.8 → 0.0.10
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.
|
@@ -1306,21 +1306,65 @@ public class DexManager {
|
|
|
1306
1306
|
// 解析 DEX 文件
|
|
1307
1307
|
DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dexBytes);
|
|
1308
1308
|
|
|
1309
|
-
//
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
}
|
|
1319
|
-
|
|
1320
|
-
|
|
1309
|
+
// 从类和方法中提取所有字符串引用
|
|
1310
|
+
Set<String> uniqueStrings = new HashSet<>();
|
|
1311
|
+
int index = 0;
|
|
1312
|
+
|
|
1313
|
+
for (ClassDef classDef : dexFile.getClasses()) {
|
|
1314
|
+
// 添加类名
|
|
1315
|
+
String className = classDef.getType();
|
|
1316
|
+
if (className != null && !uniqueStrings.contains(className)) {
|
|
1317
|
+
uniqueStrings.add(className);
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
// 从字段中提取
|
|
1321
|
+
for (Field field : classDef.getFields()) {
|
|
1322
|
+
String fieldName = field.getName();
|
|
1323
|
+
String fieldType = field.getType();
|
|
1324
|
+
if (fieldName != null && !uniqueStrings.contains(fieldName)) {
|
|
1325
|
+
uniqueStrings.add(fieldName);
|
|
1326
|
+
}
|
|
1327
|
+
if (fieldType != null && !uniqueStrings.contains(fieldType)) {
|
|
1328
|
+
uniqueStrings.add(fieldType);
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
// 从方法中提取
|
|
1333
|
+
for (Method method : classDef.getMethods()) {
|
|
1334
|
+
String methodName = method.getName();
|
|
1335
|
+
if (methodName != null && !uniqueStrings.contains(methodName)) {
|
|
1336
|
+
uniqueStrings.add(methodName);
|
|
1337
|
+
}
|
|
1338
|
+
|
|
1339
|
+
// 从方法实现中提取字符串常量
|
|
1340
|
+
MethodImplementation impl = method.getImplementation();
|
|
1341
|
+
if (impl != null) {
|
|
1342
|
+
for (Instruction instruction : impl.getInstructions()) {
|
|
1343
|
+
// 检查是否是字符串引用指令
|
|
1344
|
+
if (instruction instanceof com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction) {
|
|
1345
|
+
com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction refInstr =
|
|
1346
|
+
(com.android.tools.smali.dexlib2.iface.instruction.ReferenceInstruction) instruction;
|
|
1347
|
+
com.android.tools.smali.dexlib2.iface.reference.Reference ref = refInstr.getReference();
|
|
1348
|
+
if (ref instanceof com.android.tools.smali.dexlib2.iface.reference.StringReference) {
|
|
1349
|
+
String str = ((com.android.tools.smali.dexlib2.iface.reference.StringReference) ref).getString();
|
|
1350
|
+
if (str != null && !uniqueStrings.contains(str)) {
|
|
1351
|
+
uniqueStrings.add(str);
|
|
1352
|
+
}
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1321
1357
|
}
|
|
1322
1358
|
}
|
|
1323
1359
|
|
|
1360
|
+
// 转换为数组
|
|
1361
|
+
for (String str : uniqueStrings) {
|
|
1362
|
+
JSObject item = new JSObject();
|
|
1363
|
+
item.put("index", index++);
|
|
1364
|
+
item.put("value", str);
|
|
1365
|
+
strings.put(item);
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1324
1368
|
result.put("strings", strings);
|
|
1325
1369
|
result.put("count", strings.length());
|
|
1326
1370
|
|
|
@@ -1343,6 +1387,8 @@ public class DexManager {
|
|
|
1343
1387
|
JSObject result = new JSObject();
|
|
1344
1388
|
JSArray results = new JSArray();
|
|
1345
1389
|
|
|
1390
|
+
Log.d(TAG, "searchInDexFromApk: apkPath=" + apkPath + ", dexPath=" + dexPath + ", query=" + query);
|
|
1391
|
+
|
|
1346
1392
|
if (query == null || query.isEmpty()) {
|
|
1347
1393
|
result.put("results", results);
|
|
1348
1394
|
result.put("count", 0);
|
|
@@ -1356,12 +1402,29 @@ public class DexManager {
|
|
|
1356
1402
|
|
|
1357
1403
|
try {
|
|
1358
1404
|
zipFile = new java.util.zip.ZipFile(apkPath);
|
|
1405
|
+
|
|
1406
|
+
// 尝试多种可能的 dexPath 格式
|
|
1359
1407
|
java.util.zip.ZipEntry dexEntry = zipFile.getEntry(dexPath);
|
|
1408
|
+
if (dexEntry == null && !dexPath.startsWith("/")) {
|
|
1409
|
+
// 如果没有找到,尝试去掉开头的斜杠
|
|
1410
|
+
dexEntry = zipFile.getEntry(dexPath.replaceFirst("^/+", ""));
|
|
1411
|
+
}
|
|
1412
|
+
if (dexEntry == null) {
|
|
1413
|
+
// 如果还是没找到,尝试只用文件名
|
|
1414
|
+
String fileName = dexPath;
|
|
1415
|
+
if (dexPath.contains("/")) {
|
|
1416
|
+
fileName = dexPath.substring(dexPath.lastIndexOf("/") + 1);
|
|
1417
|
+
}
|
|
1418
|
+
dexEntry = zipFile.getEntry(fileName);
|
|
1419
|
+
}
|
|
1360
1420
|
|
|
1361
1421
|
if (dexEntry == null) {
|
|
1422
|
+
Log.e(TAG, "DEX file not found in APK: " + dexPath);
|
|
1362
1423
|
throw new IOException("DEX file not found in APK: " + dexPath);
|
|
1363
1424
|
}
|
|
1364
1425
|
|
|
1426
|
+
Log.d(TAG, "Found DEX entry: " + dexEntry.getName());
|
|
1427
|
+
|
|
1365
1428
|
dexInputStream = zipFile.getInputStream(dexEntry);
|
|
1366
1429
|
|
|
1367
1430
|
// 读取 DEX 文件到内存
|