Jawa is a rainy-day project to support inspecting, modifying, and creating JVM bytecode from Python. It’s a successor to an earlier project from 2010 which was used to magically parse new versions of Minecraft and find new network packets, entities, sounds, etc. It did this by looking for patterns in the bytecode and reconstructing higher-level objects based on what it found.
These days, there are popular new tools like Krakatau for producing human-readable output, but this kind of project isn’t always the best option when you actually react on the results.
Jawa can construct brand new ClassFiles from scratch - lets try the classic “Hello World!” example:
Now lets give it a try:
» java HelloWorld
Success! Just like that, we’ve assembled a Class that the JVM will happily run. You can compare this to the Jasmin “Hello World!” example, the defacto standard for JVM assembly syntax. Both examples are equally compact and concise. We accomplish this by using the assemble() helper which provides support for psuedo-assembly (including named labels and branches), generating a stream of Instruction and Operand objects. This is what it would look like without that helper:
This is extremely precise and will always result in bytecode exactly as provided (even when it’s wrong), but you would quickly go insane doing this by hand so it’s recommended to always use the assemble() helper.
We can also easily modify existing classes. Lets take our Hello World! example from the last section and turn it into a Hello Mars! example.
Lets give our newly modified class a try:
» java HelloMars
As a very basic example, lets make a grep tool. This version will only check the value of strings and will let us filter on a pattern.
Lets use our new tool to find possible links buried inside the Minecraft JARs: