capacitor-dex-editor 0.0.8 → 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,19 +1306,63 @@ public class DexManager {
1306
1306
  // 解析 DEX 文件
1307
1307
  DexBackedDexFile dexFile = new DexBackedDexFile(Opcodes.getDefault(), dexBytes);
1308
1308
 
1309
- // 直接从 DEX 字符串表中读取所有字符串
1310
- int stringCount = dexFile.getStringCount();
1311
- for (int i = 0; i < stringCount; i++) {
1312
- try {
1313
- String str = dexFile.getStringSection().get(i);
1314
- JSObject item = new JSObject();
1315
- item.put("index", i);
1316
- item.put("value", str != null ? str : "");
1317
- strings.put(item);
1318
- } catch (Exception e) {
1319
- // 跳过无法读取的字符串
1320
- Log.w(TAG, "Failed to read string at index " + i, e);
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);
1321
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
+ }
1357
+ }
1358
+ }
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);
1322
1366
  }
1323
1367
 
1324
1368
  result.put("strings", strings);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-dex-editor",
3
- "version": "0.0.8",
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",