Live data from Hacker News

Show HN: I wrote a Java decompiler in pure C language

github.com

91–100 of 104 posts

Re: Show HN: I wrote a Java decompiler in pure C language

#91
post #27

I 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/72357ddbcffdb75641... ) Somet…

> I am always curious how different C programs decide how to manage memory.

At a basic level, you can create memory on the stack or on the heap. Obviously I will focus on the heap as that is dynamically allocating memory of a certain size.

The C programming language does not force you how to handle memory. You are pretty much on your own. For some C programmers (and likely more inexperienced ones) they will malloc individual variables like they are creating a 'new' instance in a typical OOP language like Java. This can be a telltale sign of a programmer working with C that comes from an OOP background. As they learn and improve on their C skills they realise they should create a chunk of memory of a certain type, but could still be malloc(ing) and free(ing) all over the code, making it difficult to understand what is being used and where -- especially if you are looking at code you did not write.

You can also have programs that do not bother free(ing) memory. For example, a simple shell program that just does simple input->process->output and terminates. For these types of programs, just let the OS deal with freeing the memory.

Good C code (in my opinion) uses malloc and free in only a handful of functions. There are higher level functions for proper Allocators. One example is an Arena Allocator. Then if you want a function which may require dynamic memory, you can tell it which allocator to use. It gives you control, generally speaking. You can create a simple string library or builder with an allocator.

Of course an Allocator does not have to use memory on the heap. It can still use on the stack as well.

There are various other patterns to use in the world of memory, especially in C.

Re: Show HN: I wrote a Java decompiler in pure C language

#92
post #62
post #60

Earlier quoted context omitted.

We need people who can (and do) write in C, assembly, and all these low-level languages. Otherwise, software will just get slower and slower.

Rust has the same low-level memory model as C without the footguns.

I love Rust but we really got to stop the link between C and Rust.

If someone mentions C, that's not a free invite to start educating them on why they SHOULD use Rust. No one at the party is going to talk to you again that night

Re: Show HN: I wrote a Java decompiler in pure C language

#93

I 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?

When debugging complex projects, the C language is more flexible and convenient to view data in memory.

Re: Show HN: I wrote a Java decompiler in pure C language

#94
post #71

I 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/... 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/…

https://github.com/Vineflower/vineflower

cool, TIL!

> Examples of Vineflower's output, compared to other decompilers, can be found on the wiki.

[wiki is empty]

:-/

Re: Show HN: I wrote a Java decompiler in pure C language

#95

I 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?

This is the best question for me. Writing these codes in C language is the best way to learn the file structure of jvm/dalvik/pe. This process makes me like C language more. For me, I think it is simple and pure, which is enough.

Re: Show HN: I wrote a Java decompiler in pure C language

#96

Earlier quoted context omitted.

I'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?

By 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…

Why is it silly?

Re: Show HN: I wrote a Java decompiler in pure C language

#97

I 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?

It's thanks to people like you that rust is not more widely used, you actively make people avoid the rust cummunity because they will think everybody i like you!

Re: Show HN: I wrote a Java decompiler in pure C language

#98
post #62

Earlier quoted context omitted.

Rust has the same low-level memory model as C without the footguns.

Rust certainly does have some improvements, but I'm not 100% certain that it's the best tool for all low-level software. For example, I'm experimenting with Rust for some filesystem type code and I can't figure out how to write/read a struct to/from disk all at once. I'm brand new to Rust, so it's quite possible that it can be done and I just don't know the technique. Basically, I'm looking for something in Rust anal…

This is generally unsafe, so to make it safe there needs to be something that restricts what kind of things you can read and write.

For example, if your structure contains a reference, and you read an instance of that from disk, then you now have a potentially invalid reference, bypassing Rust's guarantees. Reading a structure of i32 numbers is safe, but it also has endianness footguns.

The zerocopy crate implements traits and gives you a derive macro to mark types as being safe to serialize/deserialize in a safe way.

Re: Show HN: I wrote a Java decompiler in pure C language

#99
post #42

Earlier quoted context omitted.

Not 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.

The most feature advanced decompiler I know of is Recaf. It supports a mix of decompilers and even bytecode editing.

This looks excellent. I'll be sure to try it out. Thanks!

Re: Show HN: I wrote a Java decompiler in pure C language

#100
post #73
post #70

Earlier quoted context omitted.

You cannot have use-after-free if you never call free, so there are no points at which memory should not be touched. That's the beauty of the never free memory management strategy.

It can still be a bug if you use something after you would have freed it because your code isn't meant to be using that object any more. It points to errors in the logic.

Agreed. I think being methodical is better here for sure.
Post reply on HN