Search in sources :

Example 1 with IDexTreeVisitor

use of jadx.core.dex.visitors.IDexTreeVisitor in project jadx by skylot.

the class Jadx method getPassesList.

public static List<IDexTreeVisitor> getPassesList(IJadxArgs args, File outDir) {
    List<IDexTreeVisitor> passes = new ArrayList<IDexTreeVisitor>();
    if (args.isFallbackMode()) {
        passes.add(new FallbackModeVisitor());
    } else {
        passes.add(new BlockSplitter());
        passes.add(new BlockProcessor());
        passes.add(new BlockExceptionHandler());
        passes.add(new BlockFinallyExtract());
        passes.add(new BlockFinish());
        passes.add(new SSATransform());
        passes.add(new DebugInfoVisitor());
        passes.add(new TypeInference());
        if (args.isRawCFGOutput()) {
            passes.add(DotGraphVisitor.dumpRaw(outDir));
        }
        passes.add(new ConstInlineVisitor());
        passes.add(new FinishTypeInference());
        passes.add(new EliminatePhiNodes());
        passes.add(new ModVisitor());
        passes.add(new CodeShrinker());
        passes.add(new ReSugarCode());
        if (args.isCFGOutput()) {
            passes.add(DotGraphVisitor.dump(outDir));
        }
        passes.add(new RegionMakerVisitor());
        passes.add(new IfRegionVisitor());
        passes.add(new ReturnVisitor());
        passes.add(new CodeShrinker());
        passes.add(new SimplifyVisitor());
        passes.add(new CheckRegions());
        if (args.isCFGOutput()) {
            passes.add(DotGraphVisitor.dumpRegions(outDir));
        }
        passes.add(new MethodInlineVisitor());
        passes.add(new ExtractFieldInit());
        passes.add(new ClassModifier());
        passes.add(new EnumVisitor());
        passes.add(new PrepareForCodeGen());
        passes.add(new LoopRegionVisitor());
        passes.add(new ProcessVariables());
        passes.add(new DependencyCollector());
        passes.add(new RenameVisitor());
    }
    return passes;
}
Also used : RegionMakerVisitor(jadx.core.dex.visitors.regions.RegionMakerVisitor) BlockExceptionHandler(jadx.core.dex.visitors.blocksmaker.BlockExceptionHandler) IfRegionVisitor(jadx.core.dex.visitors.regions.IfRegionVisitor) ClassModifier(jadx.core.dex.visitors.ClassModifier) CodeShrinker(jadx.core.dex.visitors.CodeShrinker) ArrayList(java.util.ArrayList) IDexTreeVisitor(jadx.core.dex.visitors.IDexTreeVisitor) ProcessVariables(jadx.core.dex.visitors.regions.ProcessVariables) TypeInference(jadx.core.dex.visitors.typeinference.TypeInference) FinishTypeInference(jadx.core.dex.visitors.typeinference.FinishTypeInference) ReSugarCode(jadx.core.dex.visitors.ReSugarCode) BlockFinallyExtract(jadx.core.dex.visitors.blocksmaker.BlockFinallyExtract) RenameVisitor(jadx.core.dex.visitors.RenameVisitor) CheckRegions(jadx.core.dex.visitors.regions.CheckRegions) DependencyCollector(jadx.core.dex.visitors.DependencyCollector) SSATransform(jadx.core.dex.visitors.ssa.SSATransform) PrepareForCodeGen(jadx.core.dex.visitors.PrepareForCodeGen) DebugInfoVisitor(jadx.core.dex.visitors.DebugInfoVisitor) ExtractFieldInit(jadx.core.dex.visitors.ExtractFieldInit) EnumVisitor(jadx.core.dex.visitors.EnumVisitor) FallbackModeVisitor(jadx.core.dex.visitors.FallbackModeVisitor) ModVisitor(jadx.core.dex.visitors.ModVisitor) SimplifyVisitor(jadx.core.dex.visitors.SimplifyVisitor) MethodInlineVisitor(jadx.core.dex.visitors.MethodInlineVisitor) EliminatePhiNodes(jadx.core.dex.visitors.ssa.EliminatePhiNodes) LoopRegionVisitor(jadx.core.dex.visitors.regions.LoopRegionVisitor) BlockProcessor(jadx.core.dex.visitors.blocksmaker.BlockProcessor) FinishTypeInference(jadx.core.dex.visitors.typeinference.FinishTypeInference) ConstInlineVisitor(jadx.core.dex.visitors.ConstInlineVisitor) BlockFinish(jadx.core.dex.visitors.blocksmaker.BlockFinish) ReturnVisitor(jadx.core.dex.visitors.regions.ReturnVisitor) BlockSplitter(jadx.core.dex.visitors.blocksmaker.BlockSplitter)

Example 2 with IDexTreeVisitor

use of jadx.core.dex.visitors.IDexTreeVisitor in project jadx by skylot.

the class JadxVisitorsOrderTest method check.

private static List<String> check(List<IDexTreeVisitor> passes) {
    List<Class<?>> classList = new ArrayList<Class<?>>(passes.size());
    for (IDexTreeVisitor pass : passes) {
        classList.add(pass.getClass());
    }
    List<String> errors = new ArrayList<String>();
    Set<String> names = new HashSet<String>();
    for (int i = 0; i < passes.size(); i++) {
        IDexTreeVisitor pass = passes.get(i);
        JadxVisitor info = pass.getClass().getAnnotation(JadxVisitor.class);
        if (info == null) {
            LOG.warn("No JadxVisitor annotation for visitor: {}", pass.getClass().getName());
            continue;
        }
        String passName = pass.getClass().getSimpleName();
        if (!names.add(passName)) {
            errors.add("Visitor name conflict: " + passName + ", class: " + pass.getClass().getName());
        }
        for (Class<? extends IDexTreeVisitor> cls : info.runBefore()) {
            if (classList.indexOf(cls) < i) {
                errors.add("Pass " + passName + " must be before " + cls.getSimpleName());
            }
        }
        for (Class<? extends IDexTreeVisitor> cls : info.runAfter()) {
            if (classList.indexOf(cls) > i) {
                errors.add("Pass " + passName + " must be after " + cls.getSimpleName());
            }
        }
    }
    return errors;
}
Also used : IDexTreeVisitor(jadx.core.dex.visitors.IDexTreeVisitor) JadxVisitor(jadx.core.dex.visitors.JadxVisitor) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet)

Example 3 with IDexTreeVisitor

use of jadx.core.dex.visitors.IDexTreeVisitor in project jadx by skylot.

the class IntegrationTest method decompile.

private void decompile(JadxDecompiler jadx, ClassNode cls) {
    List<IDexTreeVisitor> passes = Jadx.getPassesList(jadx.getArgs(), new File(outDir));
    ProcessClass.process(cls, passes, new CodeGen(jadx.getArgs()));
}
Also used : IDexTreeVisitor(jadx.core.dex.visitors.IDexTreeVisitor) CodeGen(jadx.core.codegen.CodeGen) File(java.io.File)

Example 4 with IDexTreeVisitor

use of jadx.core.dex.visitors.IDexTreeVisitor in project jadx by skylot.

the class IntegrationTest method decompileWithoutUnload.

private void decompileWithoutUnload(JadxDecompiler d, ClassNode cls) {
    cls.load();
    List<IDexTreeVisitor> passes = Jadx.getPassesList(d.getArgs(), new File(outDir));
    for (IDexTreeVisitor visitor : passes) {
        DepthTraversal.visit(visitor, cls);
    }
    try {
        new CodeGen(d.getArgs()).visit(cls);
    } catch (CodegenException e) {
        e.printStackTrace();
        fail(e.getMessage());
    }
// don't unload class
}
Also used : IDexTreeVisitor(jadx.core.dex.visitors.IDexTreeVisitor) CodegenException(jadx.core.utils.exceptions.CodegenException) CodeGen(jadx.core.codegen.CodeGen) File(java.io.File)

Example 5 with IDexTreeVisitor

use of jadx.core.dex.visitors.IDexTreeVisitor in project jadx by skylot.

the class JadxVisitorsOrderTest method testOrder.

@Test
public void testOrder() {
    List<IDexTreeVisitor> passes = Jadx.getPassesList(new JadxArgs(), new File("out"));
    List<String> errors = check(passes);
    for (String str : errors) {
        LOG.error(str);
    }
    assertThat(errors, empty());
}
Also used : IDexTreeVisitor(jadx.core.dex.visitors.IDexTreeVisitor) JadxArgs(jadx.api.JadxArgs) File(java.io.File) Test(org.junit.Test)

Aggregations

IDexTreeVisitor (jadx.core.dex.visitors.IDexTreeVisitor)6 File (java.io.File)3 CodeGen (jadx.core.codegen.CodeGen)2 ArrayList (java.util.ArrayList)2 JadxArgs (jadx.api.JadxArgs)1 ClassModifier (jadx.core.dex.visitors.ClassModifier)1 CodeShrinker (jadx.core.dex.visitors.CodeShrinker)1 ConstInlineVisitor (jadx.core.dex.visitors.ConstInlineVisitor)1 DebugInfoVisitor (jadx.core.dex.visitors.DebugInfoVisitor)1 DependencyCollector (jadx.core.dex.visitors.DependencyCollector)1 EnumVisitor (jadx.core.dex.visitors.EnumVisitor)1 ExtractFieldInit (jadx.core.dex.visitors.ExtractFieldInit)1 FallbackModeVisitor (jadx.core.dex.visitors.FallbackModeVisitor)1 JadxVisitor (jadx.core.dex.visitors.JadxVisitor)1 MethodInlineVisitor (jadx.core.dex.visitors.MethodInlineVisitor)1 ModVisitor (jadx.core.dex.visitors.ModVisitor)1 PrepareForCodeGen (jadx.core.dex.visitors.PrepareForCodeGen)1 ReSugarCode (jadx.core.dex.visitors.ReSugarCode)1 RenameVisitor (jadx.core.dex.visitors.RenameVisitor)1 SimplifyVisitor (jadx.core.dex.visitors.SimplifyVisitor)1