You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Li Li <fa...@gmail.com> on 2015/06/24 11:21:11 UTC

is BCEL the tool for me?

Hi all,
     I have a jar file and without the source code, I want to replace
a package and all classes of this package with my own.
     e.g.  There is a package
      com.abc.tool
      com.abc.tool.A.class
      com.abc.tool.B.class
    The com.abc.tool.A.class and com.abc.tool.B.class are used in many
other classes.
    I want to use my own implementation, So I can create my
package(com.def.tool) and my A.java B.java which has exactly the same
method as  com.abc.tool.A.class and  com.abc.tool.B.class
       com.def.tool
       com.def.tool.A.class
       com.def.tool.B.class
    But other classes in this jar still use com.abc.tool.A.class and
com.abc.tool.B.class. I want to use a byte code library to modify the
jar so it can run and use my implementation.
    Is BCEL suitable for this? Thank you

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


Re: is BCEL the tool for me?

Posted by Li Li <fa...@gmail.com>.
thank you, I will try ASM

On Wed, Jun 24, 2015 at 6:12 PM, Torsten Curdt <tc...@vafer.org> wrote:
> I would rather use ASM for this.
>
> Have a look at the maven shade plugin.
> It has an implementation of pretty much what you have in mind.
>
> cheers,
> Torsten
>
> On Wed, Jun 24, 2015 at 11:44 AM, Li Li <fa...@gmail.com> wrote:
>
>> I have to use another package name other than the original one because
>> the original package is loaded and not controlled by my code.
>>
>>
>> On Wed, Jun 24, 2015 at 5:37 PM, Benedikt Ritter <br...@apache.org>
>> wrote:
>> > Hello Li Li
>> >
>> > 2015-06-24 11:21 GMT+02:00 Li Li <fa...@gmail.com>:
>> >
>> >> Hi all,
>> >>      I have a jar file and without the source code, I want to replace
>> >> a package and all classes of this package with my own.
>> >>      e.g.  There is a package
>> >>       com.abc.tool
>> >>       com.abc.tool.A.class
>> >>       com.abc.tool.B.class
>> >>     The com.abc.tool.A.class and com.abc.tool.B.class are used in many
>> >> other classes.
>> >>     I want to use my own implementation, So I can create my
>> >> package(com.def.tool) and my A.java B.java which has exactly the same
>> >> method as  com.abc.tool.A.class and  com.abc.tool.B.class
>> >>        com.def.tool
>> >>        com.def.tool.A.class
>> >>        com.def.tool.B.class
>> >>     But other classes in this jar still use com.abc.tool.A.class and
>> >> com.abc.tool.B.class. I want to use a byte code library to modify the
>> >> jar so it can run and use my implementation.
>> >>     Is BCEL suitable for this? Thank you
>> >>
>> >
>> > This sounds like a pretty complicated solution to your problem. Why don't
>> > you just replace the class files in the jar at build time?
>> >
>> > Regards,
>> > Benedikt
>> >
>> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> >> For additional commands, e-mail: user-help@commons.apache.org
>> >>
>> >>
>> >
>> >
>> > --
>> > http://people.apache.org/~britter/
>> > http://www.systemoutprintln.de/
>> > http://twitter.com/BenediktRitter
>> > http://github.com/britter
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>

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


Re: is BCEL the tool for me?

Posted by Torsten Curdt <tc...@vafer.org>.
I would rather use ASM for this.

Have a look at the maven shade plugin.
It has an implementation of pretty much what you have in mind.

cheers,
Torsten

On Wed, Jun 24, 2015 at 11:44 AM, Li Li <fa...@gmail.com> wrote:

> I have to use another package name other than the original one because
> the original package is loaded and not controlled by my code.
>
>
> On Wed, Jun 24, 2015 at 5:37 PM, Benedikt Ritter <br...@apache.org>
> wrote:
> > Hello Li Li
> >
> > 2015-06-24 11:21 GMT+02:00 Li Li <fa...@gmail.com>:
> >
> >> Hi all,
> >>      I have a jar file and without the source code, I want to replace
> >> a package and all classes of this package with my own.
> >>      e.g.  There is a package
> >>       com.abc.tool
> >>       com.abc.tool.A.class
> >>       com.abc.tool.B.class
> >>     The com.abc.tool.A.class and com.abc.tool.B.class are used in many
> >> other classes.
> >>     I want to use my own implementation, So I can create my
> >> package(com.def.tool) and my A.java B.java which has exactly the same
> >> method as  com.abc.tool.A.class and  com.abc.tool.B.class
> >>        com.def.tool
> >>        com.def.tool.A.class
> >>        com.def.tool.B.class
> >>     But other classes in this jar still use com.abc.tool.A.class and
> >> com.abc.tool.B.class. I want to use a byte code library to modify the
> >> jar so it can run and use my implementation.
> >>     Is BCEL suitable for this? Thank you
> >>
> >
> > This sounds like a pretty complicated solution to your problem. Why don't
> > you just replace the class files in the jar at build time?
> >
> > Regards,
> > Benedikt
> >
> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> >> For additional commands, e-mail: user-help@commons.apache.org
> >>
> >>
> >
> >
> > --
> > http://people.apache.org/~britter/
> > http://www.systemoutprintln.de/
> > http://twitter.com/BenediktRitter
> > http://github.com/britter
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: is BCEL the tool for me?

Posted by Torsten Curdt <tc...@vafer.org>.
>
>
> > I have to use another package name other than the original one because
> > the original package is loaded and not controlled by my code.
> >
>
> I don't think you should mess around with the byte code in this situation.
> What if other code also uses the shared library and it depends on it's
> current behavior? You could introduce unforeseeable side effects.
>

It's really no messing and shared libraries should be no problem.

You just need to make sure to analyze and possibly rewrite all classes
involved.
The transitive hull of the class dependencies on the classpath.

The only problem is runtime loading of classes via strings. I don't think
that's covered by the code in the maven shade plugin but IIRC my original
minijar implementation handled that, too.

Really no black magic here.

Of course: if you can do it without - do it without.

cheers,
Torsten

Re: is BCEL the tool for me?

Posted by Benedikt Ritter <br...@apache.org>.
Hello Li Li,

2015-06-24 11:44 GMT+02:00 Li Li <fa...@gmail.com>:

> I have to use another package name other than the original one because
> the original package is loaded and not controlled by my code.
>

I don't think you should mess around with the byte code in this situation.
What if other code also uses the shared library and it depends on it's
current behavior? You could introduce unforeseeable side effects.

Doesn't the library you're using provide extension points you can use to
add the desired functionality in a save way?

Benedikt


>
>
> On Wed, Jun 24, 2015 at 5:37 PM, Benedikt Ritter <br...@apache.org>
> wrote:
> > Hello Li Li
> >
> > 2015-06-24 11:21 GMT+02:00 Li Li <fa...@gmail.com>:
> >
> >> Hi all,
> >>      I have a jar file and without the source code, I want to replace
> >> a package and all classes of this package with my own.
> >>      e.g.  There is a package
> >>       com.abc.tool
> >>       com.abc.tool.A.class
> >>       com.abc.tool.B.class
> >>     The com.abc.tool.A.class and com.abc.tool.B.class are used in many
> >> other classes.
> >>     I want to use my own implementation, So I can create my
> >> package(com.def.tool) and my A.java B.java which has exactly the same
> >> method as  com.abc.tool.A.class and  com.abc.tool.B.class
> >>        com.def.tool
> >>        com.def.tool.A.class
> >>        com.def.tool.B.class
> >>     But other classes in this jar still use com.abc.tool.A.class and
> >> com.abc.tool.B.class. I want to use a byte code library to modify the
> >> jar so it can run and use my implementation.
> >>     Is BCEL suitable for this? Thank you
> >>
> >
> > This sounds like a pretty complicated solution to your problem. Why don't
> > you just replace the class files in the jar at build time?
> >
> > Regards,
> > Benedikt
> >
> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> >> For additional commands, e-mail: user-help@commons.apache.org
> >>
> >>
> >
> >
> > --
> > http://people.apache.org/~britter/
> > http://www.systemoutprintln.de/
> > http://twitter.com/BenediktRitter
> > http://github.com/britter
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>


-- 
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter

Re: is BCEL the tool for me?

Posted by Dave Newton <da...@gmail.com>.
...

Byte Code Engineering Library, ASM, others.
On Jun 24, 2015 6:19 AM, "Li Li" <fa...@gmail.com> wrote:

> I am not familiar with byte code hacking, could you please recommend
> some tools for me?
>
> On Wed, Jun 24, 2015 at 6:12 PM, Dave Newton <da...@gmail.com>
> wrote:
> > There are various shading tools that could help rather than manually
> > mucking about with byte code.
> > On Jun 24, 2015 5:45 AM, "Li Li" <fa...@gmail.com> wrote:
> >
> >> I have to use another package name other than the original one because
> >> the original package is loaded and not controlled by my code.
> >>
> >>
> >> On Wed, Jun 24, 2015 at 5:37 PM, Benedikt Ritter <br...@apache.org>
> >> wrote:
> >> > Hello Li Li
> >> >
> >> > 2015-06-24 11:21 GMT+02:00 Li Li <fa...@gmail.com>:
> >> >
> >> >> Hi all,
> >> >>      I have a jar file and without the source code, I want to replace
> >> >> a package and all classes of this package with my own.
> >> >>      e.g.  There is a package
> >> >>       com.abc.tool
> >> >>       com.abc.tool.A.class
> >> >>       com.abc.tool.B.class
> >> >>     The com.abc.tool.A.class and com.abc.tool.B.class are used in
> many
> >> >> other classes.
> >> >>     I want to use my own implementation, So I can create my
> >> >> package(com.def.tool) and my A.java B.java which has exactly the same
> >> >> method as  com.abc.tool.A.class and  com.abc.tool.B.class
> >> >>        com.def.tool
> >> >>        com.def.tool.A.class
> >> >>        com.def.tool.B.class
> >> >>     But other classes in this jar still use com.abc.tool.A.class and
> >> >> com.abc.tool.B.class. I want to use a byte code library to modify the
> >> >> jar so it can run and use my implementation.
> >> >>     Is BCEL suitable for this? Thank you
> >> >>
> >> >
> >> > This sounds like a pretty complicated solution to your problem. Why
> don't
> >> > you just replace the class files in the jar at build time?
> >> >
> >> > Regards,
> >> > Benedikt
> >> >
> >> >
> >> >>
> >> >> ---------------------------------------------------------------------
> >> >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> >> >> For additional commands, e-mail: user-help@commons.apache.org
> >> >>
> >> >>
> >> >
> >> >
> >> > --
> >> > http://people.apache.org/~britter/
> >> > http://www.systemoutprintln.de/
> >> > http://twitter.com/BenediktRitter
> >> > http://github.com/britter
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> >> For additional commands, e-mail: user-help@commons.apache.org
> >>
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: is BCEL the tool for me?

Posted by Li Li <fa...@gmail.com>.
I am not familiar with byte code hacking, could you please recommend
some tools for me?

On Wed, Jun 24, 2015 at 6:12 PM, Dave Newton <da...@gmail.com> wrote:
> There are various shading tools that could help rather than manually
> mucking about with byte code.
> On Jun 24, 2015 5:45 AM, "Li Li" <fa...@gmail.com> wrote:
>
>> I have to use another package name other than the original one because
>> the original package is loaded and not controlled by my code.
>>
>>
>> On Wed, Jun 24, 2015 at 5:37 PM, Benedikt Ritter <br...@apache.org>
>> wrote:
>> > Hello Li Li
>> >
>> > 2015-06-24 11:21 GMT+02:00 Li Li <fa...@gmail.com>:
>> >
>> >> Hi all,
>> >>      I have a jar file and without the source code, I want to replace
>> >> a package and all classes of this package with my own.
>> >>      e.g.  There is a package
>> >>       com.abc.tool
>> >>       com.abc.tool.A.class
>> >>       com.abc.tool.B.class
>> >>     The com.abc.tool.A.class and com.abc.tool.B.class are used in many
>> >> other classes.
>> >>     I want to use my own implementation, So I can create my
>> >> package(com.def.tool) and my A.java B.java which has exactly the same
>> >> method as  com.abc.tool.A.class and  com.abc.tool.B.class
>> >>        com.def.tool
>> >>        com.def.tool.A.class
>> >>        com.def.tool.B.class
>> >>     But other classes in this jar still use com.abc.tool.A.class and
>> >> com.abc.tool.B.class. I want to use a byte code library to modify the
>> >> jar so it can run and use my implementation.
>> >>     Is BCEL suitable for this? Thank you
>> >>
>> >
>> > This sounds like a pretty complicated solution to your problem. Why don't
>> > you just replace the class files in the jar at build time?
>> >
>> > Regards,
>> > Benedikt
>> >
>> >
>> >>
>> >> ---------------------------------------------------------------------
>> >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> >> For additional commands, e-mail: user-help@commons.apache.org
>> >>
>> >>
>> >
>> >
>> > --
>> > http://people.apache.org/~britter/
>> > http://www.systemoutprintln.de/
>> > http://twitter.com/BenediktRitter
>> > http://github.com/britter
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>

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


Re: is BCEL the tool for me?

Posted by Dave Newton <da...@gmail.com>.
There are various shading tools that could help rather than manually
mucking about with byte code.
On Jun 24, 2015 5:45 AM, "Li Li" <fa...@gmail.com> wrote:

> I have to use another package name other than the original one because
> the original package is loaded and not controlled by my code.
>
>
> On Wed, Jun 24, 2015 at 5:37 PM, Benedikt Ritter <br...@apache.org>
> wrote:
> > Hello Li Li
> >
> > 2015-06-24 11:21 GMT+02:00 Li Li <fa...@gmail.com>:
> >
> >> Hi all,
> >>      I have a jar file and without the source code, I want to replace
> >> a package and all classes of this package with my own.
> >>      e.g.  There is a package
> >>       com.abc.tool
> >>       com.abc.tool.A.class
> >>       com.abc.tool.B.class
> >>     The com.abc.tool.A.class and com.abc.tool.B.class are used in many
> >> other classes.
> >>     I want to use my own implementation, So I can create my
> >> package(com.def.tool) and my A.java B.java which has exactly the same
> >> method as  com.abc.tool.A.class and  com.abc.tool.B.class
> >>        com.def.tool
> >>        com.def.tool.A.class
> >>        com.def.tool.B.class
> >>     But other classes in this jar still use com.abc.tool.A.class and
> >> com.abc.tool.B.class. I want to use a byte code library to modify the
> >> jar so it can run and use my implementation.
> >>     Is BCEL suitable for this? Thank you
> >>
> >
> > This sounds like a pretty complicated solution to your problem. Why don't
> > you just replace the class files in the jar at build time?
> >
> > Regards,
> > Benedikt
> >
> >
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> >> For additional commands, e-mail: user-help@commons.apache.org
> >>
> >>
> >
> >
> > --
> > http://people.apache.org/~britter/
> > http://www.systemoutprintln.de/
> > http://twitter.com/BenediktRitter
> > http://github.com/britter
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
> For additional commands, e-mail: user-help@commons.apache.org
>
>

Re: is BCEL the tool for me?

Posted by Li Li <fa...@gmail.com>.
I have to use another package name other than the original one because
the original package is loaded and not controlled by my code.


On Wed, Jun 24, 2015 at 5:37 PM, Benedikt Ritter <br...@apache.org> wrote:
> Hello Li Li
>
> 2015-06-24 11:21 GMT+02:00 Li Li <fa...@gmail.com>:
>
>> Hi all,
>>      I have a jar file and without the source code, I want to replace
>> a package and all classes of this package with my own.
>>      e.g.  There is a package
>>       com.abc.tool
>>       com.abc.tool.A.class
>>       com.abc.tool.B.class
>>     The com.abc.tool.A.class and com.abc.tool.B.class are used in many
>> other classes.
>>     I want to use my own implementation, So I can create my
>> package(com.def.tool) and my A.java B.java which has exactly the same
>> method as  com.abc.tool.A.class and  com.abc.tool.B.class
>>        com.def.tool
>>        com.def.tool.A.class
>>        com.def.tool.B.class
>>     But other classes in this jar still use com.abc.tool.A.class and
>> com.abc.tool.B.class. I want to use a byte code library to modify the
>> jar so it can run and use my implementation.
>>     Is BCEL suitable for this? Thank you
>>
>
> This sounds like a pretty complicated solution to your problem. Why don't
> you just replace the class files in the jar at build time?
>
> Regards,
> Benedikt
>
>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
>> For additional commands, e-mail: user-help@commons.apache.org
>>
>>
>
>
> --
> http://people.apache.org/~britter/
> http://www.systemoutprintln.de/
> http://twitter.com/BenediktRitter
> http://github.com/britter

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


Re: is BCEL the tool for me?

Posted by Benedikt Ritter <br...@apache.org>.
Hello Li Li

2015-06-24 11:21 GMT+02:00 Li Li <fa...@gmail.com>:

> Hi all,
>      I have a jar file and without the source code, I want to replace
> a package and all classes of this package with my own.
>      e.g.  There is a package
>       com.abc.tool
>       com.abc.tool.A.class
>       com.abc.tool.B.class
>     The com.abc.tool.A.class and com.abc.tool.B.class are used in many
> other classes.
>     I want to use my own implementation, So I can create my
> package(com.def.tool) and my A.java B.java which has exactly the same
> method as  com.abc.tool.A.class and  com.abc.tool.B.class
>        com.def.tool
>        com.def.tool.A.class
>        com.def.tool.B.class
>     But other classes in this jar still use com.abc.tool.A.class and
> com.abc.tool.B.class. I want to use a byte code library to modify the
> jar so it can run and use my implementation.
>     Is BCEL suitable for this? Thank you
>

This sounds like a pretty complicated solution to your problem. Why don't
you just replace the class files in the jar at build time?

Regards,
Benedikt


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


-- 
http://people.apache.org/~britter/
http://www.systemoutprintln.de/
http://twitter.com/BenediktRitter
http://github.com/britter