Editing class file within jar file

pollardhimself

Senior member
Nov 6, 2009
281
0
0
Im having trouble editing one line in a part of the class file with "ce2.23". I can edit it but once i put it back in the jar file wont work. Anything simple that im doing wrong?

the manifest file just has this in it
Manifest-Version: 1.0
Created-By: name was here
 

Gooberlx2

Lifer
May 4, 2001
15,381
6
91
I don't really understand how ce2.23 is supposed to work. What specifically are you trying to do?

Class files are compiled code, not intended for direct editing. Do you not have access to the source?
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
Are you simply trying to change a string?

You can do that with a hex editor. Just make sure you keep the same number of characters as the old string and don't forget the null character at the end.

Example, say you want to change "Pollard" to "Leros"

You open up your class file in a hex editor and find the following ('x' is random stuff):
'x' 'x' 'x' 'P' 'o' 'l' 'l' 'a' 'r' 'd' 'Ø' 'x' 'x' 'x'

Notice the string "Pollard" is 8 characters including the null terminator. You need to maintain that length.

You would change that to:
'x' 'x' 'x' 'L' 'e' 'r' 'o' 's' 'Ø' 'Ø' 'Ø' 'x' 'x' 'x'

That preserves the same number of characters in your file, so that other elements are not out of place.
'x' 'x' 'x' 'P' 'o' 'l' 'l' 'a' 'r' 'd' 'Ø' 'x' 'x' 'x'
'x' 'x' 'x' 'L' 'e' 'r' 'o' 's' 'Ø' 'Ø' 'Ø' 'x' 'x' 'x'

Note: This is the safe conservative way to edit a file like this. You obviously can't make a string longer with my method. I'm not sure how class files work so you might able to do it a different way, but the method I mentioned should work for nearly any kind of file.
 
Last edited:

pollardhimself

Senior member
Nov 6, 2009
281
0
0
so can i pull the .class file out of the jar file decompile it to .java then edit recompile and re-insert it into the .jar and have it work?
 

Leros

Lifer
Jul 11, 2004
21,867
7
81
I would decompile all of the class files, recompile them all, then jar them into an entirely new jar.
 

pollardhimself

Senior member
Nov 6, 2009
281
0
0
will do what the best way to compile? I have got them all decompiled into .java files there all in multiple folders. How should I got about it
 
Last edited:

pollardhimself

Senior member
Nov 6, 2009
281
0
0
There are multiple .java files Cant get the command jar cfm filename.jar *.class to work getting

at java.io.FileInputStream.open(Native.Method)
at java.io.FileInputStream.(init)(FileInputStream.java:106)
at java.io.FileInputStream.(init)(FileInputStream.java:66)
at sun.tools.jar.Main.run(Main.java:150)
at sun.tools.jar.Main.main(Main.java:1149)

Im new to java do I need to compile the .class files first then do a jar compile?

Is there anyway I can tell it to ignore the errors the coding is java thats used in building controllers
 
Last edited: