Re: Need help in generating an instruction list
Stephen Kolaroff <[email protected]>
| Newsgroups | gmane.comp.jakarta.bcel.devel |
|---|---|
| Message-ID | <[email protected]> |
I will not tell you how to deal with your particular case. When I have
to generate a tricky and/or long InstructionList, I:
1. Check how to generate the least: may be some runtime support methods,
then some appropriate invokations; or even ready code, from a template
method to where I need it.
2. When I am confident that I have found "the least effort" approach,
write a method (in Java) featuring most of the code I have to generate,
and investigate it using CCK; CCK is avilable with BCEL distro.
3. Spent several hours making the code working and my hair white.
4. Post messages like this to the BCEL Developers List
Last 2 steps are optional:)
HtH
Cheffo
maithily mundle wrote:
> Can someone tell me how to generate the code pasted below, I have to
> generate a similar, but much more complex code...
>
> try{
>
> ClassParser parser = new ClassParser(filename);
> JavaClass java_class = parser.parse();
>
> Method[] methods = java_class.getMethods();
> ConstantPool cp = java_class.getConstantPool();
> Constant[] clist = cp.getConstantPool();
>
>
> for(int k=0; k<clist.length; k++) {
> if(clist[k] instanceof ConstantString) {
> ConstantString cName =
> (ConstantString)clist[k];
> String cName1 = cName.getBytes(cp);
> //System.out.println(cName1);
> byte[] b = cName1.getBytes();
> for (int i=0; i<b.length; i++)
> b[i]^=2;
> cName1 = new String(b);
> //System.out.println(cName1);
> //cName = cName1;
> Constant cNew = new ConstantUtf8(cName1);
> clist[k] = cNew;
> }
> }
> }
> catch(Exception e){
> System.out.println(e);
> }
>
> Maithily Mundle,
> CS Department,
> OSU.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>