Click to See Complete Forum and Search --> : Java program runs, code is gibberish


hwashburn428
March 18th, 2010, 04:45 PM
Hey everyone. I recently tried to Jar my Java program to make it an executable to quickly show others. I ran it with a manifest file like I have done before but this time it seems something went wrong. I created the Jar file and can run it with no problems but my Java file has become unreadable almost as if it was encrypted.

I use Jcreator and other tools, and even with notepad the Java program shows only ASCII characters. The file is still there (11kb) and if I run it from cmd line using java filename, it runs with no problem. Could someone tell me what I did, and if its possible to reverse this. If I unjar the Jar file, its the same way.

Thanks,
Heath

hwashburn428
March 18th, 2010, 05:21 PM
Just a note it seems that my Jar file and Java file look very similar, but obviously my Jar file is much bigger because it has the packaged contents. The Java file will not compile from command line either. The last lines of my Java file in notepad does show this.

META-INF/PK
META-INF/MANIFEST.MFPK
....
and all the other class files with PK at the end and nulls around that.

ajhampson
March 19th, 2010, 09:54 AM
I'm not sure I'm understanding the problem. Are you saying that when you put the project into a jar, the original java source file was modified? :confused:

jitechno
March 19th, 2010, 10:18 AM
what means "Java file" for you ?
source.java, source.class, source.jar ?
it is impossible to encrypt source.java due to compilation, if your source.java is damaged or encrypted it happened not due to any Java tool.
print it here, if so :-)

hwashburn428
March 19th, 2010, 12:11 PM
PK


Created-By: 0.92-gcc

PK

póe*
Ãa¾\á©t‘L.âËòa7ÄÍW¸ùJ¯ðU*�S»Z¥Ëå.çkÜü1•?Î×Jó …¯Ã^/Í
bÏO–Á쟒æÓ2½QšÏHs“47+|‹ÂŸeòt%û¡@W<´G7�ÍÆ“Ö‰ñ¦°žH ¦™ #lÌf#°)6²ó–Hz®�PlÀˆ3Ímß­ïÑ÷Öâ#13Z×d�×#˜ÁpíŠëC ™“ÆL‡"ýugn(ÕD n‘îÐ…Yœ:}جk
‘D(Ž»K�áhd2k!‹aG™Ê²²æ¤Kc7&MÓbX–ÕÄ’}1˜Â²ƒ{ô‹XòÎ/¤í1öš›BF8(äÁPäÑ8(œ1Ý`òÚ’‡uàv›q�
#ùº”D“ع²ø
NáÏ#‡H<5ÒR΄WâP:ŒH²QÇ Î¯^Vè�éñÇ]V´ž=y}½­·½>oòz<y½½«�ã6ö†L�‚뀆—»ô>Kvq:Ù'’TN)Ç�.6¨¬>g²—ŠËŒÌ]®ïÇ©Ì.‚


That is what my Java Source File looks like. I was working on the file then ran a jar cvfm test.jar mymanifest.txt * to jar the file and the classes together. It took me some time but I later realized that when I open my Java Source File (.java code I was working on) it has a bunch of text like above. The jar file I made works fine. Obviously when I try to compile the program in a editor, it throws 100 or so errors, same with the command line.

The funny thing is that I can still run the Java Source File from the command line just using java test.java, it runs the program the way I had it no problem. This issue almost seems like it jar'ed the Java file and overwrote it, but I cannot try to unjar it. Also the size of the file is 11KB which is what it always has been, the jar is 22KB.

It seems that the file was some how modified when I created the jar file but I do not know how, I have done this before and never ran into this issue. The code has to be there because the file is not empty and I can run the program, but I do not know if there is anyway to fix this. I have tried restore, etc, and its xp pro so no shadow copies. Also I was using JCreator to compile and run the program, but I have always used JCreator in the past.

ajhampson
March 19th, 2010, 12:29 PM
Well, I'd say your Java file is well and truly hosed. If you can run with the command java test.java, that means test.java is a class file, not java source.

Your build (javac) output should never touch the .java file. It should produce a .class file which is then run with the java command. If your IDE is doing this, I'd say you have something wrong either with your project configuration or with the IDE itself.

Your best bet at this point is to try to decompile the class file back into Java. It won't be perfect, but it will get you restarted way ahead of starting over completely.

You can try JAD (http://www.varaneckas.com/jad) (Disclaimer: I don't know anything about this download location, the original JAD site is gone). It is no longer supported, but still works well for most code.

Let us know how it's going...

hwashburn428
March 19th, 2010, 12:47 PM
Wow thanks ajhampson. I saw that before but was skeptical but I ran it against the class file and it worked really well. It looks like it returned 99% of my code, I just need to do some rearranging and maybe add a thing here and there but it worked great. I think in the end the java file just got corrupted some how, but it frustrates me until I figure out why.

Again thanks for the help!

Heath

ajhampson
March 19th, 2010, 12:53 PM
You're welcome. Be sure to keep a backup once you get completely recovered.

alan

hwashburn428
March 19th, 2010, 01:06 PM
Yea i know. Need something like shadow copy. Robocopy over a old file file and replacing it does no good :)

ajhampson
March 19th, 2010, 01:16 PM
Well, if you're serious about coding, a version control system is a must. You can either set up your own (git or subversion) repository, or use one of the free web-based ones.

There's nothing that makes that "O crap, what have I done?" sinking feeling go away quicker than a revert to last know good version. :)

Version control, don't leave home without it. :D

jitechno
March 20th, 2010, 11:45 AM
Wow thanks ajhampson. I saw that before but was skeptical but I ran it against the class file and it worked really well. It looks like it returned 99% of my code, I just need to do some rearranging and maybe add a thing here and there but it worked great. I think in the end the java file just got corrupted some how, but it frustrates me until I figure out why.

Again thanks for the help!

Heath

I have only idea, in one or other manner you renamed class file to "java" file.
But I dont recognize how you do it, I am sure JCreator is not a player here.
But always have a copy!