0

Possible Duplicate:
java bytecode editor?

I am looking for a way to directly edit a .class file that was packed in a .jar. I have extracted the .jar file, and have a series of .class files (exactly speaking. GUImain.class is the one that I wish to edit) and need to change some strings and remove some values from being displayed. I cannot do this in a simple hex editor, as the string length will be changing to 3/4 it's current length Whenever I decompile the class files, edit them with my IDE, and attempt to recompile, I get several errors, even working out of the same folder as the copied originals. Could anybody help me out?

Community
  • 1
  • 1
Azulflame
  • 1,534
  • 2
  • 15
  • 30
  • 6
    have you thought about extending the class and overriding certain methods instead? – driangle Sep 07 '12 at 19:58
  • 1
    So, you want to edit it directly rather than decompile and re-compile (i.e. you know those options are available, but you're sure that's not what you want), or sub-classing it, etc.? Do I have that correct? – jefflunt Sep 07 '12 at 19:58
  • @ggreiner, please expand on your comment – Azulflame Sep 07 '12 at 19:59
  • @normalocity, that's what I'm saying. when I decompile and recompile, I get several errors (40+), compared to 0 if I were to edit the string directly. I'm not changing major parts of the program, just the value of a single string. – Azulflame Sep 07 '12 at 20:00
  • You say that you need to "change some strings and remove values from being displayed", to me this is saying that you want to change some of the behavior of that class. One way to accomplish that is to create a new class which extends GUIMain (if it's not final) and then override the methods whose behavior you want to modify – driangle Sep 07 '12 at 20:00
  • 1
    I think you're looking for a [java bytecode editor?](http://stackoverflow.com/questions/2395574/java-bytecode-editor) (possible duplicate) – jefflunt Sep 07 '12 at 20:01
  • More or less, I am, but I'm looking for something simple to use, I don't have a lot of spare time to learn a new program for a simple GUI modification – Azulflame Sep 07 '12 at 20:04
  • [Javassist] (http://www.csg.ci.i.u-tokyo.ac.jp/~chiba/javassist/) might be also a good candidate. – Lorand Bendig Sep 07 '12 at 20:10
  • Well, it's a question of what you need to do. A bytecode editor might be the easiest way if you absolutely, positively want to edit the bytecode. I mean, you can just open the `.class` file in a text editor, but it's not going to be easy to properly edit the bytecode in a tool that's isn't designed for it because the bytecode will be presented as if it's plaintext, and a bunch of the bytecode is going to include non-printable characters. Also, if you try to save that file with a text editor, it's going to assume ASCII or UTF-8 encoding (or something), which is going to hork the class file. – jefflunt Sep 07 '12 at 20:23
  • So, if you really, absolutely have to edit the bytecode directly, you're going to have to use a bytecode editor if, for no other reason, so that the output of you saving your changes is also valid bytecode. – jefflunt Sep 07 '12 at 20:23
  • PHilipp, it's a legitimate reason, and I'm not doing this for homework. I have the original coder's permission to do this, but he is not giving the original source code anywhere (it has 'crash code' in it, so if his mark isn't in it (I have his permission, so I have the mark), then the code won't work (this is a complex installer package that is VERY useful). it crashes the game if the crash code isn't depricated, which only his work does. Excellent anti-plagerism tool)) – Azulflame Sep 07 '12 at 21:46

0 Answers0