Search in sources :

Example 1 with MethodHandleReference

use of org.jf.dexlib2.iface.reference.MethodHandleReference in project smali by JesusFreke.

the class BaksmaliWriter method writeCallSite.

@Override
public void writeCallSite(CallSiteReference callSiteReference) throws IOException {
    writeSimpleName(callSiteReference.getName());
    writer.write('(');
    writeQuotedString(callSiteReference.getMethodName());
    writer.write(", ");
    writeMethodProtoDescriptor(callSiteReference.getMethodProto());
    for (EncodedValue encodedValue : callSiteReference.getExtraArguments()) {
        writer.write(", ");
        writeEncodedValue(encodedValue);
    }
    writer.write(")@");
    MethodHandleReference methodHandle = callSiteReference.getMethodHandle();
    if (methodHandle.getMethodHandleType() != MethodHandleType.INVOKE_STATIC) {
        throw new IllegalArgumentException("The linker method handle for a call site must be of type invoke-static");
    }
    writeMethodDescriptor((MethodReference) callSiteReference.getMethodHandle().getMemberReference());
}
Also used : MethodHandleReference(org.jf.dexlib2.iface.reference.MethodHandleReference)

Example 2 with MethodHandleReference

use of org.jf.dexlib2.iface.reference.MethodHandleReference in project smali by JesusFreke.

the class BaseMethodHandleReference method compareTo.

@Override
public int compareTo(@Nonnull MethodHandleReference o) {
    int res = Ints.compare(getMethodHandleType(), o.getMethodHandleType());
    if (res != 0)
        return res;
    Reference reference = getMemberReference();
    if (reference instanceof FieldReference) {
        // a method reference
        if (!(o.getMemberReference() instanceof FieldReference)) {
            return -1;
        }
        return ((FieldReference) reference).compareTo((FieldReference) o.getMemberReference());
    } else {
        if (!(o.getMemberReference() instanceof MethodReference)) {
            return 1;
        }
        return ((MethodReference) reference).compareTo((MethodReference) o.getMemberReference());
    }
}
Also used : FieldReference(org.jf.dexlib2.iface.reference.FieldReference) MethodReference(org.jf.dexlib2.iface.reference.MethodReference) Reference(org.jf.dexlib2.iface.reference.Reference) MethodHandleReference(org.jf.dexlib2.iface.reference.MethodHandleReference) FieldReference(org.jf.dexlib2.iface.reference.FieldReference) MethodReference(org.jf.dexlib2.iface.reference.MethodReference)

Example 3 with MethodHandleReference

use of org.jf.dexlib2.iface.reference.MethodHandleReference in project smali by JesusFreke.

the class ReferenceUtil method writeCallSite.

public static void writeCallSite(Writer writer, CallSiteReference callSiteReference) throws IOException {
    writer.write(callSiteReference.getName());
    writer.write('(');
    writer.write('"');
    StringUtils.writeEscapedString(writer, callSiteReference.getMethodName());
    writer.write('"');
    writer.write(", ");
    writeMethodProtoDescriptor(writer, callSiteReference.getMethodProto());
    for (EncodedValue encodedValue : callSiteReference.getExtraArguments()) {
        writer.write(", ");
        EncodedValueUtils.writeEncodedValue(writer, encodedValue);
    }
    writer.write(")@");
    MethodHandleReference methodHandle = callSiteReference.getMethodHandle();
    if (methodHandle.getMethodHandleType() != MethodHandleType.INVOKE_STATIC) {
        throw new IllegalArgumentException("The linker method handle for a call site must be of type invoke-static");
    }
    writeMethodDescriptor(writer, (MethodReference) callSiteReference.getMethodHandle().getMemberReference());
}
Also used : EncodedValue(org.jf.dexlib2.iface.value.EncodedValue)

Example 4 with MethodHandleReference

use of org.jf.dexlib2.iface.reference.MethodHandleReference in project smali by JesusFreke.

the class DexBackedCallSiteReference method getMethodHandle.

@Nonnull
@Override
public MethodHandleReference getMethodHandle() {
    EncodedArrayItemIterator iter = getCallSiteIterator();
    if (iter.getItemCount() < 3) {
        throw new ExceptionWithContext("Invalid call site item: must contain at least 3 entries.");
    }
    EncodedValue encodedValue = getCallSiteIterator().getNextOrNull();
    assert encodedValue != null;
    if (encodedValue.getValueType() != ValueType.METHOD_HANDLE) {
        throw new ExceptionWithContext("Invalid encoded value type (%d) for the first item in call site %d", encodedValue.getValueType(), callSiteIndex);
    }
    return ((MethodHandleEncodedValue) encodedValue).getValue();
}
Also used : MethodHandleEncodedValue(org.jf.dexlib2.iface.value.MethodHandleEncodedValue) EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) MethodTypeEncodedValue(org.jf.dexlib2.iface.value.MethodTypeEncodedValue) StringEncodedValue(org.jf.dexlib2.iface.value.StringEncodedValue) MethodHandleEncodedValue(org.jf.dexlib2.iface.value.MethodHandleEncodedValue) ExceptionWithContext(org.jf.util.ExceptionWithContext) EncodedArrayItemIterator(org.jf.dexlib2.dexbacked.util.EncodedArrayItemIterator) Nonnull(javax.annotation.Nonnull)

Example 5 with MethodHandleReference

use of org.jf.dexlib2.iface.reference.MethodHandleReference in project smali by JesusFreke.

the class CallSiteUtil method getEncodedCallSite.

public static ArrayEncodedValue getEncodedCallSite(CallSiteReference callSiteReference) {
    return new BaseArrayEncodedValue() {

        @Nonnull
        @Override
        public List<? extends EncodedValue> getValue() {
            List<EncodedValue> encodedCallSite = Lists.newArrayList();
            encodedCallSite.add(new BaseMethodHandleEncodedValue() {

                @Nonnull
                @Override
                public MethodHandleReference getValue() {
                    return callSiteReference.getMethodHandle();
                }
            });
            encodedCallSite.add(new ImmutableStringEncodedValue(callSiteReference.getMethodName()));
            encodedCallSite.add(new BaseMethodTypeEncodedValue() {

                @Nonnull
                @Override
                public MethodProtoReference getValue() {
                    return callSiteReference.getMethodProto();
                }
            });
            encodedCallSite.addAll(callSiteReference.getExtraArguments());
            return encodedCallSite;
        }
    };
}
Also used : ImmutableStringEncodedValue(org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue) BaseArrayEncodedValue(org.jf.dexlib2.base.value.BaseArrayEncodedValue) BaseMethodHandleEncodedValue(org.jf.dexlib2.base.value.BaseMethodHandleEncodedValue) BaseMethodTypeEncodedValue(org.jf.dexlib2.base.value.BaseMethodTypeEncodedValue) EncodedValue(org.jf.dexlib2.iface.value.EncodedValue) ArrayEncodedValue(org.jf.dexlib2.iface.value.ArrayEncodedValue) BaseArrayEncodedValue(org.jf.dexlib2.base.value.BaseArrayEncodedValue) Nonnull(javax.annotation.Nonnull) ImmutableStringEncodedValue(org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue) MethodProtoReference(org.jf.dexlib2.iface.reference.MethodProtoReference) MethodHandleReference(org.jf.dexlib2.iface.reference.MethodHandleReference) BaseMethodHandleEncodedValue(org.jf.dexlib2.base.value.BaseMethodHandleEncodedValue) BaseMethodTypeEncodedValue(org.jf.dexlib2.base.value.BaseMethodTypeEncodedValue)

Aggregations

MethodHandleReference (org.jf.dexlib2.iface.reference.MethodHandleReference)3 EncodedValue (org.jf.dexlib2.iface.value.EncodedValue)3 Nonnull (javax.annotation.Nonnull)2 BaseArrayEncodedValue (org.jf.dexlib2.base.value.BaseArrayEncodedValue)1 BaseMethodHandleEncodedValue (org.jf.dexlib2.base.value.BaseMethodHandleEncodedValue)1 BaseMethodTypeEncodedValue (org.jf.dexlib2.base.value.BaseMethodTypeEncodedValue)1 EncodedArrayItemIterator (org.jf.dexlib2.dexbacked.util.EncodedArrayItemIterator)1 FieldReference (org.jf.dexlib2.iface.reference.FieldReference)1 MethodProtoReference (org.jf.dexlib2.iface.reference.MethodProtoReference)1 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)1 Reference (org.jf.dexlib2.iface.reference.Reference)1 ArrayEncodedValue (org.jf.dexlib2.iface.value.ArrayEncodedValue)1 MethodHandleEncodedValue (org.jf.dexlib2.iface.value.MethodHandleEncodedValue)1 MethodTypeEncodedValue (org.jf.dexlib2.iface.value.MethodTypeEncodedValue)1 StringEncodedValue (org.jf.dexlib2.iface.value.StringEncodedValue)1 ImmutableStringEncodedValue (org.jf.dexlib2.immutable.value.ImmutableStringEncodedValue)1 ExceptionWithContext (org.jf.util.ExceptionWithContext)1