I can't just replace the entire method. I have to just inject a reassignment of a local var after the last time it normally gets set but before it gets used near the end of the method.
Here's some pseudocode
void test() {
/* stuff */
String thing = null;
if (case1) {
thing = "case1"
}
if (case2) {
thing = "case2"
}
if (case3) {
thing = "case3"
}
if (thing == null) {
thing = "default";
}
/* I want to insert this code below with ASM */
thing = "Injected by ASM";
/* stuff */
}
I could also just replace the default assignment when the code reaches that point where it checks if thing == null
. But the byte code for the default assignment is a pretty long StringBuilder
with lots of appends. There's a LDC that I can use to uniquely identify that but line I dunno how to replace the whole thing
assignment for that line. I only know how to replace the LDC (which is not enough).
The idea is I want to ignore all the case1-3
so that thing
is always what I tell ASM to set it as
But the /* stuff */
at the top and bottom of the method cannot be removed