Search in sources :

Example 16 with ConstantPool

use of com.android.dx.rop.cst.ConstantPool in project J2ME-Loader by nikita36078.

the class MemberListParser method parse.

/**
 * Does the actual parsing.
 */
private void parse() {
    int attributeContext = getAttributeContext();
    int count = getCount();
    // Skip the count.
    int at = offset + 2;
    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    if (observer != null) {
        observer.parsed(bytes, offset, 2, humanName() + "s_count: " + Hex.u2(count));
    }
    for (int i = 0; i < count; i++) {
        try {
            int accessFlags = bytes.getUnsignedShort(at);
            int nameIdx = bytes.getUnsignedShort(at + 2);
            int descIdx = bytes.getUnsignedShort(at + 4);
            CstString name = (CstString) pool.get(nameIdx);
            CstString desc = (CstString) pool.get(descIdx);
            if (observer != null) {
                observer.startParsingMember(bytes, at, name.getString(), desc.getString());
                observer.parsed(bytes, at, 0, "\n" + humanName() + "s[" + i + "]:\n");
                observer.changeIndent(1);
                observer.parsed(bytes, at, 2, "access_flags: " + humanAccessFlags(accessFlags));
                observer.parsed(bytes, at + 2, 2, "name: " + name.toHuman());
                observer.parsed(bytes, at + 4, 2, "descriptor: " + desc.toHuman());
            }
            at += 6;
            AttributeListParser parser = new AttributeListParser(cf, attributeContext, at, attributeFactory);
            parser.setObserver(observer);
            at = parser.getEndOffset();
            StdAttributeList attributes = parser.getList();
            attributes.setImmutable();
            CstNat nat = new CstNat(name, desc);
            Member member = set(i, accessFlags, nat, attributes);
            if (observer != null) {
                observer.changeIndent(-1);
                observer.parsed(bytes, at, 0, "end " + humanName() + "s[" + i + "]\n");
                observer.endParsingMember(bytes, at, name.getString(), desc.getString(), member);
            }
        } catch (ParseException ex) {
            ex.addContext("...while parsing " + humanName() + "s[" + i + "]");
            throw ex;
        } catch (RuntimeException ex) {
            ParseException pe = new ParseException(ex);
            pe.addContext("...while parsing " + humanName() + "s[" + i + "]");
            throw pe;
        }
    }
    endOffset = at;
}
Also used : StdAttributeList(com.android.dx.cf.iface.StdAttributeList) CstNat(com.android.dx.rop.cst.CstNat) ConstantPool(com.android.dx.rop.cst.ConstantPool) CstString(com.android.dx.rop.cst.CstString) ByteArray(com.android.dx.util.ByteArray) ParseException(com.android.dx.cf.iface.ParseException) Member(com.android.dx.cf.iface.Member)

Example 17 with ConstantPool

use of com.android.dx.rop.cst.ConstantPool in project J2ME-Loader by nikita36078.

the class StdAttributeFactory method signature.

/**
 * Parses a {@code Signature} attribute.
 */
private Attribute signature(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length != 2) {
        throwBadLength(2);
    }
    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    int idx = bytes.getUnsignedShort(offset);
    CstString cst = (CstString) pool.get(idx);
    Attribute result = new AttSignature(cst);
    if (observer != null) {
        observer.parsed(bytes, offset, 2, "signature: " + cst);
    }
    return result;
}
Also used : Attribute(com.android.dx.cf.iface.Attribute) AttSignature(com.android.dx.cf.attrib.AttSignature) ConstantPool(com.android.dx.rop.cst.ConstantPool) CstString(com.android.dx.rop.cst.CstString) ByteArray(com.android.dx.util.ByteArray)

Example 18 with ConstantPool

use of com.android.dx.rop.cst.ConstantPool in project J2ME-Loader by nikita36078.

the class StdAttributeFactory method constantValue.

/**
 * Parses a {@code ConstantValue} attribute.
 */
private Attribute constantValue(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length != 2) {
        return throwBadLength(2);
    }
    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    int idx = bytes.getUnsignedShort(offset);
    TypedConstant cst = (TypedConstant) pool.get(idx);
    Attribute result = new AttConstantValue(cst);
    if (observer != null) {
        observer.parsed(bytes, offset, 2, "value: " + cst);
    }
    return result;
}
Also used : TypedConstant(com.android.dx.rop.cst.TypedConstant) Attribute(com.android.dx.cf.iface.Attribute) ConstantPool(com.android.dx.rop.cst.ConstantPool) ByteArray(com.android.dx.util.ByteArray) AttConstantValue(com.android.dx.cf.attrib.AttConstantValue)

Example 19 with ConstantPool

use of com.android.dx.rop.cst.ConstantPool in project J2ME-Loader by nikita36078.

the class StdAttributeFactory method enclosingMethod.

/**
 * Parses an {@code EnclosingMethod} attribute.
 */
private Attribute enclosingMethod(DirectClassFile cf, int offset, int length, ParseObserver observer) {
    if (length != 4) {
        throwBadLength(4);
    }
    ByteArray bytes = cf.getBytes();
    ConstantPool pool = cf.getConstantPool();
    int idx = bytes.getUnsignedShort(offset);
    CstType type = (CstType) pool.get(idx);
    idx = bytes.getUnsignedShort(offset + 2);
    CstNat method = (CstNat) pool.get0Ok(idx);
    Attribute result = new AttEnclosingMethod(type, method);
    if (observer != null) {
        observer.parsed(bytes, offset, 2, "class: " + type);
        observer.parsed(bytes, offset + 2, 2, "method: " + DirectClassFile.stringOrNone(method));
    }
    return result;
}
Also used : CstNat(com.android.dx.rop.cst.CstNat) AttEnclosingMethod(com.android.dx.cf.attrib.AttEnclosingMethod) Attribute(com.android.dx.cf.iface.Attribute) ConstantPool(com.android.dx.rop.cst.ConstantPool) CstType(com.android.dx.rop.cst.CstType) ByteArray(com.android.dx.util.ByteArray)

Example 20 with ConstantPool

use of com.android.dx.rop.cst.ConstantPool in project J2ME-Loader by nikita36078.

the class CfTranslator method translate0.

/**
 * 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();
    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;
}
Also used : Constant(com.android.dx.rop.cst.Constant) TypedConstant(com.android.dx.rop.cst.TypedConstant) CstString(com.android.dx.rop.cst.CstString) CstFieldRef(com.android.dx.rop.cst.CstFieldRef) CstEnumRef(com.android.dx.rop.cst.CstEnumRef) FieldIdsSection(com.android.dx.dex.file.FieldIdsSection) MethodIdsSection(com.android.dx.dex.file.MethodIdsSection) CstMethodRef(com.android.dx.rop.cst.CstMethodRef) Annotations(com.android.dx.rop.annotation.Annotations) ClassDefItem(com.android.dx.dex.file.ClassDefItem) ConstantPool(com.android.dx.rop.cst.ConstantPool) CstType(com.android.dx.rop.cst.CstType) CstInterfaceMethodRef(com.android.dx.rop.cst.CstInterfaceMethodRef)

Aggregations

ConstantPool (com.android.dx.rop.cst.ConstantPool)20 ByteArray (com.android.dx.util.ByteArray)18 CstString (com.android.dx.rop.cst.CstString)12 Attribute (com.android.dx.cf.iface.Attribute)10 CstType (com.android.dx.rop.cst.CstType)8 ParseException (com.android.dx.cf.iface.ParseException)4 StdAttributeList (com.android.dx.cf.iface.StdAttributeList)4 CstNat (com.android.dx.rop.cst.CstNat)4 TypedConstant (com.android.dx.rop.cst.TypedConstant)4 AttCode (com.android.dx.cf.attrib.AttCode)2 AttConstantValue (com.android.dx.cf.attrib.AttConstantValue)2 AttEnclosingMethod (com.android.dx.cf.attrib.AttEnclosingMethod)2 AttInnerClasses (com.android.dx.cf.attrib.AttInnerClasses)2 AttSignature (com.android.dx.cf.attrib.AttSignature)2 AttSourceFile (com.android.dx.cf.attrib.AttSourceFile)2 InnerClassList (com.android.dx.cf.attrib.InnerClassList)2 RawAttribute (com.android.dx.cf.attrib.RawAttribute)2 ByteCatchList (com.android.dx.cf.code.ByteCatchList)2 BytecodeArray (com.android.dx.cf.code.BytecodeArray)2 Member (com.android.dx.cf.iface.Member)2