<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>bcel-user@jakarta.apache.org Archives</title>
<link rel="self" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/?format=atom"/>
<link href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/"/>
<id>http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/</id>
<updated>2009-12-06T18:27:03Z</updated>
<entry>
<title>Are SELECT instructions StackProducer?</title>
<author><name>Habib &lt;hobbbo@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200911.mbox/%3c98d65f050911270632i60f1e729ie22ac3f51cbc915d@mail.gmail.com%3e"/>
<id>urn:uuid:%3c98d65f050911270632i60f1e729ie22ac3f51cbc915d@mail-gmail-com%3e</id>
<updated>2009-11-27T14:32:10Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
I am currently learning both BCEL and java bytecode. From the javadoc I
noticed that LOOKUPSWITH and TABLESWITCH implements the StackProducer
interface, however, don't these instructions actually consume the stack
(like IfInstruction do), and hence should implement StackConsumer?


</pre>
</div>
</content>
</entry>
<entry>
<title>Bug in BCEL or BCELifier</title>
<author><name>theUser BL &lt;theuserbl@hotmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200911.mbox/%3cBAY116-W476FF68333CB495B903431A9A60@phx.gbl%3e"/>
<id>urn:uuid:%3cBAY116-W476FF68333CB495B903431A9A60@phx-gbl%3e</id>
<updated>2009-11-15T13:29:20Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Hi!

Have a look at this one:
------------------------
C:\&gt;dir
 Volume in Laufwerk C: hat keine Bezeichnung.
 Volumeseriennummer: 5481-B7B1

 Verzeichnis von C:\

15.11.2009  00:02    &lt;DIR&gt;          .
15.11.2009  00:02    &lt;DIR&gt;          ..
15.11.2009  00:04               372 Test.java
               1 Datei(en),            372 Bytes
               2 Verzeichnis(se), 158.248.124.416 Bytes frei

C:\&gt;type Test.java
public class Test {

  public static void TestMethod (int first, double second, float third) {

  third = 15;
  first = 12;
  second = 17.2;
  third = 19;
  System.out.println(first);
  System.out.println(second);
  System.out.println(third);
  System.out.println(third);

  }

  public static void main(String[] args) {
    TestMethod (0,0,0);
  }

}

C:\&gt;javac Test.java

C:\&gt;java Test
12
17.2
19.0
19.0

C:\&gt;java org.apache.bcel.util.BCELifier Test &gt; TestCreator.java

C:\&gt;type TestCreator.java
import org.apache.bcel.generic.*;
import org.apache.bcel.classfile.*;
import org.apache.bcel.*;
import java.io.*;

public class TestCreator implements Constants {
  private InstructionFactory _factory;
  private ConstantPoolGen    _cp;
  private ClassGen           _cg;

  public TestCreator() {
    _cg = new ClassGen("Test", "java.lang.Object", "Test.java", ACC_PUBLIC | ACC_SUPER, new
String[] {  });

    _cp = _cg.getConstantPool();
    _factory = new InstructionFactory(_cg, _cp);
  }

  public void create(OutputStream out) throws IOException {
    createMethod_0();
    createMethod_1();
    createMethod_2();
    _cg.getJavaClass().dump(out);
  }

  private void createMethod_0() {
    InstructionList il = new InstructionList();
    MethodGen method = new MethodGen(ACC_PUBLIC, Type.VOID, Type.NO_ARGS, new String[] { 
}, "&lt;init&gt;", "Test", il, _cp);

    InstructionHandle ih_0 = il.append(_factory.createLoad(Type.OBJECT, 0));
    il.append(_factory.createInvoke("java.lang.Object", "&lt;init&gt;", Type.VOID, Type.NO_ARGS,
Constants.INVOKESPECIAL));
    InstructionHandle ih_4 = il.append(_factory.createReturn(Type.VOID));
    method.setMaxStack();
    method.setMaxLocals();
    _cg.addMethod(method.getMethod());
    il.dispose();
  }

  private void createMethod_1() {
    InstructionList il = new InstructionList();
    MethodGen method = new MethodGen(ACC_PUBLIC | ACC_STATIC, Type.VOID, new Type[] { Type.INT,
Type.DOUBLE, Type.FLOAT }, new String[] { "arg0", "arg1", "arg2" }, "TestMethod", "Test",
il, _cp);

    InstructionHandle ih_0 = il.append(new PUSH(_cp, 15.0));
    il.append(_factory.createStore(Type.FLOAT, 3));
    InstructionHandle ih_3 = il.append(new PUSH(_cp, 12));
    il.append(_factory.createStore(Type.INT, 0));
    InstructionHandle ih_6 = il.append(new PUSH(_cp, 17.2));
    il.append(_factory.createStore(Type.DOUBLE, 1));
    InstructionHandle ih_10 = il.append(new PUSH(_cp, 19.0));
    il.append(_factory.createStore(Type.FLOAT, 3));
    InstructionHandle ih_13 = il.append(_factory.createFieldAccess("java.lang.System", "out",
new ObjectType("java.io.PrintStream"), Constants.GETSTATIC));
    il.append(_factory.createLoad(Type.INT, 0));
    il.append(_factory.createInvoke("java.io.PrintStream", "println", Type.VOID, new Type[]
{ Type.INT }, Constants.INVOKEVIRTUAL));
    InstructionHandle ih_20 = il.append(_factory.createFieldAccess("java.lang.System", "out",
new ObjectType("java.io.PrintStream"), Constants.GETSTATIC));
    il.append(_factory.createLoad(Type.DOUBLE, 1));
    il.append(_factory.createInvoke("java.io.PrintStream", "println", Type.VOID, new Type[]
{ Type.DOUBLE }, Constants.INVOKEVIRTUAL));
    InstructionHandle ih_27 = il.append(_factory.createFieldAccess("java.lang.System", "out",
new ObjectType("java.io.PrintStream"), Constants.GETSTATIC));
    il.append(_factory.createLoad(Type.FLOAT, 3));
    il.append(_factory.createInvoke("java.io.PrintStream", "println", Type.VOID, new Type[]
{ Type.FLOAT }, Constants.INVOKEVIRTUAL));
    InstructionHandle ih_34 = il.append(_factory.createFieldAccess("java.lang.System", "out",
new ObjectType("java.io.PrintStream"), Constants.GETSTATIC));
    il.append(_factory.createLoad(Type.FLOAT, 3));
    il.append(_factory.createInvoke("java.io.PrintStream", "println", Type.VOID, new Type[]
{ Type.FLOAT }, Constants.INVOKEVIRTUAL));
    InstructionHandle ih_41 = il.append(_factory.createReturn(Type.VOID));
    method.setMaxStack();
    method.setMaxLocals();
    _cg.addMethod(method.getMethod());
    il.dispose();
  }

  private void createMethod_2() {
    InstructionList il = new InstructionList();
    MethodGen method = new MethodGen(ACC_PUBLIC | ACC_STATIC, Type.VOID, new Type[] { new
ArrayType(Type.STRING, 1) }, new String[] { "arg0" }, "main", "Test", il, _cp);

    InstructionHandle ih_0 = il.append(new PUSH(_cp, 0));
    il.append(new PUSH(_cp, 0.0));
    il.append(new PUSH(_cp, 0.0));
    il.append(_factory.createInvoke("Test", "TestMethod", Type.VOID, new Type[] { Type.INT,
Type.DOUBLE, Type.FLOAT }, Constants.INVOKESTATIC));
    InstructionHandle ih_6 = il.append(_factory.createReturn(Type.VOID));
    method.setMaxStack();
    method.setMaxLocals();
    _cg.addMethod(method.getMethod());
    il.dispose();
  }

  public static void main(String[] args) throws Exception {
    TestCreator creator = new TestCreator();
    creator.create(new FileOutputStream("Test.class"));
  }
}

C:\&gt;ren Test.class Test.class.old

C:\&gt;javac TestCreator.java

C:\&gt;java TestCreator

C:\&gt;java Test
Exception in thread "main" java.lang.VerifyError: (class: Test, method: main signature: ([Ljava/lang/String;)V)
Expecting to find float on stack
Could not find the main class: Test.  Program will exit.

C:\&gt;java -version
java version "1.6.0_16"
Java(TM) SE Runtime Environment (build 1.6.0_16-b01)
Java HotSpot(TM) Client VM (build 14.2-b01, mixed mode, sharing)

C:\&gt;
-----------------------------------------------

With all other programs, which I have tested, it runs ok. But Test.java can not be BCELified
and then again with it correct created.

Btw: BCEL-Version: 5.2 (the latest one).

Greatings
theuserbl

 		 	   		  
_________________________________________________________________
http://redirect.gimas.net/?n=M0911xDateiensenden3
Große Daten übertragen? Ganz einfach mit dem Messenger!

</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Getting the local variables of a method</title>
<author><name>Matthew Wilson &lt;mj.wilson.uk@googlemail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200911.mbox/%3cbbd1d7280911030132u745cd13eta8639244c97076ae@mail.gmail.com%3e"/>
<id>urn:uuid:%3cbbd1d7280911030132u745cd13eta8639244c97076ae@mail-gmail-com%3e</id>
<updated>2009-11-03T09:32:07Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
2009/11/2 MUTHURAMAN SWAMINADHAN &lt;muthu437@yahoo.com&gt;:
&gt; I have been trying to get the local variables in a method but I don't see anything returned.
I am using the following snippet.
&gt;
&gt; LocalVariable lv[];
&gt; LocalVariableTable lvt;
&gt; lvt=mt.getLocalVariableTable(); //mt is a method  object
&gt; lv=lvt.getLocalVariableTable();
&gt;
&gt; I don't get anything back in the lv array. Can anyone advise if this is the correct approach
or if there is a better approach?

The local variable table is an optional table in the class file.
Unless you compile with the debug option (which, by default, includes
the local variables, line numbers, and location of the original
source), it will be missing.  Try "javac -g" to compile.

See the Java VM specification for more details:

  http://java.sun.com/docs/books/jvms/second_edition/html/ClassFile.doc.html#5956

You can also use javap to have a look at the local variable table (to
see if it is there in the file):

  javap -verbose MyClass

I hope that helps.

Kind regards,
Matthew

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Getting the local variables of a method</title>
<author><name>MUTHURAMAN SWAMINADHAN &lt;muthu437@yahoo.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200911.mbox/%3c473700.51271.qm@web33005.mail.mud.yahoo.com%3e"/>
<id>urn:uuid:%3c473700-51271-qm@web33005-mail-mud-yahoo-com%3e</id>
<updated>2009-11-02T21:49:42Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi,
 
I have been trying to get the local variables in a method but I don't see anything returned.
I am using the following snippet.

LocalVariable lv[];
LocalVariableTable lvt;
lvt=mt.getLocalVariableTable(); //mt is a method  object
lv=lvt.getLocalVariableTable();
 
I don't get anything back in the lv array. Can anyone advise if this is the correct approach
or if there is a better approach?

Thanks,
 Muthu
 
 
       
 
 
 
       


      

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>How to handel debug-informations?</title>
<author><name>theUser BL &lt;theuserbl@hotmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200910.mbox/%3cBAY116-W1311C5F577ED73EF662FF2A9B70@phx.gbl%3e"/>
<id>urn:uuid:%3cBAY116-W1311C5F577ED73EF662FF2A9B70@phx-gbl%3e</id>
<updated>2009-10-29T18:04:49Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Hi!

Where can I read how to handle debug-informations with BCEL?
And is it possible with it?

I have tried org.apache.bcel.util.BCELifier out.
The created programs still runs like the originals.
But the recreated programs are all WITHOUT debug-informations.
:-(

So, is it possible to create them? And how?


Btw: At http://jakarta.apache.org/bcel/faq.html there stands under the question "Can I use
BCEL in a commercial product?" the address "http://jakarta.apace.org/bcel/". You read right.
There stant "Apache" without "h" !

Btw2: At http://packages.debian.org/de/source/lenny/bcel there existing already a BCEL 5.2-3.
And as you can see at http://packages.qa.debian.org/b/bcel.html thats the stable version.
Unstable is 5.2-6.
Why are that patches not in the official BCEL-version? Why existing no new version 5.2.3 on
the BCEL-side? Or are the changes unimportant?

Greatings
theuserbl

 		 	   		  
_________________________________________________________________
Das neue Windows 7: Vereinfachen Sie Ihre täglichen Aufgaben. Finden Sie den richtigen PC.
http://www.microsoft.com/germany/windows/buy/ 
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Set serialVersionUID</title>
<author><name>Matthew Wilson &lt;mj.wilson.uk@googlemail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200910.mbox/%3cbbd1d7280910171311h3713ca83y2b4ca339c92cfb6a@mail.gmail.com%3e"/>
<id>urn:uuid:%3cbbd1d7280910171311h3713ca83y2b4ca339c92cfb6a@mail-gmail-com%3e</id>
<updated>2009-10-17T20:11:22Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
On 16/10/2009, JS &lt;jshellman@gmail.com&gt; wrote:
&gt; How would I set the serialVersionUID using BCEL? I'm using BCEL's
&gt; ClassLoader, overriding modifyClass. I have it adding the Serializable
&gt; interface successfully, but I also need to set the serialVersionUID
&gt; for the class. How would I do so?

Hi,

You want to create a FieldGen with the UID you want and add it to the
ClassGen, e.g.:

ClassGen classGen = new ClassGen( clazz );

// create a FieldGen for 'private static final int serialVersionUID'
FieldGen fieldGen = new FieldGen( Constants.ACC_PRIVATE |
Constants.ACC_FINAL | Constants.ACC_STATIC, Type.INT,
"serialVersionUID", classGen.getConstantPool() );

// set an initial value
fieldGen.setInitValue( mySerialVersionUID );

// add it to the class
classGen.addField( fieldGen.getField() );

JavaClass modifiedClass = classGen.getJavaClass();


I hope that helps.  (I haven't actually compiled and tested that code.)

Kind regards,
Matthew

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Set serialVersionUID</title>
<author><name>JS &lt;jshellman@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200910.mbox/%3c975a94850910161309n2385649ag464f6e5cf49d51f9@mail.gmail.com%3e"/>
<id>urn:uuid:%3c975a94850910161309n2385649ag464f6e5cf49d51f9@mail-gmail-com%3e</id>
<updated>2009-10-16T20:09:34Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
How would I set the serialVersionUID using BCEL? I'm using BCEL's
ClassLoader, overriding modifyClass. I have it adding the Serializable
interface successfully, but I also need to set the serialVersionUID
for the class. How would I do so?

Thanks!

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Iterating over classes from a repository</title>
<author><name>&quot;asdfgh-v6ak&quot; &lt;asdfgh-v6ak@soukroma.cz&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200908.mbox/%3c5fd02da3b6e2aceb65a93025d14d179e@www1-mail.volny.cz%3e"/>
<id>urn:uuid:%3c5fd02da3b6e2aceb65a93025d14d179e@www1-mail-volny-cz%3e</id>
<updated>2009-08-07T06:25:43Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
I want to iterate over all classes (interfaces, enums, ...) from a repository
(e.g. a jar file). How can I do it? The interface Repository is not
Iterable&lt;? extends JavaClass&gt;.


---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Matching line numbers from debug-compiled code to original source</title>
<author><name>Laran Evans &lt;laran.evans@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200907.mbox/%3c30ec9fe20907240904r5eeadfdmd8c8165a73aa3d08@mail.gmail.com%3e"/>
<id>urn:uuid:%3c30ec9fe20907240904r5eeadfdmd8c8165a73aa3d08@mail-gmail-com%3e</id>
<updated>2009-07-24T16:04:19Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
I've been reading through the documentation (mostly the BCEL JavaDocs)
to find out how to do this.

I'm compiling code with debugging info enabled. So, the line number
info is in there.

What I need to do is take the compiled .class file, and do something like this:

for each method in myClass:
- Code code  = method.getCode();
- String instructions = Utility.codeToString(code.getCode(),
code.getConstantPool(), 0, -1, false)
- Figure out the line number in the source code for each (or at least
some) instruction.

How would I do this?

I've been looking at LineNumberTable but haven't figured out how to
put the pieces together.

So, how would I do this?

Thanks.

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>LocalVariableGen appearing twice in InstructionTargeters list</title>
<author><name>Felix Dorner &lt;FDorner@zed.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200907.mbox/%3cFC95BD382E2CF447BAA1B2AF1F9FFFE602628AD2C4@MX034ZED0001.TIFDOM.COM%3e"/>
<id>urn:uuid:%3cFC95BD382E2CF447BAA1B2AF1F9FFFE602628AD2C4@MX034ZED0001-TIFDOM-COM%3e</id>
<updated>2009-07-03T10:20:26Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hey,

I can see a LocalVariableGen _twice_ in the InstructionTargeter list for the first InstructionHandle
of a method. Why would this happen? The LocalVariableGen is the one that represents the 'this'
variable. 

I assume the LocalVariableGen is an InstructionTargeter because it maintains the 'start' and
'end' instructions which defines the scope of the variable?

The first instruction is always the 'start' instruction for the 'this' variables scope right?
This would explain why the LocalVariableGen has it targeted.


Thanks for hints,
Felix  
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>RE: Extract Constructor Code to new method</title>
<author><name>Felix Dorner &lt;FDorner@zed.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200907.mbox/%3cFC95BD382E2CF447BAA1B2AF1F9FFFE602628AD26F@MX034ZED0001.TIFDOM.COM%3e"/>
<id>urn:uuid:%3cFC95BD382E2CF447BAA1B2AF1F9FFFE602628AD26F@MX034ZED0001-TIFDOM-COM%3e</id>
<updated>2009-07-02T14:54:52Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi Abdullah,

&gt; InstructionList il = new InstructionList(); Method
&gt; theOldConstructor = cg.containsMethod("&lt;&gt;", "()V"); MethodGen
&gt; theNewConstructor = new MethodGen(Constants.ACC_PUBLIC,
&gt; Type.VOID, Type.NO_ARGS, NO_STRINGS, "&lt;init&gt;",
&gt; cg.getClassName(), il, cpg);
&gt; il.append(ifact.createInvoke(cg.getSuperclassName(),
&gt; "&lt;init&gt;", Type.VOID, Type.NO_ARGS, Constants.INVOKESPECIAL));
&gt; il.append(InstructionConstants.RETURN);
&gt; cg.replaceMethod(theOldConstructor,
&gt; theNewConstructor.getMethod()); il.dispose(); cg.setConstantPool(cpg);


Wouldn't this just 'delete' the old constructor, and create a new 'default' one?
What misses is to move the code that's inside the old constructor into an ordinairy method.
What I came up with so far was to:

/* look up the default constructor */
Method constructor_method = getConstructors().get(0);
ConstantPoolGen cpgen = new ConstantPoolGen(jc.getConstantPool());

MethodGen constructor = new MethodGen(constructor_method, jc.getClassName(), new ConstantPoolGen(jc.getConstantPool()));
InstructionList constructor_code = constructor.getInstructionList();

/* a new method. Later I'd need to find a unique name.. I also copy the constructor's instruction
list*/
MethodGen newmethod = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, new Type[] {}, new String[]
{}, "xaxaxa", jc.getClassName(),  constructor_code.copy() , cpgen);

InstructionHandle[] newmethod_instructions = newmethod.getInstructionList().getInstructionHandles();

/* remove the first two instructions (the one that loads the object variable this,
And the invocation of the super-constructor... */
try {
        newmethod.getInstructionList().delete(newmethod_instructions[0], newmethod_instructions[1]);
} catch (TargetLostException e) {
        /* not only the target is lost here.. But me too.. :-)
        e.printStackTrace();
}

... Now I'd probably need to handle
 * local variables
 * exception handlers
..

What I don't really pick up is the instruction target exceptions (which in fact get thrown
by several LineNumberGen's in my tests..)

Felix

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Extract Constructor Code to new method</title>
<author><name>Abdullah Odeh Al-Zaghameem &lt;aoz_0202@yahoo.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200907.mbox/%3c479276.67686.qm@web59304.mail.re1.yahoo.com%3e"/>
<id>urn:uuid:%3c479276-67686-qm@web59304-mail-re1-yahoo-com%3e</id>
<updated>2009-07-02T13:31:07Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi,
 
One basic solution is to catch the old constructor and inject the new one. The following code
do it in simple way:
 
InstructionList il = new InstructionList();
Method theOldConstructor = cg.containsMethod("&lt;&gt;", "()V");
MethodGen theNewConstructor = new MethodGen(Constants.ACC_PUBLIC, Type.VOID, Type.NO_ARGS,
NO_STRINGS, "&lt;init&gt;", cg.getClassName(), il, cpg);
il.append(ifact.createInvoke(cg.getSuperclassName(), "&lt;init&gt;", Type.VOID, Type.NO_ARGS,
Constants.INVOKESPECIAL));
il.append(InstructionConstants.RETURN);
cg.replaceMethod(theOldConstructor, theNewConstructor.getMethod()); 
il.dispose();
cg.setConstantPool(cpg);
 
 
Regards

===============================
A b d u l l a h   O.  A l - Z a g h a m e e m
Technical University of  Berlin
Germany

--- On Thu, 7/2/09, Felix Dorner &lt;FDorner@zed.com&gt; wrote:


From: Felix Dorner &lt;FDorner@zed.com&gt;
Subject: Extract Constructor Code to new method
To: "bcel-user@jakarta.apache.org" &lt;bcel-user@jakarta.apache.org&gt;
Date: Thursday, July 2, 2009, 11:23 AM


Hey,

Given a no-arg constructor, I'd like to insert a new public method and move all instructions
into that new method. After moving that code, the constructor would look like one that's automatically
inserted by the compiler, i.e. only calls &lt;init&gt; of its superclass and returns.

I've never done anything with BCEL, though I can follow the general information pages. Still,
I have no Idea how hard my problem is and therefore wanted to ask here for some guidance.


Thanks,
Felix
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org




      

</pre>
</div>
</content>
</entry>
<entry>
<title>Extract Constructor Code to new method</title>
<author><name>Felix Dorner &lt;FDorner@zed.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200907.mbox/%3cFC95BD382E2CF447BAA1B2AF1F9FFFE602628AD1E7@MX034ZED0001.TIFDOM.COM%3e"/>
<id>urn:uuid:%3cFC95BD382E2CF447BAA1B2AF1F9FFFE602628AD1E7@MX034ZED0001-TIFDOM-COM%3e</id>
<updated>2009-07-02T08:23:12Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hey,

Given a no-arg constructor, I'd like to insert a new public method and move all instructions
into that new method. After moving that code, the constructor would look like one that's automatically
inserted by the compiler, i.e. only calls &lt;init&gt; of its superclass and returns.

I've never done anything with BCEL, though I can follow the general information pages. Still,
I have no Idea how hard my problem is and therefore wanted to ask here for some guidance.


Thanks,
Felix
---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: misunderstanding of InstructionFactory</title>
<author><name>Abdullah Odeh Al-Zaghameem &lt;aoz_0202@yahoo.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200907.mbox/%3c789634.56795.qm@web59305.mail.re1.yahoo.com%3e"/>
<id>urn:uuid:%3c789634-56795-qm@web59305-mail-re1-yahoo-com%3e</id>
<updated>2009-07-01T17:24:40Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Hi,
 
You do not mentioned the type of your problem. Is it a Runtime Exception or you just didn't
get the expected results?. If the second option is the case, then you my inject your code
at the end of the constructor which, as I can guess, fall after the RETURN instruction.
 
If the first option is the case, then AUCH!!, no way to see in dark man, because your code
is corrct (the one with ifact.createThis(), but try InstructionFactory.createThis();)
). 

Best Regards,

===============================
A b d u l l a h   O.  A l - Z a g h a m e e m
Technical University of  Berlin
Germany

--- On Mon, 6/15/09, casertap &lt;pierre.caserta@loria.fr&gt; wrote:


From: casertap &lt;pierre.caserta@loria.fr&gt;
Subject: misunderstanding of InstructionFactory
To: bcel-user@jakarta.apache.org
Date: Monday, June 15, 2009, 7:22 PM



I have a very basic class:
---------------
public class MyClass{
    public static LinkedList&lt;Class&gt; classesLoaded;
    public static void addClass(Object o){
        Class c = o.getClass();
        classesLoaded.add(c);
    }
}
----------------
I have another class which adds statements to class constructor (when the
class is charged by the JVM).

My class implements ClassFileTransformer and I use the transform method to
do the modification on each class which is loaded.

I just want to add this java code to class constructor :
MyClass.addClass(this);
MyClass.addClass = a static invocation of the addClass method
(this) = the class which the JVM is loading.
This way I can save a list of class (of my application) which are loaded by
the JVM because every constructor add an object in the classesLoaded
LinkedList.

I suppose, I must use the class InstructionFactory to genetate the byte
code, but I have some problems.

This is what i made but it does not work:

InstructionList il = new InstructionList();
InstructionFactory ifact = new InstructionFactory(constantPoolGen);

il.append(ifact.createThis());
//I think i must push This on the stack but i do not know
il.append(ifact.createInvoke("MyClass","addClass",Type.VOID, new
Type[]{Type.OBJECT}, Constants.INVOKESTATIC));

it work when I write :

il.append(new PUSH(constantPoolGen,javaClass.getClassName()));
il.append(instructionFactory.createInvoke("MyClass", "addClass", Type.VOID,
new Type[] { Type.OBJECT }, Constants.INVOKESTATIC));

but in the latter version I send a String object to the addClass method. It
is not what I want.

-- 
View this message in context: http://www.nabble.com/misunderstanding-of-InstructionFactory-tp24037858p24037858.html
Sent from the BCEL - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org




      

</pre>
</div>
</content>
</entry>
<entry>
<title>misunderstanding of InstructionFactory</title>
<author><name>casertap &lt;pierre.caserta@loria.fr&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200906.mbox/%3c24037858.post@talk.nabble.com%3e"/>
<id>urn:uuid:%3c24037858-post@talk-nabble-com%3e</id>
<updated>2009-06-15T16:22:46Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

I have a very basic class:
---------------
public class MyClass{
	public static LinkedList&lt;Class&gt; classesLoaded;
	public static void addClass(Object o){
		Class c = o.getClass();
		classesLoaded.add(c);
	}
}
----------------
I have another class which adds statements to class constructor (when the
class is charged by the JVM).

My class implements ClassFileTransformer and I use the transform method to
do the modification on each class which is loaded.

I just want to add this java code to class constructor :
MyClass.addClass(this);
MyClass.addClass = a static invocation of the addClass method
(this) = the class which the JVM is loading.
This way I can save a list of class (of my application) which are loaded by
the JVM because every constructor add an object in the classesLoaded
LinkedList.

I suppose, I must use the class InstructionFactory to genetate the byte
code, but I have some problems.

This is what i made but it does not work:

InstructionList il = new InstructionList();
InstructionFactory ifact = new InstructionFactory(constantPoolGen);

il.append(ifact.createThis());
//I think i must push This on the stack but i do not know
il.append(ifact.createInvoke("MyClass","addClass",Type.VOID, new
Type[]{Type.OBJECT}, Constants.INVOKESTATIC));

it work when I write :

il.append(new PUSH(constantPoolGen,javaClass.getClassName()));
il.append(instructionFactory.createInvoke("MyClass", "addClass", Type.VOID,
new Type[] { Type.OBJECT }, Constants.INVOKESTATIC));

but in the latter version I send a String object to the addClass method. It
is not what I want.

-- 
View this message in context: http://www.nabble.com/misunderstanding-of-InstructionFactory-tp24037858p24037858.html
Sent from the BCEL - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Shao Xing Huang is out of the office.</title>
<author><name>Shao Xing Huang &lt;huangsx@cn.ibm.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200906.mbox/%3cOF7269E106.4043A217-ON482575D3.002C48AB-482575D3.002C48AB@cn.ibm.com%3e"/>
<id>urn:uuid:%3cOF7269E106-4043A217-ON482575D3-002C48AB-482575D3-002C48AB@cn-ibm-com%3e</id>
<updated>2009-06-12T08:03:41Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Content-type: text/plain; charset=US-ASCII


I will be out of the office starting  2009-06-11 and will not return until
2009-06-18.

I will respond to your message when I return.

</pre>
</div>
</content>
</entry>
<entry>
<title>LVTT Error, applying patches, stability of the SVN trunk</title>
<author><name>scworldnetter-java@yahoo.com</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200906.mbox/%3c942833.29671.qm@web31815.mail.mud.yahoo.com%3e"/>
<id>urn:uuid:%3c942833-29671-qm@web31815-mail-mud-yahoo-com%3e</id>
<updated>2009-06-12T05:13:15Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
I've been using BCEL for a while, and I am still on an old release, even pre-5.1. Lately, I've
been getting a lot of LVTT errors, and I have found the following BugZilla entry that apparently
addresses the issue:

http://issues.apache.org/bugzilla/show_bug.cgi?id=39695

The patch for this bug appears to be on BCEL 5.2, so I went ahead and upgraded to BCEL 5.2,
but unfortunately, when I go to apply the patch, it requires a lot more changes than what
is listed in the patch. The patch calls for org.apache.bcel.classfile.LocalVariableTypeTable,
but this class isn't part of the 5.2 release. I went ahead and pulled the SVN trunk. There,
one can find org.apache.bcel.classfile.LocalVariableTypeTable, it's apparently based on LocalVariableTypeTable
from AspectJ, since it has the CPL license header. 

I built from the trunk, but perhaps it's a bit naive on my part ot expect it to be stable
since it's not near a release candidate. The first error I got was a full blown JVM crash
on Tomcat 6 on JDK 1.5: 

#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
#  Internal Error (4A41564123414C4C530E4350500013), pid=2508, tid=2468
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_02-b09 mixed mode)
# An error report file with more information is saved as hs_err_pid2508.log
#
# If you would like to submit a bug report, please visit:
#   http://java.sun.com/webapps/bugreport/crash.jsp
#

My BCEL processor seems to initialize fine via a java 5 agent, but it appears that the failure
occurs as the first modified class is passed back to the JVM, but I am not sure because this
seems like a pretty serious error. 

I should probably try to apply the patch listed in 39695, but then, what revision is that
patch based on? Am I missing something obvious here? Is there a place that shows all the revisions
that went into the trunk? It seems very difficult to track the changes made. I did a diff
on trunk and the 5.2 download, there is a pretty big delta in between the two.

</pre>
</div>
</content>
</entry>
<entry>
<title>Re: ArrayIndexOutOfBoundsException in generic.PUTFIELD</title>
<author><name>Arrin Daley &lt;arrin.daley@anu.edu.au&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200905.mbox/%3c4A1F2943.9050706@anu.edu.au%3e"/>
<id>urn:uuid:%3c4A1F2943-9050706@anu-edu-au%3e</id>
<updated>2009-05-29T00:16:03Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi Razvan

If you use the BCEL APIs you can see what effect each bytecode will have on the stack (it's
amongst the first lines explaining each bytecode), the stack is initially empty and the arguments
are in the ALOAD_0, ILOAD1 etc slots.
Anyway I've gone through and produced an idea of what the stack does for each method below,
there appears to be a couple of problems the LDC_W doesn't seem right LDC_W is typically for
loading wide constants such as double and long from the constantPool, second we end up with
the result of an ALOAD_0 still on the stack at the end of the execution of the method which
shouldn't happen either. Neither of these really explain how you are getting a StackUnderflow
problem as these are both putting too much on the stack. Anyway they are worth fixing, and
perhaps it creates trouble further down the line?

Bye Arrin

Code:
   0:	aload_0
obj,
   1:	getstatic	#19; //Field jist/runtime/JistAPI.THIS:Ljist/runtime/JistAPI$Entity;
obj, obj
   4:	ldc_w	#20; //class jist/swans/app/AppInterface$UdpApp
obj, obj, w1, w2,
   7:	invokestatic	#21; //Method jist/runtime/JistAPI.proxy:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
1st problem here the last thing put on the stack was the result of the LDC_W(a wide type constant,
like a long or a double) but the invokestatic is expecting 2 objects. 
Perhaps it's supposed to be an LDC? I'll continue as though it is... obj, obj, Class

obj, obj, obj
   10:	checkcast	#20; //class jist/swans/app/AppInterface$UdpApp
obj, obj, obj
   13:	invokeinterface	#22,  1; //InterfaceMethod jist/swans/app/AppInterface$UdpApp.getUdpEntity:()Ljist/swans/trans/TransInterface$TransUdpInterface;
obj, obj, obj
   18:	putfield	#23; //Field udpEntity:Ljist/swans/trans/TransInterface;
obj
   21:	aload_0
obj, obj
   22:	new	#1; //class java/net/InetSocketAddress
obj, obj, new
   25:	dup
obj, obj, new, new
   26:	aload_0
obj, obj, new, new, obj
   27:	getfield	#12; //Field laddr:Ljava/net/InetAddress;
obj, obj, new, new, obj
   30:	aload_0
obj, obj, new, new, obj, obj
   31:	getfield	#10; //Field lport:I
obj, obj, new, new, obj, I
   34:	invokespecial	#8; //Method java/net/InetSocketAddress."&lt;init&gt;":(Ljava/net/InetAddress;I)V
obj, obj, new
   37:	invokevirtual	#24; //Method bind:(Ljava/net/SocketAddress;)V
obj
   40:	return
There shouldn't be anything left on the stack at this point.


Code:
   0:	aload_0
obj,
   1:	getstatic	#24; //Field jist/runtime/JistAPI.THIS:Ljist/runtime/JistAPI$Entity;
obj, obj
   4:	getstatic	#25; //Field class$jist$swans$app$AppInterface$UdpApp:Ljava/lang/Class;
obj, obj, obj
   7:	ifnonnull	22
obj, obj
   10:	ldc	#26; //String jist.swans.app.AppInterface$UdpApp
obj, obj, String
   12:	invokestatic	#27; //Method class$:(Ljava/lang/String;)Ljava/lang/Class;
obj, obj, Class
   15:	dup
obj, obj, Class, Class
   16:	putstatic	#25; //Field class$jist$swans$app$AppInterface$UdpApp:Ljava/lang/Class;
obj, obj, Class
   19:	goto	25
   22:	getstatic	#25; //Field class$jist$swans$app$AppInterface$UdpApp:Ljava/lang/Class;
obj, obj, class
   25:	invokestatic	#28; //Method jist/runtime/JistAPI.proxy:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
obj, obj,
   28:	checkcast	#29; //class jist/swans/app/AppInterface$UdpApp
obj, obj,
   31:	invokeinterface	#30,  1; //InterfaceMethod jist/swans/app/AppInterface$UdpApp.getUdpEntity:()Ljist/swans/trans/TransInterface$TransUdpInterface;
obj, obj
   36:	putfield	#31; //Field udpEntity:Ljist/swans/trans/TransInterface;
.
   39:	aload_0
obj
   40:	new	#6; //class java/net/InetSocketAddress
obj, new
   43:	dup
obj, new, new
   44:	aload_0
obj, new, new, obj
   45:	getfield	#17; //Field laddr:Ljava/net/InetAddress;
obj, new, new, obj
   48:	aload_0
obj, new, new, obj, obj
   49:	getfield	#15; //Field lport:I
obj, new, new, obj, I
   52:	invokespecial	#13; //Method java/net/InetSocketAddress."&lt;init&gt;":(Ljava/net/InetAddress;I)V
obj, new
   55:	invokevirtual	#32; //Method bind:(Ljava/net/SocketAddress;)V
.
   58:	return




Razvanica wrote:
&gt; Hello Arrin, 
&gt;
&gt; Thank you for your response. I found the method that fails and it's true
&gt; that the bytecode resulting after compiling with the "-source 1.4" flag and
&gt; the one that result when I compile with the "-source 1.5" are very
&gt; different. Unfortunately for me, I don't have the skills required to judge
&gt; what exactly triggers the exception I was talking about (I understand I try
&gt; to pop from an empty stack but I haven't yet figured what exactly should be
&gt; on that stack). I will post here the 2 bytecodes, hoping you or someone else
&gt; would be able to detect the problem. 
&gt;
&gt; The bytecode that works (generated with "-source 1.4") is:
&gt; public void _jistPostInit();
&gt;   Code:
&gt;    0:	aload_0
&gt;    1:	getstatic	#24; //Field
&gt; jist/runtime/JistAPI.THIS:Ljist/runtime/JistAPI$Entity;
&gt;    4:	getstatic	#25; //Field
&gt; class$jist$swans$app$AppInterface$UdpApp:Ljava/lang/Class;
&gt;    7:	ifnonnull	22
&gt;    10:	ldc	#26; //String jist.swans.app.AppInterface$UdpApp
&gt;    12:	invokestatic	#27; //Method
&gt; class$:(Ljava/lang/String;)Ljava/lang/Class;
&gt;    15:	dup
&gt;    16:	putstatic	#25; //Field
&gt; class$jist$swans$app$AppInterface$UdpApp:Ljava/lang/Class;
&gt;    19:	goto	25
&gt;    22:	getstatic	#25; //Field
&gt; class$jist$swans$app$AppInterface$UdpApp:Ljava/lang/Class;
&gt;    25:	invokestatic	#28; //Method
&gt; jist/runtime/JistAPI.proxy:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
&gt;    28:	checkcast	#29; //class jist/swans/app/AppInterface$UdpApp
&gt;    31:	invokeinterface	#30,  1; //InterfaceMethod
&gt; jist/swans/app/AppInterface$UdpApp.getUdpEntity:()Ljist/swans/trans/TransInterface$TransUdpInterface;
&gt;    36:	putfield	#31; //Field udpEntity:Ljist/swans/trans/TransInterface;
&gt;    39:	aload_0
&gt;    40:	new	#6; //class java/net/InetSocketAddress
&gt;    43:	dup
&gt;    44:	aload_0
&gt;    45:	getfield	#17; //Field laddr:Ljava/net/InetAddress;
&gt;    48:	aload_0
&gt;    49:	getfield	#15; //Field lport:I
&gt;    52:	invokespecial	#13; //Method
&gt; java/net/InetSocketAddress."&lt;init&gt;":(Ljava/net/InetAddress;I)V
&gt;    55:	invokevirtual	#32; //Method bind:(Ljava/net/SocketAddress;)V
&gt;    58:	return
&gt;
&gt; The one that fails, generated with "-source 1.5" is:
&gt; public void _jistPostInit();
&gt;   Code:
&gt;    0:	aload_0
&gt;    1:	getstatic	#19; //Field
&gt; jist/runtime/JistAPI.THIS:Ljist/runtime/JistAPI$Entity;
&gt;    4:	ldc_w	#20; //class jist/swans/app/AppInterface$UdpApp
&gt;    7:	invokestatic	#21; //Method
&gt; jist/runtime/JistAPI.proxy:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
&gt;    10:	checkcast	#20; //class jist/swans/app/AppInterface$UdpApp
&gt;    13:	invokeinterface	#22,  1; //InterfaceMethod
&gt; jist/swans/app/AppInterface$UdpApp.getUdpEntity:()Ljist/swans/trans/TransInterface$TransUdpInterface;
&gt;    18:	putfield	#23; //Field udpEntity:Ljist/swans/trans/TransInterface;
&gt;    21:	aload_0
&gt;    22:	new	#1; //class java/net/InetSocketAddress
&gt;    25:	dup
&gt;    26:	aload_0
&gt;    27:	getfield	#12; //Field laddr:Ljava/net/InetAddress;
&gt;    30:	aload_0
&gt;    31:	getfield	#10; //Field lport:I
&gt;    34:	invokespecial	#8; //Method
&gt; java/net/InetSocketAddress."&lt;init&gt;":(Ljava/net/InetAddress;I)V
&gt;    37:	invokevirtual	#24; //Method bind:(Ljava/net/SocketAddress;)V
&gt;    40:	return
&gt;
&gt; The exception appears when the putfield operation is rewritten.
&gt;
&gt; Thank you once again for your answer,
&gt;
&gt; Razvan. 
&gt;
&gt;
&gt;
&gt;
&gt; Arrin Daley wrote:
&gt;   
&gt;&gt; Hi
&gt;&gt;
&gt;&gt; My experience is that the error you are getting is it because some 
&gt;&gt; method code has an invalid stack, in this case you are removing too many 
&gt;&gt; items from the stack, the verifier is picking this up and reporting the 
&gt;&gt; error. I'm not sure but perhaps some code doesn't call 
&gt;&gt; MethodGen.setMaxStack() after transforming, although I doubt it, because 
&gt;&gt; if the code were otherwise correct it should have complained of a stack 
&gt;&gt; overflow.
&gt;&gt;
&gt;&gt; The problem has to be with the method it is verifying at the time so if 
&gt;&gt; you can print out which method the verifier is working on and it's 
&gt;&gt; bytecodes you could go through it and find the problem. The bytecode 
&gt;&gt; pre-transformation by BCEL should be correct so the problem lies with 
&gt;&gt; the transformations your code performs.
&gt;&gt;
&gt;&gt; I'm don't know why this should be a problem with 1.5 and not 1.4.
&gt;&gt;
&gt;&gt; Hope it helps
&gt;&gt;
&gt;&gt; Bye Arrin
&gt;&gt;
&gt;&gt; Razvanica wrote:
&gt;&gt;     
&gt;&gt;&gt; Hello all,
&gt;&gt;&gt;
&gt;&gt;&gt; Here's my problem. I am trying to make some network simulations using a
&gt;&gt;&gt; tool
&gt;&gt;&gt; called JiST/SWANS. This simulator has been written for Java 1.4 and, for
&gt;&gt;&gt; my
&gt;&gt;&gt; simulations, I would like to use some 1.5 features, like genericity. 
&gt;&gt;&gt;
&gt;&gt;&gt; So what I am trying to do is to compile the original code with the
&gt;&gt;&gt; "source
&gt;&gt;&gt; -1.5" tag instead of the "source -1.4" tag. The problem is that the
&gt;&gt;&gt; simulator uses bcel to rewrite the bytecode so that JVM could be used for
&gt;&gt;&gt; simulations. The bcel library in the release doesn't work with the
&gt;&gt;&gt; "source
&gt;&gt;&gt; -1.5" tag so I replace it with bcel-5.2. I made 2 minor modifications to
&gt;&gt;&gt; the
&gt;&gt;&gt; original code :
&gt;&gt;&gt; - I have added an implementation of getClassPath in a class that
&gt;&gt;&gt; implements
&gt;&gt;&gt; org.apache.bcel.util.Repository. This class just returns null, just like
&gt;&gt;&gt; in
&gt;&gt;&gt; org.apache.bcel.util.ClassLoaderRepository
&gt;&gt;&gt; - In a class using org.apache.bcel.Repository.lookupClass() I am now
&gt;&gt;&gt; throwing java.lang.ClassNotFoundException 
&gt;&gt;&gt;
&gt;&gt;&gt; These 2 modifications shouldn't change anything as far as I understand
&gt;&gt;&gt; the
&gt;&gt;&gt; application. And when I compile the new code with the "-source 1.4" tag,
&gt;&gt;&gt; it
&gt;&gt;&gt; doesn,t change anything. Everything compiles and works just fine.
&gt;&gt;&gt; However,
&gt;&gt;&gt; when I compile the new code with the "-source 1.5" tag the compilation
&gt;&gt;&gt; goes
&gt;&gt;&gt; smoothly, but, at runtime, the rewriter throws an
&gt;&gt;&gt; ArrayIndexOutOfBoundsException.
&gt;&gt;&gt;
&gt;&gt;&gt;
&gt;&gt;&gt; This happens every time org.apache.bcel.generic.PUTFIELD.accept is
&gt;&gt;&gt; called:
&gt;&gt;&gt; java.lang.ArrayIndexOutOfBoundsException: -1 
&gt;&gt;&gt;    at java.util.ArrayList.remove(ArrayList.java:390)
&gt;&gt;&gt;    at
&gt;&gt;&gt; org.apache.bcel.verifier.structurals.OperandStack.pop(OperandStack.java:135)
&gt;&gt;&gt;    at
&gt;&gt;&gt; org.apache.bcel.verifier.structurals.ExecutionVisitor.visitPUTFIELD(ExecutionVisitor.java:1048)
&gt;&gt;&gt;    at org.apache.bcel.generic.PUTFIELD.accept(PUTFIELD.java:78)
&gt;&gt;&gt;
&gt;&gt;&gt; Does anybody have any idea what happens and if there's something I could
&gt;&gt;&gt; do
&gt;&gt;&gt; to fix this?
&gt;&gt;&gt;
&gt;&gt;&gt; Thank you.
&gt;&gt;&gt;   
&gt;&gt;&gt;       
&gt;&gt; ---------------------------------------------------------------------
&gt;&gt; To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
&gt;&gt; For additional commands, e-mail: bcel-user-help@jakarta.apache.org
&gt;&gt;
&gt;&gt;
&gt;&gt;
&gt;&gt;     
&gt;
&gt;   

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: ArrayIndexOutOfBoundsException in generic.PUTFIELD</title>
<author><name>Razvanica &lt;mos_februarie@yahoo.fr&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200905.mbox/%3c23722920.post@talk.nabble.com%3e"/>
<id>urn:uuid:%3c23722920-post@talk-nabble-com%3e</id>
<updated>2009-05-26T13:24:55Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Hello Arrin, 

Thank you for your response. I found the method that fails and it's true
that the bytecode resulting after compiling with the "-source 1.4" flag and
the one that result when I compile with the "-source 1.5" are very
different. Unfortunately for me, I don't have the skills required to judge
what exactly triggers the exception I was talking about (I understand I try
to pop from an empty stack but I haven't yet figured what exactly should be
on that stack). I will post here the 2 bytecodes, hoping you or someone else
would be able to detect the problem. 

The bytecode that works (generated with "-source 1.4") is:
public void _jistPostInit();
  Code:
   0:	aload_0
   1:	getstatic	#24; //Field
jist/runtime/JistAPI.THIS:Ljist/runtime/JistAPI$Entity;
   4:	getstatic	#25; //Field
class$jist$swans$app$AppInterface$UdpApp:Ljava/lang/Class;
   7:	ifnonnull	22
   10:	ldc	#26; //String jist.swans.app.AppInterface$UdpApp
   12:	invokestatic	#27; //Method
class$:(Ljava/lang/String;)Ljava/lang/Class;
   15:	dup
   16:	putstatic	#25; //Field
class$jist$swans$app$AppInterface$UdpApp:Ljava/lang/Class;
   19:	goto	25
   22:	getstatic	#25; //Field
class$jist$swans$app$AppInterface$UdpApp:Ljava/lang/Class;
   25:	invokestatic	#28; //Method
jist/runtime/JistAPI.proxy:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
   28:	checkcast	#29; //class jist/swans/app/AppInterface$UdpApp
   31:	invokeinterface	#30,  1; //InterfaceMethod
jist/swans/app/AppInterface$UdpApp.getUdpEntity:()Ljist/swans/trans/TransInterface$TransUdpInterface;
   36:	putfield	#31; //Field udpEntity:Ljist/swans/trans/TransInterface;
   39:	aload_0
   40:	new	#6; //class java/net/InetSocketAddress
   43:	dup
   44:	aload_0
   45:	getfield	#17; //Field laddr:Ljava/net/InetAddress;
   48:	aload_0
   49:	getfield	#15; //Field lport:I
   52:	invokespecial	#13; //Method
java/net/InetSocketAddress."&lt;init&gt;":(Ljava/net/InetAddress;I)V
   55:	invokevirtual	#32; //Method bind:(Ljava/net/SocketAddress;)V
   58:	return

The one that fails, generated with "-source 1.5" is:
public void _jistPostInit();
  Code:
   0:	aload_0
   1:	getstatic	#19; //Field
jist/runtime/JistAPI.THIS:Ljist/runtime/JistAPI$Entity;
   4:	ldc_w	#20; //class jist/swans/app/AppInterface$UdpApp
   7:	invokestatic	#21; //Method
jist/runtime/JistAPI.proxy:(Ljava/lang/Object;Ljava/lang/Class;)Ljava/lang/Object;
   10:	checkcast	#20; //class jist/swans/app/AppInterface$UdpApp
   13:	invokeinterface	#22,  1; //InterfaceMethod
jist/swans/app/AppInterface$UdpApp.getUdpEntity:()Ljist/swans/trans/TransInterface$TransUdpInterface;
   18:	putfield	#23; //Field udpEntity:Ljist/swans/trans/TransInterface;
   21:	aload_0
   22:	new	#1; //class java/net/InetSocketAddress
   25:	dup
   26:	aload_0
   27:	getfield	#12; //Field laddr:Ljava/net/InetAddress;
   30:	aload_0
   31:	getfield	#10; //Field lport:I
   34:	invokespecial	#8; //Method
java/net/InetSocketAddress."&lt;init&gt;":(Ljava/net/InetAddress;I)V
   37:	invokevirtual	#24; //Method bind:(Ljava/net/SocketAddress;)V
   40:	return

The exception appears when the putfield operation is rewritten.

Thank you once again for your answer,

Razvan. 




Arrin Daley wrote:
&gt; 
&gt; Hi
&gt; 
&gt; My experience is that the error you are getting is it because some 
&gt; method code has an invalid stack, in this case you are removing too many 
&gt; items from the stack, the verifier is picking this up and reporting the 
&gt; error. I'm not sure but perhaps some code doesn't call 
&gt; MethodGen.setMaxStack() after transforming, although I doubt it, because 
&gt; if the code were otherwise correct it should have complained of a stack 
&gt; overflow.
&gt; 
&gt; The problem has to be with the method it is verifying at the time so if 
&gt; you can print out which method the verifier is working on and it's 
&gt; bytecodes you could go through it and find the problem. The bytecode 
&gt; pre-transformation by BCEL should be correct so the problem lies with 
&gt; the transformations your code performs.
&gt; 
&gt; I'm don't know why this should be a problem with 1.5 and not 1.4.
&gt; 
&gt; Hope it helps
&gt; 
&gt; Bye Arrin
&gt; 
&gt; Razvanica wrote:
&gt;&gt; Hello all,
&gt;&gt;
&gt;&gt; Here's my problem. I am trying to make some network simulations using a
&gt;&gt; tool
&gt;&gt; called JiST/SWANS. This simulator has been written for Java 1.4 and, for
&gt;&gt; my
&gt;&gt; simulations, I would like to use some 1.5 features, like genericity. 
&gt;&gt;
&gt;&gt; So what I am trying to do is to compile the original code with the
&gt;&gt; "source
&gt;&gt; -1.5" tag instead of the "source -1.4" tag. The problem is that the
&gt;&gt; simulator uses bcel to rewrite the bytecode so that JVM could be used for
&gt;&gt; simulations. The bcel library in the release doesn't work with the
&gt;&gt; "source
&gt;&gt; -1.5" tag so I replace it with bcel-5.2. I made 2 minor modifications to
&gt;&gt; the
&gt;&gt; original code :
&gt;&gt; - I have added an implementation of getClassPath in a class that
&gt;&gt; implements
&gt;&gt; org.apache.bcel.util.Repository. This class just returns null, just like
&gt;&gt; in
&gt;&gt; org.apache.bcel.util.ClassLoaderRepository
&gt;&gt; - In a class using org.apache.bcel.Repository.lookupClass() I am now
&gt;&gt; throwing java.lang.ClassNotFoundException 
&gt;&gt;
&gt;&gt; These 2 modifications shouldn't change anything as far as I understand
&gt;&gt; the
&gt;&gt; application. And when I compile the new code with the "-source 1.4" tag,
&gt;&gt; it
&gt;&gt; doesn,t change anything. Everything compiles and works just fine.
&gt;&gt; However,
&gt;&gt; when I compile the new code with the "-source 1.5" tag the compilation
&gt;&gt; goes
&gt;&gt; smoothly, but, at runtime, the rewriter throws an
&gt;&gt; ArrayIndexOutOfBoundsException.
&gt;&gt;
&gt;&gt;
&gt;&gt; This happens every time org.apache.bcel.generic.PUTFIELD.accept is
&gt;&gt; called:
&gt;&gt; java.lang.ArrayIndexOutOfBoundsException: -1 
&gt;&gt;    at java.util.ArrayList.remove(ArrayList.java:390)
&gt;&gt;    at
&gt;&gt; org.apache.bcel.verifier.structurals.OperandStack.pop(OperandStack.java:135)
&gt;&gt;    at
&gt;&gt; org.apache.bcel.verifier.structurals.ExecutionVisitor.visitPUTFIELD(ExecutionVisitor.java:1048)
&gt;&gt;    at org.apache.bcel.generic.PUTFIELD.accept(PUTFIELD.java:78)
&gt;&gt;
&gt;&gt; Does anybody have any idea what happens and if there's something I could
&gt;&gt; do
&gt;&gt; to fix this?
&gt;&gt;
&gt;&gt; Thank you.
&gt;&gt;   
&gt; 
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
&gt; For additional commands, e-mail: bcel-user-help@jakarta.apache.org
&gt; 
&gt; 
&gt; 

-- 
View this message in context: http://www.nabble.com/ArrayIndexOutOfBoundsException-in-generic.PUTFIELD-tp23710707p23722920.html
Sent from the BCEL - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: ArrayIndexOutOfBoundsException in generic.PUTFIELD</title>
<author><name>Arrin Daley &lt;arrin.daley@anu.edu.au&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200905.mbox/%3c4A1B4A8A.3080601@anu.edu.au%3e"/>
<id>urn:uuid:%3c4A1B4A8A-3080601@anu-edu-au%3e</id>
<updated>2009-05-26T01:48:58Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi

My experience is that the error you are getting is it because some 
method code has an invalid stack, in this case you are removing too many 
items from the stack, the verifier is picking this up and reporting the 
error. I'm not sure but perhaps some code doesn't call 
MethodGen.setMaxStack() after transforming, although I doubt it, because 
if the code were otherwise correct it should have complained of a stack 
overflow.

The problem has to be with the method it is verifying at the time so if 
you can print out which method the verifier is working on and it's 
bytecodes you could go through it and find the problem. The bytecode 
pre-transformation by BCEL should be correct so the problem lies with 
the transformations your code performs.

I'm don't know why this should be a problem with 1.5 and not 1.4.

Hope it helps

Bye Arrin

Razvanica wrote:
&gt; Hello all,
&gt;
&gt; Here's my problem. I am trying to make some network simulations using a tool
&gt; called JiST/SWANS. This simulator has been written for Java 1.4 and, for my
&gt; simulations, I would like to use some 1.5 features, like genericity. 
&gt;
&gt; So what I am trying to do is to compile the original code with the "source
&gt; -1.5" tag instead of the "source -1.4" tag. The problem is that the
&gt; simulator uses bcel to rewrite the bytecode so that JVM could be used for
&gt; simulations. The bcel library in the release doesn't work with the "source
&gt; -1.5" tag so I replace it with bcel-5.2. I made 2 minor modifications to the
&gt; original code :
&gt; - I have added an implementation of getClassPath in a class that implements
&gt; org.apache.bcel.util.Repository. This class just returns null, just like in
&gt; org.apache.bcel.util.ClassLoaderRepository
&gt; - In a class using org.apache.bcel.Repository.lookupClass() I am now
&gt; throwing java.lang.ClassNotFoundException 
&gt;
&gt; These 2 modifications shouldn't change anything as far as I understand the
&gt; application. And when I compile the new code with the "-source 1.4" tag, it
&gt; doesn,t change anything. Everything compiles and works just fine. However,
&gt; when I compile the new code with the "-source 1.5" tag the compilation goes
&gt; smoothly, but, at runtime, the rewriter throws an
&gt; ArrayIndexOutOfBoundsException.
&gt;
&gt;
&gt; This happens every time org.apache.bcel.generic.PUTFIELD.accept is called:
&gt; java.lang.ArrayIndexOutOfBoundsException: -1 
&gt;    at java.util.ArrayList.remove(ArrayList.java:390)
&gt;    at
&gt; org.apache.bcel.verifier.structurals.OperandStack.pop(OperandStack.java:135)
&gt;    at
&gt; org.apache.bcel.verifier.structurals.ExecutionVisitor.visitPUTFIELD(ExecutionVisitor.java:1048)
&gt;    at org.apache.bcel.generic.PUTFIELD.accept(PUTFIELD.java:78)
&gt;
&gt; Does anybody have any idea what happens and if there's something I could do
&gt; to fix this?
&gt;
&gt; Thank you.
&gt;   

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>ArrayIndexOutOfBoundsException in generic.PUTFIELD</title>
<author><name>Razvanica &lt;mos_februarie@yahoo.fr&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200905.mbox/%3c23710707.post@talk.nabble.com%3e"/>
<id>urn:uuid:%3c23710707-post@talk-nabble-com%3e</id>
<updated>2009-05-25T17:50:17Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>

Hello all,

Here's my problem. I am trying to make some network simulations using a tool
called JiST/SWANS. This simulator has been written for Java 1.4 and, for my
simulations, I would like to use some 1.5 features, like genericity. 

So what I am trying to do is to compile the original code with the "source
-1.5" tag instead of the "source -1.4" tag. The problem is that the
simulator uses bcel to rewrite the bytecode so that JVM could be used for
simulations. The bcel library in the release doesn't work with the "source
-1.5" tag so I replace it with bcel-5.2. I made 2 minor modifications to the
original code :
- I have added an implementation of getClassPath in a class that implements
org.apache.bcel.util.Repository. This class just returns null, just like in
org.apache.bcel.util.ClassLoaderRepository
- In a class using org.apache.bcel.Repository.lookupClass() I am now
throwing java.lang.ClassNotFoundException 

These 2 modifications shouldn't change anything as far as I understand the
application. And when I compile the new code with the "-source 1.4" tag, it
doesn,t change anything. Everything compiles and works just fine. However,
when I compile the new code with the "-source 1.5" tag the compilation goes
smoothly, but, at runtime, the rewriter throws an
ArrayIndexOutOfBoundsException.


This happens every time org.apache.bcel.generic.PUTFIELD.accept is called:
java.lang.ArrayIndexOutOfBoundsException: -1 
   at java.util.ArrayList.remove(ArrayList.java:390)
   at
org.apache.bcel.verifier.structurals.OperandStack.pop(OperandStack.java:135)
   at
org.apache.bcel.verifier.structurals.ExecutionVisitor.visitPUTFIELD(ExecutionVisitor.java:1048)
   at org.apache.bcel.generic.PUTFIELD.accept(PUTFIELD.java:78)

Does anybody have any idea what happens and if there's something I could do
to fix this?

Thank you.
-- 
View this message in context: http://www.nabble.com/ArrayIndexOutOfBoundsException-in-generic.PUTFIELD-tp23710707p23710707.html
Sent from the BCEL - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>=?iso-8859-2?Q?JavaClass:_Why_are_there_the_setters=3F?=</title>
<author><name>&quot;asdfgh-v6ak&quot; &lt;asdfgh-v6ak@soukroma.cz&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200905.mbox/%3c62d7896b65d7650bcef201049c216988@www3.mail.volny.cz%3e"/>
<id>urn:uuid:%3c62d7896b65d7650bcef201049c216988@www3-mail-volny-cz%3e</id>
<updated>2009-05-25T06:01:23Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hello.
Why does JavaClass contain the setters? I thought that setters are in
ClassGen class only.
v6ak




---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>using getClassName in bcel 5.2</title>
<author><name>Satria Mandala &lt;thariqsatria@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200905.mbox/%3ce2fc37e20905220101t5fa19afnf8bdc77355186519@mail.gmail.com%3e"/>
<id>urn:uuid:%3ce2fc37e20905220101t5fa19afnf8bdc77355186519@mail-gmail-com%3e</id>
<updated>2009-05-22T08:01:22Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi Ramesh,

Let me introduced myself, my name satria.
I am new in BCEL 5.2, and need using method getClassName in class
FieldOrMethod of bcel 5.2.
Let say I have a snippet codes as follows:

public void doInstruction(ClassGen cg, MethodGen mg, InstructionHandle ih,
Instruction inst) throws ClassNotFoundException
  {
    if(inst instanceof FieldInstruction)
    {
      FieldInstruction fieldinst = (FieldInstruction)inst;
      ConstantPoolGen cpg = cg.getConstantPool();
      if(rewriter.isEntity(fieldinst.getClassName(cpg)) &amp;&amp;
          !rewriter.isIgnored(fieldinst.getClassName(cpg))
        )
    ....
   }
}

The FieldInstruction extends the FieldOrMethod class. Unfortunately, the
method String getClassName(ConstantPoolGen cpg ) deprecated.

Referring to note in this code, In Java 1.5 may get wrong. Thus a suggestion
is to use the getReferenceType().

I need getting array of String classname from the
fieldinst.getClassName(cpg).
If I used "fieldinst.getLoadClassType(cpg).getClassName()", the method
getLoadClassType(cpg), would return getClassType(cpg), which deprecated
also.

Any suggestion? In addition I can not use the getReferenceType() using the
fieldinst variable.

Regards,
Satria Mandala
Network Security Laboratory
FSKSM - 81310 UTM Skudai
Johor Malaysia


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: java.lang.VerifyError: arguments are not type compatible</title>
<author><name>Ramesh Jha &lt;ramesh.raman.jha@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200905.mbox/%3cc0c58cdf0905210548r69d3c1e6v30caeb098533957c@mail.gmail.com%3e"/>
<id>urn:uuid:%3cc0c58cdf0905210548r69d3c1e6v30caeb098533957c@mail-gmail-com%3e</id>
<updated>2009-05-21T12:48:19Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Thanks a lot.

I will recheck it. and update you.


</pre>
</div>
</content>
</entry>
<entry>
<title>Class Constructor problem</title>
<author><name>Abdullah Odeh Al-Zaghameem &lt;aoz_0202@yahoo.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200905.mbox/%3c290920.61782.qm@web59310.mail.re1.yahoo.com%3e"/>
<id>urn:uuid:%3c290920-61782-qm@web59310-mail-re1-yahoo-com%3e</id>
<updated>2009-05-07T17:01:09Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi all,
 
I am working on a model that weave some code in classes bytecode at load-time. I face the
following problem regarding the class constructor!! :
 
I tried first to modify the type of the constructor argument by using [setArgumentType], but
i got a strange response!!!!; i.e. after saving back the bytecode and browsing it using some
java-decompilers, the constructor's parameter type is still the same as the old one, at the
new source code, BUT it was changed in the constant pool!!. (the &lt;init&gt; signature is
changed) I found no mental explanation for that tell now.
 
Then, I tried to add a new constructor!! using BCEL, but I fail; I don't know if that because
BCEL doesn't has the suitable APIs to do that, or its illigal to do such thing!!.
 
Any comments and ideas will be appreciated so much.
Thanks,
A. O .Z


      

</pre>
</div>
</content>
</entry>
<entry>
<title>Change the parameter type problem</title>
<author><name>Abdullah Odeh Al-Zaghameem &lt;aoz_0202@yahoo.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200905.mbox/%3c384422.83076.qm@web59307.mail.re1.yahoo.com%3e"/>
<id>urn:uuid:%3c384422-83076-qm@web59307-mail-re1-yahoo-com%3e</id>
<updated>2009-05-05T13:19:13Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi all, and have a nice day ,,
 
I tried to change the type of a method parameter (which is the only one) using the method:
 
 setArgumentType( index, Type).
 
but I got a VerifyError:
 
methodName signature: (Ljava/lang/Object;)Lpkg/Tm$Q;) Incompatible object argument for function
call

The original type of the parameter is a user-defind class (say  myPackage..myClass) and the
method has protected access flag! 
 
Any notes and ideas will be highly appreciated
 
Thanx in advance
Abdullah



      

</pre>
</div>
</content>
</entry>
<entry>
<title>Re: VerifyError Exception :((</title>
<author><name>Abdullah Odeh Al-Zaghameem &lt;aoz_0202@yahoo.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200904.mbox/%3c186878.62989.qm@web59307.mail.re1.yahoo.com%3e"/>
<id>urn:uuid:%3c186878-62989-qm@web59307-mail-re1-yahoo-com%3e</id>
<updated>2009-04-30T14:13:25Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
 
Hi Frederic,,
 
Thank you so much for yr immediate response, and yes you are right, if we don't want the produced
value we should pop it a way. But this solves another problem i.e. when the method is of type
VOID.
 
But, Oppps!!, the solution of my problem is to invoke "valueOf" static method for the corresponding
parameter type class (if the parameter has a basic type!!), e.g:
 
 if the parameter X is of type int then we should invoke the method  Integer.valueOf(int)
before we store the parameter in the object array :))
 
I am so happy now !! LOL, see you in another problem.

Cheers (only water),
Abdullah

===============================
A b d u l l a h   O.  A l - Z a g h a m e e m
Technical University of  Berlin

--- On Thu, 4/30/09, Fred Gidouin &lt;gidouin@gmail.com&gt; wrote:

From: Fred Gidouin &lt;gidouin@gmail.com&gt;
Subject: Re: VerifyError Exception :((
To: "BCEL Users List" &lt;bcel-user@jakarta.apache.org&gt;, aoz_0202@yahoo.com
Date: Thursday, April 30, 2009, 3:42 PM

Hi Abdullah,

Your anotherMethod probably returns something. This is inconsistent
with the state of the stack after a call.

You can make it void or just add a POP instruction after the
INVOKEVIRTUAL to discard the returned value.

Hope that helps.

Frederic.

On Thu, Apr 30, 2009 at 2:18 PM, Abdullah Odeh Al-Zaghameem
&lt;aoz_0202@yahoo.com&gt; wrote:
&gt;
&gt; Hi all,,
&gt; This is my first question in bcel-mailing list. I have the following
problem:
&gt;
&gt; I write a simple code to transform a method code such that it should
invoke another method providing its parameters as an argument to this new
method. for example:
&gt;
&gt; // original method
&gt; public void orgMethod(String A, int B, Object C) {...}
&gt;
&gt; //should be transformed to:
&gt;
&gt; public void orgMethod(String A, int B, Object C)
&gt; {
&gt;    Object[] args = new Object[]{A, B, C};
&gt;    anotherMethod("origMethod", args);
&gt; }
&gt;
&gt; The funny thing at this point is that I use the BCEL library to weave the
new method's code as follow:
&gt;
&gt;
////////////////////////////////////////////////////////////////////////////////////////////
&gt; LocalVariableGen selfArgs = mg2.addLocalVariable("args", new
ArrayType(Type.OBJECT, 1), null, null);
&gt;                   // mg2 is an MethodGen instance that is
initiated from origMethod .. :)
&gt;
&gt;  LocalVariableGen for_q = mg2.addLocalVariable("indx",
Type.INT, null, null);
&gt;  int methodNameIndex = cpg.addString(mg2.getName());
&gt;                         il2.append(new
ICONST(mg2.getArgumentNames().length));
&gt;                         il2.append(new
ANEWARRAY(objectType_Index));
&gt;                         il2.append(new
ASTORE(selfArgs.getIndex()));
&gt;                         il2.append(new ICONST(-1));
&gt;                         il2.append(new
ISTORE(for_q.getIndex()));
&gt;                         for(int i = 1; i&lt;=
mg2.getArgumentNames().length; i++)
&gt;                         {
&gt;                             il2..append(new
IINC(for_q.getIndex(), 1));
&gt;                             il2..append(new
ALOAD(selfArgs.getIndex()));
&gt;                             il2..append(new
ILOAD(for_q.getIndex()));
&gt;                            
il2.append(InstructionFactory.createLoad(mg2.getArgumentTypes()[i-1], i));
&gt;                            
il2.append(InstructionFactory.createArrayStore(Type.OBJECT));
&gt;
&gt;                         }
&gt;
&gt;                     il2.append(new ALOAD(0));
&gt;                     il2.append(new LDC(methodNameIndex));
&gt;                     il2.append(new
ALOAD(selfArgs.getIndex()));
&gt;                    
il2.append(ifact.createInvoke(fullQualifiedClassName, "anotherMethod",
Type.OBJECT, new Type[]{Type.STRING, new ArrayType(Type.OBJECT,1)},
Constants.INVOKEVIRTUAL));
&gt;
////////////////////////////////////////////////////////////////////////////////////////////
&gt;
&gt; which produces a nice code!!.
&gt;
&gt; public void orgMethod(String A, int B, Object C)
&gt;
&gt; {
&gt;
&gt;    Object[] args = new Object[3];
&gt;    int indx = -1;
&gt;    indx ++;
&gt;    args[indx] = A;
&gt;    indx ++;
&gt;
&gt;    args[indx] = B;
&gt;    indx ++;
&gt;
&gt;    args[indx] = C;
&gt;
&gt;    anotherMethod("origMethod", args);
&gt;
&gt; }
&gt;  But an exception is thrown after the new origMethod.
&gt;
&gt; Exception in thread "main" java.lang.VerifyError: (class: pkg/C,
method: origMethod signature: (Ljava.lang.String;ILjava.lang.Object;)V)
Expecting to find object/array on stack
&gt;
&gt; any help will be so much appreciated.
&gt; Abdullah
&gt;
&gt;
&gt;
&gt;
&gt;



      

</pre>
</div>
</content>
</entry>
<entry>
<title>Re: VerifyError Exception :((</title>
<author><name>Fred Gidouin &lt;gidouin@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200904.mbox/%3cdf4689fe0904300542l1c8ba6d5p7f325dd20bd12012@mail.gmail.com%3e"/>
<id>urn:uuid:%3cdf4689fe0904300542l1c8ba6d5p7f325dd20bd12012@mail-gmail-com%3e</id>
<updated>2009-04-30T12:42:59Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi Abdullah,

Your anotherMethod probably returns something. This is inconsistent
with the state of the stack after a call.

You can make it void or just add a POP instruction after the
INVOKEVIRTUAL to discard the returned value.

Hope that helps.

Frederic.

On Thu, Apr 30, 2009 at 2:18 PM, Abdullah Odeh Al-Zaghameem
&lt;aoz_0202@yahoo.com&gt; wrote:
&gt;
&gt; Hi all,,
&gt; This is my first question in bcel-mailing list. I have the following problem:
&gt;
&gt; I write a simple code to transform a method code such that it should invoke another method
providing its parameters as an argument to this new method. for example:
&gt;
&gt; // original method
&gt; public void orgMethod(String A, int B, Object C) {...}
&gt;
&gt; //should be transformed to:
&gt;
&gt; public void orgMethod(String A, int B, Object C)
&gt; {
&gt; Â Â  Object[] args = new Object[]{A, B, C};
&gt; Â Â  anotherMethod("origMethod", args);
&gt; }
&gt;
&gt; The funny thing at this point is that I use the BCEL library to weave the new method's
code as follow:
&gt;
&gt; ////////////////////////////////////////////////////////////////////////////////////////////
&gt; LocalVariableGen selfArgs = mg2.addLocalVariable("args", new ArrayType(Type.OBJECT, 1),
null, null);
&gt; Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â Â  // mg2 is an MethodGen instance that is initiated
from origMethod .. :)
&gt;
&gt; Â LocalVariableGen for_q = mg2.addLocalVariable("indx", Type.INT, null, null);
&gt; Â int methodNameIndex = cpg.addString(mg2.getName());
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  il2.append(new ICONST(mg2.getArgumentNames().length));
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  il2.append(new ANEWARRAY(objectType_Index));
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  il2.append(new ASTORE(selfArgs.getIndex()));
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  il2.append(new ICONST(-1));
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  il2.append(new ISTORE(for_q.getIndex()));
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  for(int i = 1; i&lt;= mg2.getArgumentNames().length;
i++)
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  {
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  il2.append(new IINC(for_q.getIndex(),
1));
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  il2.append(new ALOAD(selfArgs.getIndex()));
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  il2.append(new ILOAD(for_q.getIndex()));
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  il2.append(InstructionFactory.createLoad(mg2.getArgumentTypes()[i-1],
i));
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â  Â  il2.append(InstructionFactory.createArrayStore(Type.OBJECT));
&gt;
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  }
&gt;
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  il2.append(new ALOAD(0));
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  il2.append(new LDC(methodNameIndex));
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  il2.append(new ALOAD(selfArgs.getIndex()));
&gt; Â Â Â  Â Â Â  Â Â Â  Â Â Â  Â Â Â  il2.append(ifact.createInvoke(fullQualifiedClassName,
"anotherMethod", Type.OBJECT, new Type[]{Type.STRING, new ArrayType(Type.OBJECT,1)}, Constants.INVOKEVIRTUAL));
&gt; ////////////////////////////////////////////////////////////////////////////////////////////
&gt;
&gt; which produces a nice code!!.
&gt;
&gt; public void orgMethod(String A, int B, Object C)
&gt;
&gt; {
&gt;
&gt; Â Â  Object[] args = new Object[3];
&gt; Â Â  int indx = -1;
&gt; Â Â  indx ++;
&gt; Â Â  args[indx] = A;
&gt; Â Â  indx ++;
&gt;
&gt; Â Â  args[indx] = B;
&gt; Â Â  indx ++;
&gt;
&gt; Â Â  args[indx] = C;
&gt;
&gt; Â Â  anotherMethod("origMethod", args);
&gt;
&gt; }
&gt; Â But an exception is thrown after the new origMethod.
&gt;
&gt; Exception in thread "main" java.lang.VerifyError: (class: pkg/C, method: origMethod signature:
(Ljava.lang.String;ILjava.lang.Object;)V) Expecting to find object/array on stack
&gt;
&gt; any help will be so much appreciated.
&gt; Abdullah
&gt;
&gt;
&gt;
&gt;
&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>VerifyError Exception :((</title>
<author><name>Abdullah Odeh Al-Zaghameem &lt;aoz_0202@yahoo.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200904.mbox/%3c849178.25281.qm@web59306.mail.re1.yahoo.com%3e"/>
<id>urn:uuid:%3c849178-25281-qm@web59306-mail-re1-yahoo-com%3e</id>
<updated>2009-04-30T12:18:24Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi all,,
This is my first question in bcel-mailing list. I have the following problem:

I write a simple code to transform a method code such that it should invoke another method
providing its parameters as an argument to this new method. for example:

// original method 
public void orgMethod(String A, int B, Object C) {...}

//should be transformed to:

public void orgMethod(String A, int B, Object C) 
{
   Object[] args = new Object[]{A, B, C};
   anotherMethod("origMethod", args);
}

The funny thing at this point is that I use the BCEL library to weave the new method's code
as follow:

////////////////////////////////////////////////////////////////////////////////////////////
LocalVariableGen selfArgs = mg2.addLocalVariable("args", new ArrayType(Type.OBJECT, 1), null,
null);
                  // mg2 is an MethodGen instance that is initiated from origMethod .. :)
                 
 LocalVariableGen for_q = mg2.addLocalVariable("indx", Type.INT, null, null);
 int methodNameIndex = cpg.addString(mg2.getName());
                        il2.append(new ICONST(mg2.getArgumentNames().length));
                        il2.append(new ANEWARRAY(objectType_Index));
                        il2.append(new ASTORE(selfArgs.getIndex()));
                        il2.append(new ICONST(-1));
                        il2.append(new ISTORE(for_q.getIndex()));
                        for(int i = 1; i&lt;= mg2.getArgumentNames().length; i++)
                        {    
                            il2.append(new IINC(for_q.getIndex(), 1));
                            il2.append(new ALOAD(selfArgs.getIndex()));
                            il2.append(new ILOAD(for_q.getIndex()));
                            il2.append(InstructionFactory.createLoad(mg2.getArgumentTypes()[i-1],
i)); 
                            il2.append(InstructionFactory.createArrayStore(Type.OBJECT));

                        }
                 
                    il2.append(new ALOAD(0));
                    il2.append(new LDC(methodNameIndex));
                    il2.append(new ALOAD(selfArgs.getIndex()));
                    il2.append(ifact.createInvoke(fullQualifiedClassName, "anotherMethod",
Type.OBJECT, new Type[]{Type.STRING, new ArrayType(Type.OBJECT,1)}, Constants.INVOKEVIRTUAL));
////////////////////////////////////////////////////////////////////////////////////////////

which produces a nice code!!.

public void orgMethod(String A, int B, Object C) 

{

   Object[] args = new Object[3];
   int indx = -1;
   indx ++;
   args[indx] = A;
   indx ++;

   args[indx] = B;
   indx ++;

   args[indx] = C;

   anotherMethod("origMethod", args);

}
 But an exception is thrown after the new origMethod.

Exception in thread "main" java.lang.VerifyError: (class: pkg/C, method: origMethod signature:
(Ljava.lang.String;ILjava.lang.Object;)V) Expecting to find object/array on stack

any help will be so much appreciated.
Abdullah




      

</pre>
</div>
</content>
</entry>
<entry>
<title>How can I get the line number for a particular line of a Code object?</title>
<author><name>Laran Evans &lt;laran@laranevans.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200904.mbox/%3c30ec9fe20904081233g3450be1bj8dee4b99418ea437@mail.gmail.com%3e"/>
<id>urn:uuid:%3c30ec9fe20904081233g3450be1bj8dee4b99418ea437@mail-gmail-com%3e</id>
<updated>2009-04-08T19:33:09Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
I'm just analyzing code, not re-engineering.

What I want to do is get the corresponding line number in source code
for a given instruction. Here's my basic code.

Code code = method.getCode();
String instructions = Utility.codeToString(code.getCode(),
constantPool, 0, -1, false);
BufferedReader reader = new BufferedReader(new StringReader(instructions));
String line = null;
while(null != (line = reader.readLine())) {
  // How can I get the source code line number that corresponds to
this line in the instructions?
}

Another thing I want to do is analyze constructor invocations within code.

In the same code above inside the while loop I can recognize lines
that start with "new ", which tells me that a constructor is being
called. But, every time I see an object being "newed" it's always the
"&lt;init&gt;" method being invoked. Can I inspect the code in that method
as well?

I hope this all makes sense. I appreciate any help I can get.

Thanks.

- Laran Evans

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Method.Invoke</title>
<author><name>Sergio Ciruela =?iso-8859-1?Q?Mart=EDn?= &lt;sciruela@ugr.es&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200903.mbox/%3c50930.150.214.27.163.1236848434.squirrel@goliat11.ugr.es%3e"/>
<id>urn:uuid:%3c50930-150-214-27-163-1236848434-squirrel@goliat11-ugr-es%3e</id>
<updated>2009-03-12T09:00:34Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi!


How I can use Invoke method from bcel. I would like to simulate the next
process but using BCEL API to avoid castings and searchs.

Method m=clazz.getMethod("x");
m.invoke(new class(),objs[]);


In java.lang.reflect.invoke Object invoke(Object obj, Object[] args)
Invokes the underlying method represented by this Method object, on the
specified object with the specified parameters.

Thanks


---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: How to replace a complete instruction in J2ME Bytecode</title>
<author><name>&quot;Klaus Teller&quot; &lt;klaus.teller@gmx.net&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200902.mbox/%3c20090216045308.65880@gmx.net%3e"/>
<id>urn:uuid:%3c20090216045308-65880@gmx-net%3e</id>
<updated>2009-02-16T04:53:08Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi Arin,

I would like to follow up on this problem. Right now, i can indeed replace the method following
your instruction. The method i'm replacing is Connector.open. I can replace it with another
MyConnector.open. 

The only problem i have now is that in my custom open method, if i'm not able to call methods
from other objects. The following error message is produced:

Approximate bytecode offset 3: Inconsistent or missing stackmap at target

Any idea how i can address this?

Thanks,

Klaus.


 
-------- Original-Nachricht --------
&gt; Datum: Tue, 10 Feb 2009 16:27:08 +1100
&gt; Von: Arrin Daley &lt;arrin.daley@anu.edu.au&gt;
&gt; An: BCEL Users List &lt;bcel-user@jakarta.apache.org&gt;
&gt; Betreff: Re: How to replace a complete instruction in J2ME Bytecode

&gt; Hi Klaus
&gt; 
&gt; I've primarily only used JavaClass but should've probably used ClassGen.
&gt; 
&gt; Do you do a MethodGen.getMethod()? this returns a Method object which 
&gt; you should then make part of the JavaClass (via JavaClass.setMethods()) 
&gt; or ClassGen (via setMethods() or setMethodAt()) which you got the method 
&gt; from. Your supposed to do a setMaxStack() and setMaxLocals() before a 
&gt; call to getMethod() but your changes shouldn't change the stack or local 
&gt; variables, but it's probably good practice.
&gt; 
&gt; You will also have to get a ConstantPool via 
&gt; ConstantPoolGen.getFinalConstantPool() and make this part of your 
&gt; JavaClass, I don't think it's required for ClassGen as I think it 
&gt; happens when you ask for a JavaClass, not sure though, you might need to 
&gt; check.
&gt; Note: sorry I remembered constant pools being associated with methods 
&gt; but they're associated with the class.
&gt; 
&gt; Basically you need to make sure your changes take effect in the 
&gt; JavaClass before you dump it, so ConstantPoolGen needs to create a new 
&gt; ConstantPool, MethodGen needs to create a new Method, and ClassGen (if 
&gt; you use it) needs to create a new JavaClass, otherwise the JavaClass 
&gt; will continue to have the old state and that's what will be dumped.
&gt; ClassGen may take care of some of this for you via getJavaClass().
&gt; 
&gt; Hope it helps,
&gt; 
&gt; Bye Arrin
&gt; 
&gt; 
&gt; Klaus Teller wrote:
&gt; &gt; Hi Arin,
&gt; &gt;
&gt; &gt; Thanks for your feedback; very insightful. I went through all the steps,
&gt; identified the right invokestatic, added it into the constant pool, and
&gt; updated the index of the invokestatic. 
&gt; &gt;
&gt; &gt; Right now, the only issue i'm having is that the dump doesn't include my
&gt; changes, which might indicate that something is missing.
&gt; &gt;
&gt; &gt; Any idea?
&gt; &gt;
&gt; &gt; If you wish, i can send you the code offline.
&gt; &gt;
&gt; &gt; Thanks again,
&gt; &gt;
&gt; &gt; Klaus.
&gt; &gt;
&gt; &gt;
&gt; &gt; -------- Original-Nachricht --------
&gt; &gt;   
&gt; &gt;&gt; Datum: Tue, 10 Feb 2009 12:32:16 +1100
&gt; &gt;&gt; Von: Arrin Daley &lt;arrin.daley@anu.edu.au&gt;
&gt; &gt;&gt; An: BCEL Users List &lt;bcel-user@jakarta.apache.org&gt;
&gt; &gt;&gt; Betreff: Re: How to replace a complete instruction in J2ME Bytecode
&gt; &gt;&gt;     
&gt; &gt;
&gt; &gt;   
&gt; &gt;&gt; Hi Klaus
&gt; &gt;&gt;
&gt; &gt;&gt; You'll need to find the INVOKESTATIC instruction first, if you have an 
&gt; &gt;&gt; idea which methods and classes the call(s) exist in this will help, 
&gt; &gt;&gt; InstructionFinder is about finding a pattern of instructions you could 
&gt; &gt;&gt; use it to find INVOKESTATIC instructions but that would probably be 
&gt; &gt;&gt; overkill, you could just use an iterator or something similar.
&gt; &gt;&gt;
&gt; &gt;&gt; Once you have found the INVOKESTATIC instructions you could then test
&gt; to 
&gt; &gt;&gt; see which one(s) match your function call, you could do this by looking
&gt; &gt;&gt; at the classname and method name and possibly arguments the other way 
&gt; &gt;&gt; would be to look up the index for the method in the constant pool (if
&gt; it 
&gt; &gt;&gt; exists in the constant pool, don't put it in if it doesn't) and compare
&gt; &gt;&gt; this index to that of the INVOKESTATIC instruction which you have
&gt; found. 
&gt; &gt;&gt; If the static method doesn't exist in the constant pool then there
&gt; isn't 
&gt; &gt;&gt; a call to that static method in the code your currently looking at so 
&gt; &gt;&gt; you could move on to the next method to search.
&gt; &gt;&gt;
&gt; &gt;&gt; Once you find an INVOKESTATIC that matches you need to put your new 
&gt; &gt;&gt; static method in the constant pool via a ConstantPoolGen, this will 
&gt; &gt;&gt; return an index which you can then use with the setIndex method on the 
&gt; &gt;&gt; INVOKESTATIC instruction. You can use the setIndex because you are just
&gt; &gt;&gt; changing the target of INVOKESTATIC instructions, otherwise you would 
&gt; &gt;&gt; have to replace the instruction itself.
&gt; &gt;&gt;
&gt; &gt;&gt; I'm not sure what other finalising things you will need to do, the 
&gt; &gt;&gt; ConstantPool, ConstantPoolGen  will have changed so will need to 
&gt; &gt;&gt; finalise that, and you will have to get a Method from the MethodGen 
&gt; &gt;&gt; object you previously had but I think that's about all...
&gt; &gt;&gt;
&gt; &gt;&gt; Another way might be to define an InstructionVisitor overriding the 
&gt; &gt;&gt; visit method for INVOKESTATIC to find and edit the appropriate
&gt; &gt;&gt; instructions.
&gt; &gt;&gt;
&gt; &gt;&gt; Hope it helps
&gt; &gt;&gt;
&gt; &gt;&gt; Bye Arrin
&gt; &gt;&gt;
&gt; &gt;&gt; Klaus Teller wrote:
&gt; &gt;&gt;     
&gt; &gt;&gt;&gt; Hi Folks,
&gt; &gt;&gt;&gt;
&gt; &gt;&gt;&gt; I have a J2ME Library that contains the following instruction:
&gt; &gt;&gt;&gt;
&gt; &gt;&gt;&gt; invokestatic
&gt; &gt;&gt;&gt;       
&gt; &gt;&gt;
&gt; javax/microedition/io/Connector/open(Ljava/lang/String;IZ)Ljavax/microedition/io/Connection;
&gt; &gt;&gt;     
&gt; &gt;&gt;&gt; I would like to replace it with:
&gt; &gt;&gt;&gt;
&gt; &gt;&gt;&gt; invokestatic
&gt; &gt;&gt;&gt;       
&gt; &gt;&gt;
&gt; mypackage/AlphaConnector/open(Ljava/lang/String;IZ)Ljavax/microedition/io/Connection;
&gt; &gt;&gt;     
&gt; &gt;&gt;&gt; What do i need to do?
&gt; &gt;&gt;&gt;
&gt; &gt;&gt;&gt; I couldn't find a way to search instruction based on the operand (that
&gt; &gt;&gt;&gt;       
&gt; &gt;&gt; is the second part of the instruction). I tried IntructionFinder; but
&gt; it
&gt; &gt;&gt; couldn't help me. 
&gt; &gt;&gt;     
&gt; &gt;&gt;&gt; I would very much appreciate any input.
&gt; &gt;&gt;&gt;
&gt; &gt;&gt;&gt; Thanks,
&gt; &gt;&gt;&gt; Klaus.
&gt; &gt;&gt;&gt;
&gt; &gt;&gt;&gt;   
&gt; &gt;&gt;&gt;       
&gt; &gt;&gt; ---------------------------------------------------------------------
&gt; &gt;&gt; To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
&gt; &gt;&gt; For additional commands, e-mail: bcel-user-help@jakarta.apache.org
&gt; &gt;&gt;     
&gt; &gt;
&gt; &gt;   
&gt; 
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
&gt; For additional commands, e-mail: bcel-user-help@jakarta.apache.org

-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: How to replace a complete instruction in J2ME Bytecode</title>
<author><name>&quot;Klaus Teller&quot; &lt;klaus.teller@gmx.net&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200902.mbox/%3c20090210142145.199070@gmx.net%3e"/>
<id>urn:uuid:%3c20090210142145-199070@gmx-net%3e</id>
<updated>2009-02-10T14:21:45Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Awesome Arin, the class is now saved properly. Next step will now be to get the new class running.
Stay tuned.

Klaus.
-------- Original-Nachricht --------
&gt; Datum: Tue, 10 Feb 2009 16:27:08 +1100
&gt; Von: Arrin Daley &lt;arrin.daley@anu.edu.au&gt;
&gt; An: BCEL Users List &lt;bcel-user@jakarta.apache.org&gt;
&gt; Betreff: Re: How to replace a complete instruction in J2ME Bytecode

&gt; Hi Klaus
&gt; 
&gt; I've primarily only used JavaClass but should've probably used ClassGen.
&gt; 
&gt; Do you do a MethodGen.getMethod()? this returns a Method object which 
&gt; you should then make part of the JavaClass (via JavaClass.setMethods()) 
&gt; or ClassGen (via setMethods() or setMethodAt()) which you got the method 
&gt; from. Your supposed to do a setMaxStack() and setMaxLocals() before a 
&gt; call to getMethod() but your changes shouldn't change the stack or local 
&gt; variables, but it's probably good practice.
&gt; 
&gt; You will also have to get a ConstantPool via 
&gt; ConstantPoolGen.getFinalConstantPool() and make this part of your 
&gt; JavaClass, I don't think it's required for ClassGen as I think it 
&gt; happens when you ask for a JavaClass, not sure though, you might need to 
&gt; check.
&gt; Note: sorry I remembered constant pools being associated with methods 
&gt; but they're associated with the class.
&gt; 
&gt; Basically you need to make sure your changes take effect in the 
&gt; JavaClass before you dump it, so ConstantPoolGen needs to create a new 
&gt; ConstantPool, MethodGen needs to create a new Method, and ClassGen (if 
&gt; you use it) needs to create a new JavaClass, otherwise the JavaClass 
&gt; will continue to have the old state and that's what will be dumped.
&gt; ClassGen may take care of some of this for you via getJavaClass().
&gt; 
&gt; Hope it helps,
&gt; 
&gt; Bye Arrin
&gt; 
&gt; 
&gt; Klaus Teller wrote:
&gt; &gt; Hi Arin,
&gt; &gt;
&gt; &gt; Thanks for your feedback; very insightful. I went through all the steps,
&gt; identified the right invokestatic, added it into the constant pool, and
&gt; updated the index of the invokestatic. 
&gt; &gt;
&gt; &gt; Right now, the only issue i'm having is that the dump doesn't include my
&gt; changes, which might indicate that something is missing.
&gt; &gt;
&gt; &gt; Any idea?
&gt; &gt;
&gt; &gt; If you wish, i can send you the code offline.
&gt; &gt;
&gt; &gt; Thanks again,
&gt; &gt;
&gt; &gt; Klaus.
&gt; &gt;
&gt; &gt;
&gt; &gt; -------- Original-Nachricht --------
&gt; &gt;   
&gt; &gt;&gt; Datum: Tue, 10 Feb 2009 12:32:16 +1100
&gt; &gt;&gt; Von: Arrin Daley &lt;arrin.daley@anu.edu.au&gt;
&gt; &gt;&gt; An: BCEL Users List &lt;bcel-user@jakarta.apache.org&gt;
&gt; &gt;&gt; Betreff: Re: How to replace a complete instruction in J2ME Bytecode
&gt; &gt;&gt;     
&gt; &gt;
&gt; &gt;   
&gt; &gt;&gt; Hi Klaus
&gt; &gt;&gt;
&gt; &gt;&gt; You'll need to find the INVOKESTATIC instruction first, if you have an 
&gt; &gt;&gt; idea which methods and classes the call(s) exist in this will help, 
&gt; &gt;&gt; InstructionFinder is about finding a pattern of instructions you could 
&gt; &gt;&gt; use it to find INVOKESTATIC instructions but that would probably be 
&gt; &gt;&gt; overkill, you could just use an iterator or something similar.
&gt; &gt;&gt;
&gt; &gt;&gt; Once you have found the INVOKESTATIC instructions you could then test
&gt; to 
&gt; &gt;&gt; see which one(s) match your function call, you could do this by looking
&gt; &gt;&gt; at the classname and method name and possibly arguments the other way 
&gt; &gt;&gt; would be to look up the index for the method in the constant pool (if
&gt; it 
&gt; &gt;&gt; exists in the constant pool, don't put it in if it doesn't) and compare
&gt; &gt;&gt; this index to that of the INVOKESTATIC instruction which you have
&gt; found. 
&gt; &gt;&gt; If the static method doesn't exist in the constant pool then there
&gt; isn't 
&gt; &gt;&gt; a call to that static method in the code your currently looking at so 
&gt; &gt;&gt; you could move on to the next method to search.
&gt; &gt;&gt;
&gt; &gt;&gt; Once you find an INVOKESTATIC that matches you need to put your new 
&gt; &gt;&gt; static method in the constant pool via a ConstantPoolGen, this will 
&gt; &gt;&gt; return an index which you can then use with the setIndex method on the 
&gt; &gt;&gt; INVOKESTATIC instruction. You can use the setIndex because you are just
&gt; &gt;&gt; changing the target of INVOKESTATIC instructions, otherwise you would 
&gt; &gt;&gt; have to replace the instruction itself.
&gt; &gt;&gt;
&gt; &gt;&gt; I'm not sure what other finalising things you will need to do, the 
&gt; &gt;&gt; ConstantPool, ConstantPoolGen  will have changed so will need to 
&gt; &gt;&gt; finalise that, and you will have to get a Method from the MethodGen 
&gt; &gt;&gt; object you previously had but I think that's about all...
&gt; &gt;&gt;
&gt; &gt;&gt; Another way might be to define an InstructionVisitor overriding the 
&gt; &gt;&gt; visit method for INVOKESTATIC to find and edit the appropriate
&gt; &gt;&gt; instructions.
&gt; &gt;&gt;
&gt; &gt;&gt; Hope it helps
&gt; &gt;&gt;
&gt; &gt;&gt; Bye Arrin
&gt; &gt;&gt;
&gt; &gt;&gt; Klaus Teller wrote:
&gt; &gt;&gt;     
&gt; &gt;&gt;&gt; Hi Folks,
&gt; &gt;&gt;&gt;
&gt; &gt;&gt;&gt; I have a J2ME Library that contains the following instruction:
&gt; &gt;&gt;&gt;
&gt; &gt;&gt;&gt; invokestatic
&gt; &gt;&gt;&gt;       
&gt; &gt;&gt;
&gt; javax/microedition/io/Connector/open(Ljava/lang/String;IZ)Ljavax/microedition/io/Connection;
&gt; &gt;&gt;     
&gt; &gt;&gt;&gt; I would like to replace it with:
&gt; &gt;&gt;&gt;
&gt; &gt;&gt;&gt; invokestatic
&gt; &gt;&gt;&gt;       
&gt; &gt;&gt;
&gt; mypackage/AlphaConnector/open(Ljava/lang/String;IZ)Ljavax/microedition/io/Connection;
&gt; &gt;&gt;     
&gt; &gt;&gt;&gt; What do i need to do?
&gt; &gt;&gt;&gt;
&gt; &gt;&gt;&gt; I couldn't find a way to search instruction based on the operand (that
&gt; &gt;&gt;&gt;       
&gt; &gt;&gt; is the second part of the instruction). I tried IntructionFinder; but
&gt; it
&gt; &gt;&gt; couldn't help me. 
&gt; &gt;&gt;     
&gt; &gt;&gt;&gt; I would very much appreciate any input.
&gt; &gt;&gt;&gt;
&gt; &gt;&gt;&gt; Thanks,
&gt; &gt;&gt;&gt; Klaus.
&gt; &gt;&gt;&gt;
&gt; &gt;&gt;&gt;   
&gt; &gt;&gt;&gt;       
&gt; &gt;&gt; ---------------------------------------------------------------------
&gt; &gt;&gt; To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
&gt; &gt;&gt; For additional commands, e-mail: bcel-user-help@jakarta.apache.org
&gt; &gt;&gt;     
&gt; &gt;
&gt; &gt;   
&gt; 
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
&gt; For additional commands, e-mail: bcel-user-help@jakarta.apache.org

-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: How to replace a complete instruction in J2ME Bytecode</title>
<author><name>Arrin Daley &lt;arrin.daley@anu.edu.au&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200902.mbox/%3c4991102C.2090500@anu.edu.au%3e"/>
<id>urn:uuid:%3c4991102C-2090500@anu-edu-au%3e</id>
<updated>2009-02-10T05:27:08Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi Klaus

I've primarily only used JavaClass but should've probably used ClassGen.

Do you do a MethodGen.getMethod()? this returns a Method object which 
you should then make part of the JavaClass (via JavaClass.setMethods()) 
or ClassGen (via setMethods() or setMethodAt()) which you got the method 
from. Your supposed to do a setMaxStack() and setMaxLocals() before a 
call to getMethod() but your changes shouldn't change the stack or local 
variables, but it's probably good practice.

You will also have to get a ConstantPool via 
ConstantPoolGen.getFinalConstantPool() and make this part of your 
JavaClass, I don't think it's required for ClassGen as I think it 
happens when you ask for a JavaClass, not sure though, you might need to 
check.
Note: sorry I remembered constant pools being associated with methods 
but they're associated with the class.

Basically you need to make sure your changes take effect in the 
JavaClass before you dump it, so ConstantPoolGen needs to create a new 
ConstantPool, MethodGen needs to create a new Method, and ClassGen (if 
you use it) needs to create a new JavaClass, otherwise the JavaClass 
will continue to have the old state and that's what will be dumped.
ClassGen may take care of some of this for you via getJavaClass().

Hope it helps,

Bye Arrin


Klaus Teller wrote:
&gt; Hi Arin,
&gt;
&gt; 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.

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

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: How to replace a complete instruction in J2ME Bytecode</title>
<author><name>&quot;Klaus Teller&quot; &lt;klaus.teller@gmx.net&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200902.mbox/%3c20090210043650.49720@gmx.net%3e"/>
<id>urn:uuid:%3c20090210043650-49720@gmx-net%3e</id>
<updated>2009-02-10T04:36:50Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
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 --------
&gt; Datum: Tue, 10 Feb 2009 12:32:16 +1100
&gt; Von: Arrin Daley &lt;arrin.daley@anu.edu.au&gt;
&gt; An: BCEL Users List &lt;bcel-user@jakarta.apache.org&gt;
&gt; Betreff: Re: How to replace a complete instruction in J2ME Bytecode

&gt; Hi Klaus
&gt; 
&gt; You'll need to find the INVOKESTATIC instruction first, if you have an 
&gt; idea which methods and classes the call(s) exist in this will help, 
&gt; InstructionFinder is about finding a pattern of instructions you could 
&gt; use it to find INVOKESTATIC instructions but that would probably be 
&gt; overkill, you could just use an iterator or something similar.
&gt; 
&gt; Once you have found the INVOKESTATIC instructions you could then test to 
&gt; see which one(s) match your function call, you could do this by looking 
&gt; at the classname and method name and possibly arguments the other way 
&gt; would be to look up the index for the method in the constant pool (if it 
&gt; exists in the constant pool, don't put it in if it doesn't) and compare 
&gt; this index to that of the INVOKESTATIC instruction which you have found. 
&gt; If the static method doesn't exist in the constant pool then there isn't 
&gt; a call to that static method in the code your currently looking at so 
&gt; you could move on to the next method to search.
&gt; 
&gt; Once you find an INVOKESTATIC that matches you need to put your new 
&gt; static method in the constant pool via a ConstantPoolGen, this will 
&gt; return an index which you can then use with the setIndex method on the 
&gt; INVOKESTATIC instruction. You can use the setIndex because you are just 
&gt; changing the target of INVOKESTATIC instructions, otherwise you would 
&gt; have to replace the instruction itself.
&gt; 
&gt; I'm not sure what other finalising things you will need to do, the 
&gt; ConstantPool, ConstantPoolGen  will have changed so will need to 
&gt; finalise that, and you will have to get a Method from the MethodGen 
&gt; object you previously had but I think that's about all...
&gt; 
&gt; Another way might be to define an InstructionVisitor overriding the 
&gt; visit method for INVOKESTATIC to find and edit the appropriate
&gt; instructions.
&gt; 
&gt; Hope it helps
&gt; 
&gt; Bye Arrin
&gt; 
&gt; Klaus Teller wrote:
&gt; &gt; Hi Folks,
&gt; &gt;
&gt; &gt; I have a J2ME Library that contains the following instruction:
&gt; &gt;
&gt; &gt; invokestatic
&gt; javax/microedition/io/Connector/open(Ljava/lang/String;IZ)Ljavax/microedition/io/Connection;
&gt; &gt;
&gt; &gt;
&gt; &gt; I would like to replace it with:
&gt; &gt;
&gt; &gt; invokestatic
&gt; mypackage/AlphaConnector/open(Ljava/lang/String;IZ)Ljavax/microedition/io/Connection;
&gt; &gt;
&gt; &gt; What do i need to do?
&gt; &gt;
&gt; &gt; I couldn't find a way to search instruction based on the operand (that
&gt; is the second part of the instruction). I tried IntructionFinder; but it
&gt; couldn't help me. 
&gt; &gt;
&gt; &gt; I would very much appreciate any input.
&gt; &gt;
&gt; &gt; Thanks,
&gt; &gt; Klaus.
&gt; &gt;
&gt; &gt;   
&gt; 
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
&gt; For additional commands, e-mail: bcel-user-help@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-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: How to replace a complete instruction in J2ME Bytecode</title>
<author><name>Arrin Daley &lt;arrin.daley@anu.edu.au&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200902.mbox/%3c4990D920.3030406@anu.edu.au%3e"/>
<id>urn:uuid:%3c4990D920-3030406@anu-edu-au%3e</id>
<updated>2009-02-10T01:32:16Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
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:
&gt; Hi Folks,
&gt;
&gt; I have a J2ME Library that contains the following instruction:
&gt;
&gt; invokestatic javax/microedition/io/Connector/open(Ljava/lang/String;IZ)Ljavax/microedition/io/Connection;
&gt;
&gt;
&gt; I would like to replace it with:
&gt;
&gt; invokestatic mypackage/AlphaConnector/open(Ljava/lang/String;IZ)Ljavax/microedition/io/Connection;
&gt;
&gt; What do i need to do?
&gt;
&gt; 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. 
&gt;
&gt; I would very much appreciate any input.
&gt;
&gt; Thanks,
&gt; Klaus.
&gt;
&gt;   

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>How to replace a complete instruction in J2ME Bytecode</title>
<author><name>&quot;Klaus Teller&quot; &lt;klaus.teller@gmx.net&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200902.mbox/%3c20090210005802.326770@gmx.net%3e"/>
<id>urn:uuid:%3c20090210005802-326770@gmx-net%3e</id>
<updated>2009-02-10T00:58:02Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
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.

-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>BCEL with J2ME</title>
<author><name>&quot;Marcelo Dias&quot; &lt;maruero@gmail.com&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200901.mbox/%3cddd8735c0901121358l55c32am4c11e5e724a28030@mail.gmail.com%3e"/>
<id>urn:uuid:%3cddd8735c0901121358l55c32am4c11e5e724a28030@mail-gmail-com%3e</id>
<updated>2009-01-12T21:58:54Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Hi, It's my first time asking you in this mail list, and I have two
questions.

First question:
How can I use BCEL to create (update) java classes that have to pass in the
CLDC verification process?
I'm trying to use a BCEL aplication to create a class before it is
preverifyed, but when executing the result aplication, a verification Error
is thrown.

Second question:
Is there a 'how to create your stackmap for classes created with BCEL'
tutorial? :-)

If anyone use BCEL to instrument J2ME class in another way, please tell me.

Thank's in advance!

Marcelo


</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Class Copy</title>
<author><name>yugo_amaril &lt;gabriele.costa@iit.cnr.it&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200812.mbox/%3c20814598.post@talk.nabble.com%3e"/>
<id>urn:uuid:%3c20814598-post@talk-nabble-com%3e</id>
<updated>2008-12-03T15:02:14Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>



Torsten Curdt wrote:
&gt; 
&gt; Much easier with ASM.
&gt; 
&gt; see org.objectweb.asm.commons.Remapper
&gt; 
&gt; cheers
&gt; --
&gt; Torsten
&gt; 
&gt; ---------------------------------------------------------------------
&gt; To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
&gt; For additional commands, e-mail: bcel-user-help@jakarta.apache.org
&gt; 
&gt; 
&gt; 
Probably, but I HAVE to use BCEL
-- 
View this message in context: http://www.nabble.com/Class-Copy-tp20811743p20814598.html
Sent from the BCEL - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
<entry>
<title>Re: Class Copy</title>
<author><name>&quot;Torsten Curdt&quot; &lt;tcurdt@apache.org&gt;</name></author>
<link rel="alternate" href="http://mail-archives.apache.org/mod_mbox/jakarta-bcel-user/200812.mbox/%3c6c59d89a0812030443t7f208640j9d4825486dfd285a@mail.gmail.com%3e"/>
<id>urn:uuid:%3c6c59d89a0812030443t7f208640j9d4825486dfd285a@mail-gmail-com%3e</id>
<updated>2008-12-03T12:43:37Z</updated>
<content type="xhtml">
<div xmlns="http://www.w3.org/1999/xhtml">
<pre>
Much easier with ASM.

see org.objectweb.asm.commons.Remapper

cheers
--
Torsten

---------------------------------------------------------------------
To unsubscribe, e-mail: bcel-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: bcel-user-help@jakarta.apache.org



</pre>
</div>
</content>
</entry>
</feed>
