KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have rewritten the question (the question remains the same, just with less background noise) in hopes of creating less confusion directed at all the wrong things - due to this, some of the comments below may seem out of context. Analyzing Java bytecode, what is the easiest way to find all the possible reference types given as parameters for a given Java bytecode instruction? I'm interested in the type of the reference, that is, that a given putfield instruction will receive an Integer, or that it might receive an Integer or a Float, etc. For example, consider this code block: 0: aload_1 1: invokestatic #21; //Method java/lang/Integer.valueOf:(Ljava/lang/String;)Ljava/lang/Integer; 4: astore_2 5: aload_2 6: ifnull 17 9: aload_0 10: aload_2 11: putfield #27; //Field value:Ljava/lang/Number; 14: goto 25 17: aload_0 18: iconst_0 19: invokestatic #29; //Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; 22: putfield #27; //Field value:Ljava/lang/Number; 25: return We can deduce that the putfield instruction at pc 11 will receive a ref type of Integer . 0: aload pushes ref type of String (the method param) 1: invokestatic pops the ref type and pushes a ref type of Integer (invoked method return type) 4: astore pops the ref type of Integer and stores it in local variable 2 5: aload pushes the ref type of Integer from local variable 2 6: ifnull pops the ref type of Integer and conditionally jumps to pc 17 9: aload pushes "this" 10: aload pushes the ref type of Integer 11: putfield: we know we have a ref type of Integer that the instruction will put in field Do any of the bytecode/code analysis libraries do this for me, or do I have to write this myself? The ASM project has an <a href="http://asm.ow2.org/asm33/javadoc/user/org/objectweb/asm
Tags (comma-separated)
Save Edits
Cancel