PDA

View Full Version : Editing an application with .jar extension




dbconfession
May 2, 2013, 11:23 PM
I have an application that was custom built for me and I need to get into it to make some changes. The file extension is .jar. I know that .jar files are just archive files, but this is the file I launch to run the program. It doesn't actually unarchive anything (afaik) but is the pplication file itself.

Normally I could right click and "show package contents" for most apps, but since this is a .jar file that's not an option.

Any ideas on how to get at the code?



ArtOfWarfare
May 2, 2013, 11:28 PM
A .jar file is already compiled. If you were able to edit it, you'd see java byte code, which isn't practical to edit by hand.

When you open a .app file, the code within it is also already compiled (albeit machine code), which also isn't practical to edit by hand.

You probably can't get from a .jar back to the original .java any more than you could get back to the original .c/.m/.cpp/.mm of a .app.

jhiesey
May 2, 2013, 11:59 PM
ArtOfWarfare is exactly right. All of the code in a .jar is compiled into .class files, which aren't editable by hand.

That being said, if you really just want to be able to look inside like you can with a .app bundle, you can rename a .jar file to .zip and double-click it to extract the contents. Unfortunately this doesn't really get you what you want.

lee1210
May 3, 2013, 12:57 AM
Bytecode, unless specifically obfuscated with something like proguard, is more easily decompiled than many other languages, at least in my experience.

I've had pretty good luck going from Android .apk files, unzipped to a classes.dex, to a jar with .class files with dex2jar, to java source code with jad. It's not perfect, but it's workable.

You'd need to "unjar" the archive with:
jar -xvf yourJar.jar

Then you'd target the .class file (if you knew which class you wanted) with JAD or another Java decompiler. Then you'd have a .java file in similar format as the original code, but likely a bit worse for the wear. You'd edit this, recompile the file with javac (getting a new .class file). Then you'd need to jar everything back up with something like:
jar -cvf yourJar2.jar <your files here>

Basically, it's possible. I've had better luck decompiling Java compared to, say, decompiling C.

It's also not impossible to manually edit Java bytecode, it's just difficult. It's certainly easier to edit than straight machine code. Occasionally a word appears instead of just raw bytes.

-Lee