Search in sources :

Example 11 with ClassDef

use of org.jf.dexlib2.iface.ClassDef in project atlas by alibaba.

the class PatchUtils method getBundleClassDef.

private static Map<String, ClassDef> getBundleClassDef(File file) throws IOException {
    HashMap<String, ClassDef> classDefMap = new HashMap<String, ClassDef>();
    File[] dexFiles = getDexFiles(file);
    HashSet<ClassDef> classDefs = new HashSet<ClassDef>();
    for (File dexFile : dexFiles) {
        classDefs.addAll(DexFileFactory.loadDexFile(dexFile, 19, true).getClasses());
    }
    for (ClassDef classDef : classDefs) {
        classDefMap.put(classDef.getType(), classDef);
    }
    return classDefMap;
}
Also used : ClassDef(org.jf.dexlib2.iface.ClassDef) HashMap(java.util.HashMap) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) HashSet(java.util.HashSet)

Example 12 with ClassDef

use of org.jf.dexlib2.iface.ClassDef in project atlas by alibaba.

the class PatchUtils method getTpatchClassDef.

public static void getTpatchClassDef(File tpatchFile, Map<String, Map<String, ClassDef>> bundleMap) throws IOException {
    if (tpatchFile == null || !tpatchFile.exists()) {
        return;
    }
    File unZipFolder = new File(tpatchFile.getParentFile(), tpatchFile.getName().split("\\.")[0]);
    unZipFolder.mkdirs();
    ZipUtils.unzip(tpatchFile, unZipFolder.getAbsolutePath());
    File[] bundleFolder = unZipFolder.listFiles(new FileFilter() {

        @Override
        public boolean accept(File pathname) {
            return pathname.isDirectory() && pathname.getName().startsWith("lib");
        }
    });
    for (File file : bundleFolder) {
        Map<String, ClassDef> dexClasses = getBundleClassDef(file);
        bundleMap.put(file.getName(), dexClasses);
    }
    FileUtils.deleteDirectory(tpatchFile.getParentFile());
}
Also used : ClassDef(org.jf.dexlib2.iface.ClassDef) FileFilter(java.io.FileFilter) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File)

Example 13 with ClassDef

use of org.jf.dexlib2.iface.ClassDef in project atlas by alibaba.

the class SmaliCodeUtils method createBaksmaliOptions.

/**
     * 生成解析成smali代码的选项
     *
     * @return
     */
private static baksmaliOptions createBaksmaliOptions(ClassDef classDef) {
    baksmaliOptions options = new baksmaliOptions();
    options.deodex = false;
    options.noParameterRegisters = false;
    options.useLocalsDirective = true;
    options.useSequentialLabels = true;
    options.outputDebugInfo = true;
    options.addCodeOffsets = false;
    options.jobs = -1;
    options.noAccessorComments = false;
    // 128
    options.registerInfo = 0;
    options.ignoreErrors = false;
    options.inlineResolver = null;
    options.checkPackagePrivateAccess = false;
    options.apiLevel = DEFAULT_API_LEVEL;
    List<ClassDef> classDefs = Lists.newArrayList();
    classDefs.add(classDef);
    options.syntheticAccessorResolver = new SyntheticAccessorResolver(classDefs);
    return options;
}
Also used : org.jf.baksmali.baksmaliOptions(org.jf.baksmali.baksmaliOptions) ClassDef(org.jf.dexlib2.iface.ClassDef) SyntheticAccessorResolver(org.jf.dexlib2.util.SyntheticAccessorResolver)

Example 14 with ClassDef

use of org.jf.dexlib2.iface.ClassDef in project android-classyshark by google.

the class StressTest method runAllClassesInDex.

public static void runAllClassesInDex(String jarCanonicalPath) throws Exception {
    DexFile dexFile = DexlibLoader.loadDexFile(new File(jarCanonicalPath));
    Set<? extends ClassDef> allClassesInDex = dexFile.getClasses();
    for (ClassDef currentClass : allClassesInDex) {
        String normType = DexlibAdapter.getClassStringFromDex(currentClass.getType());
        Translator sourceGenerator = TranslatorFactory.createTranslator(normType, new File(jarCanonicalPath));
        sourceGenerator.apply();
        System.out.println(sourceGenerator.toString());
    }
}
Also used : ClassDef(org.jf.dexlib2.iface.ClassDef) Translator(com.google.classyshark.silverghost.translator.Translator) DexFile(org.jf.dexlib2.iface.DexFile) File(java.io.File) DexFile(org.jf.dexlib2.iface.DexFile)

Example 15 with ClassDef

use of org.jf.dexlib2.iface.ClassDef in project android-classyshark by google.

the class DexlibAdapter method getClassDefByName.

public static ClassDef getClassDefByName(String className, DexFile dexFile) throws Exception {
    ClassDef result = null;
    String dexName;
    for (ClassDef currentClassDef : dexFile.getClasses()) {
        dexName = currentClassDef.getType();
        if (isMatchFromDex(className, dexName)) {
            result = currentClassDef;
            break;
        }
    }
    return result;
}
Also used : ClassDef(org.jf.dexlib2.iface.ClassDef)

Aggregations

ClassDef (org.jf.dexlib2.iface.ClassDef)47 DexFile (org.jf.dexlib2.iface.DexFile)23 Test (org.junit.Test)21 Method (org.jf.dexlib2.iface.Method)18 DexBackedClassDef (org.jf.dexlib2.dexbacked.DexBackedClassDef)15 ImmutableClassDef (org.jf.dexlib2.immutable.ImmutableClassDef)14 ImmutableDexFile (org.jf.dexlib2.immutable.ImmutableDexFile)14 MethodImplementation (org.jf.dexlib2.iface.MethodImplementation)13 ImmutableMethod (org.jf.dexlib2.immutable.ImmutableMethod)12 IndentingWriter (org.jf.util.IndentingWriter)11 File (java.io.File)10 IOException (java.io.IOException)10 HashSet (java.util.HashSet)8 DexBackedDexFile (org.jf.dexlib2.dexbacked.DexBackedDexFile)8 Instruction (org.jf.dexlib2.iface.instruction.Instruction)8 Nonnull (javax.annotation.Nonnull)7 MethodImplementationBuilder (org.jf.dexlib2.builder.MethodImplementationBuilder)7 BuilderInstruction10x (org.jf.dexlib2.builder.instruction.BuilderInstruction10x)7 ImmutableMethodParameter (org.jf.dexlib2.immutable.ImmutableMethodParameter)7 MethodReference (org.jf.dexlib2.iface.reference.MethodReference)6