Editing an application with .jar extension

Discussion in 'Mac Programming' started by dbconfession, May 2, 2013.

  1. dbconfession macrumors newbie

    May 4, 2006
    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?
  2. ArtOfWarfare macrumors G3


    Nov 26, 2007
    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.
  3. jhiesey macrumors newbie

    Mar 6, 2013
    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.
  4. lee1210 macrumors 68040


    Jan 10, 2005
    Dallas, TX
    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.


Share This Page