jadx.api.JadxDecompiler Java Examples

The following examples show how to use jadx.api.JadxDecompiler. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JadxCLIArgs.java    From jadx with Apache License 2.0 6 votes vote down vote up
private boolean process(JCommanderWrapper<JadxCLIArgs> jcw) {
	if (printHelp) {
		jcw.printUsage();
		return false;
	}
	if (printVersion) {
		System.out.println(JadxDecompiler.getVersion());
		return false;
	}
	try {
		if (threadsCount <= 0) {
			throw new JadxException("Threads count must be positive, got: " + threadsCount);
		}
		LogHelper.setLogLevelFromArgs(this);
	} catch (JadxException e) {
		System.err.println("ERROR: " + e.getMessage());
		jcw.printUsage();
		return false;
	}
	return true;
}
 
Example #2
Source File: JadxUpdate.java    From jadx with Apache License 2.0 6 votes vote down vote up
private static Release checkForNewRelease() throws IOException {
	String version = JadxDecompiler.getVersion();
	if (version.contains("dev")) {
		LOG.debug("Ignore check for update: development version");
		return null;
	}

	List<Release> list = get(GITHUB_RELEASES_URL, RELEASES_LIST_TYPE);
	if (list == null) {
		return null;
	}
	list.removeIf(release -> release.getName().equalsIgnoreCase(version) || release.isPreRelease());
	if (list.isEmpty()) {
		return null;
	}
	list.sort(RELEASE_COMPARATOR);
	Release latest = list.get(list.size() - 1);
	if (VersionComparator.checkAndCompare(version, latest.getName()) >= 0) {
		return null;
	}
	LOG.info("Found new jadx version: {}", latest);
	return latest;
}
 
Example #3
Source File: RunProgramJad.java    From APKRepatcher with MIT License 5 votes vote down vote up
public static void decompileJar2Java(File jarPath, String outputSourceDirectory) throws JadxException
{
	 JadxDecompiler jadx = new JadxDecompiler();
	 jadx.setOutputDir(new File(outputSourceDirectory));
	 jadx.loadFile(jarPath);
	 jadx.save();
		if (jadx.getErrorsCount() != 0) {
			jadx.printErrorsReport();
		} else {
		}
}
 
Example #4
Source File: LogHelper.java    From jadx with Apache License 2.0 5 votes vote down vote up
public static void applyLogLevel(LogLevelEnum logLevel) {
	Logger rootLogger = (Logger) LoggerFactory.getLogger(Logger.ROOT_LOGGER_NAME);
	rootLogger.setLevel(logLevel.getLevel());

	if (logLevel != LogLevelEnum.QUIET) {
		// show progress for all levels except quiet
		setLevelForClass(JadxCLI.class, Level.INFO);
		setLevelForClass(JadxDecompiler.class, Level.INFO);
	}
}
 
Example #5
Source File: JadxCLI.java    From jadx with Apache License 2.0 5 votes vote down vote up
static int processAndSave(JadxArgs jadxArgs) {
	jadxArgs.setCodeCache(new NoOpCodeCache());
	try (JadxDecompiler jadx = new JadxDecompiler(jadxArgs)) {
		jadx.load();
		jadx.save();
		int errorsCount = jadx.getErrorsCount();
		if (errorsCount != 0) {
			jadx.printErrorsReport();
			LOG.error("finished with errors, count: {}", errorsCount);
		} else {
			LOG.info("done");
		}
	}
	return 0;
}
 
Example #6
Source File: JSourcesTest.java    From jadx with Apache License 2.0 5 votes vote down vote up
@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());
}
 
Example #7
Source File: JadxWrapper.java    From jadx with Apache License 2.0 5 votes vote down vote up
public void openFile(File file) {
	close();
	this.openFile = file;
	try {
		JadxArgs jadxArgs = settings.toJadxArgs();
		jadxArgs.setInputFile(file);

		this.decompiler = new JadxDecompiler(jadxArgs);
		this.decompiler.load();
	} catch (Exception e) {
		LOG.error("Jadx init error", e);
		close();
	}
}
 
Example #8
Source File: JNode.java    From jadx with Apache License 2.0 5 votes vote down vote up
@Nullable
public JavaNode getJavaNodeAtPosition(JadxDecompiler decompiler, int line, int offset) {
	ICodeInfo codeInfo = getCodeInfo();
	if (codeInfo == null) {
		return null;
	}
	return decompiler.getJavaNodeAtPosition(codeInfo, line, offset);
}
 
Example #9
Source File: BaseExternalTest.java    From jadx with Apache License 2.0 5 votes vote down vote up
private void processByPatterns(JadxDecompiler jadx, String clsPattern, @Nullable String mthPattern) {
	RootNode root = JadxInternalAccess.getRoot(jadx);
	int processed = 0;
	for (ClassNode classNode : root.getClasses(true)) {
		String clsFullName = classNode.getClassInfo().getFullName();
		if (clsFullName.equals(clsPattern)) {
			if (processCls(mthPattern, classNode)) {
				processed++;
			}
		}
	}
	assertThat("No classes processed", processed, greaterThan(0));
}
 
Example #10
Source File: BaseExternalTest.java    From jadx with Apache License 2.0 5 votes vote down vote up
protected void decompile(JadxArgs jadxArgs, @Nullable String clsPatternStr, @Nullable String mthPatternStr) {
	JadxDecompiler jadx = new JadxDecompiler(jadxArgs);
	jadx.load();

	if (clsPatternStr == null) {
		processAll(jadx);
		// jadx.saveSources();
	} else {
		processByPatterns(jadx, clsPatternStr, mthPatternStr);
	}
	printErrorReport(jadx);
}
 
Example #11
Source File: SmaliTest.java    From jadx with Apache License 2.0 5 votes vote down vote up
protected List<ClassNode> loadFromSmaliFiles() {
	File outDex = createTempFile(".dex");
	compileSmali(outDex, collectSmaliFiles(getTestPkg(), getTestName()));

	JadxDecompiler d = loadFiles(Collections.singletonList(outDex));
	RootNode root = JadxInternalAccess.getRoot(d);
	List<ClassNode> classes = root.getClasses(false);
	decompileAndCheck(d, classes);
	return classes;
}
 
Example #12
Source File: BaseExternalTest.java    From Box with Apache License 2.0 5 votes vote down vote up
private void processByPatterns(JadxDecompiler jadx, String clsPattern, @Nullable String mthPattern) {
	RootNode root = JadxInternalAccess.getRoot(jadx);
	int processed = 0;
	for (ClassNode classNode : root.getClasses(true)) {
		String clsFullName = classNode.getClassInfo().getFullName();
		if (clsFullName.equals(clsPattern)) {
			if (processCls(mthPattern, classNode)) {
				processed++;
			}
		}
	}
	assertThat("No classes processed", processed, greaterThan(0));
}
 
Example #13
Source File: IntegrationTest.java    From Box with Apache License 2.0 5 votes vote down vote up
public ClassNode getClassNodeFromFile(File file, String clsName) {
	JadxDecompiler d = loadFiles(Collections.singletonList(file));
	RootNode root = JadxInternalAccess.getRoot(d);

	ClassNode cls = root.searchClassByName(clsName);
	assertThat("Class not found: " + clsName, cls, notNullValue());
	assertThat(clsName, is(cls.getClassInfo().getFullName()));

	decompileAndCheck(d, Collections.singletonList(cls));
	return cls;
}
 
Example #14
Source File: SmaliTest.java    From Box with Apache License 2.0 5 votes vote down vote up
protected List<ClassNode> loadFromSmaliFiles() {
	File outDex = createTempFile(".dex");
	compileSmali(outDex, collectSmaliFiles(getTestPkg(), getTestName()));

	JadxDecompiler d = loadFiles(Collections.singletonList(outDex));
	RootNode root = JadxInternalAccess.getRoot(d);
	List<ClassNode> classes = root.getClasses(false);
	decompileAndCheck(d, classes);
	return classes;
}
 
Example #15
Source File: SmaliTest.java    From Box with Apache License 2.0 5 votes vote down vote up
protected List<ClassNode> loadFromSmaliFiles() {
	File outDex = createTempFile(".dex");
	compileSmali(outDex, collectSmaliFiles(getTestPkg(), getTestName()));

	JadxDecompiler d = loadFiles(Collections.singletonList(outDex));
	RootNode root = JadxInternalAccess.getRoot(d);
	List<ClassNode> classes = root.getClasses(false);
	decompileAndCheck(d, classes);
	return classes;
}
 
Example #16
Source File: BaseExternalTest.java    From Box with Apache License 2.0 5 votes vote down vote up
protected void decompile(JadxArgs jadxArgs, @Nullable String clsPatternStr, @Nullable String mthPatternStr) {
	JadxDecompiler jadx = new JadxDecompiler(jadxArgs);
	jadx.load();

	if (clsPatternStr == null) {
		processAll(jadx);
		// jadx.saveSources();
	} else {
		processByPatterns(jadx, clsPatternStr, mthPatternStr);
	}
	printErrorReport(jadx);
}
 
Example #17
Source File: IntegrationTest.java    From Box with Apache License 2.0 5 votes vote down vote up
public ClassNode getClassNodeFromFile(File file, String clsName) {
	JadxDecompiler d = loadFiles(Collections.singletonList(file));
	RootNode root = JadxInternalAccess.getRoot(d);

	ClassNode cls = root.searchClassByName(clsName);
	assertThat("Class not found: " + clsName, cls, notNullValue());
	assertThat(clsName, is(cls.getClassInfo().getFullName()));

	decompileAndCheck(d, Collections.singletonList(cls));
	return cls;
}
 
Example #18
Source File: BaseExternalTest.java    From Box with Apache License 2.0 5 votes vote down vote up
protected void decompile(JadxArgs jadxArgs, @Nullable String clsPatternStr, @Nullable String mthPatternStr) {
	JadxDecompiler jadx = new JadxDecompiler(jadxArgs);
	jadx.load();

	if (clsPatternStr == null) {
		processAll(jadx);
		// jadx.saveSources();
	} else {
		processByPatterns(jadx, clsPatternStr, mthPatternStr);
	}
	printErrorReport(jadx);
}
 
Example #19
Source File: BaseExternalTest.java    From Box with Apache License 2.0 5 votes vote down vote up
private void processByPatterns(JadxDecompiler jadx, String clsPattern, @Nullable String mthPattern) {
	RootNode root = JadxInternalAccess.getRoot(jadx);
	int processed = 0;
	for (ClassNode classNode : root.getClasses(true)) {
		String clsFullName = classNode.getClassInfo().getFullName();
		if (clsFullName.equals(clsPattern)) {
			if (processCls(mthPattern, classNode)) {
				processed++;
			}
		}
	}
	assertThat("No classes processed", processed, greaterThan(0));
}
 
Example #20
Source File: BaseExternalTest.java    From jadx with Apache License 2.0 4 votes vote down vote up
private void printErrorReport(JadxDecompiler jadx) {
	jadx.printErrorsReport();
	assertThat(jadx.getErrorsCount(), is(0));
}
 
Example #21
Source File: IntegrationTest.java    From Box with Apache License 2.0 4 votes vote down vote up
protected void decompileWithoutUnload(JadxDecompiler jadx, ClassNode cls) {
	ProcessClass.process(cls);
	generateClsCode(cls);
	// don't unload class
}
 
Example #22
Source File: JadxWrapper.java    From jadx with Apache License 2.0 4 votes vote down vote up
public JadxDecompiler getDecompiler() {
	return decompiler;
}
 
Example #23
Source File: BaseExternalTest.java    From Box with Apache License 2.0 4 votes vote down vote up
private void processAll(JadxDecompiler jadx) {
	for (JavaClass javaClass : jadx.getClasses()) {
		javaClass.decompile();
	}
}
 
Example #24
Source File: AboutDialog.java    From jadx with Apache License 2.0 4 votes vote down vote up
public final void initUI() {
	Font font = new Font("Serif", Font.BOLD, 13);

	URL logoURL = getClass().getResource("/logos/jadx-logo-48px.png");
	Icon logo = new ImageIcon(logoURL, "jadx logo");

	JLabel name = new JLabel("jadx", logo, SwingConstants.CENTER);
	name.setFont(font);
	name.setAlignmentX(0.5f);

	JLabel desc = new JLabel("Dex to Java decompiler");
	desc.setFont(font);
	desc.setAlignmentX(0.5f);

	JLabel version = new JLabel("jadx version: " + JadxDecompiler.getVersion());
	version.setFont(font);
	version.setAlignmentX(0.5f);

	String javaVm = System.getProperty("java.vm.name");
	String javaVer = System.getProperty("java.version");

	javaVm = javaVm == null ? "" : javaVm;

	JLabel javaVmLabel = new JLabel("Java VM: " + javaVm);
	javaVmLabel.setFont(font);
	javaVmLabel.setAlignmentX(0.5f);

	javaVer = javaVer == null ? "" : javaVer;
	JLabel javaVerLabel = new JLabel("Java version: " + javaVer);
	javaVerLabel.setFont(font);
	javaVerLabel.setAlignmentX(0.5f);

	JPanel textPane = new JPanel();
	textPane.setBorder(BorderFactory.createEmptyBorder(15, 15, 15, 15));
	textPane.setLayout(new BoxLayout(textPane, BoxLayout.PAGE_AXIS));
	textPane.add(Box.createRigidArea(new Dimension(0, 10)));
	textPane.add(name);
	textPane.add(Box.createRigidArea(new Dimension(0, 10)));
	textPane.add(desc);
	textPane.add(Box.createRigidArea(new Dimension(0, 10)));
	textPane.add(version);
	textPane.add(Box.createRigidArea(new Dimension(0, 20)));
	textPane.add(javaVmLabel);
	textPane.add(javaVerLabel);
	textPane.add(Box.createRigidArea(new Dimension(0, 20)));

	JButton close = new JButton(NLS.str("tabs.close"));
	close.addActionListener(event -> dispose());
	close.setAlignmentX(0.5f);

	Container contentPane = getContentPane();
	contentPane.add(textPane, BorderLayout.CENTER);
	contentPane.add(close, BorderLayout.PAGE_END);

	UiUtils.setWindowIcons(this);

	setModalityType(ModalityType.APPLICATION_MODAL);

	setTitle(NLS.str("about_dialog.title"));
	pack();
	setDefaultCloseOperation(DISPOSE_ON_CLOSE);
	setLocationRelativeTo(null);
}
 
Example #25
Source File: CodeArea.java    From jadx with Apache License 2.0 4 votes vote down vote up
private JadxDecompiler getDecompiler() {
	return getMainWindow().getWrapper().getDecompiler();
}
 
Example #26
Source File: BaseExternalTest.java    From Box with Apache License 2.0 4 votes vote down vote up
private void printErrorReport(JadxDecompiler jadx) {
	jadx.printErrorsReport();
	assertThat(jadx.getErrorsCount(), is(0));
}
 
Example #27
Source File: ResourcesSaver.java    From Box with Apache License 2.0 4 votes vote down vote up
public ResourcesSaver(File outDir, ResourceFile resourceFile, JadxDecompiler.ReverseCallBack reverseCallBack) {
	this.resourceFile = resourceFile;
	this.outDir = outDir;
	this.reverseCallBack=reverseCallBack;
}
 
Example #28
Source File: BaseExternalTest.java    From jadx with Apache License 2.0 4 votes vote down vote up
private void processAll(JadxDecompiler jadx) {
	for (JavaClass javaClass : jadx.getClasses()) {
		javaClass.decompile();
	}
}
 
Example #29
Source File: IntegrationTest.java    From Box with Apache License 2.0 4 votes vote down vote up
protected void decompileWithoutUnload(JadxDecompiler jadx, ClassNode cls) {
	ProcessClass.process(cls);
	generateClsCode(cls);
	// don't unload class
}
 
Example #30
Source File: IntegrationTest.java    From jadx with Apache License 2.0 4 votes vote down vote up
protected void decompileWithoutUnload(JadxDecompiler jadx, ClassNode cls) {
	ProcessClass.process(cls);
	generateClsCode(cls);
	// don't unload class
}