Search in sources :

Example 1 with IMethodRef

use of jadx.api.plugins.input.data.IMethodRef in project jadx by skylot.

the class InsnDecoder method invokeSpecial.

private InsnNode invokeSpecial(InsnData insn) {
    IMethodRef mthRef = InsnDataUtils.getMethodRef(insn);
    if (mthRef == null) {
        throw new JadxRuntimeException("Failed to load method reference for insn: " + insn);
    }
    MethodInfo mthInfo = MethodInfo.fromRef(root, mthRef);
    // convert 'special' to 'direct/super' same as dx
    InvokeType type;
    if (mthInfo.isConstructor() || Objects.equals(mthInfo.getDeclClass(), method.getParentClass().getClassInfo())) {
        type = InvokeType.DIRECT;
    } else {
        type = InvokeType.SUPER;
    }
    return new InvokeNode(mthInfo, insn, type, false);
}
Also used : IMethodRef(jadx.api.plugins.input.data.IMethodRef) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) MethodInfo(jadx.core.dex.info.MethodInfo)

Example 2 with IMethodRef

use of jadx.api.plugins.input.data.IMethodRef in project jadx by skylot.

the class CustomStringConcat method isStringConcat.

public static boolean isStringConcat(List<EncodedValue> values) {
    if (values.size() < 4) {
        return false;
    }
    IMethodHandle methodHandle = (IMethodHandle) values.get(0).getValue();
    if (methodHandle.getType() != MethodHandleType.INVOKE_STATIC) {
        return false;
    }
    IMethodRef methodRef = methodHandle.getMethodRef();
    if (!methodRef.getName().equals("makeConcatWithConstants")) {
        return false;
    }
    if (!methodRef.getParentClassType().equals("Ljava/lang/invoke/StringConcatFactory;")) {
        return false;
    }
    if (!Objects.equals(values.get(1).getValue(), "makeConcatWithConstants")) {
        return false;
    }
    if (values.get(3).getType() != EncodedType.ENCODED_STRING) {
        return false;
    }
    return true;
}
Also used : IMethodHandle(jadx.api.plugins.input.data.IMethodHandle) IMethodRef(jadx.api.plugins.input.data.IMethodRef)

Example 3 with IMethodRef

use of jadx.api.plugins.input.data.IMethodRef in project jadx by skylot.

the class CustomLambdaCall method isLambdaInvoke.

/**
 * Expect LambdaMetafactory.metafactory method
 */
public static boolean isLambdaInvoke(List<EncodedValue> values) {
    if (values.size() < 6) {
        return false;
    }
    IMethodHandle methodHandle = (IMethodHandle) values.get(0).getValue();
    if (methodHandle.getType() != MethodHandleType.INVOKE_STATIC) {
        return false;
    }
    IMethodRef methodRef = methodHandle.getMethodRef();
    if (!methodRef.getName().equals("metafactory")) {
        return false;
    }
    if (!methodRef.getParentClassType().equals("Ljava/lang/invoke/LambdaMetafactory;")) {
        return false;
    }
    return true;
}
Also used : IMethodHandle(jadx.api.plugins.input.data.IMethodHandle) IMethodRef(jadx.api.plugins.input.data.IMethodRef)

Example 4 with IMethodRef

use of jadx.api.plugins.input.data.IMethodRef in project jadx by skylot.

the class InvokeDecoder method decode.

@Override
public void decode(CodeDecodeState state) {
    DataReader reader = state.reader();
    int mthIdx = reader.readS2();
    if (payloadSize == 4) {
        reader.skip(2);
    }
    JavaInsnData insn = state.insn();
    insn.setIndex(mthIdx);
    boolean instanceCall;
    IMethodProto mthProto;
    if (apiOpcode == Opcode.INVOKE_CUSTOM) {
        ICallSite callSite = insn.getIndexAsCallSite();
        insn.setPayload(callSite);
        mthProto = (IMethodProto) callSite.getValues().get(2).getValue();
        // 'this' arg already included in proto args
        instanceCall = false;
    } else {
        IMethodRef mthRef = insn.getIndexAsMethod();
        mthRef.load();
        insn.setPayload(mthRef);
        mthProto = mthRef;
        instanceCall = apiOpcode != Opcode.INVOKE_STATIC;
    }
    int argsCount = mthProto.getArgTypes().size();
    if (instanceCall) {
        argsCount++;
    }
    // allocate twice of the size for worst case
    insn.setRegsCount(argsCount * 2);
    int[] regs = insn.getRegsArray();
    // calculate actual count of registers
    // set '1' in regs to be filled with stack values later, '0' for skip
    int regsCount = 0;
    if (instanceCall) {
        regs[regsCount++] = 1;
    }
    for (String type : mthProto.getArgTypes()) {
        int size = getRegsCountForType(type);
        regs[regsCount++] = 1;
        if (size == 2) {
            regs[regsCount++] = 0;
        }
    }
    insn.setRegsCount(regsCount);
    for (int i = regsCount - 1; i >= 0; i--) {
        if (regs[i] == 1) {
            state.pop(i);
        }
    }
    String returnType = mthProto.getReturnType();
    if (!returnType.equals("V")) {
        insn.setResultReg(state.push(returnType));
    } else {
        insn.setResultReg(-1);
    }
}
Also used : DataReader(jadx.plugins.input.java.data.DataReader) IMethodProto(jadx.api.plugins.input.data.IMethodProto) JavaInsnData(jadx.plugins.input.java.data.code.JavaInsnData) IMethodRef(jadx.api.plugins.input.data.IMethodRef) ICallSite(jadx.api.plugins.input.data.ICallSite)

Example 5 with IMethodRef

use of jadx.api.plugins.input.data.IMethodRef in project jadx by skylot.

the class UsageInfoVisitor method processInsn.

private static void processInsn(RootNode root, MethodNode mth, InsnData insnData, UsageInfo usageInfo) {
    if (insnData.getOpcode() == Opcode.UNKNOWN) {
        return;
    }
    switch(insnData.getIndexType()) {
        case TYPE_REF:
            insnData.decode();
            ArgType usedType = ArgType.parse(insnData.getIndexAsType());
            usageInfo.clsUse(mth, usedType);
            break;
        case FIELD_REF:
            insnData.decode();
            FieldNode fieldNode = root.resolveField(FieldInfo.fromRef(root, insnData.getIndexAsField()));
            if (fieldNode != null) {
                usageInfo.fieldUse(mth, fieldNode);
            }
            break;
        case METHOD_REF:
            {
                insnData.decode();
                IMethodRef mthRef;
                ICustomPayload payload = insnData.getPayload();
                if (payload != null) {
                    mthRef = ((IMethodRef) payload);
                } else {
                    mthRef = insnData.getIndexAsMethod();
                }
                MethodNode methodNode = root.resolveMethod(MethodInfo.fromRef(root, mthRef));
                if (methodNode != null) {
                    usageInfo.methodUse(mth, methodNode);
                }
                break;
            }
        case CALL_SITE:
            {
                insnData.decode();
                ICallSite callSite = InsnDataUtils.getCallSite(insnData);
                IMethodHandle methodHandle = InsnDataUtils.getMethodHandleAt(callSite, 4);
                if (methodHandle != null) {
                    IMethodRef mthRef = methodHandle.getMethodRef();
                    MethodNode mthNode = root.resolveMethod(MethodInfo.fromRef(root, mthRef));
                    if (mthNode != null) {
                        usageInfo.methodUse(mth, mthNode);
                    }
                }
                break;
            }
    }
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) IMethodHandle(jadx.api.plugins.input.data.IMethodHandle) FieldNode(jadx.core.dex.nodes.FieldNode) MethodNode(jadx.core.dex.nodes.MethodNode) IMethodRef(jadx.api.plugins.input.data.IMethodRef) ICustomPayload(jadx.api.plugins.input.insns.custom.ICustomPayload) ICallSite(jadx.api.plugins.input.data.ICallSite)

Aggregations

IMethodRef (jadx.api.plugins.input.data.IMethodRef)8 IMethodHandle (jadx.api.plugins.input.data.IMethodHandle)3 ICallSite (jadx.api.plugins.input.data.ICallSite)2 MethodInfo (jadx.core.dex.info.MethodInfo)2 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)2 IMethodProto (jadx.api.plugins.input.data.IMethodProto)1 AnnotationsAttr (jadx.api.plugins.input.data.attributes.types.AnnotationsAttr)1 Opcode (jadx.api.plugins.input.insns.Opcode)1 ICustomPayload (jadx.api.plugins.input.insns.custom.ICustomPayload)1 AttributeStorage (jadx.core.dex.attributes.AttributeStorage)1 ArgType (jadx.core.dex.instructions.args.ArgType)1 FieldNode (jadx.core.dex.nodes.FieldNode)1 MethodNode (jadx.core.dex.nodes.MethodNode)1 DataReader (jadx.plugins.input.java.data.DataReader)1 JavaInsnData (jadx.plugins.input.java.data.code.JavaInsnData)1