Search in sources :

Example 1 with MethodHandleType

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

the class ConstPoolReader method getMethodHandle.

private IMethodHandle getMethodHandle(int idx) {
    jumpToData(idx);
    int kind = data.readU1();
    int refIdx = data.readU2();
    MethodHandleType handleType = convertMethodHandleKind(kind);
    if (handleType.isField()) {
        return new FieldRefHandle(handleType, getFieldRef(refIdx));
    }
    return new MethodRefHandle(handleType, getMethodRef(refIdx));
}
Also used : MethodRefHandle(jadx.api.plugins.input.data.impl.MethodRefHandle) MethodHandleType(jadx.api.plugins.input.data.MethodHandleType) FieldRefHandle(jadx.api.plugins.input.data.impl.FieldRefHandle)

Example 2 with MethodHandleType

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

the class SectionReader method getMethodHandle.

public IMethodHandle getMethodHandle(int idx) {
    int methodHandleOff = dexReader.getHeader().getMethodHandleOff();
    absPos(methodHandleOff + idx * 8);
    MethodHandleType handleType = getMethodHandleType(readUShort());
    skip(2);
    int refId = readUShort();
    if (handleType.isField()) {
        return new FieldRefHandle(handleType, getFieldRef(refId));
    }
    return new MethodRefHandle(handleType, getMethodRef(refId));
}
Also used : MethodRefHandle(jadx.api.plugins.input.data.impl.MethodRefHandle) MethodHandleType(jadx.api.plugins.input.data.MethodHandleType) FieldRefHandle(jadx.api.plugins.input.data.impl.FieldRefHandle)

Example 3 with MethodHandleType

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

the class CustomLambdaCall method buildMethodCall.

@NotNull
private static InvokeCustomNode buildMethodCall(MethodNode mth, InsnData insn, boolean isRange, List<EncodedValue> values, IMethodHandle callMthHandle) {
    RootNode root = mth.root();
    IMethodProto lambdaProto = (IMethodProto) values.get(2).getValue();
    MethodInfo lambdaInfo = MethodInfo.fromMethodProto(root, mth.getParentClass().getClassInfo(), "", lambdaProto);
    MethodHandleType methodHandleType = callMthHandle.getType();
    InvokeCustomNode invokeCustomNode = new InvokeCustomNode(lambdaInfo, insn, false, isRange);
    invokeCustomNode.setHandleType(methodHandleType);
    ClassInfo implCls = ClassInfo.fromType(root, lambdaInfo.getReturnType());
    String implName = (String) values.get(1).getValue();
    IMethodProto implProto = (IMethodProto) values.get(3).getValue();
    MethodInfo implMthInfo = MethodInfo.fromMethodProto(root, implCls, implName, implProto);
    invokeCustomNode.setImplMthInfo(implMthInfo);
    MethodInfo callMthInfo = MethodInfo.fromRef(root, callMthHandle.getMethodRef());
    InvokeNode invokeNode = buildInvokeNode(methodHandleType, invokeCustomNode, callMthInfo);
    if (methodHandleType == MethodHandleType.INVOKE_CONSTRUCTOR) {
        ConstructorInsn ctrInsn = new ConstructorInsn(mth, invokeNode);
        invokeCustomNode.setCallInsn(ctrInsn);
    } else {
        invokeCustomNode.setCallInsn(invokeNode);
    }
    MethodNode callMth = root.resolveMethod(callMthInfo);
    if (callMth != null) {
        invokeCustomNode.getCallInsn().addAttr(callMth);
        if (callMth.getAccessFlags().isSynthetic() && callMth.getParentClass().equals(mth.getParentClass())) {
            // inline only synthetic methods from same class
            callMth.add(AFlag.DONT_GENERATE);
            invokeCustomNode.setInlineInsn(true);
        }
    }
    if (!invokeCustomNode.isInlineInsn()) {
        IMethodProto effectiveMthProto = (IMethodProto) values.get(5).getValue();
        List<ArgType> args = Utils.collectionMap(effectiveMthProto.getArgTypes(), ArgType::parse);
        boolean sameArgs = args.equals(callMthInfo.getArgumentsTypes());
        invokeCustomNode.setUseRef(sameArgs);
    }
    // prevent args inlining into not generated invoke custom node
    for (InsnArg arg : invokeCustomNode.getArguments()) {
        arg.add(AFlag.DONT_INLINE);
    }
    return invokeCustomNode;
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) RootNode(jadx.core.dex.nodes.RootNode) IMethodProto(jadx.api.plugins.input.data.IMethodProto) InvokeCustomNode(jadx.core.dex.instructions.InvokeCustomNode) MethodHandleType(jadx.api.plugins.input.data.MethodHandleType) MethodNode(jadx.core.dex.nodes.MethodNode) InsnArg(jadx.core.dex.instructions.args.InsnArg) InvokeNode(jadx.core.dex.instructions.InvokeNode) MethodInfo(jadx.core.dex.info.MethodInfo) ConstructorInsn(jadx.core.dex.instructions.mods.ConstructorInsn) ClassInfo(jadx.core.dex.info.ClassInfo) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MethodHandleType (jadx.api.plugins.input.data.MethodHandleType)3 FieldRefHandle (jadx.api.plugins.input.data.impl.FieldRefHandle)2 MethodRefHandle (jadx.api.plugins.input.data.impl.MethodRefHandle)2 IMethodProto (jadx.api.plugins.input.data.IMethodProto)1 ClassInfo (jadx.core.dex.info.ClassInfo)1 MethodInfo (jadx.core.dex.info.MethodInfo)1 InvokeCustomNode (jadx.core.dex.instructions.InvokeCustomNode)1 InvokeNode (jadx.core.dex.instructions.InvokeNode)1 ArgType (jadx.core.dex.instructions.args.ArgType)1 InsnArg (jadx.core.dex.instructions.args.InsnArg)1 ConstructorInsn (jadx.core.dex.instructions.mods.ConstructorInsn)1 MethodNode (jadx.core.dex.nodes.MethodNode)1 RootNode (jadx.core.dex.nodes.RootNode)1 NotNull (org.jetbrains.annotations.NotNull)1