CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 11 of 11
  1. #1
    Join Date
    Mar 2010
    Posts
    6

    Java program runs, code is gibberish

    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

  2. #2
    Join Date
    Mar 2010
    Posts
    6

    Re: Java program runs, code is gibberish

    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.

  3. #3
    Join Date
    Jun 2007
    Location
    Aurora CO USA
    Posts
    137

    Re: Java program runs, code is gibberish

    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?

  4. #4
    Join Date
    Mar 2010
    Posts
    74

    Re: Java program runs, code is gibberish

    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 :-)

  5. #5
    Join Date
    Mar 2010
    Posts
    6

    Re: Java program runs, code is gibberish

    PK


    Created-By: 0.92-gcc

    PK

    póe*
    Ãa¾\á©t‘L.âËòa7ÄÍW¸ùJ¯ðU*�S»Z¥Ëå.çkÜü1•?Î×Jó …¯Ã^/Í
    b&#207;O–&#193;&#236;Ÿ’&#230;&#211;2&#189;Qš&#207;Hs“47+|‹&#194;Ÿe&#242;t&#37;&#251;&#194;&#161;@W<&#180;G7�&#205;&#198;“&#214;‰&#241;&#166;&#176;žH &#166;™ #l&#204;f#&#1766&#178;&#243;–Hz&#174;�Pl&#192;ˆ3&#205;m&#223;&#173;&#239;&#209;&#247;&#214;&#226;#13Z&#215;d�&#215;#˜&#193;p&#237;Š&#235;C&#160;™“&#198;L‡"&#253;ugn(&#213;D n‘&#238;&#208;…Yœ:}&#216;&#172;k
    ‘D(Ž&#187;K�&#225;hd2k!‹aG™&#202;&#178;&#178;&#230;&#164;Kc7&M&#211;bX–&#213;&#196;’}1˜&#194;&#178;ƒ{&#244;‹X&#242;&#206;/&#164;&#237;1&#246;š›BF8(&#228;&#193;P&#228;&#209;8(œ1&#221;`&#242;&#218;’‡u&#224;v›q�
    #&#249;&#186;”D“&#216;&#185;&#178;&#248;
    N&#225;&#207;#‡H<5&#210;R&#206;„W&#226;P:ŒH&#178;Q&#199; &#206;&#175;^V&#232;�&#233;&#241;&#199;]V&#180;ž=y}&#189;&#173;&#183;&#189;>o&#242;z<y&#189;&#189;&#171;�&#227;6&#246;†L�‚&#235;€†—&#187;&#244;>Kvq:&#217;'’TN)&#199;�.6&#168;&#172;>g&#178;—Š&#203;Œ&#204;]&#174;&#239;&#199;&#169;&#204;.‚


    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.

  6. #6
    Join Date
    Jun 2007
    Location
    Aurora CO USA
    Posts
    137

    Re: Java program runs, code is gibberish

    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 (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...

  7. #7
    Join Date
    Mar 2010
    Posts
    6

    Re: Java program runs, code is gibberish

    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

  8. #8
    Join Date
    Jun 2007
    Location
    Aurora CO USA
    Posts
    137

    Re: Java program runs, code is gibberish

    You're welcome. Be sure to keep a backup once you get completely recovered.

    alan

  9. #9
    Join Date
    Mar 2010
    Posts
    6

    Post Re: Java program runs, code is gibberish

    Yea i know. Need something like shadow copy. Robocopy over a old file file and replacing it does no good

  10. #10
    Join Date
    Jun 2007
    Location
    Aurora CO USA
    Posts
    137

    Re: Java program runs, code is gibberish

    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.

  11. #11
    Join Date
    Mar 2010
    Posts
    74

    Re: Java program runs, code is gibberish

    Quote Originally Posted by hwashburn428 View Post
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured