use of jadx.core.dex.instructions.args.InsnWrapArg in project jadx by skylot.
the class EnumVisitor method getConstString.
private String getConstString(DexNode dex, InsnArg arg) {
if (arg.isInsnWrap()) {
InsnNode constInsn = ((InsnWrapArg) arg).getWrapInsn();
Object constValue = InsnUtils.getConstValueByInsn(dex, constInsn);
if (constValue instanceof String) {
return (String) constValue;
}
}
return null;
}
use of jadx.core.dex.instructions.args.InsnWrapArg in project jadx by skylot.
the class TestDuplicateCast method test.
@Test
public void test() {
dontUnloadClass();
ClassNode cls = getClassNode(TestCls.class);
MethodNode mth = getMethod(cls, "method");
String code = cls.getCode().toString();
assertThat(code, containsString("return (int[]) o;"));
List<InsnNode> insns = mth.getBasicBlocks().get(1).getInstructions();
assertEquals(insns.size(), 1);
InsnNode insnNode = insns.get(0);
assertEquals(InsnType.RETURN, insnNode.getType());
assertTrue(insnNode.getArg(0).isInsnWrap());
InsnNode wrapInsn = ((InsnWrapArg) insnNode.getArg(0)).getWrapInsn();
assertEquals(InsnType.CHECK_CAST, wrapInsn.getType());
assertFalse(wrapInsn.getArg(0).isInsnWrap());
}
use of jadx.core.dex.instructions.args.InsnWrapArg in project jadx by skylot.
the class NameGen method makeNameFromInsn.
private String makeNameFromInsn(InsnNode insn) {
switch(insn.getType()) {
case INVOKE:
InvokeNode inv = (InvokeNode) insn;
return makeNameFromInvoke(inv.getCallMth());
case CONSTRUCTOR:
ConstructorInsn co = (ConstructorInsn) insn;
return makeNameForObject(co.getClassType().getType());
case ARRAY_LENGTH:
return "length";
case ARITH:
case TERNARY:
case CAST:
for (InsnArg arg : insn.getArguments()) {
if (arg.isInsnWrap()) {
InsnNode wrapInsn = ((InsnWrapArg) arg).getWrapInsn();
String wName = makeNameFromInsn(wrapInsn);
if (wName != null) {
return wName;
}
}
}
break;
default:
break;
}
return null;
}
use of jadx.core.dex.instructions.args.InsnWrapArg in project jadx by skylot.
the class InsnGen method processVarArg.
/**
* Expand varArgs from filled array.
*/
private boolean processVarArg(CodeWriter code, MethodNode callMth, InsnArg lastArg) throws CodegenException {
if (callMth == null || !callMth.getAccessFlags().isVarArgs()) {
return false;
}
if (!lastArg.getType().isArray() || !lastArg.isInsnWrap()) {
return false;
}
InsnNode insn = ((InsnWrapArg) lastArg).getWrapInsn();
if (insn.getType() == InsnType.FILLED_NEW_ARRAY) {
int count = insn.getArgsCount();
for (int i = 0; i < count; i++) {
InsnArg elemArg = insn.getArg(i);
addArg(code, elemArg, false);
if (i < count - 1) {
code.add(", ");
}
}
return true;
}
return false;
}
use of jadx.core.dex.instructions.args.InsnWrapArg in project jadx by skylot.
the class ReSugarCode method checkEnumMapAccess.
public static EnumMapInfo checkEnumMapAccess(MethodNode mth, InsnNode checkInsn) {
InsnArg sgetArg = checkInsn.getArg(0);
InsnArg invArg = checkInsn.getArg(1);
if (!sgetArg.isInsnWrap() || !invArg.isInsnWrap()) {
return null;
}
InsnNode invInsn = ((InsnWrapArg) invArg).getWrapInsn();
InsnNode sgetInsn = ((InsnWrapArg) sgetArg).getWrapInsn();
if (invInsn.getType() != InsnType.INVOKE || sgetInsn.getType() != InsnType.SGET) {
return null;
}
InvokeNode inv = (InvokeNode) invInsn;
if (!inv.getCallMth().getShortId().equals("ordinal()I")) {
return null;
}
ClassNode enumCls = mth.dex().resolveClass(inv.getCallMth().getDeclClass());
if (enumCls == null || !enumCls.isEnum()) {
return null;
}
Object index = ((IndexInsnNode) sgetInsn).getIndex();
if (!(index instanceof FieldInfo)) {
return null;
}
FieldNode enumMapField = mth.dex().resolveField((FieldInfo) index);
if (enumMapField == null || !enumMapField.getAccessFlags().isSynthetic()) {
return null;
}
return new EnumMapInfo(inv.getArg(0), enumMapField);
}
Aggregations