6 ms·
Show HN: I wrote a Java decompiler in pure C language
- cosmolev 1y agoHow does the output compare to https://www.decompiler.com/ https://www.decompiler.com/ in terms of correctness?
- appendixv3 1y agoVery cool project! Love the idea of a Java decompiler written in C — the speed must be great. Any plan to support `.dex` in the future? Also curious how you handle inner classes inside JARs.
- tslater2006 1y agoThe readme shows support for dumping dex files. Edit: missed that it has a comment that stays "unsupport for now" but at least it looks like something planned
- deleted 1y ago[deleted]
- mdaniel 1y agoThe "jikes" compiler from IBM <https://github.com/daveshields/jikespg https://github.com/daveshields/jikespg> was written in C++ and was for the longest time screaming fast. It also had its own parser generator lpg which was fun to play with, if you're into those things <https://github.com/daveshields/jikespg https://github.com/daveshields/jikespg> It seems someone liked it and made a "v2" along with LSP support https://github.com/A-LPG/LPG2#lpg2 https://github.com/A-LPG/LPG2#lpg2
- amiga386 1y agoJikes also gave massively better error messages than the official Java compiler, from what I remember, and it certainly ran a lot faster on the Amiga (https://aminet.net/package/dev/lang/jikes https://aminet.net/package/dev/lang/jikes) than trying to run javac via Kaffe (https://en.wikipedia.org/wiki/Kaffe https://en.wikipedia.org/wiki/Kaffe) did.
- pjmlp 1y agoCertainly not everything on Jikes, given that it was one of the first bootstraped Java toolchains. https://www.jikesrvm.org/ https://www.jikesrvm.org/
- neocanable 1y agoI am writing the part of decompiling dex and apk. The current speed is about 10 times faster than that of Java, and it takes up less resources than Java. And the compiled binary is smaller, only about 300k. Thank you for your attention.
- mdaniel 1y agoThis has been my life experience with things written in C/C++, so speed doesn't matter. Or, I guess from an alternative perspective, it ran very fast, but exited very fast, too :-D $ ./objdir/garlic $the_jar_file -o out-dir -t $(nproc) Progress : 85 (1024)Segmentation fault: 11
- neocanable 1y agoSorry for giving you a bad experience. Please provide the jar file or class file. I hope I can fix it as soon as possible.
- uecker 1y agoIs it? This is my experience with Python. The C/C++ programs I use daily never seem to crash (Linux, bash, terminals, X, firefox, vim, etc.). It must be years ago one of those programs crashed while I used it.
- 1718627440 1y agoAlso a segfault IS the protection layer intervening, it is equivalent to a exception in other languages. The real problem is, when there is no segfault.
- uecker 1y agoThis is absolutely true. But even this does not happen in the software I use every day. Software written is C is definitely the most stable I use - by far. That there are people running around claiming that it is impossible to write stable software in C and it crashes all the time due to bugs is rather unfortunate, as it is far from the truth.
- neocanable 1y agoIt is processes inner classes recursively. First read all entry from jar, and analyze the relationships between classes. Then do some decompile job.
- neocanable 1y agothe project support dex and apk now.
- keepamovin 1y agoBy hand or with AI? Fascinating. So much work! What was your motivation for this?
- xandrius 1y agoIrrelevant to me. People would never ask whether someone has created something looking at SO or not. If the thing works as advertised, good for them!
- lyxell 1y agoTo some people the process leading to a finished project is the most interesting thing about posts like these.
- johnisgood 1y agoLLMs can explain the process, and you can build projects with LLMs explaining the process.
- shortrounddev2 1y agoLLM output is simply not interesting
- johnisgood 1y agoI did not say that you should copy paste its output verbatim. I thought this was obvious. Additionally, "interesting" is highly subjective. It could be technically correct, yet uninteresting.
- nticompass 1y agoLLMs can attempt to explain the code, but it can't explain people's thought process and that's the interesting part. I want to hear about the reverse engineering, how you thought the code through. LLMs are boring.
- yusina 1y ago[flagged]
- bongodongobob 1y ago[flagged]
- deleted 1y ago[deleted]
- deleted 1y ago[deleted]
- stefanos82 1y agoNice job! I don't know whether you know https://github.com/java-decompiler/jd-gui https://github.com/java-decompiler/jd-gui or not, but in case you haven't seen it before, maybe you could use it as a reference, since it's written in Java, for extra fun with your adventure?
- rafram 1y agoThings may have changed, but my impression as of several years ago was that JD-GUI was far, far behind the state of the art (Fernflower, aka the built-in IntelliJ decompiler) in terms of correctness, re-sugaring, support for modern Java features, and so on. Fernflower is open source as part of IntelliJ: https://github.com/fesh0r/fernflower https://github.com/fesh0r/fernflower
- pinoy420 1y ago[dead]
- GranPC 1y agoIs there a good GUI for this a la jadx-gui that isn't an entire IDE?
- rafram 1y agoNot that I know of. The features I'd want in order to consider a decompiler GUI "good" (e.g. a good text editing control, go-to-definition, find usages, manual renaming of obfuscated symbol names) quickly approach the scope of an entire IDE, though.
- DefineOutside 1y agoThe most feature advanced decompiler I know of is Recaf. It supports a mix of decompilers and even bytecode editing.
- GranPC 1y ago
- gibibit 1y agoI am always curious how different C programs decide how to manage memory. In this case there are is a custom string library. Functions returned owned heap-allocated strings. However, I think there's a problem where static strings are used interchangably with heap-allocated strings, such as in the function `string class_simple_name(string full)` ( https://github.com/neocanable/garlic/blob/72357ddbcffdb756416dd2fc1481f8c22be1c2c5/src/decompiler/klass.c#L202 https://github.com/neocanable/garlic/blob/72357ddbcffdb75641... ) Sometimes it returns a static string like `g_str_int` and sometimes a newly heap-allocated string, such as returned by `class_type_array_name(g_str_int, depth)`. Callers have no way to properly release the memory allocated by this function.
- neocanable 1y agoIn multi-threaded mode, each thread will create a separate memory pool. If in single-threaded mode, a global memory pool is used. You can refer to https://github.com/neocanable/garlic/blob/72357ddbcffdb756416dd2fc1481f8c22be1c2c5/src/libs/memory/mem_pool.c https://github.com/neocanable/garlic/blob/72357ddbcffdb75641.... The x_alloc and x_alloc_in in it indicate where the memory is allocated. When each task ends, the memory allocated in the memory pool is released, and the cycle repeats.
- IshKebab 1y agoInteresting. Someone should come up with a language that prevents these sorts of mistakes!
- brabel 1y agoThat’s impossible. Just be more careful and everything should work, the author’s C was just a bit rusty!
- neocanable 1y agoThis project is my first project written in C language. Before this, my C language level was only at printf("hello world"). I am very happy because this project made me dare to use secondary pointers.
- kamma4434 1y agoI cannot help but wonder why starting a new project in C in 2025. It’s like driving a car with no seat belts. You sure you want to do that?
- zzo38computer 1y agoIn my experience, although many of the other programming languages do improve some things compared with C, they also make many things worse and avoid some of the benefits of C programming.
- pjmlp 1y agoI can't recall anything in that sense regarding Modula-2 and Object Pascal, other than not bringing UNIX to the party.
- ronsor 1y agoYes, yes I'm sure. I like using C sometimes.
- sim7c00 1y agoi only write in C. if id build a car it wouldnt have seatbelts. boring, put in ejector seats! not safe? no problem for C :).
- SunlitCat 1y agoejector seats in C car? goto eject; ...more code we are going to ignore, it could be important but nah, ignore it, what could be happen?... eject: up_through_the_roof(); :D
- uecker 1y agoI moved from C++ to C and I am more productive. I also think this "no seat belts" meme is exaggerated, as there are plenty of tools and strategies to make C fairly safe to use. (it is true though that many people do not put the seat belts on).
- 1y ago
- ConanRus 1y agoCan you also write a C decompiler in pure Java language?
- dardeaup 1y agoOf course it can be done! It wouldn't be as general purpose as the Java decompiler in C because the C decompiler would have to know about the CPU architecture of the executable code (just as the Java decompiler has to know about JVM opcodes).
- mdaniel 1y agohttps://github.com/NationalSecurityAgency/ghidra/blob/Ghidra_11.3.2_build/Ghidra/Processors/x86/src/main/java/ghidra/app/plugin/core/analysis/X86Analyzer.java https://github.com/NationalSecurityAgency/ghidra/blob/Ghidra... (Apache 2)
- kazinator 1y agoYou've used GPL2 code taken from git (hashmap.c) in your Apache 2.0 project. https://opensource.stackexchange.com/questions/10737/inclusion-of-gpl-2-0-code-into-my-apache-2-0-program https://opensource.stackexchange.com/questions/10737/inclusi...
- issafram 1y agoI'm curious, how did you notice this? Do you have a scanner that checks these sorts of things or is it something that you are passionate about?
- trealira 1y agoI'm not them, but it does straight up say in hashmap.c that the code was copied from https://github.com/git/git/blob/master/hashmap.c https://github.com/git/git/blob/master/hashmap.c, which is under the GPL license.
- issafram 1y agoYea I saw that after looking it up. I wasn't questioning the statement, but me personally I wouldn't look at each file and look for license violations. That's all.
- kazinator 1y agoBy the following very short garden path: 1. How silly to write such a thing in C from scratch. Such a project will invariably invent half of Lisp in order to have the right kind of infrastructure for doing this and that. 2. Let's look for some of it up and down the tree. Oh look, there is a bitset and hashmap, see? I don't see test cases for these anywhere; is it original work from this project or battle-tested code taken from elsewhere? 3. Open hashmap.c ... GPL violation found in half a minute.
- issafram 1y agoYea I'm not criticizing you. Was just genuinely curious. Thanks
- jbellis 1y agoI don't think it's available in a standalone repo but it IS available as a standalone library, IntelliJ's FernFlower decompiler is the gold standard https://github.com/JetBrains/intellij-community/blob/master/plugins/java-decompiler/engine/src/org/jetbrains/java/decompiler/main/Fernflower.java https://github.com/JetBrains/intellij-community/blob/master/... https://www.jetbrains.com/intellij-repository/releases https://www.jetbrains.com/intellij-repository/releases I guess there's some history there that I'm not familiar with because JBoss also has a FernFlower decompiler library https://mvnrepository.com/artifact/org.jboss.windup.decompiler/decompiler-fernflower https://mvnrepository.com/artifact/org.jboss.windup.decompil...
- neocanable 1y agoThe decompiler support android apk and dex now