P
P
pqgg7nwkd42017-03-03 21:41:18
Java
pqgg7nwkd4, 2017-03-03 21:41:18

How to replace class name in .class file code?

Good afternoon.
Suppose I have a class .class file with the name com.example1.FooFoo.
Now I want this file to be loaded as the com.example1.Bar class.
In other words, write a ClassLoader that:
1. Received a request from the application to load the com.example1.Bar class.
2. In some way that doesn't matter now, I determined that I needed to load the code from the com/example1/FooFoo.class file.
3. Loaded bytecode from file com/example1/FooFoo.class (which compiled as class FooFoo)
4. Replaced FooFoo class name in bytecode with Bar
5. Called defineClass

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene Khrustalev, 2017-03-03
@eugenehr

Here, I think, you need to write (or find) JavaAgent .
May I ask - what is it for?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question