Extract Byte Array from a FilledNewArrayNode #2564
-
Hello, I have been trying to extract the Byte Array from a FilledNewArrayNode and I cannot figure out how to do that. Looking at the example scripts, I can see that Strings can be extracted by just using the .string property of the ConstStringNode, but that doesn't seem to be the case for FilledNewArrayNode. Any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
@RealOkabe import jadx.core.dex.instructions.InsnType
import jadx.core.dex.instructions.args.LiteralArg
val jadx = getJadxInstance()
jadx.replace.insns { _, insn ->
if (insn.type == InsnType.FILLED_NEW_ARRAY) {
val byteArr = ByteArray(insn.argsCount)
var i = 0
insn.arguments.forEach { arg ->
if (arg is LiteralArg) {
byteArr[i++] = arg.literal.toByte()
}
}
jadx.log.info { "Array: ${byteArr.asList()}" }
}
null
}
For this smali sample: .class public final Ltest/Example;
.super Ljava/lang/Object;
.method public test()[B
.registers 10
const/4 v1, 0x1
const/4 v2, 0x2
const/4 v3, 0x3
filled-new-array {v1, v2, v3}, [B
move-result-object v1
return-object v1
.end method Output will be:
|
Beta Was this translation helpful? Give feedback.
-
Thank you for the answer. That works for literals in a byte array. |
Beta Was this translation helpful? Give feedback.
-
@RealOkabe you can try this method like this: import jadx.core.dex.instructions.InsnType
import jadx.core.dex.instructions.args.LiteralArg
import jadx.core.utils.InsnUtils
val jadx = getJadxInstance()
jadx.replace.insns { mth, insn ->
if (insn.type == InsnType.FILLED_NEW_ARRAY) {
val byteArr = ByteArray(insn.argsCount)
var i = 0
insn.arguments.forEach { arg ->
val constVal = InsnUtils.getConstValueByArg(mth.root(), arg)
if (constVal is LiteralArg) {
byteArr[i++] = constVal.literal.toByte()
}
}
jadx.log.info { "Array: ${byteArr.asList()}" }
}
null
} It should handle most cases of moved constants |
Beta Was this translation helpful? Give feedback.
-
@skylot thank you for all your help. The code you provided works for almost all cases. I appreciate it. |
Beta Was this translation helpful? Give feedback.
@RealOkabe you can try this method
jadx/jadx-core/src/main/java/jadx/core/utils/InsnUtils.java
Line 62 in 681f8a9
like this: