5 ms·
Snowman native code to C/C++ decompiler for x86/x86_64/ARM
- blueflow 5y agoIf we would write some code in rust, compile it to, for example, x86_64. And then de-compile it to C. It would be perfectly memory-safe C code, right?
- thargor90 5y agoI would guess that writing a decompiler that gets c semantics 100% correct is also really hard. Think about inline assembly, memory barriers, etc. I don't think this would work, unless the c file just contains inline assembly.
- vnorilo 5y agoSome architectural/program assumptions may not be encoded in assembly or preserved in the asm -> C -> asm roundtrip, especially if the assemblers are for different architectures. The obvious example is pointer word size and memory model.
- josephg 5y agoRust might work reasonably well though, given its compiled with llvm. If not, I'm sure whatever asm structures llvm outputs for rust all have C equivalents. I'd be curious to see the output! It'd be funny decompiling the rust compiler to C, then running it on another platform that way. (Though it would still be, for example, an x86 rust compiler running on arm).
- vnorilo 5y agoStrictly speaking all x86 MOVs would have to decompile to some level of atomic load/stores, because of the ordering guarantees on x86. That's an example of "lost in translation" as we don't know if the original source required ordering or not. x86 cannot express the weakest memory model supported by C.
- pjc50 5y agoYes, but it wouldn't necessarily be readable. And it definitely wouldn't be portable!
- tym0 5y agoIsn't Mozilla doing that? Rust to WASM to C. Edit: Sorry I misremembered, they seem to compile C/C++ code to WASM then back to C: https://hacks.mozilla.org/2021/12/webassembly-and-back-again-fine-grained-sandboxing-in-firefox-95/ https://hacks.mozilla.org/2021/12/webassembly-and-back-again... Although technically the plugins could be written in Rust.
- eatonphil 5y agoLink?
- astrange 5y agoIt wouldn't look much like what you'd expect C to look like. If it did decompile back to idiomatic C it could introduce some kind of aliasing bug along the way that'd make it not so memory safe.
- speed_spread 5y agoThe simpler way to obtain C from Rust would be to use mrustc https://github.com/thepowersgang/mrustc https://github.com/thepowersgang/mrustc Not that the C will be much more readable than the dissassembly, but there's a chance less information will be lost.
- shin_lao 5y agoNothing is perfectly memory-safe. Also, not sure I would see the point of this translation?
- MaxBarraclough 5y ago> Nothing is perfectly memory-safe. How about formally verified SPARK code?
- astrange 5y agoIt’s strange that people think if they put the word “formal” in front of something it means it’ll work perfectly.
- MaxBarraclough 5y agoThe guidelines ask that you Please don't post shallow dismissals. Are you aware of the scope of SPARK's assurances? You can't accidentally dereference a NULL pointer in verified SPARK code, for instance.
- astrange 5y agoYes, but that's a quality of SPARK, not of the category of "formal methods" by default. For instance, if you write your own proof and then prove the program meets it, there could still be a logic error in your proof. Also, "in verified code" is a big loophole enough to leave security issues in - for instance a web browser (probably the thing you'd most like to prove security-issue-free) can still overwrite its own memory through things like OS image and font code, JavaScript JITs generating code to an insecure ABI you don't have a model for, syscalls to kernel code that can write back into your memory, etc. Believing "formal" makes things magically correct does seem to be a common problem; it also comes up when people say something has a "formal audit" or needs to get one from someone. How do they "formally" audit it? Are they wearing suits?
- 5y ago
- kalnins 5y agoAs Rust is llvm based, you don't need to compile it to C. Just write a backend that translates LLVM IR to C instead of x86_64. The IR is very C looking, it's probably overly complex. Compiling down to asm, lot of information is lost regarding memory layout etc, so it's not the best source for generating code.
- AlexDenisov 5y agoHere is a talk by Dr. Yegor Derevenets about this project https://www.youtube.com/watch?v=f_0EF2BqeQ4 https://www.youtube.com/watch?v=f_0EF2BqeQ4
- secondcoming 5y agoThe main website seems to be dead, and there are no examples of its output.
- orra 5y agoA shame. My understanding is this was state of the art, for a free and open source decompiler. Of course, times change and AFAICT Ghidra has taken up that mantle.
- taviso 5y agoI'm surprised to hear that, I thought retdec was pretty well regarded.
- orra 5y agoGood point. I don't mean this as a slight against retdec. Simply, retdec was proprietary for quite a while, and it escaped my mind. retdec haven't tagged (or built) a release in a couple years, unfortunately, but there is recent activity on their repo.
- mdaniel 5y agohttps://web.archive.org/web/20220207001349/https://derevenets.com/examples.html https://web.archive.org/web/20220207001349/https://derevenet...
- marcelluscat 5y agoas someone who's used snowman for ctfs, here's my recommendation for it.
- orko223 5y ago
- kubb 5y agoHow about this for an idea: a decompiler that uses Machine Learning to name the decompiled variables and functions. Would be nice even if it worked only sometimes.
- planede 5y agoIt's also something that could be somewhat easy to get a lot of learning material for.
- efferifick 5y agoYes, but the problem is learning through the graph data. I.e., it is not a well-structured problem like an image which will always have a certain size in pixels. Coming from a compiler background I am genuinely excited about the research on learning how to label nodes and edges in graphs, but I know little about the challenges in the ML side to bring this kind of technology into reality.
- kuroguro 5y agoFor an AI-less solution there is IDA's Lumina which works pretty well. There's also a reverse engineered server for it [0] so you could build plugins for other disasemblers/decompilers to use with non-official servers. It basically hashes machine code (with address parts removed) [1], then when reverse engineers label and push symbols to the server (or get them from some debug build), others can pull and see what the functions are called in completely unrelated projects, that use the same libraries / have the same functions. [0] https://abda.nl/lumen/ https://abda.nl/lumen/ [1] https://github.com/naim94a/lumen/issues/2 https://github.com/naim94a/lumen/issues/2
- efferifick 5y agoSomething very similar: a "decompiler" that decompiles minified javascript and guesses variables and functions: http://www.jsnice.org/ http://www.jsnice.org/
- glouwbug 5y agoIt's certainly possible - Compile all the C projects on github with `gcc -O0`. Map statements, blocks, or functions to ASM output. Put everything in a giant SQL. Repeat for all of gcc's compiler flags. Wait, did I say it was possible? I'm curious what a neural netted compiler would produce. Probably your average CRUD software.
- orko223 5y ago
- xphos 5y agoCritic for the author have picture of you decompile so people can feel it out and judge the quality. I wanted to check it out but I was on my phone so I can quite build and run the repo
- richardfey 5y agoA few months ago I was looking for a 16bit equivalent. Unfortunately I couldn't find a snowman for Win3.1!