Is there a java classfile / bytecode editor to edit instructions? [closed]
Asked Answered
S

4

37

Is there a utility (or eclipse plugin) for editing java class files? I'd like to manipulate the bytecode of a java class file without recompiling it nor having a complete buildpath.

E.g. to rename methods, add/delete instructions, change constants etc.

The only utilities I found are:

  • classeditor but it's very limited in functionality (e.g. renaming of things and manipulating instructions isn't possible).

  • jbe doesn't save changes (maybe because class verifying fails - before I made any changes, although the class runs perfectly)

    (jbe initially had a classpath issue, adding the class path to the jbe.bat file helped)

Severen answered 22/7, 2010 at 11:33 Comment(7)
What's wrong with jbe? It's Java so it should run anywhere.Regretful
@musikk An exception is thrown: Exception in thread "main" java.lang.NoClassDefFoundError: ee/ioc/cs/jbe/browser /BrowserApplicationSeveren
an exception is not a crash. You have a classpath issue.Portsalut
@Thorbjørn Ravn Andersen: jbe had a classpath issue when using the shipped jbe.bat. I altered it, now it runs, but I still cannot use it (see edited text above)Severen
I generally discard a project if I cannot get the provided get-started-examples to run. If that doesn't run, then what else doesn't?Portsalut
@Thorbjørn Ravn Andersen: This is one of the reasons why I am asking for other utilities than the above mentioned.Severen
possible duplicate of java bytecode editor?Toogood
W
10

I have not seen any byte code -> byte code frontends, but plenty backends.

I would suggest that you have a look at the many byte code manipulation libraries like javassist which allow loading byte code, manipulate it, and save it back to disk, and then write a small main that does exactly that.

Woodruff answered 22/7, 2010 at 11:55 Comment(0)
S
25

I use reJ for editing class files directly.

It allows you to edit instructions, methods, constant pool, diff classes, and a split view with a hex editor.

It's ridiculously awesome.

Sensillum answered 29/1, 2011 at 16:29 Comment(3)
reJ seems to be dead (last release took place in 2007)Severen
reJ would be awesome if editing worked. I've just tried to insert an "ifne" instruction that requires a parameter, I get a NullPointerException because its graphical user interface remains unfinished, it doesn't allow to pass the expected branch offset. Actually, I would advise to use reJ to display the instructions, Java Decompiler to check whether the changes are understood and a plain hexadecimal editor to edit the class file(s).Tramway
By the way, JByteMod just works, it does what reJ fails to do: grax.info I've used it to patch JOGL 2.3.2 :)Tramway
W
10

I have not seen any byte code -> byte code frontends, but plenty backends.

I would suggest that you have a look at the many byte code manipulation libraries like javassist which allow loading byte code, manipulate it, and save it back to disk, and then write a small main that does exactly that.

Woodruff answered 22/7, 2010 at 11:55 Comment(0)
L
10

I wrote an open source Java assembler and dissasembler you may find useful.

It lets you disassemble a classfile into human readable assembly, edit it, and then reassemble it into a class. It was originally designed for writing obfuscated crackmes, so there are a lot of obscure features it supports that many other tools don't. If you need any features it doesn't currently support, feel free to contact me and I'll see what I can do.

Lophophore answered 18/12, 2012 at 16:49 Comment(0)
C
3

Find this list of byte code manipulation/code generation libraries helpful?

Caper answered 22/7, 2010 at 15:37 Comment(1)
I need working tools, I don't have the time to code such a tool by myself (neither with the help of those libraries).Severen

© 2022 - 2024 — McMap. All rights reserved.