Search in sources :

Example 1 with ILoadResult

use of jadx.api.plugins.input.data.ILoadResult in project jadx by skylot.

the class DexInputPluginTest method processFile.

private static void processFile(Path sample) throws IOException {
    System.out.println("Input file: " + sample.toAbsolutePath());
    long start = System.currentTimeMillis();
    List<Path> files = Collections.singletonList(sample);
    try (ILoadResult result = new DexInputPlugin().loadFiles(files)) {
        AtomicInteger count = new AtomicInteger();
        result.visitClasses(cls -> {
            System.out.println();
            System.out.println("Class: " + cls.getType());
            System.out.println("AccessFlags: " + AccessFlags.format(cls.getAccessFlags(), AccessFlagsScope.CLASS));
            System.out.println("SuperType: " + cls.getSuperType());
            System.out.println("Interfaces: " + cls.getInterfacesTypes());
            System.out.println("Attributes: " + cls.getAttributes());
            count.getAndIncrement();
            cls.visitFieldsAndMethods(System.out::println, mth -> {
                System.out.println("---");
                System.out.println(mth);
                ICodeReader codeReader = mth.getCodeReader();
                if (codeReader != null) {
                    codeReader.visitInstructions(insn -> {
                        insn.decode();
                        System.out.println(insn);
                    });
                }
                System.out.println("---");
                System.out.println(mth.disassembleMethod());
                System.out.println("---");
            });
            System.out.println("----");
            System.out.println(cls.getDisassembledCode());
            System.out.println("----");
        });
        assertThat(count.get()).isGreaterThan(0);
    }
    System.out.println("Time: " + (System.currentTimeMillis() - start) + "ms");
}
Also used : Path(java.nio.file.Path) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ILoadResult(jadx.api.plugins.input.data.ILoadResult) ICodeReader(jadx.api.plugins.input.data.ICodeReader)

Example 2 with ILoadResult

use of jadx.api.plugins.input.data.ILoadResult in project jadx by skylot.

the class JadxDecompiler method loadInputFiles.

private void loadInputFiles() {
    loadedInputs.clear();
    List<Path> inputPaths = Utils.collectionMap(args.getInputFiles(), File::toPath);
    List<Path> inputFiles = FileUtils.expandDirs(inputPaths);
    long start = System.currentTimeMillis();
    for (JadxInputPlugin inputPlugin : pluginManager.getInputPlugins()) {
        ILoadResult loadResult = inputPlugin.loadFiles(inputFiles);
        if (loadResult != null && !loadResult.isEmpty()) {
            loadedInputs.add(loadResult);
        }
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Loaded using {} inputs plugin in {} ms", loadedInputs.size(), System.currentTimeMillis() - start);
    }
}
Also used : Path(java.nio.file.Path) ILoadResult(jadx.api.plugins.input.data.ILoadResult) JadxInputPlugin(jadx.api.plugins.input.JadxInputPlugin) File(java.io.File)

Example 3 with ILoadResult

use of jadx.api.plugins.input.data.ILoadResult in project jadx by skylot.

the class ConvertToClsSet method main.

public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        usage();
        System.exit(1);
    }
    List<Path> inputPaths = Stream.of(args).map(Paths::get).collect(Collectors.toList());
    Path output = inputPaths.remove(0);
    JadxPluginManager pluginManager = new JadxPluginManager();
    pluginManager.load();
    List<ILoadResult> loadedInputs = new ArrayList<>();
    for (JadxInputPlugin inputPlugin : pluginManager.getInputPlugins()) {
        loadedInputs.add(inputPlugin.loadFiles(inputPaths));
    }
    JadxArgs jadxArgs = new JadxArgs();
    jadxArgs.setRenameFlags(EnumSet.noneOf(JadxArgs.RenameEnum.class));
    RootNode root = new RootNode(jadxArgs);
    root.loadClasses(loadedInputs);
    // from pre-decompilation stage run only SignatureProcessor
    SignatureProcessor signatureProcessor = new SignatureProcessor();
    signatureProcessor.init(root);
    for (ClassNode classNode : root.getClasses()) {
        signatureProcessor.visit(classNode);
    }
    ClsSet set = new ClsSet(root);
    set.loadFrom(root);
    set.save(output);
    LOG.info("Output: {}", output);
    LOG.info("done");
}
Also used : Path(java.nio.file.Path) RootNode(jadx.core.dex.nodes.RootNode) ClassNode(jadx.core.dex.nodes.ClassNode) ClsSet(jadx.core.clsp.ClsSet) ILoadResult(jadx.api.plugins.input.data.ILoadResult) ArrayList(java.util.ArrayList) SignatureProcessor(jadx.core.dex.visitors.SignatureProcessor) JadxPluginManager(jadx.api.plugins.JadxPluginManager) JadxArgs(jadx.api.JadxArgs) JadxInputPlugin(jadx.api.plugins.input.JadxInputPlugin)

Example 4 with ILoadResult

use of jadx.api.plugins.input.data.ILoadResult in project jadx by skylot.

the class RootNode method loadClasses.

public void loadClasses(List<ILoadResult> loadedInputs) {
    for (ILoadResult loadedInput : loadedInputs) {
        loadedInput.visitClasses(cls -> {
            try {
                addClassNode(new ClassNode(RootNode.this, cls));
            } catch (Exception e) {
                addDummyClass(cls, e);
            }
            Utils.checkThreadInterrupt();
        });
    }
    if (classes.size() != clsMap.size()) {
        // class name duplication detected
        markDuplicatedClasses(classes);
    }
    classes = new ArrayList<>(clsMap.values());
    // print stats for loaded classes
    int mthCount = classes.stream().mapToInt(c -> c.getMethods().size()).sum();
    int insnsCount = classes.stream().flatMap(c -> c.getMethods().stream()).mapToInt(MethodNode::getInsnsCount).sum();
    LOG.info("Loaded classes: {}, methods: {}, instructions: {}", classes.size(), mthCount, insnsCount);
    // sort classes by name, expect top classes before inner
    classes.sort(Comparator.comparing(ClassNode::getFullName));
    // move inner classes
    initInnerClasses();
}
Also used : ArgType(jadx.core.dex.instructions.args.ArgType) IDexTreeVisitor(jadx.core.dex.visitors.IDexTreeVisitor) CacheStorage(jadx.core.utils.CacheStorage) LoggerFactory(org.slf4j.LoggerFactory) ResourceEntry(jadx.core.xmlgen.entry.ResourceEntry) HashMap(java.util.HashMap) TypeUtils(jadx.core.dex.nodes.utils.TypeUtils) ClassInfo(jadx.core.dex.info.ClassInfo) FieldInfo(jadx.core.dex.info.FieldInfo) ICodeCache(jadx.api.ICodeCache) ClspGraph(jadx.core.clsp.ClspGraph) ArrayList(java.util.ArrayList) ResourcesLoader(jadx.api.ResourcesLoader) ValuesParser(jadx.core.xmlgen.entry.ValuesParser) ErrorsCounter(jadx.core.utils.ErrorsCounter) Map(java.util.Map) IClassData(jadx.api.plugins.input.data.IClassData) ResourceType(jadx.api.ResourceType) InfoStorage(jadx.core.dex.info.InfoStorage) Jadx(jadx.core.Jadx) ResourceFile(jadx.api.ResourceFile) Logger(org.slf4j.Logger) ResourceStorage(jadx.core.xmlgen.ResourceStorage) DepthTraversal(jadx.core.dex.visitors.DepthTraversal) StringUtils(jadx.core.utils.StringUtils) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException) ILoadResult(jadx.api.plugins.input.data.ILoadResult) Collectors(java.util.stream.Collectors) MethodUtils(jadx.core.dex.nodes.utils.MethodUtils) ICodeData(jadx.api.data.ICodeData) MethodInfo(jadx.core.dex.info.MethodInfo) TypeUpdate(jadx.core.dex.visitors.typeinference.TypeUpdate) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) JadxArgs(jadx.api.JadxArgs) ConstStorage(jadx.core.dex.info.ConstStorage) ResTableParser(jadx.core.xmlgen.ResTableParser) TypeCompare(jadx.core.dex.visitors.typeinference.TypeCompare) Comparator(java.util.Comparator) NotNull(org.jetbrains.annotations.NotNull) AndroidResourcesUtils(jadx.core.utils.android.AndroidResourcesUtils) ICodeWriter(jadx.api.ICodeWriter) Utils(jadx.core.utils.Utils) ILoadResult(jadx.api.plugins.input.data.ILoadResult) JadxRuntimeException(jadx.core.utils.exceptions.JadxRuntimeException)

Aggregations

ILoadResult (jadx.api.plugins.input.data.ILoadResult)4 Path (java.nio.file.Path)3 JadxArgs (jadx.api.JadxArgs)2 JadxInputPlugin (jadx.api.plugins.input.JadxInputPlugin)2 ArrayList (java.util.ArrayList)2 ICodeCache (jadx.api.ICodeCache)1 ICodeWriter (jadx.api.ICodeWriter)1 ResourceFile (jadx.api.ResourceFile)1 ResourceType (jadx.api.ResourceType)1 ResourcesLoader (jadx.api.ResourcesLoader)1 ICodeData (jadx.api.data.ICodeData)1 JadxPluginManager (jadx.api.plugins.JadxPluginManager)1 IClassData (jadx.api.plugins.input.data.IClassData)1 ICodeReader (jadx.api.plugins.input.data.ICodeReader)1 Jadx (jadx.core.Jadx)1 ClsSet (jadx.core.clsp.ClsSet)1 ClspGraph (jadx.core.clsp.ClspGraph)1 ClassInfo (jadx.core.dex.info.ClassInfo)1 ConstStorage (jadx.core.dex.info.ConstStorage)1 FieldInfo (jadx.core.dex.info.FieldInfo)1