// code to patch class-file:
|
| import javassist.*;
| import javassist.expr.*;
| import java.io.*;
| import java.util.*;
| public class Patch
| {
| public static void main(String args[])
| throws Exception
| {
| File f=new File(args[0]);
| FileInputStream fis=new FileInputStream(f);
| ClassPool cp=new ClassPool();
| cp.appendSystemPath();
| CtClass c=cp.makeClass(fis);
| c.instrument(
| new ExprEditor()
| {
| public void edit(NewExpr call)
| throws CannotCompileException
| {
| if
("java.util.ArrayList".equals(call.getClassName()))
| {
| call.replace("$_=new
ArrayListWrapper(\"hi there\",$$);")
| ;
| }
| }
| });
| c.writeFile("patched");
| c.detach();
| fis.close();
| }
| }
|
| // the wrapper:
|
| public class ArrayListWrapper extends java.util.ArrayList
| {
| public ArrayListWrapper(String bla,int size)
| {
| }
| public ArrayListWrapper(String bla)
| {
| }
| }
|
| // class to patch:
|
| import java.util.*;
| public class Test
| {
| public static void test()
| {
| try
| {
| ArrayList h=new ArrayList();
| }
| catch (Exception e)
| {
| e.printStackTrace();
| }
| }
| public static void main(String args[])
| {
| test();
| }
| }
When I run Patch on Test.class and decompile the created Test.class jad complains:
Parsing Test.class...Overwrite Test.jad [y/n/a/s] ? y
Generating Test.jad
Couldn't fully decompile method test
Couldn't resolve all exception handlers in method test
Perhaps I'm relying on jad too much... the class seems to work, but the strange thing
is, that jad does not complain when puting somehting (which will not be removed by the
optimizer :)) before the new ArrayList statement in my Test-class.
What I'm seeing now is that the code, which cannot be decompiled by jad, seems to run.
Maybe I should forget about jad :)
I saw this at work when trying to patch some class-files compiled by some jdk from IBM
(1.3). The problem described above occured during patching a class which contains a
couple of nop's in the byte-code at the beginning of bytecode of a method like the one
in Test.class. Perhaps that was the problem...I'm still not sure. I got VerifyErrors
and even Web$phere-crashes, but that's regular stuff :)
I'm still not sure about this. Perhaps it's a problem of jad, but I've never had any
problems with jad.
I'm using Sun's JDK 1.4.1_03 on Linux. At work it's 1.3 on Window$. Same behavior.
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3845658#3845658
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3845658
-------------------------------------------------------
SF.Net email is sponsored by Shop4tech.com-Lowest price on Blank Media
100pk Sonic DVD-R 4x for only $29 -100pk Sonic DVD+R for only $33
Save 50% off Retail on Ink & Toner - Free Shipping and Free Gift.
http://www.shop4tech.com/z/Inkjet_Cartridges/9_108_r285
_______________________________________________
JBoss-user mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-user