use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.
the class ExtractFieldInit method compareInsns.
private static boolean compareInsns(List<InsnNode> base, List<InsnNode> other) {
if (base.size() != other.size()) {
return false;
}
int count = base.size();
for (int i = 0; i < count; i++) {
InsnNode baseInsn = base.get(i);
InsnNode otherInsn = other.get(i);
if (!baseInsn.isSame(otherInsn)) {
return false;
}
}
return true;
}
use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.
the class ExtractFieldInit method moveStaticFieldsInit.
private static void moveStaticFieldsInit(ClassNode cls) {
MethodNode classInitMth = cls.getClassInitMth();
if (classInitMth == null) {
return;
}
for (FieldNode field : cls.getFields()) {
if (field.contains(AFlag.DONT_GENERATE)) {
continue;
}
if (field.getAccessFlags().isStatic()) {
List<InsnNode> initInsns = getFieldAssigns(classInitMth, field, InsnType.SPUT);
if (initInsns.size() == 1) {
InsnNode insn = initInsns.get(0);
if (checkInsn(insn)) {
InstructionRemover.remove(classInitMth, insn);
addFieldInitAttr(classInitMth, field, insn);
}
}
}
}
}
use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.
the class MethodInlineVisitor method inlineMth.
private static void inlineMth(MethodNode mth, BlockNode firstBlock, BlockNode returnBlock) {
List<InsnNode> insnList = firstBlock.getInstructions();
if (insnList.isEmpty()) {
// synthetic field getter
BlockNode block = mth.getBasicBlocks().get(1);
InsnNode insn = block.getInstructions().get(0);
// set arg from 'return' instruction
addInlineAttr(mth, InsnNode.wrapArg(insn.getArg(0)));
return;
}
// synthetic field setter or method invoke
if (insnList.size() == 1) {
addInlineAttr(mth, insnList.get(0));
return;
}
// other field operations
if (insnList.size() == 2 && returnBlock.getInstructions().size() == 1 && !mth.getReturnType().equals(ArgType.VOID)) {
InsnNode get = insnList.get(0);
InsnNode put = insnList.get(1);
InsnArg retArg = returnBlock.getInstructions().get(0).getArg(0);
if (get.getType() == InsnType.IGET && put.getType() == InsnType.IPUT && retArg.isRegister() && get.getResult().equalRegisterAndType((RegisterArg) retArg)) {
RegisterArg retReg = (RegisterArg) retArg;
retReg.getSVar().removeUse(retReg);
CodeShrinker.shrinkMethod(mth);
insnList = firstBlock.getInstructions();
if (insnList.size() == 1) {
addInlineAttr(mth, insnList.get(0));
}
}
}
}
use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.
the class LoopRegion method checkPreCondition.
/**
* Check if pre-conditions can be inlined into loop condition
*/
public boolean checkPreCondition() {
List<InsnNode> insns = preCondition.getInstructions();
if (insns.isEmpty()) {
return true;
}
IfNode ifInsn = getIfInsn();
int size = insns.size();
for (int i = 0; i < size; i++) {
InsnNode insn = insns.get(i);
if (insn.getResult() == null) {
return false;
}
RegisterArg res = insn.getResult();
if (res.getSVar().getUseCount() > 1) {
return false;
}
boolean found = false;
// search result arg in other insns
for (int j = i + 1; j < size; j++) {
if (insns.get(i).containsArg(res)) {
found = true;
}
}
// or in if insn
if (!found && ifInsn.containsArg(res)) {
found = true;
}
if (!found) {
return false;
}
}
return true;
}
use of jadx.core.dex.nodes.InsnNode in project jadx by skylot.
the class TryCatchBlock method merge.
public boolean merge(MethodNode mth, TryCatchBlock tryBlock) {
if (tryBlock == this) {
return false;
}
for (InsnNode insn : tryBlock.getInsns()) {
this.addInsn(insn);
}
this.handlers.addAll(tryBlock.handlers);
for (ExceptionHandler eh : handlers) {
eh.setTryBlock(this);
}
// clear
tryBlock.handlers.clear();
tryBlock.removeWholeBlock(mth);
return true;
}
Aggregations