use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.
the class ModVisitor method removeStep.
/**
* Remove unnecessary instructions
*/
private static void removeStep(MethodNode mth, InstructionRemover remover) {
for (BlockNode block : mth.getBasicBlocks()) {
remover.setBlock(block);
for (InsnNode insn : block.getInstructions()) {
switch(insn.getType()) {
case NOP:
case GOTO:
case NEW_INSTANCE:
remover.add(insn);
break;
default:
break;
}
}
remover.perform();
}
}
use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.
the class ModVisitor method getParentInsnSkipMove.
private static InsnNode getParentInsnSkipMove(RegisterArg arg) {
SSAVar sVar = arg.getSVar();
if (sVar.getUseCount() != 1) {
return null;
}
RegisterArg useArg = sVar.getUseList().get(0);
InsnNode parentInsn = useArg.getParentInsn();
if (parentInsn == null) {
return null;
}
if (parentInsn.getType() == InsnType.MOVE) {
return getParentInsnSkipMove(parentInsn.getResult());
}
return parentInsn;
}
use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.
the class PrepareForCodeGen method checkInsn.
/**
* Remove parenthesis for wrapped insn in arith '+' or '-'
* ('(a + b) +c' => 'a + b + c')
*/
private static void checkInsn(InsnNode insn) {
if (insn.getType() == InsnType.ARITH) {
ArithNode arith = (ArithNode) insn;
ArithOp op = arith.getOp();
if (op == ArithOp.ADD || op == ArithOp.SUB) {
for (int i = 0; i < 2; i++) {
InsnArg arg = arith.getArg(i);
if (arg.isInsnWrap()) {
InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
wrapInsn.add(AFlag.DONT_WRAP);
checkInsn(wrapInsn);
}
}
}
} else {
for (InsnArg arg : insn.getArguments()) {
if (arg.isInsnWrap()) {
InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
checkInsn(wrapInsn);
}
}
}
}
use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.
the class PrepareForCodeGen method modifyArith.
/**
* Replace arithmetic operation with short form
* ('a = a + 2' => 'a += 2')
*/
private static void modifyArith(BlockNode block) {
List<InsnNode> list = block.getInstructions();
for (InsnNode insn : list) {
if (insn.getType() == InsnType.ARITH) {
RegisterArg res = insn.getResult();
InsnArg arg = insn.getArg(0);
boolean replace = false;
if (res.equals(arg)) {
replace = true;
} else if (arg.isRegister()) {
RegisterArg regArg = (RegisterArg) arg;
replace = res.equalRegisterAndType(regArg);
}
if (replace) {
insn.add(AFlag.ARITH_ONEARG);
}
}
}
}
use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.
the class PrepareForCodeGen method checkInline.
private static void checkInline(BlockNode block) {
List<InsnNode> list = block.getInstructions();
for (int i = 0; i < list.size(); i++) {
InsnNode insn = list.get(i);
// replace 'move' with inner wrapped instruction
if (insn.getType() == InsnType.MOVE && insn.getArg(0).isInsnWrap()) {
InsnNode wrapInsn = ((InsnWrapArg) insn.getArg(0)).getWrapInsn();
wrapInsn.setResult(insn.getResult());
wrapInsn.copyAttributesFrom(insn);
list.set(i, wrapInsn);
}
}
}
Aggregations