Search in sources :

Example 1 with MetaObjectClass

use of com.google.classyshark.silverghost.translator.java.clazz.reflect.MetaObjectClass in project android-classyshark by google.

the class MetaObjectFactory method getMetaObjectFromAar.

private static MetaObject getMetaObjectFromAar(String className, File archiveFile) {
    try {
        File file = File.createTempFile("classes", "jar");
        file.deleteOnExit();
        OutputStream out = new FileOutputStream(file);
        FileInputStream fin = new FileInputStream(archiveFile);
        BufferedInputStream bin = new BufferedInputStream(fin);
        ZipInputStream zin = new ZipInputStream(bin);
        ZipEntry ze;
        while ((ze = zin.getNextEntry()) != null) {
            if (ze.getName().endsWith(".jar")) {
                byte[] buffer = new byte[8192];
                int len;
                while ((len = zin.read(buffer)) != -1) {
                    out.write(buffer, 0, len);
                }
                out.close();
                MetaObject result = getMetaObjectFromJar(className, file);
                return result;
            }
        }
    } catch (Exception e) {
    }
    return new MetaObjectClass(Exception.class);
}
Also used : ZipInputStream(java.util.zip.ZipInputStream) BufferedInputStream(java.io.BufferedInputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) ZipEntry(java.util.zip.ZipEntry) File(java.io.File) DexFile(org.jf.dexlib2.iface.DexFile) MetaObjectClass(com.google.classyshark.silverghost.translator.java.clazz.reflect.MetaObjectClass) FileInputStream(java.io.FileInputStream) MalformedURLException(java.net.MalformedURLException)

Example 2 with MetaObjectClass

use of com.google.classyshark.silverghost.translator.java.clazz.reflect.MetaObjectClass in project android-classyshark by google.

the class MetaObjectFactory method getMetaObjectFromApk.

private static MetaObject getMetaObjectFromApk(String className, File apk) {
    MetaObject result;
    try {
        File classesDexWithClass = MultidexReader.extractClassesDexWithClass(className, apk);
        result = getMetaObjectFromDex(className, classesDexWithClass);
    } catch (Exception e) {
        result = new MetaObjectClass(Exception.class);
    }
    return result;
}
Also used : File(java.io.File) DexFile(org.jf.dexlib2.iface.DexFile) MetaObjectClass(com.google.classyshark.silverghost.translator.java.clazz.reflect.MetaObjectClass) MalformedURLException(java.net.MalformedURLException)

Example 3 with MetaObjectClass

use of com.google.classyshark.silverghost.translator.java.clazz.reflect.MetaObjectClass in project android-classyshark by google.

the class MetaObjectFactory method getMetaObjectFromDex.

private static MetaObject getMetaObjectFromDex(String className, File archiveFile) {
    MetaObject result;
    try {
        DexFile dexFile = DexlibLoader.loadDexFile(archiveFile);
        ClassDef classDef = DexlibAdapter.getClassDefByName(className, dexFile);
        result = new MetaObjectDex(classDef);
    } catch (Exception e) {
        result = new MetaObjectClass(Exception.class);
    }
    return result;
}
Also used : ClassDef(org.jf.dexlib2.iface.ClassDef) MetaObjectClass(com.google.classyshark.silverghost.translator.java.clazz.reflect.MetaObjectClass) DexFile(org.jf.dexlib2.iface.DexFile) MalformedURLException(java.net.MalformedURLException) MetaObjectDex(com.google.classyshark.silverghost.translator.java.dex.MetaObjectDex)

Aggregations

MetaObjectClass (com.google.classyshark.silverghost.translator.java.clazz.reflect.MetaObjectClass)3 MalformedURLException (java.net.MalformedURLException)3 DexFile (org.jf.dexlib2.iface.DexFile)3 File (java.io.File)2 MetaObjectDex (com.google.classyshark.silverghost.translator.java.dex.MetaObjectDex)1 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 OutputStream (java.io.OutputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipInputStream (java.util.zip.ZipInputStream)1 ClassDef (org.jf.dexlib2.iface.ClassDef)1