Search in sources :

Example 11 with DirectClassFile

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

the class ClassReferenceListBuilder method run.

public void run(String refClassName) throws IOException {
    classNames.add(refClassName);
    while (true) {
        Set<String> temp = getUnAnalyzeClasses();
        if (temp.isEmpty()) {
            break;
        }
        for (String tempName : temp) {
            alreadyAnalyzedClasses.add(tempName);
            refcname = tempName;
            //                System.out.println("scan:---------->" + refcname);
            for (Enumeration<? extends ZipEntry> entries = jarOfRoots.entries(); entries.hasMoreElements(); ) {
                ZipEntry entry = entries.nextElement();
                String name = entry.getName();
                currentName = name;
                if (name.endsWith(CLASS_EXTENSION) && shouldScan(name)) {
                    DirectClassFile classFile;
                    try {
                        classFile = path.getClass(name);
                    } catch (FileNotFoundException e) {
                        throw new IOException("Class " + name + " is missing form original class path " + path, e);
                    }
                    //                        System.out.println("=====classname:" + name);
                    addDependencies(classFile.getConstantPool());
                }
            }
        }
    }
}
Also used : DirectClassFile(com.android.dx.cf.direct.DirectClassFile) ZipEntry(java.util.zip.ZipEntry) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException)

Example 12 with DirectClassFile

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

the class ClassReferenceListBuilder method addClassWithHierachy.

private void addClassWithHierachy(String classBinaryName) {
    if (classNames.contains(classBinaryName) || !refcname.equals(classBinaryName + CLASS_EXTENSION)) {
        return;
    }
    try {
        DirectClassFile classFile = path.getClass(currentName);
        classNames.add(currentName);
        File entryFile = new File(patchDir + "/" + currentName);
        entryFile.getParentFile().mkdirs();
        if (!entryFile.exists()) {
            entryFile.createNewFile();
            //                Iterable<ClassPathElement> elements = path.getElements();
            //                for (ClassPathElement element : elements) {
            //                    InputStream in = element.open(currentName);
            byte[] bytes = NuwaProcessor.referHackWhenInit(classFile.getBytes().makeDataInputStream());
            //                    System.out.println(classFile.getFilePath() + ",size:" + bytes.length);
            FileUtils.writeByteArrayToFile(entryFile, bytes);
        //                }
        }
        //            NuwaProcessor.referHackWhenInit();
        CstType superClass = classFile.getSuperclass();
        if (superClass != null) {
            addClassWithHierachy(superClass.getClassType().getClassName());
        }
        TypeList interfaceList = classFile.getInterfaces();
        int interfaceNumber = interfaceList.size();
        for (int i = 0; i < interfaceNumber; i++) {
            addClassWithHierachy(interfaceList.getType(i).getClassName());
        }
    } catch (FileNotFoundException e) {
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : DirectClassFile(com.android.dx.cf.direct.DirectClassFile) CstType(com.android.dx.rop.cst.CstType) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) File(java.io.File) DirectClassFile(com.android.dx.cf.direct.DirectClassFile) StdTypeList(com.android.dx.rop.type.StdTypeList) TypeList(com.android.dx.rop.type.TypeList)

Example 13 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 14 with DirectClassFile

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

the class ClassReferenceListBuilder method addClassWithHierarchy.

private void addClassWithHierarchy(String classBinaryName) {
    if (classNames.contains(classBinaryName)) {
        return;
    }
    try {
        DirectClassFile classFile = path.getClass(classBinaryName + CLASS_EXTENSION);
        if (CLASS_TO_CHECK != null && classBinaryName.contains(CLASS_TO_CHECK)) {
            found();
        }
        classNames.add(classBinaryName);
        CstType superClass = classFile.getSuperclass();
        if (superClass != null) {
            addClassWithHierarchy(superClass.getClassType().getClassName());
        }
        TypeList interfaceList = classFile.getInterfaces();
        int interfaceNumber = interfaceList.size();
        for (int i = 0; i < interfaceNumber; i++) {
            addClassWithHierarchy(interfaceList.getType(i).getClassName());
        }
    } catch (FileNotFoundException e) {
    // Ignore: The referenced type is not in the path it must be part of the libraries.
    }
}
Also used : DirectClassFile(com.android.dx.cf.direct.DirectClassFile) CstType(com.android.dx.rop.cst.CstType) FileNotFoundException(java.io.FileNotFoundException) StdTypeList(com.android.dx.rop.type.StdTypeList) TypeList(com.android.dx.rop.type.TypeList)

Example 15 with DirectClassFile

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

the class AnnotationLister method process.

/** Processes based on configuration specified in constructor. */
void process() {
    for (String path : args.files) {
        ClassPathOpener opener;
        opener = new ClassPathOpener(path, true, new ClassPathOpener.Consumer() {

            public boolean processFileBytes(String name, long lastModified, byte[] bytes) {
                if (!name.endsWith(".class")) {
                    return true;
                }
                ByteArray ba = new ByteArray(bytes);
                DirectClassFile cf = new DirectClassFile(ba, name, true);
                cf.setAttributeFactory(StdAttributeFactory.THE_ONE);
                AttributeList attributes = cf.getAttributes();
                Attribute att;
                String cfClassName = cf.getThisClass().getClassType().getClassName();
                if (cfClassName.endsWith(PACKAGE_INFO)) {
                    att = attributes.findFirst(AttRuntimeInvisibleAnnotations.ATTRIBUTE_NAME);
                    for (; att != null; att = attributes.findNext(att)) {
                        BaseAnnotations ann = (BaseAnnotations) att;
                        visitPackageAnnotation(cf, ann);
                    }
                    att = attributes.findFirst(AttRuntimeVisibleAnnotations.ATTRIBUTE_NAME);
                    for (; att != null; att = attributes.findNext(att)) {
                        BaseAnnotations ann = (BaseAnnotations) att;
                        visitPackageAnnotation(cf, ann);
                    }
                } else if (isMatchingInnerClass(cfClassName) || isMatchingPackage(cfClassName)) {
                    printMatch(cf);
                } else {
                    att = attributes.findFirst(AttRuntimeInvisibleAnnotations.ATTRIBUTE_NAME);
                    for (; att != null; att = attributes.findNext(att)) {
                        BaseAnnotations ann = (BaseAnnotations) att;
                        visitClassAnnotation(cf, ann);
                    }
                    att = attributes.findFirst(AttRuntimeVisibleAnnotations.ATTRIBUTE_NAME);
                    for (; att != null; att = attributes.findNext(att)) {
                        BaseAnnotations ann = (BaseAnnotations) att;
                        visitClassAnnotation(cf, ann);
                    }
                }
                return true;
            }

            public void onException(Exception ex) {
                throw new RuntimeException(ex);
            }

            public void onProcessArchiveStart(File file) {
            }
        });
        opener.process();
    }
}
Also used : ClassPathOpener(com.android.dx.cf.direct.ClassPathOpener) DirectClassFile(com.android.dx.cf.direct.DirectClassFile) Attribute(com.android.dx.cf.iface.Attribute) AttributeList(com.android.dx.cf.iface.AttributeList) BaseAnnotations(com.android.dx.cf.attrib.BaseAnnotations) ByteArray(com.android.dx.util.ByteArray) File(java.io.File) DirectClassFile(com.android.dx.cf.direct.DirectClassFile)

Aggregations

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