Search in sources :

Example 61 with CstString

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

the class Form21c method isCompatible.

/**
 * {@inheritDoc}
 */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof CstInsn)) {
        return false;
    }
    RegisterSpecList regs = insn.getRegisters();
    RegisterSpec reg;
    switch(regs.size()) {
        case 1:
            {
                reg = regs.get(0);
                break;
            }
        case 2:
            {
                /*
                 * This format is allowed for ops that are effectively
                 * 2-arg but where the two args are identical.
                 */
                reg = regs.get(0);
                if (reg.getReg() != regs.get(1).getReg()) {
                    return false;
                }
                break;
            }
        default:
            {
                return false;
            }
    }
    if (!unsignedFitsInByte(reg.getReg())) {
        return false;
    }
    CstInsn ci = (CstInsn) insn;
    int cpi = ci.getIndex();
    Constant cst = ci.getConstant();
    if (!unsignedFitsInShort(cpi)) {
        return false;
    }
    return (cst instanceof CstType) || (cst instanceof CstFieldRef) || (cst instanceof CstString);
}
Also used : CstInsn(com.android.dx.dex.code.CstInsn) Constant(com.android.dx.rop.cst.Constant) CstType(com.android.dx.rop.cst.CstType) CstFieldRef(com.android.dx.rop.cst.CstFieldRef) CstString(com.android.dx.rop.cst.CstString) RegisterSpecList(com.android.dx.rop.code.RegisterSpecList) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Example 62 with CstString

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

the class Form31c method isCompatible.

/**
 * {@inheritDoc}
 */
@Override
public boolean isCompatible(DalvInsn insn) {
    if (!(insn instanceof CstInsn)) {
        return false;
    }
    RegisterSpecList regs = insn.getRegisters();
    RegisterSpec reg;
    switch(regs.size()) {
        case 1:
            {
                reg = regs.get(0);
                break;
            }
        case 2:
            {
                /*
                 * This format is allowed for ops that are effectively
                 * 2-arg but where the two args are identical.
                 */
                reg = regs.get(0);
                if (reg.getReg() != regs.get(1).getReg()) {
                    return false;
                }
                break;
            }
        default:
            {
                return false;
            }
    }
    if (!unsignedFitsInByte(reg.getReg())) {
        return false;
    }
    CstInsn ci = (CstInsn) insn;
    Constant cst = ci.getConstant();
    return (cst instanceof CstType) || (cst instanceof CstFieldRef) || (cst instanceof CstString);
}
Also used : CstInsn(com.android.dx.dex.code.CstInsn) Constant(com.android.dx.rop.cst.Constant) CstType(com.android.dx.rop.cst.CstType) CstFieldRef(com.android.dx.rop.cst.CstFieldRef) CstString(com.android.dx.rop.cst.CstString) RegisterSpecList(com.android.dx.rop.code.RegisterSpecList) RegisterSpec(com.android.dx.rop.code.RegisterSpec)

Example 63 with CstString

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

the class AnnotationUtils method makeSignature.

/**
 * Constructs a standard {@code Signature} annotation.
 *
 * @param signature {@code non-null;} the signature string
 * @return {@code non-null;} the annotation
 */
public static Annotation makeSignature(CstString signature) {
    Annotation result = new Annotation(SIGNATURE_TYPE, SYSTEM);
    /*
         * Split the string into pieces that are likely to be common
         * across many signatures and the rest of the file.
         */
    String raw = signature.getString();
    int rawLength = raw.length();
    ArrayList<String> pieces = new ArrayList<String>(20);
    for (int at = 0; at < rawLength; ) /*at*/
    {
        char c = raw.charAt(at);
        int endAt = at + 1;
        if (c == 'L') {
            // Scan to ';' or '<'. Consume ';' but not '<'.
            while (endAt < rawLength) {
                c = raw.charAt(endAt);
                if (c == ';') {
                    endAt++;
                    break;
                } else if (c == '<') {
                    break;
                }
                endAt++;
            }
        } else {
            // Scan to 'L' without consuming it.
            while (endAt < rawLength) {
                c = raw.charAt(endAt);
                if (c == 'L') {
                    break;
                }
                endAt++;
            }
        }
        pieces.add(raw.substring(at, endAt));
        at = endAt;
    }
    int size = pieces.size();
    CstArray.List list = new CstArray.List(size);
    for (int i = 0; i < size; i++) {
        list.set(i, new CstString(pieces.get(i)));
    }
    list.setImmutable();
    result.put(new NameValuePair(VALUE_STRING, new CstArray(list)));
    result.setImmutable();
    return result;
}
Also used : NameValuePair(com.android.dx.rop.annotation.NameValuePair) CstArray(com.android.dx.rop.cst.CstArray) ArrayList(java.util.ArrayList) CstString(com.android.dx.rop.cst.CstString) ArrayList(java.util.ArrayList) TypeList(com.android.dx.rop.type.TypeList) CstString(com.android.dx.rop.cst.CstString) Annotation(com.android.dx.rop.annotation.Annotation) CstAnnotation(com.android.dx.rop.cst.CstAnnotation)

Example 64 with CstString

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

the class HeaderItem method writeTo.

/**
 * {@inheritDoc}
 */
@Override
public void writeTo(DexFile file, AnnotatedOutput out) {
    int mapOff = file.getMap().getFileOffset();
    Section firstDataSection = file.getFirstDataSection();
    Section lastDataSection = file.getLastDataSection();
    int dataOff = firstDataSection.getFileOffset();
    int dataSize = lastDataSection.getFileOffset() + lastDataSection.writeSize() - dataOff;
    String magic = file.getDexOptions().getMagic();
    if (out.annotates()) {
        out.annotate(8, "magic: " + new CstString(magic).toQuoted());
        out.annotate(4, "checksum");
        out.annotate(20, "signature");
        out.annotate(4, "file_size:       " + Hex.u4(file.getFileSize()));
        out.annotate(4, "header_size:     " + Hex.u4(SizeOf.HEADER_ITEM));
        out.annotate(4, "endian_tag:      " + Hex.u4(DexFormat.ENDIAN_TAG));
        out.annotate(4, "link_size:       0");
        out.annotate(4, "link_off:        0");
        out.annotate(4, "map_off:         " + Hex.u4(mapOff));
    }
    // Write the magic number.
    for (int i = 0; i < 8; i++) {
        out.writeByte(magic.charAt(i));
    }
    // Leave space for the checksum and signature.
    out.writeZeroes(24);
    out.writeInt(file.getFileSize());
    out.writeInt(SizeOf.HEADER_ITEM);
    out.writeInt(DexFormat.ENDIAN_TAG);
    /*
         * Write zeroes for the link size and data, as the output
         * isn't a staticly linked file.
         */
    out.writeZeroes(8);
    out.writeInt(mapOff);
    // Write out each section's respective header part.
    file.getStringIds().writeHeaderPart(out);
    file.getTypeIds().writeHeaderPart(out);
    file.getProtoIds().writeHeaderPart(out);
    file.getFieldIds().writeHeaderPart(out);
    file.getMethodIds().writeHeaderPart(out);
    file.getClassDefs().writeHeaderPart(out);
    if (out.annotates()) {
        out.annotate(4, "data_size:       " + Hex.u4(dataSize));
        out.annotate(4, "data_off:        " + Hex.u4(dataOff));
    }
    out.writeInt(dataSize);
    out.writeInt(dataOff);
}
Also used : CstString(com.android.dx.rop.cst.CstString) CstString(com.android.dx.rop.cst.CstString)

Example 65 with CstString

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

the class ProtoIdItem method makeShortForm.

/**
 * Creates the short-form of the given prototype.
 *
 * @param prototype {@code non-null;} the prototype
 * @return {@code non-null;} the short form
 */
private static CstString makeShortForm(Prototype prototype) {
    StdTypeList parameters = prototype.getParameterTypes();
    int size = parameters.size();
    StringBuilder sb = new StringBuilder(size + 1);
    sb.append(shortFormCharFor(prototype.getReturnType()));
    for (int i = 0; i < size; i++) {
        sb.append(shortFormCharFor(parameters.getType(i)));
    }
    return new CstString(sb.toString());
}
Also used : StdTypeList(com.android.dx.rop.type.StdTypeList) CstString(com.android.dx.rop.cst.CstString)

Aggregations

CstString (com.android.dx.rop.cst.CstString)69 CstType (com.android.dx.rop.cst.CstType)29 Constant (com.android.dx.rop.cst.Constant)25 ByteArray (com.android.dx.util.ByteArray)15 ConstantPool (com.android.dx.rop.cst.ConstantPool)12 ParseException (com.android.dx.cf.iface.ParseException)10 NameValuePair (com.android.dx.rop.annotation.NameValuePair)10 RegisterSpec (com.android.dx.rop.code.RegisterSpec)10 CstFieldRef (com.android.dx.rop.cst.CstFieldRef)10 CstNat (com.android.dx.rop.cst.CstNat)10 Annotation (com.android.dx.rop.annotation.Annotation)8 Type (com.android.dx.rop.type.Type)8 CstAnnotation (com.android.dx.rop.cst.CstAnnotation)6 CstMethodRef (com.android.dx.rop.cst.CstMethodRef)6 Attribute (com.android.dx.cf.iface.Attribute)5 ClassDefItem (com.android.dx.dex.file.ClassDefItem)5 CstInsn (com.android.dx.dex.code.CstInsn)4 AnnotationsList (com.android.dx.rop.annotation.AnnotationsList)4 LocalItem (com.android.dx.rop.code.LocalItem)4 RegisterSpecList (com.android.dx.rop.code.RegisterSpecList)4