Filed under: Technology and Software
Reverse Engineering is some thing which i really wanted to do. It was just out of curiousity i tried it some time back when i was in my UG. Now it was a requirement for my project so i had to reverse Engineer a code ie convert the .class file to .java file.
I used Mocha written by Hanpeter van Vliet , One of the most used tool ,to reverse Engineer in Java. It has around 200+ classes in a .zip file. There is no need to unzip the “mocha.zip” file contained in the distribution zip file; Java knows how to get .class files out of zip files. Simply put “mocha.zip” in a safe place, for instance the JDK directory. Add the full pathname of “mocha.zip” to your CLASSPATH string, for instance:
SET CLASSPATH=c:\myclasses;c:\jdk\mocha.zip
Now the next question would be to invoke it.
Mocha is invoked from the commandline like this:
java mocha.Decompiler [-v] [-o] Class1.class Class2.class …
Where
“java” invokes the Java virtual machine,
“mocha.Decompiler” (note the case!) specifies the class to run,
“-v” optionally specifies verbose output,
“-o” optionally overwrites existing .mocha files,
“ClassX.class” specifies the .class file(s) to decompile.
Wildcards (* and ?) are accepted.
Cool you just did a great Job of converting a compiled .class file back to your .java file
cheers!!
Filed under: Uncategorized
Well, its quite unlike that you want to convert your Java App to Native Code, because of its Platform Independence. But when an application is targetted to one particular platform probably we can convert to the native Code, that improves the speed of your app.
Now the next Question would be .. How to Convert it?
Here is a code which converts to the Native Code…
—————————————————————————
//The #include directive treats
//text in the file specified by
//filename as if it appeared in the
//current file.
#include
#include
#include
//The #define directive defines a macro.
#define MAIN_CLASS “MyFrame.jar”
int main()
{
//malloc() allocates a block of size
//bytes from the memory heap.
char* cmdline = (char*)malloc(1024 );
//sends formatted output to a string
sprintf( cmdline, “javaw.exe -jar %s”, MAIN_CLASS );
//system() invokes the
//DOS command interpreter
system( cmdline );
//deallocate the memory
//block.
free (cmdline);
return 0;
}
————————————————————————


