capacitor-dex-editor 0.0.12 → 0.0.14
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.
|
@@ -1699,30 +1699,73 @@ public class DexManager {
|
|
|
1699
1699
|
}
|
|
1700
1700
|
|
|
1701
1701
|
/**
|
|
1702
|
-
* 格式化指令参数
|
|
1702
|
+
* 格式化指令参数 - 使用正确的 Smali 语法格式
|
|
1703
|
+
* invoke 指令格式: invoke-xxx {v0, v1}, Lclass;->method()V
|
|
1703
1704
|
*/
|
|
1704
1705
|
private String formatInstruction(Instruction instruction) {
|
|
1705
1706
|
StringBuilder sb = new StringBuilder();
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
if (
|
|
1718
|
-
|
|
1707
|
+
String opName = instruction.getOpcode().name.toLowerCase();
|
|
1708
|
+
boolean isInvokeOrFilled = opName.startsWith("invoke") || opName.startsWith("filled-new-array");
|
|
1709
|
+
|
|
1710
|
+
// 收集寄存器
|
|
1711
|
+
java.util.List<Integer> registers = new java.util.ArrayList<>();
|
|
1712
|
+
|
|
1713
|
+
// 处理多寄存器指令 (invoke 指令使用 FiveRegisterInstruction)
|
|
1714
|
+
if (instruction instanceof com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction) {
|
|
1715
|
+
com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction regInstr =
|
|
1716
|
+
(com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction) instruction;
|
|
1717
|
+
int regCount = regInstr.getRegisterCount();
|
|
1718
|
+
if (regCount >= 1) registers.add(regInstr.getRegisterC());
|
|
1719
|
+
if (regCount >= 2) registers.add(regInstr.getRegisterD());
|
|
1720
|
+
if (regCount >= 3) registers.add(regInstr.getRegisterE());
|
|
1721
|
+
if (regCount >= 4) registers.add(regInstr.getRegisterF());
|
|
1722
|
+
if (regCount >= 5) registers.add(regInstr.getRegisterG());
|
|
1723
|
+
} else if (instruction instanceof com.android.tools.smali.dexlib2.iface.instruction.RegisterRangeInstruction) {
|
|
1724
|
+
com.android.tools.smali.dexlib2.iface.instruction.RegisterRangeInstruction regInstr =
|
|
1725
|
+
(com.android.tools.smali.dexlib2.iface.instruction.RegisterRangeInstruction) instruction;
|
|
1726
|
+
int start = regInstr.getStartRegister();
|
|
1727
|
+
int count = regInstr.getRegisterCount();
|
|
1728
|
+
for (int i = 0; i < count; i++) {
|
|
1729
|
+
registers.add(start + i);
|
|
1730
|
+
}
|
|
1731
|
+
} else {
|
|
1732
|
+
// 处理普通寄存器指令
|
|
1733
|
+
if (instruction instanceof com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction) {
|
|
1734
|
+
com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction regInstr =
|
|
1735
|
+
(com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction) instruction;
|
|
1736
|
+
registers.add(regInstr.getRegisterA());
|
|
1737
|
+
}
|
|
1738
|
+
|
|
1739
|
+
if (instruction instanceof com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction) {
|
|
1740
|
+
com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction regInstr =
|
|
1741
|
+
(com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction) instruction;
|
|
1742
|
+
registers.add(regInstr.getRegisterB());
|
|
1743
|
+
}
|
|
1744
|
+
|
|
1745
|
+
if (instruction instanceof com.android.tools.smali.dexlib2.iface.instruction.ThreeRegisterInstruction) {
|
|
1746
|
+
com.android.tools.smali.dexlib2.iface.instruction.ThreeRegisterInstruction regInstr =
|
|
1747
|
+
(com.android.tools.smali.dexlib2.iface.instruction.ThreeRegisterInstruction) instruction;
|
|
1748
|
+
registers.add(regInstr.getRegisterC());
|
|
1749
|
+
}
|
|
1719
1750
|
}
|
|
1720
1751
|
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1752
|
+
// 格式化寄存器部分
|
|
1753
|
+
if (!registers.isEmpty()) {
|
|
1754
|
+
if (isInvokeOrFilled) {
|
|
1755
|
+
// invoke 指令使用 {} 包裹寄存器
|
|
1756
|
+
sb.append("{");
|
|
1757
|
+
for (int i = 0; i < registers.size(); i++) {
|
|
1758
|
+
if (i > 0) sb.append(", ");
|
|
1759
|
+
sb.append("v").append(registers.get(i));
|
|
1760
|
+
}
|
|
1761
|
+
sb.append("}");
|
|
1762
|
+
} else {
|
|
1763
|
+
// 普通指令直接列出寄存器
|
|
1764
|
+
for (int i = 0; i < registers.size(); i++) {
|
|
1765
|
+
if (i > 0) sb.append(", ");
|
|
1766
|
+
sb.append("v").append(registers.get(i));
|
|
1767
|
+
}
|
|
1768
|
+
}
|
|
1726
1769
|
}
|
|
1727
1770
|
|
|
1728
1771
|
// 处理引用指令
|
|
@@ -1780,8 +1823,8 @@ public class DexManager {
|
|
|
1780
1823
|
}
|
|
1781
1824
|
|
|
1782
1825
|
try {
|
|
1783
|
-
// 创建临时目录存储 smali
|
|
1784
|
-
java.io.File tempDir = new java.io.File(
|
|
1826
|
+
// 创建临时目录存储 smali 文件(使用系统临时目录)
|
|
1827
|
+
java.io.File tempDir = new java.io.File(System.getProperty("java.io.tmpdir"), "smali_temp_" + System.currentTimeMillis());
|
|
1785
1828
|
if (!tempDir.mkdirs()) {
|
|
1786
1829
|
result.put("success", false);
|
|
1787
1830
|
result.put("error", "无法创建临时目录");
|