Search in sources :

Example 6 with JadxDecompiler

use of jadx.api.JadxDecompiler in project bytecode-viewer by Konloch.

the class JADXDecompiler method decompileClassNode.

@Override
public String decompileClassNode(ClassNode cn, byte[] b) {
    String fileStart = tempDirectory + fs;
    String exception = "";
    final File tempClass = new File(MiscUtils.getUniqueName(fileStart, ".class") + ".class");
    try (FileOutputStream fos = new FileOutputStream(tempClass)) {
        fos.write(b);
    } catch (final IOException e) {
        BytecodeViewer.handleException(e);
    }
    File fuckery = new File(fuckery(fileStart));
    fuckery.mkdirs();
    try {
        JadxArgs args = new JadxArgs();
        args.setInputFile(tempClass);
        args.setOutDir(fuckery);
        args.setOutDirSrc(fuckery);
        args.setOutDirRes(fuckery);
        JadxDecompiler jadx = new JadxDecompiler(args);
        jadx.load();
        jadx.saveSources();
    } catch (StackOverflowError | Exception e) {
        StringWriter exceptionWriter = new StringWriter();
        e.printStackTrace(new PrintWriter(exceptionWriter));
        e.printStackTrace();
        exception = exceptionWriter.toString();
    }
    tempClass.delete();
    if (fuckery.exists())
        return findFile(MiscUtils.listFiles(fuckery));
    if (exception.isEmpty())
        exception = "Decompiled source file not found!";
    return JADX + " " + ERROR + "! " + ExceptionUI.SEND_STACKTRACE_TO + nl + nl + TranslatedStrings.SUGGESTED_FIX_DECOMPILER_ERROR + nl + nl + exception;
}
Also used : JadxDecompiler(jadx.api.JadxDecompiler) StringWriter(java.io.StringWriter) FileOutputStream(java.io.FileOutputStream) JadxArgs(jadx.api.JadxArgs) IOException(java.io.IOException) File(java.io.File) IOException(java.io.IOException) PrintWriter(java.io.PrintWriter)

Example 7 with JadxDecompiler

use of jadx.api.JadxDecompiler in project jadx by skylot.

the class JSourcesTest method init.

@BeforeEach
public void init() {
    JRoot root = mock(JRoot.class);
    when(root.isFlatPackages()).thenReturn(false);
    JadxWrapper wrapper = mock(JadxWrapper.class);
    sources = new JSources(root, wrapper);
    decompiler = new JadxDecompiler(new JadxArgs());
}
Also used : JadxWrapper(jadx.gui.JadxWrapper) JadxDecompiler(jadx.api.JadxDecompiler) JadxArgs(jadx.api.JadxArgs) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 8 with JadxDecompiler

use of jadx.api.JadxDecompiler in project jadx by skylot.

the class ExportTask method scheduleJobs.

@Override
public List<Runnable> scheduleJobs() {
    wrapCodeCache();
    JadxDecompiler decompiler = wrapper.getDecompiler();
    decompiler.getArgs().setRootDir(saveDir);
    List<Runnable> saveTasks = decompiler.getSaveTasks();
    this.timeLimit = DecompileTask.calcDecompileTimeLimit(saveTasks.size());
    return saveTasks;
}
Also used : JadxDecompiler(jadx.api.JadxDecompiler)

Example 9 with JadxDecompiler

use of jadx.api.JadxDecompiler in project jadx by skylot.

the class JadxCLI method processAndSave.

private static int processAndSave(JadxCLIArgs cliArgs) {
    LogHelper.initLogLevel(cliArgs);
    LogHelper.setLogLevelsForLoadingStage();
    JadxArgs jadxArgs = cliArgs.toJadxArgs();
    jadxArgs.setCodeCache(new NoOpCodeCache());
    jadxArgs.setCodeWriterProvider(SimpleCodeWriter::new);
    try (JadxDecompiler jadx = new JadxDecompiler(jadxArgs)) {
        jadx.load();
        if (checkForErrors(jadx)) {
            return 1;
        }
        LogHelper.setLogLevelsForDecompileStage();
        if (!SingleClassMode.process(jadx, cliArgs)) {
            save(jadx);
        }
        int errorsCount = jadx.getErrorsCount();
        if (errorsCount != 0) {
            jadx.printErrorsReport();
            LOG.error("finished with errors, count: {}", errorsCount);
        } else {
            LOG.info("done");
        }
    }
    return 0;
}
Also used : JadxDecompiler(jadx.api.JadxDecompiler) SimpleCodeWriter(jadx.api.impl.SimpleCodeWriter) JadxArgs(jadx.api.JadxArgs) NoOpCodeCache(jadx.api.impl.NoOpCodeCache)

Example 10 with JadxDecompiler

use of jadx.api.JadxDecompiler in project jadx by skylot.

the class BaseExternalTest method decompile.

protected JadxDecompiler decompile(JadxArgs jadxArgs, @Nullable String clsPatternStr, @Nullable String mthPatternStr) {
    JadxDecompiler jadx = new JadxDecompiler(jadxArgs);
    jadx.load();
    if (clsPatternStr == null) {
        jadx.save();
    } else {
        processByPatterns(jadx, clsPatternStr, mthPatternStr);
    }
    printErrorReport(jadx);
    return jadx;
}
Also used : JadxDecompiler(jadx.api.JadxDecompiler)

Aggregations

JadxDecompiler (jadx.api.JadxDecompiler)12 JadxArgs (jadx.api.JadxArgs)4 ClassNode (jadx.core.dex.nodes.ClassNode)4 File (java.io.File)4 IOException (java.io.IOException)4 RootNode (jadx.core.dex.nodes.RootNode)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 IAttributeNode (jadx.core.dex.attributes.IAttributeNode)2 MethodNode (jadx.core.dex.nodes.MethodNode)2 ProcessState (jadx.core.dex.nodes.ProcessState)2 ErrorsCounter (jadx.core.utils.ErrorsCounter)2 Utils (jadx.core.utils.Utils)2 JadxRuntimeException (jadx.core.utils.exceptions.JadxRuntimeException)2 JClass (jadx.gui.treemodel.JClass)2 JNode (jadx.gui.treemodel.JNode)2 MainWindow (jadx.gui.ui.MainWindow)2 TabbedPane (jadx.gui.ui.TabbedPane)2 ContentPanel (jadx.gui.ui.panel.ContentPanel)2 HtmlPanel (jadx.gui.ui.panel.HtmlPanel)2