capacitor-dex-editor 0.0.7 → 0.0.9

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,29 +1306,49 @@ public class DexManager {
1306
1306
  // 解析 DEX 文件
1307
1307
  DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dexBytes);
1308
1308
 
1309
- // 收集字符串
1309
+ // 从类和方法中提取所有字符串引用
1310
1310
  Set<String> uniqueStrings = new HashSet<>();
1311
1311
  int index = 0;
1312
1312
 
1313
1313
  for (ClassDef classDef : dexFile.getClasses()) {
1314
- // 从方法中提取字符串
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
+ // 从方法中提取
1315
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
+ // 从方法实现中提取字符串常量
1316
1340
  MethodImplementation impl = method.getImplementation();
1317
1341
  if (impl != null) {
1318
1342
  for (Instruction instruction : impl.getInstructions()) {
1319
- String instrStr = instruction.toString();
1320
- // 提取字符串常量
1321
- if (instrStr.contains("\"")) {
1322
- int start = instrStr.indexOf("\"");
1323
- int end = instrStr.lastIndexOf("\"");
1324
- if (start != -1 && end > start) {
1325
- String str = instrStr.substring(start + 1, end);
1326
- if (!uniqueStrings.contains(str)) {
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)) {
1327
1351
  uniqueStrings.add(str);
1328
- JSObject item = new JSObject();
1329
- item.put("index", index++);
1330
- item.put("value", str);
1331
- strings.put(item);
1332
1352
  }
1333
1353
  }
1334
1354
  }
@@ -1337,6 +1357,14 @@ public class DexManager {
1337
1357
  }
1338
1358
  }
1339
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
+
1340
1368
  result.put("strings", strings);
1341
1369
  result.put("count", strings.length());
1342
1370
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-dex-editor",
3
- "version": "0.0.7",
3
+ "version": "0.0.9",
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",