use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.
the class InstructionRemover method removeAll.
// Don't use 'instrList.removeAll(toRemove)' because it will remove instructions by content
// and here can be several instructions with same content
private static void removeAll(MethodNode mth, List<InsnNode> insns, List<InsnNode> toRemove) {
for (InsnNode rem : toRemove) {
unbindInsn(mth, rem);
int insnsCount = insns.size();
for (int i = 0; i < insnsCount; i++) {
if (insns.get(i) == rem) {
insns.remove(i);
break;
}
}
}
}
use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.
the class RegionUtils method getLastInsn.
public static InsnNode getLastInsn(IContainer container) {
if (container instanceof IBlock) {
IBlock block = (IBlock) container;
List<InsnNode> insnList = block.getInstructions();
if (insnList.isEmpty()) {
return null;
}
return insnList.get(insnList.size() - 1);
} else if (container instanceof IBranchRegion) {
return null;
} else if (container instanceof IRegion) {
IRegion region = (IRegion) container;
List<IContainer> blocks = region.getSubBlocks();
if (blocks.isEmpty()) {
return null;
}
return getLastInsn(blocks.get(blocks.size() - 1));
} else {
throw new JadxRuntimeException(unknownContainerType(container));
}
}
use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.
the class TestDuplicateCast method test.
@Test
public void test() {
dontUnloadClass();
ClassNode cls = getClassNode(TestCls.class);
MethodNode mth = getMethod(cls, "method");
String code = cls.getCode().toString();
assertThat(code, containsString("return (int[]) o;"));
List<InsnNode> insns = mth.getBasicBlocks().get(1).getInstructions();
assertEquals(insns.size(), 1);
InsnNode insnNode = insns.get(0);
assertEquals(InsnType.RETURN, insnNode.getType());
assertTrue(insnNode.getArg(0).isInsnWrap());
InsnNode wrapInsn = ((InsnWrapArg) insnNode.getArg(0)).getWrapInsn();
assertEquals(InsnType.CHECK_CAST, wrapInsn.getType());
assertFalse(wrapInsn.getArg(0).isInsnWrap());
}
use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.
the class NameGen method makeNameFromInsn.
private String makeNameFromInsn(InsnNode insn) {
switch(insn.getType()) {
case INVOKE:
InvokeNode inv = (InvokeNode) insn;
return makeNameFromInvoke(inv.getCallMth());
case CONSTRUCTOR:
ConstructorInsn co = (ConstructorInsn) insn;
return makeNameForObject(co.getClassType().getType());
case ARRAY_LENGTH:
return "length";
case ARITH:
case TERNARY:
case CAST:
for (InsnArg arg : insn.getArguments()) {
if (arg.isInsnWrap()) {
InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
String wName = makeNameFromInsn(wrapInsn);
if (wName != null) {
return wName;
}
}
}
break;
default:
break;
}
return null;
}
use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.
the class NameGen method guessName.
private String guessName(RegisterArg arg) {
SSAVar sVar = arg.getSVar();
if (sVar != null && sVar.getName() == null) {
RegisterArg assignArg = sVar.getAssign();
InsnNode assignInsn = assignArg.getParentInsn();
if (assignInsn != null) {
String name = makeNameFromInsn(assignInsn);
if (name != null && !NameMapper.isReserved(name)) {
assignArg.setName(name);
return name;
}
}
}
return makeNameForType(arg.getType());
}
Aggregations