use of jadx.core.dex.instructions.args.InsnWrapArg in project jadx by skylot.
the class ExtractFieldInit method checkInsn.
private static boolean checkInsn(FieldInitInfo initInfo) {
if (!initInfo.singlePath) {
return false;
}
IndexInsnNode insn = initInfo.putInsn;
InsnArg arg = insn.getArg(0);
if (arg.isInsnWrap()) {
InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
if (!wrapInsn.canReorderRecursive() && insn.contains(AType.EXC_CATCH)) {
return false;
}
} else {
return arg.isLiteral() || arg.isThis();
}
Set<RegisterArg> regs = new HashSet<>();
insn.getRegisterArgs(regs);
if (!regs.isEmpty()) {
for (RegisterArg reg : regs) {
if (!reg.isThis()) {
return false;
}
}
}
return true;
}
use of jadx.core.dex.instructions.args.InsnWrapArg in project jadx by skylot.
the class ExtractFieldInit method moveCommonFieldsInit.
private static void moveCommonFieldsInit(ClassNode cls) {
List<MethodNode> constructors = getConstructorsList(cls);
if (constructors.isEmpty()) {
return;
}
List<ConstructorInitInfo> infoList = new ArrayList<>(constructors.size());
for (MethodNode constructorMth : constructors) {
if (constructorMth.isNoCode()) {
return;
}
List<FieldInitInfo> inits = collectFieldsInit(cls, constructorMth, InsnType.IPUT);
filterFieldsInit(inits);
if (inits.isEmpty()) {
return;
}
infoList.add(new ConstructorInitInfo(constructorMth, inits));
}
// compare collected instructions
ConstructorInitInfo common = null;
for (ConstructorInitInfo info : infoList) {
if (common == null) {
common = info;
continue;
}
if (!compareFieldInits(common.fieldInits, info.fieldInits)) {
return;
}
}
if (common == null) {
return;
}
// all checks passed
for (ConstructorInitInfo info : infoList) {
for (FieldInitInfo fieldInit : info.fieldInits) {
IndexInsnNode putInsn = fieldInit.putInsn;
InsnArg arg = putInsn.getArg(0);
if (arg instanceof InsnWrapArg) {
((InsnWrapArg) arg).getWrapInsn().add(AFlag.DECLARE_VAR);
}
InsnRemover.remove(info.constructorMth, putInsn);
}
}
for (FieldInitInfo fieldInit : common.fieldInits) {
addFieldInitAttr(common.constructorMth, fieldInit.fieldNode, fieldInit.putInsn);
}
fixFieldsOrder(cls, common.fieldInits);
}
use of jadx.core.dex.instructions.args.InsnWrapArg in project jadx by skylot.
the class InsnNode method visitInsns.
/**
* Visit this instruction and all inner (wrapped) instructions
* To terminate visiting return non-null value
*/
@Nullable
public <R> R visitInsns(Function<InsnNode, R> visitor) {
R result = visitor.apply(this);
if (result != null) {
return result;
}
for (InsnArg arg : this.getArguments()) {
if (arg.isInsnWrap()) {
InsnNode innerInsn = ((InsnWrapArg) arg).getWrapInsn();
R res = innerInsn.visitInsns(visitor);
if (res != null) {
return res;
}
}
}
return null;
}
use of jadx.core.dex.instructions.args.InsnWrapArg in project jadx by skylot.
the class InsnNode method rebindArgs.
/**
* Fix SSAVar info in register arguments.
* Must be used after altering instructions.
*/
public void rebindArgs() {
RegisterArg resArg = getResult();
if (resArg != null) {
resArg.getSVar().setAssign(resArg);
}
for (InsnArg arg : getArguments()) {
if (arg instanceof RegisterArg) {
RegisterArg reg = (RegisterArg) arg;
SSAVar ssaVar = reg.getSVar();
ssaVar.use(reg);
ssaVar.updateUsedInPhiList();
} else if (arg instanceof InsnWrapArg) {
((InsnWrapArg) arg).getWrapInsn().rebindArgs();
}
}
}
use of jadx.core.dex.instructions.args.InsnWrapArg in project jadx by skylot.
the class InsnNode method visitArgs.
/**
* Visit all args recursively (including inner instructions), but excluding wrapped args.
* To terminate visiting return non-null value
*/
@Nullable
public <R> R visitArgs(Function<InsnArg, R> visitor) {
for (InsnArg arg : getArguments()) {
R result;
if (arg.isInsnWrap()) {
InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
result = wrapInsn.visitArgs(visitor);
} else {
result = visitor.apply(arg);
}
if (result != null) {
return result;
}
}
return null;
}
Aggregations