Search in sources :

Example 6 with DirectClassFile

use of com.android.dx.cf.direct.DirectClassFile in project buck by facebook.

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.android.dx.cf.direct.DirectClassFile) ByteArray(com.android.dx.util.ByteArray)

Example 7 with DirectClassFile

use of com.android.dx.cf.direct.DirectClassFile in project kotlin by JetBrains.

the class DxChecker method checkFileWithDx.

private static void checkFileWithDx(byte[] bytes, @NotNull String relativePath, @NotNull Main.Arguments arguments) {
    DirectClassFile cf = new DirectClassFile(bytes, relativePath, true);
    cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
    CfTranslator.translate(cf, bytes, arguments.cfOptions, arguments.dexOptions, new DexFile(arguments.dexOptions));
}
Also used : DirectClassFile(com.android.dx.cf.direct.DirectClassFile) DexFile(com.android.dx.dex.file.DexFile)

Example 8 with DirectClassFile

use of com.android.dx.cf.direct.DirectClassFile in project RocooFix by dodola.

the class Path method getClass.

synchronized DirectClassFile getClass(String path) throws FileNotFoundException {
    DirectClassFile classFile = null;
    for (ClassPathElement element : elements) {
        try {
            InputStream in = element.open(path);
            try {
                byte[] bytes = readStream(in, baos, readBuffer);
                baos.reset();
                classFile = new DirectClassFile(bytes, path, false);
                classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
                break;
            } finally {
                in.close();
            }
        } catch (IOException e) {
        // search next element
        }
    }
    if (classFile == null) {
        throw new FileNotFoundException("File \"" + path + "\" not found");
    }
    return classFile;
}
Also used : DirectClassFile(com.android.dx.cf.direct.DirectClassFile) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 9 with DirectClassFile

use of com.android.dx.cf.direct.DirectClassFile in project RocooFix by dodola.

the class ClassReferenceListBuilder method addRoots.

/**
     * @param jarOfRoots Archive containing the class files resulting of the tracing, typically
     * this is the result of running ProGuard.
     */
public void addRoots(ZipFile jarOfRoots) throws IOException {
    // keep roots
    for (Enumeration<? extends ZipEntry> entries = jarOfRoots.entries(); entries.hasMoreElements(); ) {
        ZipEntry entry = entries.nextElement();
        String name = entry.getName();
        if (name.endsWith(CLASS_EXTENSION)) {
            classNames.add(name.substring(0, name.length() - CLASS_EXTENSION.length()));
        }
    }
    // keep direct references of roots (+ direct references hierarchy)
    for (Enumeration<? extends ZipEntry> entries = jarOfRoots.entries(); entries.hasMoreElements(); ) {
        ZipEntry entry = entries.nextElement();
        String name = entry.getName();
        if (name.endsWith(CLASS_EXTENSION)) {
            DirectClassFile classFile;
            try {
                classFile = path.getClass(name);
                addDependencies(classFile);
            } catch (FileNotFoundException e) {
            }
        }
    }
}
Also used : DirectClassFile(com.android.dx.cf.direct.DirectClassFile) ZipEntry(java.util.zip.ZipEntry) FileNotFoundException(java.io.FileNotFoundException)

Example 10 with DirectClassFile

use of com.android.dx.cf.direct.DirectClassFile in project RocooFix by dodola.

the class Path method getClass.

synchronized DirectClassFile getClass(String path) throws FileNotFoundException {
    DirectClassFile classFile = null;
    for (ClassPathElement element : elements) {
        try {
            InputStream in = element.open(path);
            try {
                byte[] bytes = readStream(in, baos, readBuffer);
                baos.reset();
                classFile = new DirectClassFile(bytes, path, false);
                classFile.setAttributeFactory(StdAttributeFactory.THE_ONE);
                break;
            } finally {
                in.close();
            }
        } catch (IOException e) {
        // search next element
        }
    }
    if (classFile == null) {
        throw new FileNotFoundException("File \"" + path + "\" not found");
    }
    return classFile;
}
Also used : DirectClassFile(com.android.dx.cf.direct.DirectClassFile) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Aggregations

DirectClassFile (com.android.dx.cf.direct.DirectClassFile)19 FileNotFoundException (java.io.FileNotFoundException)11 IOException (java.io.IOException)6 ByteArray (com.android.dx.util.ByteArray)5 CstType (com.android.dx.rop.cst.CstType)4 StdTypeList (com.android.dx.rop.type.StdTypeList)3 TypeList (com.android.dx.rop.type.TypeList)3 InputStream (java.io.InputStream)3 ZipEntry (java.util.zip.ZipEntry)3 File (java.io.File)2 BaseAnnotations (com.android.dx.cf.attrib.BaseAnnotations)1 ClassPathOpener (com.android.dx.cf.direct.ClassPathOpener)1 StdAttributeFactory (com.android.dx.cf.direct.StdAttributeFactory)1 Attribute (com.android.dx.cf.iface.Attribute)1 AttributeList (com.android.dx.cf.iface.AttributeList)1 DexOptions (com.android.dx.dex.DexOptions)1 CfOptions (com.android.dx.dex.cf.CfOptions)1 DexFile (com.android.dx.dex.file.DexFile)1 DexException (com.googlecode.d2j.DexException)1 ClassVisitorFactory (com.googlecode.d2j.dex.ClassVisitorFactory)1