-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Jadx scripts guide
Jadx uses Kotlin to support scripting.
Note
In latest jadx version script support moved into external plugin and not bundled with jadx, check this page for installation details.
Simple jadx script: hello.jadx.kts
log.info { "Hello from jadx script!" }
// get jadx decompiler script instance
val jadx = getJadxInstance()
// adjust options if needed
jadx.args.isDeobfuscationOn = false
// rename example
jadx.rename.all { name ->
when (name) {
"HelloWorld" -> "HelloJadx"
else -> null
}
}
// run some code after loading is finished
jadx.afterLoad {
log.info { "Loaded classes: ${jadx.classes.size}" }
// print class code
jadx.classes.firstOrNull()?.let { cls ->
log.info { "Class: '${cls.name}'" }
log.info { cls.code }
}
}
jadx.gui.ifAvailable {
// if a script is running in jadx-gui,
// we can add menu entry to run custom code
addMenuAction("Decompile All") {
jadx.decompile.allThreaded()
}
}Warning
Script file name should end with .jadx.kts
Check script examples in examples
Add script file as input:
jadx classes.dex hello.jadx.kts- Add script file to the project (using
Add filesor right-click menu onInputs/Scriptsand selectNew script) - Script will appear in
Inputs/Scriptssection - After script change, you can run it using
Runbutton in script editor toolbar or reload whole project (Reloadbutton in toolbar orF5). Also, you can enableLive reloadoption inFilemenu to reload a project automatically on script change
Each part of jadx script is executed at different time or stages.
Script base code loaded and evaluated at the loading stage, at this point classes info is not yet loaded,
but it is possible to change loading options.
If you need to process already loaded classes, code to do so should be placed in jadx.afterLoad block.
Also, to execute during decompilation you can use jadx.addPass or use utility methods in jadx.stages
For simplify usage of jadx API in scripts, wrapper methods were added and divided into next sections:
-
rename- to rename any classes, methods, fields -
replace- replace/change instructions in methods -
stages- execute custom code at different decompilation stages -
search- search class or method -
gui- methods to access jadx-gui UI -
events- receive or send jadx events (only UI events for now) -
decompile- run classes decompilation -
debug- utility methods used to view/access internal information
For more details, check the source code here.
Now jadx.internalDecompiler can be used to access data in jadx decompiler (same as in Use jadx as a library.
This can be useful if this is no other way to access some jadx data, but it is suggested to not use this field.
Please feel free to open an issue if you still need to use jadx.internalDecompiler.