fix(script): add example script for resources rename (#2126)
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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" }
|
||||
}
|
||||
+11
@@ -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<InsnNode?>) -> Unit) {
|
||||
jadx.addPass(object : ScriptOrderedDecompilePass(
|
||||
jadx,
|
||||
|
||||
Reference in New Issue
Block a user