CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Java and JSP (http://www.codingforums.com/forumdisplay.php?f=54)
-   -   Java Decompiler (edit .jar files) (http://www.codingforums.com/showthread.php?t=175470)

UrbanTwitch 08-26-2009 12:10 AM

Java Decompiler (edit .jar files)
 
I've been through Google and back. What's a good editor in which I can edit .jar files (decompiler) of Java?

Thanks.

(free to download, please)

ckeyrouz 08-26-2009 12:21 AM

There is a difference between decompiling and editing a jar content.

A jar (java archive) as its name says is an archive or collection of java classes that are ready to be executed.

A java decompiler is a tool that makes a reverse engineering from .class extension to .java extension.

I do not know what is your need, anyway check how we solve both issues.

For editing the content of the jar file (adding, removing, decompiling) you can go to the command prompt (or shell terminal for linux or unix based os) and on which you have installed the JDK not the JRE and you can write the following command:

\etc\jdk\bin> jar

and it will scroll down in front of you all the possible combinations of options on how to use jar (for example to explode the content of a jar you can write: jar -xvf (full path to jar file)

On the other hand if you want to decompile a class file into a java file, you can download the jad (java decompiler) from the following url:

http://www.softpedia.com/progDownloa...oad-85911.html

UrbanTwitch 08-26-2009 12:41 AM

I'm using Windows Vista 64-bit and that program you linked me too doesn't work. The screen flashes (cmd) for 1 sec and closes.

ckeyrouz 08-26-2009 01:21 AM

It is an exe file that should be called from command prompt.

After you explode your jar file into the following folder for example:
com/test/MyClass.class

you type:
cd com
cd test
jad MyClass.class

You need to make sure that jad.exe is in your classpath or in the same folder.

Hope this helps

besides you can simply go the command prompt and type jad
and you will see a help how to use it

UrbanTwitch 08-26-2009 01:31 AM

But I have the .jar file. Inside it is a library of folders and iwant to edit Minecraft.class. How do i do that?

ckeyrouz 08-26-2009 01:36 AM

I already told you how.
Anyway

you type jar -xvf jarfile.jar (make sure you are in the same folder where the jar file is)

After that you search for your class in the hierarchy of folders and you into that folder and write:
jad Minecraft.class

You will have in the same folder now a file named: Minercraft.jad (simply rename it to Minercraft.java)

UrbanTwitch 08-26-2009 01:44 AM

I get:
-xvf is not a recognizable interneral or external command .. blah blah

I had jad.exe in the same folder as minecraft-server.jar... :S

ckeyrouz 08-26-2009 01:47 AM

the command is:
Code:

jar -xvf jarfile.jar
By the way I have two questions:
  1. Did you extract the files from the jar.
  2. Do you have jdk installed or only jre.

Another thing the command jar -xvf is to UNZIP the jar file.

Please post here the command you are using as is to see what's wrong in it.

UrbanTwitch 08-26-2009 01:48 AM

I have both jdk 6 and jre 6 installed.

I have the .jar file on my folder. I don't know what you mean, though..

mkay i just got some folders with classes in 'em. We're off to a good start.
How do I recompile them back to the .jar file

edit: dangit, i just tried editing a .class file and all i got was random symbols.

ckeyrouz 08-26-2009 04:10 AM

Code:

jar -cvf fileName.jar -C srcfolder/
if you type simply the word jar on the command prompt you will get this result ( a full help on the usage of the command jar)
Code:

Usage: jar {ctxui}[vfm0Me] [jar-file] [manifest-file] [entry-point] [-C dir] fil
es ...
Options:
    -c  create new archive
    -t  list table of contents for archive
    -x  extract named (or all) files from archive
    -u  update existing archive
    -v  generate verbose output on standard output
    -f  specify archive file name
    -m  include manifest information from specified manifest file
    -e  specify application entry point for stand-alone application
        bundled into an executable jar file
    -0  store only; use no ZIP compression
    -M  do not create a manifest file for the entries
    -i  generate index information for the specified jar files
    -C  change to the specified directory and include the following file
If any file is a directory then it is processed recursively.
The manifest file name, the archive file name and the entry point name are
specified in the same order as the 'm', 'f' and 'e' flags.

Example 1: to archive two class files into an archive called classes.jar:
      jar cvf classes.jar Foo.class Bar.class
Example 2: use an existing manifest file 'mymanifest' and archive all the
          files in the foo/ directory into 'classes.jar':
      jar cvfm classes.jar mymanifest -C foo/ .


UrbanTwitch 08-26-2009 04:12 AM

Right o. What's a good free .class editor?

ckeyrouz 08-26-2009 04:23 AM

Personally I use Eclipse Galileo, it is not only a java text editor but an IDE oriented software (project based) so I think it will be complex for you.

If you want something simpler try this one:
http://sourceforge.net/projects/eje/

It is built with Java I used to work on it a bit, but ideally Eclipse Galileo.

UrbanTwitch 08-26-2009 05:58 AM

I want to open .class files, not .java files. I tried opening .class files and I got:
http://i27.tinypic.com/n6febd.jpg

Help?

ckeyrouz 08-26-2009 06:30 AM

A class file is a compiled file so you cannot read its content.

By the way do you know java?
Sorry for asking that but the minimum thing to know is that a java file compiles to .class file then the JRE transforms it into machine language and this is the property of java that makes it platform independant.

ckeyrouz 08-26-2009 06:43 AM

I suggest that you start with this tutorial:

Code:

http://www.freejavaguide.com/corejava.htm


All times are GMT +1. The time now is 08:06 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.