1

I'm working on a coremod for Minecraft, and transform a lot of the classes as they are loaded. The problem however is that there are multiple coremods which also transform the same classes that I am, and I am getting some strange behavior that I want to look into.

Then comes the problem, how do I inspect the bytecode after it has been transformed multiple times? When I transform it I just get an byte[] input that I run trough ASM and then return my modified bytecode.

My idea was to just to dump the class bytecode to a .class file after the class was loaded, and inspect it from there. But I can't seem to find any way to actually get the bytecode after the class is loaded. The closest I can find is getResource, but that returns the bytecode as it was BEFORE it was transformed, not what I want.

TLDR: How do I get the bytecode of a class AFTER it has been modified and loaded? -Can't use ClassLoader.getResource as it returns unmodified version. -Can't get it during load time as I want to catch transforms happening after my own.

Is there some external program that can dump the in-memory bytecode or something?

Hoping someone can help me with this =)

3
  • How are the transforms happening? Normally you'd use Java Agent for this. Commented Feb 28, 2014 at 4:16
  • As I understand the code I'm hooking into is already doing this, I just have to provide a transformer: "@Override public byte[] transform(String name1, String name2, byte[] bytedata)" I can't really make any changes to this(Forge Mod Loader) so I was hoping there was a way other than Agents to get the bytecode =/ Commented Feb 28, 2014 at 4:21
  • Unfortunately there isn't. Commented Feb 28, 2014 at 4:21

1 Answer 1

1

As far as I know, the only interface for runtime access to bytecode is provided by Java Agents. This is also how you create classfile transformers in the first place, so you should already be using one. Just modify it to dump the classfile.

Edit: As far as the order of transformation, according to the docs, it is

Retransformation incapable transformers
Retransformation incapable native transformers
Retransformation capable transformers
Retransformation capable native transformers

So ideally you'd want a retransformation capable native transformer. But writing native code is a pain. Setting your transformer to enable retransformation will help a lot, but it's still possible for another retransformer registered later to run after you. The best option I can think of is to register your agent again. Or find all calls to register a transformer and insert yours afterwards.

Sign up to request clarification or add additional context in comments.

4 Comments

I can dump my transformed bytecode, the problem is that there are transform running after mine, and I would like to access the final bytecode after these are done with it. I guess I'll just have to dig into the code of the Agent that loads my code.
Register your transformer again.
Oh, not a bad idea, then my registered transformer should be the last one =D
I know the post was 7 years ago, but how i did this was have a static bool (reInit), and during the transform() method, if that bool is false, i use reflection with the LaunchClassLoader to re-organise them, making my transformer the last. And if it's true, i just continue dumping bytecode to a file. Here's the pastbin if you wanna check it out: pastebin.com/Rn5xqyfp

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.