0

There is a web application, that is being ran on Windows, inside a Tomcat browser. Application users number of .jar files as a storage for it's logic.

When I open a jar file, that I need to alter a logic of, I see a bunch of .class files. (Java compiled classes, I assume). When I try to open .class file in a text editor, I see a semi-readable gibberish.

When I feed this compiled .class to a service like showmycode.com, I can see the actual java code. At this point I alter the code according to my need and want to put the updated .class file for application to use (put it back inside a jar).

Is it mandatory that I compile the .class file to a "semi-readable gibberish", or I can put it there as a source code file (probably not, but thought I would ask just in case). If I have to compile the atered code, can I do it without bringing up a project in some Java IDE, and just compile it into .class via command line or something?

Maxim V. Pavlov
  • 10,303
  • 17
  • 74
  • 174
  • 1
    Why are you performing decompiling-editing-recompiling cycles to begin with? You should never have to do that. Simply work on the original, documented, un-obfuscated source code and when your code is ready compile it. That way you always have readable, documented code. – Benjamin Gruenbaum Nov 08 '14 at 12:44
  • Seeing your background is in C# - what you're doing is akin to decompiling .NET DLLs/EXEs, editing the code and then recompiling them. It doesn't make very much sense as a workflow. If you _have_ to decompile a file - do it _once_, then document it, make sense of it and _always use the source_ from that point on. – Benjamin Gruenbaum Nov 08 '14 at 12:46
  • I am altering an app that I don't have access to the sources of. – Maxim V. Pavlov Nov 08 '14 at 13:01
  • It's still better to use reflection to do that in most cases. – Benjamin Gruenbaum Nov 08 '14 at 13:11
  • I don't understand how seeing sources (reflection in .Net) will help me alter the logic of the .jar file. – Maxim V. Pavlov Nov 08 '14 at 14:55

1 Answers1

0

There are two main methods for editing an application you don't have the source for.

The first one, as you've discovered is decompile, edit, recompile. The advantage is that you don't have to know anything about bytecode since it's just decompiled to Java. The main disadvantage is that even the best decompilers can't guarantee producing recompileable code. And if the application has been obfuscated at all, you can forget about recompilation.

The alternative is disassemble, edit, reassemble. I'd recommend Krakatau for this (disclosure, I wrote it). One alternative is ASM, but it's designed for programatic modification, not hand editing, and it's clunkier.

The main advantage of bytecode editing is that it always works, even if the application has been obfuscated. The downside is that it obviously requires you to understand and be able to program directly in bytecode.

Antimony
  • 37,781
  • 10
  • 100
  • 107