■ ■ ■ ■ ■ ■
jadx-plugins/jadx-script/examples/scripts/deobf_by_code.jadx.kts
| 1 | + | /* |
| 2 | + | Rename method if specific string is found |
| 3 | + | */ |
| 4 | + | |
| 5 | + | import jadx.api.plugins.input.insns.Opcode |
| 6 | + | import jadx.core.dex.nodes.MethodNode |
| 7 | + | |
| 8 | + | val renamesMap = mapOf( |
| 9 | + | "specificString" to "newMethodName", |
| 10 | + | "AA6" to "aa6Method" |
| 11 | + | ) |
| 12 | + | |
| 13 | + | val jadx = getJadxInstance() |
| 14 | + | |
| 15 | + | var n = 0 |
| 16 | + | jadx.rename.all { _, node -> |
| 17 | + | var newName : String? = null |
| 18 | + | if (node is MethodNode) { |
| 19 | + | // use quick instructions scanner |
| 20 | + | node.codeReader?.visitInstructions { insn -> |
| 21 | + | if (insn.opcode == Opcode.CONST_STRING) { |
| 22 | + | insn.decode() |
| 23 | + | val constStr = insn.indexAsString |
| 24 | + | val renameStr = renamesMap[constStr] |
| 25 | + | if (renameStr != null) { |
| 26 | + | log.info { "Found '$constStr' in method $node, renaming to '$renameStr'" } |
| 27 | + | newName = renameStr |
| 28 | + | n++ |
| 29 | + | } |
| 30 | + | } |
| 31 | + | } |
| 32 | + | } |
| 33 | + | newName |
| 34 | + | } |
| 35 | + | |
| 36 | + | jadx.afterLoad { |
| 37 | + | log.info { "Script '$scriptName' renamed $n methods" } |
| 38 | + | } |
| 39 | + | |