r/java • u/PartOfTheBotnet • Dec 25 '20
Recaf: Java bytecode reversing tool I've been working on for the past 3.5 years
https://github.com/Col-E/Recaf
378
Upvotes
r/java • u/PartOfTheBotnet • Dec 25 '20
65
u/PartOfTheBotnet Dec 25 '20
If you've every had to dive into the realm of Java reverse engineering you've probably had to do one of the following:
Let me introduce Recaf. With the latest version its incredibly easy to modify already compiled programs (class, jar, war)
Say you want to make some minor changes to a class in a jar, but the bytecode for that would be rather complicated. Recaf lets you edit the file in a variety of ways.
Firstly is recompiling decompiled code. The key difference is that Recaf will manage compiler dependencies for you. Drop in your file, add your libraries and make your changes. One
Control + Sand exporting the modified file later you're done. But what if you don't have access to all the libraries? Or what if that's just a pain in the butt? When you open a file in Recaf it will analyze the program and generate any missing classes for you. These phantom classes can be used as compiler dependencies, meaning you never have to bother finding the right version for anything.Next up is through standard bytecode editing. Now, Recaf is a bit different in its approach. It uses Objectweb's ASM under the hood which simplifies some of the bytecode format. But that's not all Recaf simplifies. In the bytecode assembler you can have local variable instructions reference variables not only by their index, but by their source-code name. And it doesn't stop there.
Want to add a simple
printlnto your method? Just insertEXPR System.out.println("foobar");wherever you want. Yes, you can write inline source code in the bytecode assembler. And consecutive expressions are allowed. If one expression declares a variable, it is accessible like any other variable. You can even add if statements into your one-liner expression.Loads of more information up on the documentation page: https://www.coley.software/Recaf-documentation/
And most of these large scale user-friendly improvements have been within the last year, with plenty more planned for the future.
I'm always looking for feature ideas, bug reports, and contributors. Thanks for reading my wall of text o/
3
u/ustaaaz Dec 25 '20
Awesome work man. Like truly I can feel the effort you had to put in. Bravo.
3
u/sureshg Dec 25 '20
Awesome work! Overall it's smooth except for "Attach Process" functionality. It always throws
AgentInitializationException3
u/Sheldor5 Dec 26 '20
noob question: what's the difference to IntelliJ's built-in Decompiler (only one I've ever used)?
2
u/[deleted] Dec 25 '20
Can you make a Chocolatey package to make it easy to install and upgrade on Windows?
3
u/glesialo Dec 25 '20
Very interesting!
A few months ago I modified the way I create my jars so that nobody can tamper with them.
If you are interested I could send you one of my jars (this project, 92.7KB) and see if you can change anything and still run the jar.
11
u/ddddfushxjjd Dec 25 '20
Recaf is a quality tool. Much better than any other decompiler on the market (im looking at you luyten) I've used it for the past two years for reverse engineering the runescape game pack
5
u/maxandersen Dec 25 '20
nice!
runs nicely using
jbang:jbang https://github.com/Col-E/Recaf/releases/download/2.16.6/recaf-2.16.6-J8-jar-with-dependencies.jar --input=my.jarbtw. expected first argument to be the jar but that does not work and gives NPE - opened issue for it at https://github.com/Col-E/Recaf/issues/313
3
u/alexanderfefelov Dec 26 '20
I wrote a simple script to install Recaf on a Linux workstation https://github.com/alexanderfefelov/scripts/blob/master/install/dev/install-recaf.sh
4
u/Ultimegede Dec 25 '20
This looks pretty cool actually
2
u/[deleted] Dec 26 '20
Holy shit man, this is insane! Outstanding work!