public JadxArgs toJadxArgs() { JadxArgs args = new JadxArgs(); args.setInputFiles(files.stream().map(FileUtils::toFile).collect(Collectors.toList())); args.setOutDir(FileUtils.toFile(outDir)); args.setOutDirSrc(FileUtils.toFile(outDirSrc)); args.setOutDirRes(FileUtils.toFile(outDirRes)); args.setThreadsCount(threadsCount); args.setSkipSources(skipSources); args.setSkipResources(skipResources); args.setFallbackMode(fallbackMode); args.setShowInconsistentCode(showInconsistentCode); args.setCfgOutput(cfgOutput); args.setRawCFGOutput(rawCfgOutput); args.setReplaceConsts(replaceConsts); args.setDeobfuscationOn(deobfuscationOn); args.setDeobfuscationForceSave(deobfuscationForceSave); args.setDeobfuscationMinLength(deobfuscationMinLength); args.setDeobfuscationMaxLength(deobfuscationMaxLength); args.setUseSourceNameAsClassAlias(deobfuscationUseSourceNameAsAlias); args.setEscapeUnicode(escapeUnicode); args.setExportAsGradleProject(exportAsGradleProject); args.setUseImports(useImports); return args; }
@NotNull private static File makeDirFromInput(JadxArgs args) { File outDir; String outDirName; File file = args.getInputFiles().get(0); String name = file.getName(); int pos = name.lastIndexOf('.'); if (pos != -1) { outDirName = name.substring(0, pos); } else { outDirName = name + "-" + JadxArgs.DEFAULT_OUT_DIR; } LOG.info("output directory: {}", outDirName); outDir = new File(outDirName); return outDir; }
private static void setFromOut(JadxArgs args) { if (args.getOutDirSrc() == null) { args.setOutDirSrc(new File(args.getOutDir(), JadxArgs.DEFAULT_SRC_DIR)); } if (args.getOutDirRes() == null) { args.setOutDirRes(new File(args.getOutDir(), JadxArgs.DEFAULT_RES_DIR)); } }
public void setRootDir(File rootDir) { setOutDir(rootDir); setOutDirSrc(new File(rootDir, DEFAULT_SRC_DIR)); setOutDirRes(new File(rootDir, DEFAULT_RES_DIR)); }
public IntegrationTest() { args = new JadxArgs(); args.setOutDir(new File(outDir)); args.setShowInconsistentCode(true); args.setThreadsCount(1); args.setSkipResources(true); }
protected JadxArgs prepare(String inputFile) { JadxArgs args = new JadxArgs(); args.getInputFiles().add(new File(getSamplesDir(), inputFile)); args.setOutDir(new File("../jadx-external-tests-tmp")); return args; }
private static void validateOutDirs(JadxArgs args) { File outDir = args.getOutDir(); File srcDir = args.getOutDirSrc(); File resDir = args.getOutDirRes(); if (outDir == null) { if (srcDir != null) { outDir = srcDir; } else if (resDir != null) { outDir = resDir; } else { outDir = makeDirFromInput(args); } } args.setOutDir(outDir); setFromOut(args); checkDir(args.getOutDir()); checkDir(args.getOutDirSrc()); checkDir(args.getOutDirRes()); }
private ExecutorService getSaveExecutor(boolean saveSources, boolean saveResources) { if (root == null) { throw new JadxRuntimeException("No loaded files"); } int threadsCount = args.getThreadsCount(); LOG.debug("processing threads count: {}", threadsCount); LOG.info("processing ..."); ExecutorService executor = Executors.newFixedThreadPool(threadsCount); File sourcesOutDir; File resOutDir; if (args.isExportAsGradleProject()) { ExportGradleProject export = new ExportGradleProject(root, args.getOutDir()); export.init(); sourcesOutDir = export.getSrcOutDir(); resOutDir = export.getResOutDir(); } else { sourcesOutDir = args.getOutDirSrc(); resOutDir = args.getOutDirRes(); } if (saveResources) { appendResourcesSave(executor, resOutDir); } if (saveSources) { appendSourcesSave(executor, sourcesOutDir); } return executor; }
public JadxDecompiler() { this(new JadxArgs()); }
private void saveAll(boolean export) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setToolTipText(NLS.str("file.save_all_msg")); String currentDirectory = settings.getLastSaveFilePath(); if (!currentDirectory.isEmpty()) { fileChooser.setCurrentDirectory(new File(currentDirectory)); } int ret = fileChooser.showDialog(mainPanel, NLS.str("file.select")); if (ret == JFileChooser.APPROVE_OPTION) { JadxArgs decompilerArgs = wrapper.getArgs(); decompilerArgs.setExportAsGradleProject(export); if (export) { decompilerArgs.setSkipSources(false); decompilerArgs.setSkipResources(false); } else { decompilerArgs.setSkipSources(settings.isSkipSources()); decompilerArgs.setSkipResources(settings.isSkipResources()); } settings.setLastSaveFilePath(fileChooser.getCurrentDirectory().getPath()); ProgressMonitor progressMonitor = new ProgressMonitor(mainPanel, NLS.str("msg.saving_sources"), "", 0, 100); progressMonitor.setMillisToPopup(0); wrapper.saveAll(fileChooser.getSelectedFile(), progressMonitor); } }
private JadxArgs makeArgs() { JadxArgs args = new JadxArgs(); args.getInputFiles().add(FileUtils.createTempFile("some.apk")); return args; } }
private void checkOutDirs(String outDir, String srcDir, String resDir) { JadxArgsValidator.validate(args); LOG.debug("Got dirs: out={}, src={}, res={}", args.getOutDir(), args.getOutDirSrc(), args.getOutDirRes()); assertThat(args.getOutDir(), is(toFile(outDir))); assertThat(args.getOutDirSrc(), is(toFile(srcDir))); assertThat(args.getOutDirRes(), is(toFile(resDir))); }
public void openFile(File file) { this.openFile = file; try { this.decompiler = new JadxDecompiler(settings.toJadxArgs()); this.decompiler.getArgs().setInputFiles(Collections.singletonList(file)); this.decompiler.load(); } catch (Exception e) { LOG.error("Error load file: {}", file, e); } }
@Override public void visit(MethodNode mth) { if (mth.isNoCode()) { return; } File outRootDir = mth.root().getArgs().getOutDir(); new DumpDotGraph(outRootDir).process(mth); }
private void setOutDirs(String outDir, String srcDir, String resDir) { args = makeArgs(); args.setOutDir(toFile(outDir)); args.setOutDirSrc(toFile(srcDir)); args.setOutDirRes(toFile(resDir)); LOG.debug("Set dirs: out={}, src={}, res={}", outDir, srcDir, resDir); }
@Test @Ignore public void testExampleUsage() { JadxArgs args = new JadxArgs(); args.getInputFiles().add(new File("test.apk")); args.setOutDir(new File("jadx-test-output")); JadxDecompiler jadx = new JadxDecompiler(args); jadx.load(); jadx.save(); }
@Deprecated public static String literalToString(long lit, ArgType type) { return literalToString(lit, type, new StringUtils(new JadxArgs())); }
public ClassNode getClassNodeFromFile(File file, String clsName) { JadxDecompiler d = null; try { args.setInputFiles(Collections.singletonList(file)); d = new JadxDecompiler(args); d.load(); } catch (Exception e) { e.printStackTrace(); fail(e.getMessage()); } RootNode root = JadxInternalAccess.getRoot(d); insertResources(root); ClassNode cls = root.searchClassByName(clsName); assertThat("Class not found: " + clsName, cls, notNullValue()); assertThat(clsName, is(cls.getClassInfo().getFullName())); if (unloadCls) { decompile(d, cls); } else { decompileWithoutUnload(d, cls); } System.out.println("-----------------------------------------------------------"); System.out.println(cls.getCode()); System.out.println("-----------------------------------------------------------"); checkCode(cls); compile(cls); runAutoCheck(clsName); return cls; }
public static void main(String[] args) throws IOException, DecodeException { if (args.length < 2) { usage(); System.exit(1); } File output = new File(args[0]); List<InputFile> inputFiles = new ArrayList<>(args.length - 1); for (int i = 1; i < args.length; i++) { File f = new File(args[i]); if (f.isDirectory()) { addFilesFromDirectory(f, inputFiles); } else { InputFile.addFilesFrom(f, inputFiles); } } for (InputFile inputFile : inputFiles) { LOG.info("Loaded: {}", inputFile.getFile()); } RootNode root = new RootNode(new JadxArgs()); root.load(inputFiles); ClsSet set = new ClsSet(); set.load(root); set.save(output); LOG.info("Output: {}", output); LOG.info("done"); }
private static void checkInputFiles(JadxArgs args) { List<File> inputFiles = args.getInputFiles(); if (inputFiles.isEmpty()) { throw new JadxArgsValidateException("Please specify input file"); } if (inputFiles.size() > 1) { for (File inputFile : inputFiles) { String fileName = inputFile.getName(); if (fileName.startsWith("--")) { throw new JadxArgsValidateException("Unknown argument: " + fileName); } } throw new JadxArgsValidateException("Only one input file supported"); } for (File file : inputFiles) { checkFile(file); } }