Search in sources :

Example 1 with IMethodHandle

use of jadx.api.plugins.input.data.IMethodHandle 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 2 with IMethodHandle

use of jadx.api.plugins.input.data.IMethodHandle 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 3 with IMethodHandle

use of jadx.api.plugins.input.data.IMethodHandle 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)

Example 4 with IMethodHandle

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

the class CustomLambdaCall method buildLambdaMethodCall.

public static InvokeCustomNode buildLambdaMethodCall(MethodNode mth, InsnData insn, boolean isRange, List<EncodedValue> values) {
    IMethodHandle callMthHandle = (IMethodHandle) values.get(4).getValue();
    if (callMthHandle.getType().isField()) {
        throw new JadxRuntimeException("Not yet supported");
    }
    InvokeCustomNode resNode = buildMethodCall(mth, insn, isRange, values, callMthHandle);
    int resReg = insn.getResultReg();
    if (resReg != -1) {
        resNode.setResult(InsnArg.reg(resReg, mth.getReturnType()));
    }
    return resNode;
}
Also used : IMethodHandle(jadx.api.plugins.input.data.IMethodHandle) InvokeCustomNode(jadx.core.dex.instructions.InvokeCustomNode) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Aggregations

IMethodHandle (jadx.api.plugins.input.data.IMethodHandle)4 IMethodRef (jadx.api.plugins.input.data.IMethodRef)3 ICallSite (jadx.api.plugins.input.data.ICallSite)1 ICustomPayload (jadx.api.plugins.input.insns.custom.ICustomPayload)1 InvokeCustomNode (jadx.core.dex.instructions.InvokeCustomNode)1 ArgType (jadx.core.dex.instructions.args.ArgType)1 FieldNode (jadx.core.dex.nodes.FieldNode)1 MethodNode (jadx.core.dex.nodes.MethodNode)1 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)1