use of jadx.core.dex.instructions.IfNode in project jadx by skylot.
the class IfMakerHelper method makeIfInfo.
static IfInfo makeIfInfo(BlockNode ifBlock) {
IfNode ifNode = (IfNode) ifBlock.getInstructions().get(0);
IfCondition condition = IfCondition.fromIfNode(ifNode);
IfInfo info = new IfInfo(condition, ifNode.getThenBlock(), ifNode.getElseBlock());
info.setIfBlock(ifBlock);
info.getMergedBlocks().add(ifBlock);
return info;
}
use of jadx.core.dex.instructions.IfNode in project jadx by skylot.
the class BlockSplitter method isDoWhile.
private static boolean isDoWhile(Map<Integer, BlockNode> blocksMap, BlockNode curBlock, InsnNode insn) {
// split 'do-while' block (last instruction: 'if', target this block)
if (insn.getType() != InsnType.IF) {
return false;
}
IfNode ifs = (IfNode) insn;
BlockNode targetBlock = blocksMap.get(ifs.getTarget());
return targetBlock == curBlock;
}
use of jadx.core.dex.instructions.IfNode in project jadx by skylot.
the class ModVisitor method makeBooleanConvertInsn.
public static TernaryInsn makeBooleanConvertInsn(RegisterArg result, InsnArg castArg, ArgType type) {
InsnArg zero = LiteralArg.make(0, type);
long litVal = 1;
if (type == ArgType.DOUBLE) {
litVal = DOUBLE_TO_BITS;
} else if (type == ArgType.FLOAT) {
litVal = FLOAT_TO_BITS;
}
InsnArg one = LiteralArg.make(litVal, type);
IfNode ifNode = new IfNode(IfOp.EQ, -1, castArg, LiteralArg.litTrue());
IfCondition condition = IfCondition.fromIfNode(ifNode);
return new TernaryInsn(condition, result, one, zero);
}
use of jadx.core.dex.instructions.IfNode in project jadx by skylot.
the class IfMakerHelper method makeIfInfo.
@Nullable
static IfInfo makeIfInfo(MethodNode mth, BlockNode ifBlock) {
InsnNode lastInsn = BlockUtils.getLastInsn(ifBlock);
if (lastInsn == null || lastInsn.getType() != InsnType.IF) {
return null;
}
IfNode ifNode = (IfNode) lastInsn;
IfCondition condition = IfCondition.fromIfNode(ifNode);
IfInfo info = new IfInfo(mth, condition, ifNode.getThenBlock(), ifNode.getElseBlock());
info.getMergedBlocks().add(ifBlock);
return info;
}
use of jadx.core.dex.instructions.IfNode in project jadx by skylot.
the class IfCondition method simplifyCmpOp.
private static IfCondition simplifyCmpOp(Compare c) {
if (!c.getA().isInsnWrap()) {
return null;
}
if (!c.getB().isLiteral()) {
return null;
}
long lit = ((LiteralArg) c.getB()).getLiteral();
if (lit != 0 && lit != 1) {
return null;
}
InsnNode wrapInsn = ((InsnWrapArg) c.getA()).getWrapInsn();
switch(wrapInsn.getType()) {
case CMP_L:
case CMP_G:
if (lit == 0) {
IfNode insn = c.getInsn();
insn.changeCondition(insn.getOp(), wrapInsn.getArg(0), wrapInsn.getArg(1));
}
break;
case ARITH:
if (c.getB().getType() == ArgType.BOOLEAN) {
ArithOp arithOp = ((ArithNode) wrapInsn).getOp();
if (arithOp == ArithOp.OR || arithOp == ArithOp.AND) {
IfOp ifOp = c.getInsn().getOp();
boolean isTrue = ifOp == IfOp.NE && lit == 0 || ifOp == IfOp.EQ && lit == 1;
IfOp op = isTrue ? IfOp.NE : IfOp.EQ;
Mode mode = isTrue && arithOp == ArithOp.OR || !isTrue && arithOp == ArithOp.AND ? Mode.OR : Mode.AND;
IfNode if1 = new IfNode(op, -1, wrapInsn.getArg(0), LiteralArg.litFalse());
IfNode if2 = new IfNode(op, -1, wrapInsn.getArg(1), LiteralArg.litFalse());
return new IfCondition(mode, Arrays.asList(new IfCondition(new Compare(if1)), new IfCondition(new Compare(if2))));
}
}
break;
default:
break;
}
return null;
}
Aggregations