Adding a parameter to function in Java Bytecode -


i've got compiled .jar plugin x.class file. x.class file contains method y parameters y(string s1, string s2....). need pass 1 more string - launched rej , dirtyjoe, edited descriptor of y method, changed maximum local variables count 8 9, added new local variable, set same previous variables, gave index, edited code , saved method. packed .jar file , tried compile in unity new version of plugin. unfortunately - gave me error saying new variable invalid -

exception simulation: local 0008: invalid  ...at bytecode offset 00000036 locals[0000]: ljava/lang/string; locals[0001]: ljava/lang/string; locals[0002]: ljava/lang/string; locals[0003]: ljava/lang/string; locals[0004]: ljava/lang/string; locals[0005]: [b locals[0006]: landroid/net/uri; locals[0007]: landroid/content/intent; locals[0008]: <invalid> stack[0001]: landroid/content/intent; stack[top0]: string{"android.intent.extra.text"} ...while working on block 0036 ...while working on method startshareintentmedia:(ljava/lang/string;ljava/lang/string;ljava/lang/string;ljava/lang/string;ljava/lang/string;ljava/lang/string;)v ...while processing startshareintentmedia (ljava/lang/string;ljava/lang/string;ljava/lang/string;ljava/lang/string;ljava/lang/string;ljava/lang/string;)v ...while processing com/androidnative/features/social/common/socialgate.class 

that's first time java bytecode, hope i'll help. thanks!

editing bytecode not faint of heart. i'd recommend reading jvm specification before start.

that being said, there couple things doing wrong, based on description.

at beginning of method, method parameters passed in in local variable slots 0..n-1. can't choose index new local variable, have use index after last current parameter. if bytecode using slot else, you'll have adjust usages of else. alternatively, can add move sequence (i.e. aload n astore y) @ beginning of method. won't affect usages of slot local variable later in method.

if have debugging information, localvariabletable, you'll have adjust references in that. if bytecode has stackmaptable you'll have adjust that. assuming code isn't using invokedynamic, it's easier change bytecode version 50.0 , remove stack map table entirely.

next up, you'll have change method descriptor. descriptor gives signature of method, , in bytecode, methods identified (class, name, descriptor) triple. you'll need add string in parameter @ end of descriptor before final closing parenthesis , return type. you'll have add new descriptor constant pool if it's not there already.

then you'll have adjust definition of method reference new descriptor, , adjust every single place method called (better hope inheritance , reflection aren't involved!).

and of course, you'll have adjust every callsite pass in new parameter.


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -