Hi Arin, Thanks for your feedback; very insightful. I went through all the steps, identified the right invokestatic, added it into the constant pool, and updated the index of the invokestatic.
Right now, the only issue i'm having is that the dump doesn't include my changes, which might indicate that something is missing. Any idea? If you wish, i can send you the code offline. Thanks again, Klaus. -------- Original-Nachricht -------- > Datum: Tue, 10 Feb 2009 12:32:16 +1100 > Von: Arrin Daley <arrin.da...@anu.edu.au> > An: BCEL Users List <bcel-user@jakarta.apache.org> > Betreff: Re: How to replace a complete instruction in J2ME Bytecode > Hi Klaus > > You'll need to find the INVOKESTATIC instruction first, if you have an > idea which methods and classes the call(s) exist in this will help, > InstructionFinder is about finding a pattern of instructions you could > use it to find INVOKESTATIC instructions but that would probably be > overkill, you could just use an iterator or something similar. > > Once you have found the INVOKESTATIC instructions you could then test to > see which one(s) match your function call, you could do this by looking > at the classname and method name and possibly arguments the other way > would be to look up the index for the method in the constant pool (if it > exists in the constant pool, don't put it in if it doesn't) and compare > this index to that of the INVOKESTATIC instruction which you have found. > If the static method doesn't exist in the constant pool then there isn't > a call to that static method in the code your currently looking at so > you could move on to the next method to search. > > Once you find an INVOKESTATIC that matches you need to put your new > static method in the constant pool via a ConstantPoolGen, this will > return an index which you can then use with the setIndex method on the > INVOKESTATIC instruction. You can use the setIndex because you are just > changing the target of INVOKESTATIC instructions, otherwise you would > have to replace the instruction itself. > > I'm not sure what other finalising things you will need to do, the > ConstantPool, ConstantPoolGen will have changed so will need to > finalise that, and you will have to get a Method from the MethodGen > object you previously had but I think that's about all... > > Another way might be to define an InstructionVisitor overriding the > visit method for INVOKESTATIC to find and edit the appropriate > instructions. > > Hope it helps > > Bye Arrin > > Klaus Teller wrote: > > Hi Folks, > > > > I have a J2ME Library that contains the following instruction: > > > > invokestatic > javax/microedition/io/Connector/open(Ljava/lang/String;IZ)Ljavax/microedition/io/Connection; > > > > > > I would like to replace it with: > > > > invokestatic > mypackage/AlphaConnector/open(Ljava/lang/String;IZ)Ljavax/microedition/io/Connection; > > > > What do i need to do? > > > > I couldn't find a way to search instruction based on the operand (that > is the second part of the instruction). I tried IntructionFinder; but it > couldn't help me. > > > > I would very much appreciate any input. > > > > Thanks, > > Klaus. > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: bcel-user-unsubscr...@jakarta.apache.org > For additional commands, e-mail: bcel-user-h...@jakarta.apache.org -- Jetzt 1 Monat kostenlos! GMX FreeDSL - Telefonanschluss + DSL für nur 17,95 Euro/mtl.!* http://dsl.gmx.de/?ac=OM.AD.PD003K11308T4569a --------------------------------------------------------------------- To unsubscribe, e-mail: bcel-user-unsubscr...@jakarta.apache.org For additional commands, e-mail: bcel-user-h...@jakarta.apache.org