chore(script): adjust scripts format

This commit is contained in:
Skylot 2023-09-12 19:52:50 +01:00
parent 24657f6b3c
commit 2dc0db230c
No known key found for this signature in database
GPG Key ID: 47866607B16F25C8
13 changed files with 59 additions and 38 deletions

View File

@ -22,6 +22,7 @@ sourceSets {
main {
kotlin.srcDirs(
"scripts",
"scripts/deobf",
"scripts/gui",
"context",
)

View File

@ -1,4 +1,6 @@
// custom deobfuscator example
/**
* Custom regexp deobfuscator
*/
val jadx = getJadxInstance()
jadx.args.isDeobfuscationOn = false
@ -7,7 +9,6 @@ jadx.args.renameFlags = emptySet()
val regexOpt = jadx.options.registerString(
"regex",
"Apply rename for names matches regex",
values = listOf(),
defaultValue = "[Oo0]+",
)
@ -17,12 +18,14 @@ jadx.rename.all { name, node ->
when {
name matches regex -> {
val newName = "${node.typeName()}${n++}"
println("renaming ${node.typeName()} '$node' to '$newName'")
log.info { "renaming ${node.typeName()} '$node' to '$newName'" }
newName
}
else -> null
}
}
jadx.afterLoad {
println("Renames count: $n")
log.info { "Renames count: $n" }
}

View File

@ -1,4 +1,7 @@
// animal deobfuscator ^_^
/**
* Animal deobfuscator ^_^
*/
@file:DependsOn("com.github.javafaker:javafaker:1.0.2")
import com.github.javafaker.Faker
@ -21,6 +24,7 @@ jadx.rename.all { name, node ->
val alias = faker.name().firstName().cap() + faker.animal().name().cap()
makeUnique(prefix, alias)
}
else -> null
}
}
@ -33,7 +37,7 @@ fun makeUnique(prefix: Char, name: String): String {
}
jadx.afterLoad {
println("Renames count: ${usedNames.size + dups}, names: ${usedNames.size}, dups: $dups")
log.info { "Renames count: ${usedNames.size + dups}, names: ${usedNames.size}, dups: $dups" }
}
fun String.cap() = this.replaceFirstChar(Char::uppercaseChar)

View File

@ -1,13 +1,12 @@
/*
Rename method if specific string is found
*/
/**
* Rename method if specified string is found
*/
import jadx.api.plugins.input.insns.Opcode
import jadx.core.dex.nodes.MethodNode
val renamesMap = mapOf(
"specificString" to "newMethodName",
"AA6" to "aa6Method",
)
val jadx = getJadxInstance()

View File

@ -1,6 +1,6 @@
/*
Rename class and fields using strings from toString() method
*/
/**
* Rename class and fields using strings from toString() method
*/
import jadx.core.deobf.NameMapper
import jadx.core.dex.attributes.AFlag

View File

@ -20,24 +20,22 @@ jadx.gui.ifAvailable {
fun setBookmark(node: ICodeNodeRef) {
val enclosing = jadx.gui.enclosingNodeUnderCaret ?: run {
jadx.log.info { "No enclosing node" }
log.info { "No enclosing node" }
return
}
// You can bookmark a field, method or a class
val target = if (enclosing is MethodNode) enclosing else node
jadx.log.info { "Setting bookmark to: $target" }
log.info { "Setting bookmark to: $target" }
savedBookmark = target
}
fun jumpToBookmark() {
if (savedBookmark == null) {
jadx.log.info { "No bookmark" }
} else {
val res = jadx.gui.open(savedBookmark!!)
if (!res) {
jadx.log.info { "Failed to jump to bookmark" }
savedBookmark?.let {
if (!jadx.gui.open(it)) {
log.warn { "Failed to jump to bookmark: $it" }
}
} ?: run {
log.info { "No bookmark" }
}
}

View File

@ -12,8 +12,8 @@ jadx.gui.ifAvailable {
}
fun runAction(node: ICodeNodeRef) {
jadx.log.info { "Node under caret: ${jadx.gui.nodeUnderCaret}" }
jadx.log.info { "Enclosing node under caret: ${jadx.gui.enclosingNodeUnderCaret}" }
jadx.log.info { "Node under mouse: ${jadx.gui.nodeUnderMouse}" }
jadx.log.info { "Enclosing Node under mouse: ${jadx.gui.enclosingNodeUnderMouse}" }
log.info { "Node under caret: ${jadx.gui.nodeUnderCaret}" }
log.info { "Enclosing node under caret: ${jadx.gui.enclosingNodeUnderCaret}" }
log.info { "Node under mouse: ${jadx.gui.nodeUnderMouse}" }
log.info { "Enclosing Node under mouse: ${jadx.gui.enclosingNodeUnderMouse}" }
}

View File

@ -1,11 +1,23 @@
import jadx.api.plugins.events.JadxEvents
/**
* Log events
*/
import jadx.api.plugins.events.JadxEvents
val jadx = getJadxInstance()
jadx.events.addListener(JadxEvents.NODE_RENAMED_BY_USER) { rename ->
log.info { "Rename from '${rename.oldName}' to '${rename.newName}' for node ${rename.node}" }
jadx.gui.ifAvailable {
// GUI only events
jadx.events.addListener(JadxEvents.NODE_RENAMED_BY_USER) { rename ->
log.info { "Rename from '${rename.oldName}' to '${rename.newName}' for node ${rename.node}" }
}
jadx.events.addListener(JadxEvents.RELOAD_PROJECT) {
log.info { "Project reloaded" }
}
jadx.events.addListener(JadxEvents.RELOAD_SETTINGS_WINDOW) {
log.info { "Settings window reloaded" }
}
}

View File

@ -1,9 +1,11 @@
// customize jadx-gui
/**
* Add menu action (into 'Plugins' section)
*/
val jadx = getJadxInstance()
jadx.gui.ifAvailable {
addMenuAction("Decompile All") {
jadx.decompile.all()
jadx.decompile.allThreaded()
}
}

View File

@ -20,10 +20,10 @@ jadx.rename.all { name ->
// run some code after loading is finished
jadx.afterLoad {
println("Loaded classes: ${jadx.classes.size}")
log.info { "Loaded classes: ${jadx.classes.size}" }
// print first class code
jadx.classes.firstOrNull()?.let { cls ->
println("Class: '${cls.name}'")
println(cls.code)
log.info { "Class: '${cls.name}'" }
log.info { cls.code }
}
}

View File

@ -25,6 +25,6 @@ jadx.gui.ifAvailable {
fun printOptions() {
allOptions.forEach { opt ->
println("Option: '${opt.name}', id: '${opt.id}', value: '${opt.value}'")
log.info { "Option: '${opt.name}', id: '${opt.id}', value: '${opt.value}'" }
}
}

View File

@ -1,4 +1,7 @@
// instructions modification example
/**
* Instructions modification example.
* Replace first arg with const string.
*/
import jadx.core.dex.instructions.ConstStringNode
import jadx.core.dex.instructions.InvokeNode

View File

@ -11,7 +11,6 @@ import jadx.core.dex.instructions.args.InsnArg
import jadx.core.dex.instructions.args.InsnWrapArg
import jadx.core.dex.instructions.args.RegisterArg
val jadx = getJadxInstance()
val mthSignature = "com.xshield.aa.iIiIiiiiII(Ljava/lang/String;)Ljava/lang/String;"