tr4nc3
tr4nc3

Reputation: 641

Bytecode sequence decompilation

I have byte[] array which I know is a bytecode sequence for a method inside a class file. Is there some way to perform selective decompilation of this byte[] array? I do not have access to the actual .class file. I have looked at Javassist library that has a lot of methods (javassist.bytecode.CodeAttribute class) but I was unable to find such specific methods.
Anyone have a clue?

I can take this byte[] array and produce the actual bytecode to JavaByte code mnemonics using the JVM reference manual but I need to produce the decompiled Java source code. Thanks!

Upvotes: 2

Views: 559

Answers (2)

Antimony
Antimony

Reputation: 39451

It is impossible to produce valid Java source using only the bytecode of a specific method because all names are stored in the class wide constant pool, among other things. The best you can hope for is to generate bytecode mnemonics.

Upvotes: 2

Ryan Stewart
Ryan Stewart

Reputation: 128799

I've never heard of dealing with the bytecode for a single method. I think you're going to find that you can't do anything with it. What bytecode do you have? Where did you get it from? Are you familiar with the class file format and how methods are stored? For instance, the name of a method is stored in the constant pool, which is part of the overall class file, not part of any one method. Keep reading about the method format to see what else has to be there. I very strongly suspect that either you don't have what you think you have in that byte[], or else you're not going to have enough information to make anything of it.

Disclaimer: I've only dabbled in bytecode manipulation, so don't take what I say as authoritative. Believe what the spec says.

Upvotes: 3

Related Questions