Search in sources :

Example 6 with DirectClassFile

use of com.taobao.android.dx.cf.direct.DirectClassFile in project atlas by alibaba.

the class Main method processClass.

/**
     * Processes one classfile.
     *
     * @param name {@code non-null;} name of the file, clipped such that it
     * <i>should</i> correspond to the name of the class it contains
     * @param bytes {@code non-null;} contents of the file
     * @return whether processing was successful
     */
private boolean processClass(String name, byte[] bytes) {
    if (!args.coreLibrary) {
        checkClassName(name);
    }
    DirectClassFile cf = new DirectClassFile(bytes, name, args.cfOptions.strictNameCheck);
    cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    cf.getMagic();
    int numMethodIds = outputDex.getMethodIds().items().size();
    int numFieldIds = outputDex.getFieldIds().items().size();
    int constantPoolSize = cf.getConstantPool().size();
    int maxMethodIdsInDex = numMethodIds + constantPoolSize + cf.getMethods().size() + MAX_METHOD_ADDED_DURING_DEX_CREATION;
    int maxFieldIdsInDex = numFieldIds + constantPoolSize + cf.getFields().size() + MAX_FIELD_ADDED_DURING_DEX_CREATION;
    if (args.multiDex && // Never switch to the next dex if current dex is already empty
    (outputDex.getClassDefs().items().size() > 0) && ((maxMethodIdsInDex > args.maxNumberOfIdxPerDex) || (maxFieldIdsInDex > args.maxNumberOfIdxPerDex))) {
        DexFile completeDex = outputDex;
        createDexFile();
        assert (completeDex.getMethodIds().items().size() <= numMethodIds + MAX_METHOD_ADDED_DURING_DEX_CREATION) && (completeDex.getFieldIds().items().size() <= numFieldIds + MAX_FIELD_ADDED_DURING_DEX_CREATION);
    }
    try {
        ClassDefItem clazz = CfTranslator.translate(cf, bytes, args.cfOptions, args.dexOptions, args.optimizerOptions, outputDex);
        synchronized (outputDex) {
            outputDex.add(clazz);
        }
        return true;
    } catch (ParseException ex) {
        dxConsole.err.println("\ntrouble processing:");
        if (args.debug) {
            ex.printStackTrace(dxConsole.err);
        } else {
            ex.printContext(dxConsole.err);
        }
    }
    errors.incrementAndGet();
    return false;
}
Also used : DirectClassFile(com.taobao.android.dx.cf.direct.DirectClassFile) ClassDefItem(com.taobao.android.dx.dex.file.ClassDefItem) ParseException(com.taobao.android.dx.cf.iface.ParseException) DexFile(com.taobao.android.dx.dex.file.DexFile)

Example 7 with DirectClassFile

use of com.taobao.android.dx.cf.direct.DirectClassFile in project atlas by alibaba.

the class BlockDumper method dump.

/**
     * Does the dumping.
     */
public void dump() {
    byte[] bytes = getBytes();
    ByteArray ba = new ByteArray(bytes);
    /*
         * First, parse the file completely, so we can safely refer to
         * attributes, etc.
         */
    classFile = new DirectClassFile(ba, getFilePath(), getStrictParse());
    classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
    // Force parsing to happen.
    classFile.getMagic();
    // Next, reparse it and observe the process.
    DirectClassFile liveCf = new DirectClassFile(ba, getFilePath(), getStrictParse());
    liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    liveCf.setObserver(this);
    // Force parsing to happen.
    liveCf.getMagic();
}
Also used : DirectClassFile(com.taobao.android.dx.cf.direct.DirectClassFile) ByteArray(com.taobao.android.dx.util.ByteArray)

Example 8 with DirectClassFile

use of com.taobao.android.dx.cf.direct.DirectClassFile in project atlas by alibaba.

the class DotDumper method run.

private void run() {
    ByteArray ba = new ByteArray(bytes);
    /*
         * First, parse the file completely, so we can safely refer to
         * attributes, etc.
         */
    classFile = new DirectClassFile(ba, filePath, strictParse);
    classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
    // Force parsing to happen.
    classFile.getMagic();
    // Next, reparse it and observe the process.
    DirectClassFile liveCf = new DirectClassFile(ba, filePath, strictParse);
    liveCf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    liveCf.setObserver(this);
    // Force parsing to happen.
    liveCf.getMagic();
}
Also used : DirectClassFile(com.taobao.android.dx.cf.direct.DirectClassFile) ByteArray(com.taobao.android.dx.util.ByteArray)

Aggregations

DirectClassFile (com.taobao.android.dx.cf.direct.DirectClassFile)8 ByteArray (com.taobao.android.dx.util.ByteArray)4 FileNotFoundException (java.io.FileNotFoundException)3 IOException (java.io.IOException)2 BaseAnnotations (com.taobao.android.dx.cf.attrib.BaseAnnotations)1 ClassPathOpener (com.taobao.android.dx.cf.direct.ClassPathOpener)1 Attribute (com.taobao.android.dx.cf.iface.Attribute)1 AttributeList (com.taobao.android.dx.cf.iface.AttributeList)1 ParseException (com.taobao.android.dx.cf.iface.ParseException)1 ClassDefItem (com.taobao.android.dx.dex.file.ClassDefItem)1 DexFile (com.taobao.android.dx.dex.file.DexFile)1 CstType (com.taobao.android.dx.rop.cst.CstType)1 TypeList (com.taobao.android.dx.rop.type.TypeList)1 File (java.io.File)1 InputStream (java.io.InputStream)1 ZipEntry (java.util.zip.ZipEntry)1