use of jadx.core.dex.instructions.args.InsnArg in project jadx by skylot.
the class ConstInlineVisitor method checkInsn.
private static boolean checkInsn(MethodNode mth, InsnNode insn) {
if (insn.getType() != InsnType.CONST || insn.contains(AFlag.DONT_INLINE)) {
return false;
}
InsnArg arg = insn.getArg(0);
if (!arg.isLiteral()) {
return false;
}
long lit = ((LiteralArg) arg).getLiteral();
SSAVar sVar = insn.getResult().getSVar();
if (lit == 0 && checkObjectInline(sVar)) {
if (sVar.getUseCount() == 1) {
InsnNode assignInsn = insn.getResult().getAssignInsn();
if (assignInsn != null) {
assignInsn.add(AFlag.DONT_INLINE);
}
}
return false;
}
ArgType resType = insn.getResult().getType();
// make sure arg has correct type
if (!arg.getType().isTypeKnown()) {
arg.merge(mth.dex(), resType);
}
return replaceConst(mth, insn, lit);
}
use of jadx.core.dex.instructions.args.InsnArg in project jadx by skylot.
the class ConstInlineVisitor method fixTypes.
/**
* This is method similar to PostTypeInference.process method,
* but contains some expensive operations needed only after constant inline
*/
private static void fixTypes(MethodNode mth, InsnNode insn, LiteralArg litArg) {
DexNode dex = mth.dex();
PostTypeInference.process(mth, insn);
switch(insn.getType()) {
case CONST:
insn.getArg(0).merge(dex, insn.getResult());
break;
case MOVE:
insn.getResult().merge(dex, insn.getArg(0));
insn.getArg(0).merge(dex, insn.getResult());
break;
case IPUT:
case SPUT:
IndexInsnNode node = (IndexInsnNode) insn;
insn.getArg(0).merge(dex, ((FieldInfo) node.getIndex()).getType());
break;
case IF:
{
InsnArg arg0 = insn.getArg(0);
InsnArg arg1 = insn.getArg(1);
if (arg0 == litArg) {
arg0.merge(dex, arg1);
} else {
arg1.merge(dex, arg0);
}
break;
}
case CMP_G:
case CMP_L:
InsnArg arg0 = insn.getArg(0);
InsnArg arg1 = insn.getArg(1);
if (arg0 == litArg) {
arg0.merge(dex, arg1);
} else {
arg1.merge(dex, arg0);
}
break;
case RETURN:
if (insn.getArgsCount() != 0) {
insn.getArg(0).merge(dex, mth.getReturnType());
}
break;
case INVOKE:
InvokeNode inv = (InvokeNode) insn;
List<ArgType> types = inv.getCallMth().getArgumentsTypes();
int count = insn.getArgsCount();
int k = types.size() == count ? 0 : -1;
for (int i = 0; i < count; i++) {
InsnArg arg = insn.getArg(i);
if (!arg.getType().isTypeKnown()) {
ArgType type;
if (k >= 0) {
type = types.get(k);
} else {
type = mth.getParentClass().getClassInfo().getType();
}
arg.merge(dex, type);
}
k++;
}
break;
case ARITH:
litArg.merge(dex, insn.getResult());
break;
case APUT:
case AGET:
if (litArg == insn.getArg(1)) {
litArg.merge(dex, ArgType.INT);
}
break;
case NEW_ARRAY:
if (litArg == insn.getArg(0)) {
litArg.merge(dex, ArgType.INT);
}
break;
default:
break;
}
}
use of jadx.core.dex.instructions.args.InsnArg in project jadx by skylot.
the class DependencyCollector method processInsn.
// TODO: add custom instructions processing
private static void processInsn(DexNode dex, Set<ClassNode> depList, InsnNode insnNode) {
RegisterArg result = insnNode.getResult();
if (result != null) {
addDep(dex, depList, result.getType());
}
for (InsnArg arg : insnNode.getArguments()) {
if (arg.isInsnWrap()) {
processInsn(dex, depList, ((InsnWrapArg) arg).getWrapInsn());
} else {
addDep(dex, depList, arg.getType());
}
}
processCustomInsn(dex, depList, insnNode);
}
use of jadx.core.dex.instructions.args.InsnArg in project jadx by skylot.
the class InsnNode method isSame.
/**
* 'Soft' equals, don't compare arguments, only instruction specific parameters.
*/
public boolean isSame(InsnNode other) {
if (this == other) {
return true;
}
if (insnType != other.insnType || arguments.size() != other.arguments.size()) {
return false;
}
// check wrapped instructions
int size = arguments.size();
for (int i = 0; i < size; i++) {
InsnArg arg = arguments.get(i);
InsnArg otherArg = other.arguments.get(i);
if (arg.isInsnWrap()) {
if (!otherArg.isInsnWrap()) {
return false;
}
InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
InsnNode otherWrapInsn = ((InsnWrapArg) otherArg).getWrapInsn();
if (!wrapInsn.isSame(otherWrapInsn)) {
return false;
}
}
}
return true;
}
use of jadx.core.dex.instructions.args.InsnArg in project jadx by skylot.
the class DebugInfoParser method addrChange.
private int addrChange(int addr, int addrInc, int line) {
int newAddr = addr + addrInc;
int maxAddr = insnByOffset.length - 1;
newAddr = Math.min(newAddr, maxAddr);
for (int i = addr + 1; i <= newAddr; i++) {
InsnNode insn = insnByOffset[i];
if (insn == null) {
continue;
}
for (InsnArg arg : insn.getArguments()) {
if (arg.isRegister()) {
activeRegisters[((RegisterArg) arg).getRegNum()] = arg;
}
}
RegisterArg res = insn.getResult();
if (res != null) {
activeRegisters[res.getRegNum()] = res;
}
}
setSourceLines(addr, newAddr, line);
return newAddr;
}
Aggregations