capacitor-dex-editor 0.0.13 → 0.0.15
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.
|
@@ -1672,12 +1672,39 @@ public class DexManager {
|
|
|
1672
1672
|
MethodImplementation impl = method.getImplementation();
|
|
1673
1673
|
if (impl != null) {
|
|
1674
1674
|
smali.append(" .registers ").append(impl.getRegisterCount()).append("\n");
|
|
1675
|
+
smali.append("\n");
|
|
1675
1676
|
|
|
1676
|
-
//
|
|
1677
|
+
// 输出指令,跟踪标签位置
|
|
1678
|
+
java.util.Map<Integer, String> labelMap = new java.util.HashMap<>();
|
|
1679
|
+
int codeOffset = 0;
|
|
1680
|
+
|
|
1681
|
+
// 第一遍:收集所有标签位置
|
|
1682
|
+
for (Instruction instruction : impl.getInstructions()) {
|
|
1683
|
+
if (instruction instanceof com.android.tools.smali.dexlib2.iface.instruction.OffsetInstruction) {
|
|
1684
|
+
com.android.tools.smali.dexlib2.iface.instruction.OffsetInstruction offInstr =
|
|
1685
|
+
(com.android.tools.smali.dexlib2.iface.instruction.OffsetInstruction) instruction;
|
|
1686
|
+
int targetOffset = codeOffset + offInstr.getCodeOffset();
|
|
1687
|
+
labelMap.put(targetOffset, ":cond_" + Integer.toHexString(targetOffset));
|
|
1688
|
+
}
|
|
1689
|
+
codeOffset += instruction.getCodeUnits();
|
|
1690
|
+
}
|
|
1691
|
+
|
|
1692
|
+
// 第二遍:输出指令
|
|
1693
|
+
codeOffset = 0;
|
|
1677
1694
|
for (Instruction instruction : impl.getInstructions()) {
|
|
1678
|
-
|
|
1679
|
-
|
|
1695
|
+
// 输出标签(如果有)
|
|
1696
|
+
if (labelMap.containsKey(codeOffset)) {
|
|
1697
|
+
smali.append("\n ").append(labelMap.get(codeOffset)).append("\n");
|
|
1698
|
+
}
|
|
1699
|
+
|
|
1700
|
+
smali.append(" ").append(instruction.getOpcode().name.toLowerCase().replace('_', '-'));
|
|
1701
|
+
String params = formatInstruction(instruction);
|
|
1702
|
+
if (!params.isEmpty()) {
|
|
1703
|
+
smali.append(" ").append(params);
|
|
1704
|
+
}
|
|
1680
1705
|
smali.append("\n");
|
|
1706
|
+
|
|
1707
|
+
codeOffset += instruction.getCodeUnits();
|
|
1681
1708
|
}
|
|
1682
1709
|
}
|
|
1683
1710
|
|
|
@@ -1699,30 +1726,73 @@ public class DexManager {
|
|
|
1699
1726
|
}
|
|
1700
1727
|
|
|
1701
1728
|
/**
|
|
1702
|
-
* 格式化指令参数
|
|
1729
|
+
* 格式化指令参数 - 使用正确的 Smali 语法格式
|
|
1730
|
+
* invoke 指令格式: invoke-xxx {v0, v1}, Lclass;->method()V
|
|
1703
1731
|
*/
|
|
1704
1732
|
private String formatInstruction(Instruction instruction) {
|
|
1705
1733
|
StringBuilder sb = new StringBuilder();
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
if (
|
|
1718
|
-
|
|
1734
|
+
String opName = instruction.getOpcode().name.toLowerCase();
|
|
1735
|
+
boolean isInvokeOrFilled = opName.startsWith("invoke") || opName.startsWith("filled-new-array");
|
|
1736
|
+
|
|
1737
|
+
// 收集寄存器
|
|
1738
|
+
java.util.List<Integer> registers = new java.util.ArrayList<>();
|
|
1739
|
+
|
|
1740
|
+
// 处理多寄存器指令 (invoke 指令使用 FiveRegisterInstruction)
|
|
1741
|
+
if (instruction instanceof com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction) {
|
|
1742
|
+
com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction regInstr =
|
|
1743
|
+
(com.android.tools.smali.dexlib2.iface.instruction.FiveRegisterInstruction) instruction;
|
|
1744
|
+
int regCount = regInstr.getRegisterCount();
|
|
1745
|
+
if (regCount >= 1) registers.add(regInstr.getRegisterC());
|
|
1746
|
+
if (regCount >= 2) registers.add(regInstr.getRegisterD());
|
|
1747
|
+
if (regCount >= 3) registers.add(regInstr.getRegisterE());
|
|
1748
|
+
if (regCount >= 4) registers.add(regInstr.getRegisterF());
|
|
1749
|
+
if (regCount >= 5) registers.add(regInstr.getRegisterG());
|
|
1750
|
+
} else if (instruction instanceof com.android.tools.smali.dexlib2.iface.instruction.RegisterRangeInstruction) {
|
|
1751
|
+
com.android.tools.smali.dexlib2.iface.instruction.RegisterRangeInstruction regInstr =
|
|
1752
|
+
(com.android.tools.smali.dexlib2.iface.instruction.RegisterRangeInstruction) instruction;
|
|
1753
|
+
int start = regInstr.getStartRegister();
|
|
1754
|
+
int count = regInstr.getRegisterCount();
|
|
1755
|
+
for (int i = 0; i < count; i++) {
|
|
1756
|
+
registers.add(start + i);
|
|
1757
|
+
}
|
|
1758
|
+
} else {
|
|
1759
|
+
// 处理普通寄存器指令
|
|
1760
|
+
if (instruction instanceof com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction) {
|
|
1761
|
+
com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction regInstr =
|
|
1762
|
+
(com.android.tools.smali.dexlib2.iface.instruction.OneRegisterInstruction) instruction;
|
|
1763
|
+
registers.add(regInstr.getRegisterA());
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
if (instruction instanceof com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction) {
|
|
1767
|
+
com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction regInstr =
|
|
1768
|
+
(com.android.tools.smali.dexlib2.iface.instruction.TwoRegisterInstruction) instruction;
|
|
1769
|
+
registers.add(regInstr.getRegisterB());
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
if (instruction instanceof com.android.tools.smali.dexlib2.iface.instruction.ThreeRegisterInstruction) {
|
|
1773
|
+
com.android.tools.smali.dexlib2.iface.instruction.ThreeRegisterInstruction regInstr =
|
|
1774
|
+
(com.android.tools.smali.dexlib2.iface.instruction.ThreeRegisterInstruction) instruction;
|
|
1775
|
+
registers.add(regInstr.getRegisterC());
|
|
1776
|
+
}
|
|
1719
1777
|
}
|
|
1720
1778
|
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1779
|
+
// 格式化寄存器部分
|
|
1780
|
+
if (!registers.isEmpty()) {
|
|
1781
|
+
if (isInvokeOrFilled) {
|
|
1782
|
+
// invoke 指令使用 {} 包裹寄存器
|
|
1783
|
+
sb.append("{");
|
|
1784
|
+
for (int i = 0; i < registers.size(); i++) {
|
|
1785
|
+
if (i > 0) sb.append(", ");
|
|
1786
|
+
sb.append("v").append(registers.get(i));
|
|
1787
|
+
}
|
|
1788
|
+
sb.append("}");
|
|
1789
|
+
} else {
|
|
1790
|
+
// 普通指令直接列出寄存器
|
|
1791
|
+
for (int i = 0; i < registers.size(); i++) {
|
|
1792
|
+
if (i > 0) sb.append(", ");
|
|
1793
|
+
sb.append("v").append(registers.get(i));
|
|
1794
|
+
}
|
|
1795
|
+
}
|
|
1726
1796
|
}
|
|
1727
1797
|
|
|
1728
1798
|
// 处理引用指令
|