is there a way to inject arbitrary code into a jar file? for example, given a jar file, the program would inject an init function in method m in class X that would check for certain conditions and exit if the condition is not met.
can this be done?
is there a way to inject arbitrary code into a jar file? for example,
Share
If the jar is signed – no**. If the jar is not signed – then yes, this is of course possible. From altering a method of a class to add or substitute a whole class.
The JAR file is actually a ZIP file containing class files – the binary representations of the source program consisting of the compiled byte-code, string and other literals, and other necessary information. These class files are having a format defined by the Java VM Specification. As any file may be read and treated somehow the class file also may be read altered and then written back.
As for determining what has to be changed/added/removed – it is of course the task for a human who want to change a behavior of the program and have enough skills to read JavaVM assembly language and/or reverse-engineered source code. There are a few java decompilers available that produces the java source that is usually hard to understand but still possible.
** If the fact that jar is tampered is not important, then one may remove the signature and still do a modifications