diff --git a/jadx-core/src/main/java/jadx/api/ResourceFile.java b/jadx-core/src/main/java/jadx/api/ResourceFile.java index 927c61f84..bd92e73aa 100644 --- a/jadx-core/src/main/java/jadx/api/ResourceFile.java +++ b/jadx-core/src/main/java/jadx/api/ResourceFile.java @@ -62,6 +62,10 @@ public class ResourceFile { return deobfName != null ? deobfName : name; } + public void setDeobfName(String resFullName) { + this.deobfName = resFullName; + } + public ResourceType getType() { return type; } @@ -84,7 +88,7 @@ public class ResourceFile { } String alias = sb.toString(); if (!alias.equals(name)) { - deobfName = alias; + setDeobfName(alias); return true; } return false; diff --git a/jadx-plugins/jadx-script/examples/scripts/deobf/deobf-resources.jadx.kts b/jadx-plugins/jadx-script/examples/scripts/deobf/deobf-resources.jadx.kts new file mode 100644 index 000000000..6469f1091 --- /dev/null +++ b/jadx-plugins/jadx-script/examples/scripts/deobf/deobf-resources.jadx.kts @@ -0,0 +1,34 @@ +import jadx.api.plugins.options.OptionFlag.PER_PROJECT + +/** + * Custom resources regexp deobfuscator + */ + +val jadx = getJadxInstance() + +val regexOpt = jadx.options.registerString( + name = "regex", + desc = "Apply resources rename for file names matches regex", + defaultValue = """[Oo0]+\.xml""", +).flags(PER_PROJECT) + +val regex = regexOpt.value.toRegex() +var n = 0 + +jadx.stages.prepare { + for (resFile in jadx.internalDecompiler.resources) { + val fullName = resFile.originalName + val name = fullName.substringAfterLast('/') + if (name matches regex) { + val path = fullName.substringBeforeLast('/') // TODO: path also may be obfuscated + val ext = name.substringAfterLast('.') + val newName = "$path/res-${n++}.$ext" + log.info { "renaming resource: '$fullName' to '$newName'" } + resFile.deobfName = newName + } + } +} + +jadx.afterLoad { + log.info { "Renames count: $n" } +} diff --git a/jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/Stages.kt b/jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/Stages.kt index 7187aa949..75c1d2e75 100644 --- a/jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/Stages.kt +++ b/jadx-plugins/jadx-script/jadx-script-runtime/src/main/kotlin/jadx/plugins/script/runtime/data/Stages.kt @@ -3,11 +3,22 @@ package jadx.plugins.script.runtime.data import jadx.core.dex.nodes.BlockNode import jadx.core.dex.nodes.InsnNode import jadx.core.dex.nodes.MethodNode +import jadx.core.dex.nodes.RootNode import jadx.core.dex.regions.Region import jadx.plugins.script.runtime.JadxScriptInstance class Stages(private val jadx: JadxScriptInstance) { + fun prepare(block: (RootNode) -> Unit) { + jadx.addPass(object : ScriptPreparePass(jadx, "StagePrepare") { + override fun init(root: RootNode) { + jadx.debug.catchExceptions("Prepare init block") { + block.invoke(root) + } + } + }) + } + fun rawInsns(block: (MethodNode, Array) -> Unit) { jadx.addPass(object : ScriptOrderedDecompilePass( jadx,