com.android.dx.rop.cst.CstBaseMethodRef Java Examples

The following examples show how to use com.android.dx.rop.cst.CstBaseMethodRef. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MethodIdsSection.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the index of the given reference, which must have been added
 * to this instance.
 *
 * @param ref {@code non-null;} the reference to look up
 * @return {@code >= 0;} the reference's index
 */
public int indexOf(CstBaseMethodRef ref) {
    if (ref == null) {
        throw new NullPointerException("ref == null");
    }

    throwIfNotPrepared();

    MethodIdItem item = methodIds.get(ref);

    if (item == null) {
        throw new IllegalArgumentException("not found");
    }

    return item.getIndex();
}
 
Example #2
Source File: MethodIdsSection.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the index of the given reference, which must have been added
 * to this instance.
 *
 * @param ref {@code non-null;} the reference to look up
 * @return {@code >= 0;} the reference's index
 */
public int indexOf(CstBaseMethodRef ref) {
    if (ref == null) {
        throw new NullPointerException("ref == null");
    }

    throwIfNotPrepared();

    MethodIdItem item = methodIds.get(ref);

    if (item == null) {
        throw new IllegalArgumentException("not found");
    }

    return item.getIndex();
}
 
Example #3
Source File: MethodIdsSection.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Interns an element into this instance.
 *
 * @param method {@code non-null;} the reference to intern
 * @return {@code non-null;} the interned reference
 */
public synchronized MethodIdItem intern(CstBaseMethodRef method) {
    if (method == null) {
        throw new NullPointerException("method == null");
    }

    throwIfPrepared();

    MethodIdItem result = methodIds.get(method);

    if (result == null) {
        result = new MethodIdItem(method);
        methodIds.put(method, result);
    }

    return result;
}
 
Example #4
Source File: MethodIdsSection.java    From buck with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public IndexedItem get(Constant cst) {
    if (cst == null) {
        throw new NullPointerException("cst == null");
    }

    throwIfNotPrepared();

    IndexedItem result = methodIds.get((CstBaseMethodRef) cst);

    if (result == null) {
        throw new IllegalArgumentException("not found");
    }

    return result;
}
 
Example #5
Source File: DexFile.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@link IndexedItem} corresponding to the given constant,
 * if it is a constant that has such a correspondence, or return
 * {@code null} if it isn't such a constant. This will throw
 * an exception if the given constant <i>should</i> have been found
 * but wasn't.
 *
 * @param cst {@code non-null;} the constant to look up
 * @return {@code null-ok;} its corresponding item, if it has a corresponding
 * item, or {@code null} if it's not that sort of constant
 */
/*package*/ IndexedItem findItemOrNull(Constant cst) {
    IndexedItem item;

    if (cst instanceof CstString) {
        return stringIds.get(cst);
    } else if (cst instanceof CstType) {
        return typeIds.get(cst);
    } else if (cst instanceof CstBaseMethodRef) {
        return methodIds.get(cst);
    } else if (cst instanceof CstFieldRef) {
        return fieldIds.get(cst);
    } else {
        return null;
    }
}
 
Example #6
Source File: DexFile.java    From buck with Apache License 2.0 6 votes vote down vote up
/**
 * Interns the given constant in the appropriate section of this
 * instance, or do nothing if the given constant isn't the sort
 * that should be interned.
 *
 * @param cst {@code non-null;} constant to possibly intern
 */
/*package*/ void internIfAppropriate(Constant cst) {
    if (cst instanceof CstString) {
        stringIds.intern((CstString) cst);
    } else if (cst instanceof CstType) {
        typeIds.intern((CstType) cst);
    } else if (cst instanceof CstBaseMethodRef) {
        methodIds.intern((CstBaseMethodRef) cst);
    } else if (cst instanceof CstFieldRef) {
        fieldIds.intern((CstFieldRef) cst);
    } else if (cst instanceof CstEnumRef) {
        fieldIds.intern(((CstEnumRef) cst).getFieldRef());
    } else if (cst == null) {
        throw new NullPointerException("cst == null");
    }
}
 
Example #7
Source File: ClassReferenceListBuilder.java    From RocooFix with MIT License 6 votes vote down vote up
private void addDependencies(DirectClassFile classFile) {
    for (Constant constant : classFile.getConstantPool().getEntries()) {
        if (constant instanceof CstType) {
            checkDescriptor(((CstType) constant).getClassType().getDescriptor());
        } else if (constant instanceof CstFieldRef) {
            checkDescriptor(((CstFieldRef) constant).getType().getDescriptor());
        } else if (constant instanceof CstBaseMethodRef) {
            checkPrototype(((CstBaseMethodRef) constant).getPrototype());
        }
    }
    FieldList fields = classFile.getFields();
    int nbField = fields.size();
    for (int i = 0; i < nbField; i++) {
      checkDescriptor(fields.get(i).getDescriptor().getString());
    }
    MethodList methods = classFile.getMethods();
    int nbMethods = methods.size();
    for (int i = 0; i < nbMethods; i++) {
      checkPrototype(Prototype.intern(methods.get(i).getDescriptor().getString()));
    }
}
 
Example #8
Source File: MethodIdsSection.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the index of the given reference, which must have been added
 * to this instance.
 *
 * @param ref {@code non-null;} the reference to look up
 * @return {@code >= 0;} the reference's index
 */
public int indexOf(CstBaseMethodRef ref) {
    if (ref == null) {
        throw new NullPointerException("ref == null");
    }

    throwIfNotPrepared();

    MethodIdItem item = methodIds.get(ref);

    if (item == null) {
        throw new IllegalArgumentException("not found");
    }

    return item.getIndex();
}
 
Example #9
Source File: MethodIdsSection.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Interns an element into this instance.
 *
 * @param method {@code non-null;} the reference to intern
 * @return {@code non-null;} the interned reference
 */
public synchronized MethodIdItem intern(CstBaseMethodRef method) {
    if (method == null) {
        throw new NullPointerException("method == null");
    }

    throwIfPrepared();

    MethodIdItem result = methodIds.get(method);

    if (result == null) {
        result = new MethodIdItem(method);
        methodIds.put(method, result);
    }

    return result;
}
 
Example #10
Source File: MethodIdsSection.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public IndexedItem get(Constant cst) {
    if (cst == null) {
        throw new NullPointerException("cst == null");
    }

    throwIfNotPrepared();

    IndexedItem result = methodIds.get((CstBaseMethodRef) cst);

    if (result == null) {
        throw new IllegalArgumentException("not found");
    }

    return result;
}
 
Example #11
Source File: DexFile.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@link IndexedItem} corresponding to the given constant,
 * if it is a constant that has such a correspondence, or return
 * {@code null} if it isn't such a constant. This will throw
 * an exception if the given constant <i>should</i> have been found
 * but wasn't.
 *
 * @param cst {@code non-null;} the constant to look up
 * @return {@code null-ok;} its corresponding item, if it has a corresponding
 * item, or {@code null} if it's not that sort of constant
 */
/*package*/ IndexedItem findItemOrNull(Constant cst) {

    if (cst instanceof CstString) {
        return stringIds.get(cst);
    } else if (cst instanceof CstType) {
        return typeIds.get(cst);
    } else if (cst instanceof CstBaseMethodRef) {
        return methodIds.get(cst);
    } else if (cst instanceof CstFieldRef) {
        return fieldIds.get(cst);
    } else if (cst instanceof CstProtoRef) {
        return protoIds.get(cst);
    } else {
        return null;
    }
}
 
Example #12
Source File: DexFile.java    From J2ME-Loader with Apache License 2.0 6 votes vote down vote up
/**
 * Interns the given constant in the appropriate section of this
 * instance, or do nothing if the given constant isn't the sort
 * that should be interned.
 *
 * @param cst {@code non-null;} constant to possibly intern
 */
/*package*/ void internIfAppropriate(Constant cst) {
    if (cst instanceof CstString) {
        stringIds.intern((CstString) cst);
    } else if (cst instanceof CstType) {
        typeIds.intern((CstType) cst);
    } else if (cst instanceof CstBaseMethodRef) {
        methodIds.intern((CstBaseMethodRef) cst);
    } else if (cst instanceof CstFieldRef) {
        fieldIds.intern((CstFieldRef) cst);
    } else if (cst instanceof CstEnumRef) {
        fieldIds.intern(((CstEnumRef) cst).getFieldRef());
    } else if (cst == null) {
        throw new NullPointerException("cst == null");
    }
}
 
Example #13
Source File: ClassReferenceListBuilder.java    From Box with Apache License 2.0 6 votes vote down vote up
private void addDependencies(DirectClassFile classFile) {
    for (Constant constant : classFile.getConstantPool().getEntries()) {
        if (constant instanceof CstType) {
            checkDescriptor(((CstType) constant).getClassType().getDescriptor());
        } else if (constant instanceof CstFieldRef) {
            checkDescriptor(((CstFieldRef) constant).getType().getDescriptor());
        } else if (constant instanceof CstBaseMethodRef) {
            checkPrototype(((CstBaseMethodRef) constant).getPrototype());
        }
    }

    FieldList fields = classFile.getFields();
    int nbField = fields.size();
    for (int i = 0; i < nbField; i++) {
      checkDescriptor(fields.get(i).getDescriptor().getString());
    }

    MethodList methods = classFile.getMethods();
    int nbMethods = methods.size();
    for (int i = 0; i < nbMethods; i++) {
      checkPrototype(Prototype.intern(methods.get(i).getDescriptor().getString()));
    }
}
 
Example #14
Source File: MethodIdsSection.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Interns an element into this instance.
 *
 * @param method {@code non-null;} the reference to intern
 * @return {@code non-null;} the interned reference
 */
public synchronized MethodIdItem intern(CstBaseMethodRef method) {
    if (method == null) {
        throw new NullPointerException("method == null");
    }

    throwIfPrepared();

    MethodIdItem result = methodIds.get(method);

    if (result == null) {
        result = new MethodIdItem(method);
        methodIds.put(method, result);
    }

    return result;
}
 
Example #15
Source File: MethodIdsSection.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public IndexedItem get(Constant cst) {
    if (cst == null) {
        throw new NullPointerException("cst == null");
    }

    throwIfNotPrepared();

    IndexedItem result = methodIds.get((CstBaseMethodRef) cst);

    if (result == null) {
        throw new IllegalArgumentException("not found");
    }

    return result;
}
 
Example #16
Source File: DexFile.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@link IndexedItem} corresponding to the given constant,
 * if it is a constant that has such a correspondence, or return
 * {@code null} if it isn't such a constant. This will throw
 * an exception if the given constant <i>should</i> have been found
 * but wasn't.
 *
 * @param cst {@code non-null;} the constant to look up
 * @return {@code null-ok;} its corresponding item, if it has a corresponding
 * item, or {@code null} if it's not that sort of constant
 */
/*package*/ IndexedItem findItemOrNull(Constant cst) {
    if (cst instanceof CstString) {
        return stringIds.get(cst);
    } else if (cst instanceof CstType) {
        return typeIds.get(cst);
    } else if (cst instanceof CstBaseMethodRef) {
        return methodIds.get(cst);
    } else if (cst instanceof CstFieldRef) {
        return fieldIds.get(cst);
    } else if (cst instanceof CstEnumRef) {
        return fieldIds.intern(((CstEnumRef) cst).getFieldRef());
    } else if (cst instanceof CstProtoRef) {
        return protoIds.get(cst);
    } else if (cst instanceof CstMethodHandle) {
        return methodHandles.get(cst);
    } else if (cst instanceof CstCallSiteRef) {
        return callSiteIds.get(cst);
    } else {
        return null;
    }
}
 
Example #17
Source File: DexFile.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Interns the given constant in the appropriate section of this
 * instance, or do nothing if the given constant isn't the sort
 * that should be interned.
 *
 * @param cst {@code non-null;} constant to possibly intern
 */
/*package*/ void internIfAppropriate(Constant cst) {
    if (cst == null) {
        throw new NullPointerException("cst == null");
    }

    if (cst instanceof CstString) {
        stringIds.intern((CstString) cst);
    } else if (cst instanceof CstType) {
        typeIds.intern((CstType) cst);
    } else if (cst instanceof CstBaseMethodRef) {
        methodIds.intern((CstBaseMethodRef) cst);
    } else if (cst instanceof CstFieldRef) {
        fieldIds.intern((CstFieldRef) cst);
    } else if (cst instanceof CstEnumRef) {
        fieldIds.intern(((CstEnumRef) cst).getFieldRef());
    } else if (cst instanceof CstProtoRef) {
        protoIds.intern(((CstProtoRef) cst).getPrototype());
    } else if (cst instanceof CstMethodHandle) {
        methodHandles.intern((CstMethodHandle) cst);
    }
}
 
Example #18
Source File: DexFile.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the {@link IndexedItem} corresponding to the given constant,
 * if it is a constant that has such a correspondence, or return
 * {@code null} if it isn't such a constant. This will throw
 * an exception if the given constant <i>should</i> have been found
 * but wasn't.
 *
 * @param cst {@code non-null;} the constant to look up
 * @return {@code null-ok;} its corresponding item, if it has a corresponding
 * item, or {@code null} if it's not that sort of constant
 */
/*package*/ IndexedItem findItemOrNull(Constant cst) {
    if (cst instanceof CstString) {
        return stringIds.get(cst);
    } else if (cst instanceof CstType) {
        return typeIds.get(cst);
    } else if (cst instanceof CstBaseMethodRef) {
        return methodIds.get(cst);
    } else if (cst instanceof CstFieldRef) {
        return fieldIds.get(cst);
    } else if (cst instanceof CstEnumRef) {
        return fieldIds.intern(((CstEnumRef) cst).getFieldRef());
    } else if (cst instanceof CstProtoRef) {
        return protoIds.get(cst);
    } else if (cst instanceof CstMethodHandle) {
        return methodHandles.get(cst);
    } else if (cst instanceof CstCallSiteRef) {
        return callSiteIds.get(cst);
    } else {
        return null;
    }
}
 
Example #19
Source File: ClassReferenceListBuilder.java    From Box with Apache License 2.0 6 votes vote down vote up
private void addDependencies(DirectClassFile classFile) {
    for (Constant constant : classFile.getConstantPool().getEntries()) {
        if (constant instanceof CstType) {
            checkDescriptor(((CstType) constant).getClassType().getDescriptor());
        } else if (constant instanceof CstFieldRef) {
            checkDescriptor(((CstFieldRef) constant).getType().getDescriptor());
        } else if (constant instanceof CstBaseMethodRef) {
            checkPrototype(((CstBaseMethodRef) constant).getPrototype());
        }
    }

    FieldList fields = classFile.getFields();
    int nbField = fields.size();
    for (int i = 0; i < nbField; i++) {
      checkDescriptor(fields.get(i).getDescriptor().getString());
    }

    MethodList methods = classFile.getMethods();
    int nbMethods = methods.size();
    for (int i = 0; i < nbMethods; i++) {
      checkPrototype(Prototype.intern(methods.get(i).getDescriptor().getString()));
    }
}
 
Example #20
Source File: MethodIdsSection.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Gets the index of the given reference, which must have been added
 * to this instance.
 *
 * @param ref {@code non-null;} the reference to look up
 * @return {@code >= 0;} the reference's index
 */
public int indexOf(CstBaseMethodRef ref) {
    if (ref == null) {
        throw new NullPointerException("ref == null");
    }

    throwIfNotPrepared();

    MethodIdItem item = methodIds.get(ref);

    if (item == null) {
        throw new IllegalArgumentException("not found");
    }

    return item.getIndex();
}
 
Example #21
Source File: MethodIdsSection.java    From Box with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
@Override
public IndexedItem get(Constant cst) {
    if (cst == null) {
        throw new NullPointerException("cst == null");
    }

    throwIfNotPrepared();

    IndexedItem result = methodIds.get((CstBaseMethodRef) cst);

    if (result == null) {
        throw new IllegalArgumentException("not found");
    }

    return result;
}
 
Example #22
Source File: MethodIdsSection.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Interns an element into this instance.
 *
 * @param method {@code non-null;} the reference to intern
 * @return {@code non-null;} the interned reference
 */
public synchronized MethodIdItem intern(CstBaseMethodRef method) {
    if (method == null) {
        throw new NullPointerException("method == null");
    }

    throwIfPrepared();

    MethodIdItem result = methodIds.get(method);

    if (result == null) {
        result = new MethodIdItem(method);
        methodIds.put(method, result);
    }

    return result;
}
 
Example #23
Source File: DexFile.java    From Box with Apache License 2.0 6 votes vote down vote up
/**
 * Interns the given constant in the appropriate section of this
 * instance, or do nothing if the given constant isn't the sort
 * that should be interned.
 *
 * @param cst {@code non-null;} constant to possibly intern
 */
/*package*/ void internIfAppropriate(Constant cst) {
    if (cst == null) {
        throw new NullPointerException("cst == null");
    }

    if (cst instanceof CstString) {
        stringIds.intern((CstString) cst);
    } else if (cst instanceof CstType) {
        typeIds.intern((CstType) cst);
    } else if (cst instanceof CstBaseMethodRef) {
        methodIds.intern((CstBaseMethodRef) cst);
    } else if (cst instanceof CstFieldRef) {
        fieldIds.intern((CstFieldRef) cst);
    } else if (cst instanceof CstEnumRef) {
        fieldIds.intern(((CstEnumRef) cst).getFieldRef());
    } else if (cst instanceof CstProtoRef) {
        protoIds.intern(((CstProtoRef) cst).getPrototype());
    } else if (cst instanceof CstMethodHandle) {
        methodHandles.intern((CstMethodHandle) cst);
    }
}
 
Example #24
Source File: MethodHandleItem.java    From Box with Apache License 2.0 5 votes vote down vote up
private int getTargetIndex(DexFile file) {
    Constant ref = methodHandle.getRef();
    if (methodHandle.isAccessor()) {
        FieldIdsSection fieldIds = file.getFieldIds();
        return fieldIds.indexOf((CstFieldRef) ref);
    } else if (methodHandle.isInvocation()) {
        if (ref instanceof CstInterfaceMethodRef) {
            ref = ((CstInterfaceMethodRef)ref).toMethodRef();
        }
        MethodIdsSection methodIds = file.getMethodIds();
        return methodIds.indexOf((CstBaseMethodRef) ref);
    } else {
        throw new IllegalStateException("Unhandled invocation type");
    }
}
 
Example #25
Source File: MethodHandleItem.java    From Box with Apache License 2.0 5 votes vote down vote up
private int getTargetIndex(DexFile file) {
    Constant ref = methodHandle.getRef();
    if (methodHandle.isAccessor()) {
        FieldIdsSection fieldIds = file.getFieldIds();
        return fieldIds.indexOf((CstFieldRef) ref);
    } else if (methodHandle.isInvocation()) {
        if (ref instanceof CstInterfaceMethodRef) {
            ref = ((CstInterfaceMethodRef)ref).toMethodRef();
        }
        MethodIdsSection methodIds = file.getMethodIds();
        return methodIds.indexOf((CstBaseMethodRef) ref);
    } else {
        throw new IllegalStateException("Unhandled invocation type");
    }
}
 
Example #26
Source File: DalvInsnList.java    From buck with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the size of the outgoing arguments area required by this
 * method. This is equal to the largest argument word count of any
 * method referred to by this instance.
 *
 * @return {@code >= 0;} the required outgoing arguments size
 */
public int getOutsSize() {
    int sz = size();
    int result = 0;

    for (int i = 0; i < sz; i++) {
        DalvInsn insn = (DalvInsn) get0(i);

        if (!(insn instanceof CstInsn)) {
            continue;
        }

        Constant cst = ((CstInsn) insn).getConstant();

        if (!(cst instanceof CstBaseMethodRef)) {
            continue;
        }

        boolean isStatic =
            (insn.getOpcode().getFamily() == Opcodes.INVOKE_STATIC);
        int count =
            ((CstBaseMethodRef) cst).getParameterWordCount(isStatic);

        if (count > result) {
            result = count;
        }
    }

    return result;
}
 
Example #27
Source File: MethodIdsSection.java    From J2ME-Loader with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs an instance. The file offset is initially unknown.
 *
 * @param file {@code non-null;} file that this instance is part of
 */
public MethodIdsSection(DexFile file) {
    super("method_ids", file);

    methodIds = new TreeMap<CstBaseMethodRef, MethodIdItem>();
}
 
Example #28
Source File: CfTranslator.java    From Box with Apache License 2.0 4 votes vote down vote up
/**
 * Performs the main act of translation. This method is separated
 * from {@link #translate} just to keep things a bit simpler in
 * terms of exception handling.
 *
 *
 * @param context {@code non-null;} the state global to this invocation.
 * @param cf {@code non-null;} the class file
 * @param bytes {@code non-null;} contents of the file
 * @param cfOptions options for class translation
 * @param dexOptions options for dex output
 * @param dexFile {@code non-null;} dex output
 * @return {@code non-null;} the translated class
 */
private static ClassDefItem translate0(DxContext context, DirectClassFile cf, byte[] bytes,
        CfOptions cfOptions, DexOptions dexOptions, DexFile dexFile) {

    context.optimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile,
            cfOptions.dontOptimizeListFile);

    // Build up a class to output.

    CstType thisClass = cf.getThisClass();
    int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER;
    CstString sourceFile = (cfOptions.positionInfo == PositionList.NONE) ? null :
        cf.getSourceFile();
    ClassDefItem out =
        new ClassDefItem(thisClass, classAccessFlags,
                cf.getSuperclass(), cf.getInterfaces(), sourceFile);

    Annotations classAnnotations =
        AttributeTranslator.getClassAnnotations(cf, cfOptions);
    if (classAnnotations.size() != 0) {
        out.setClassAnnotations(classAnnotations, dexFile);
    }

    FieldIdsSection fieldIdsSection = dexFile.getFieldIds();
    MethodIdsSection methodIdsSection = dexFile.getMethodIds();
    MethodHandlesSection methodHandlesSection = dexFile.getMethodHandles();
    CallSiteIdsSection callSiteIds = dexFile.getCallSiteIds();
    processFields(cf, out, dexFile);
    processMethods(context, cf, cfOptions, dexOptions, out, dexFile);

    // intern constant pool method, field and type references
    ConstantPool constantPool = cf.getConstantPool();
    int constantPoolSize = constantPool.size();

    for (int i = 0; i < constantPoolSize; i++) {
        Constant constant = constantPool.getOrNull(i);
        if (constant instanceof CstMethodRef) {
            methodIdsSection.intern((CstBaseMethodRef) constant);
        } else if (constant instanceof CstInterfaceMethodRef) {
            methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef());
        } else if (constant instanceof CstFieldRef) {
            fieldIdsSection.intern((CstFieldRef) constant);
        } else if (constant instanceof CstEnumRef) {
            fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef());
        } else if (constant instanceof CstMethodHandle) {
            methodHandlesSection.intern((CstMethodHandle) constant);
        } else if (constant instanceof CstInvokeDynamic) {
            CstInvokeDynamic cstInvokeDynamic = (CstInvokeDynamic) constant;
            int index = cstInvokeDynamic.getBootstrapMethodIndex();
            BootstrapMethodsList.Item bootstrapMethod = cf.getBootstrapMethods().get(index);
            CstCallSite callSite =
                    CstCallSite.make(bootstrapMethod.getBootstrapMethodHandle(),
                                     cstInvokeDynamic.getNat(),
                                     bootstrapMethod.getBootstrapMethodArguments());
            cstInvokeDynamic.setDeclaringClass(cf.getThisClass());
            cstInvokeDynamic.setCallSite(callSite);
            for (CstCallSiteRef ref : cstInvokeDynamic.getReferences()) {
                callSiteIds.intern(ref);
            }
        }
    }

    return out;
}
 
Example #29
Source File: MethodIdsSection.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs an instance. The file offset is initially unknown.
 *
 * @param file {@code non-null;} file that this instance is part of
 */
public MethodIdsSection(DexFile file) {
    super("method_ids", file);

    methodIds = new TreeMap<CstBaseMethodRef, MethodIdItem>();
}
 
Example #30
Source File: CfTranslator.java    From buck with Apache License 2.0 4 votes vote down vote up
/**
 * Performs the main act of translation. This method is separated
 * from {@link #translate} just to keep things a bit simpler in
 * terms of exception handling.
 *
 *
 * @param context
 * @param cf {@code non-null;} the class file
 * @param bytes {@code non-null;} contents of the file
 * @param cfOptions options for class translation
 * @param dexOptions options for dex output
 * @param dexFile {@code non-null;} dex output
 * @return {@code non-null;} the translated class
 */
private static ClassDefItem translate0(DxContext context, DirectClassFile cf, byte[] bytes,
                                       CfOptions cfOptions, DexOptions dexOptions, DexFile dexFile) {

    context.optimizerOptions.loadOptimizeLists(cfOptions.optimizeListFile,
            cfOptions.dontOptimizeListFile);

    // Build up a class to output.

    CstType thisClass = cf.getThisClass();
    int classAccessFlags = cf.getAccessFlags() & ~AccessFlags.ACC_SUPER;
    CstString sourceFile = (cfOptions.positionInfo == PositionList.NONE) ? null :
        cf.getSourceFile();
    ClassDefItem out =
        new ClassDefItem(thisClass, classAccessFlags,
                cf.getSuperclass(), cf.getInterfaces(), sourceFile);

    Annotations classAnnotations =
        AttributeTranslator.getClassAnnotations(cf, cfOptions);
    if (classAnnotations.size() != 0) {
        out.setClassAnnotations(classAnnotations, dexFile);
    }

    FieldIdsSection fieldIdsSection = dexFile.getFieldIds();
    MethodIdsSection methodIdsSection = dexFile.getMethodIds();
    processFields(cf, out, dexFile);
    processMethods(context, cf, cfOptions, dexOptions, out, dexFile);

    // intern constant pool method, field and type references
    ConstantPool constantPool = cf.getConstantPool();
    int constantPoolSize = constantPool.size();

    for (int i = 0; i < constantPoolSize; i++) {
        Constant constant = constantPool.getOrNull(i);
        if (constant instanceof CstMethodRef) {
            methodIdsSection.intern((CstBaseMethodRef) constant);
        } else if (constant instanceof CstInterfaceMethodRef) {
            methodIdsSection.intern(((CstInterfaceMethodRef) constant).toMethodRef());
        } else if (constant instanceof CstFieldRef) {
            fieldIdsSection.intern((CstFieldRef) constant);
        } else if (constant instanceof CstEnumRef) {
            fieldIdsSection.intern(((CstEnumRef) constant).getFieldRef());
        }
    }

    return out;
}