Is there a way to write code (make binaries) such that it would be extremely difficult to recover the source code via decompilers or a disassembler?
Is there a way to write code (make binaries) such that it would be extremely difficult to recover the source code via decompilers or a disassembler?
To protect it beyond a basic level - You can try but it's a cat-and-mouse game. A sufficiently skilled reverser will drop a debugger on your program, execute the code until it's past any decryption and then dump it from memory. So better schemes to obfuscate applications have been developed, like VMProtect, which makes a simple virtual machine with a custom instruction set and uses it to obfuscate your application. It's of course possible to break that as well, but it takes more time and requires more skill.
When writing in a higher language such as e.g. C, you can use code obfuscators to make your C code extremely hard to read.
If you want to make decompiling even impossible, you could modify the machine code generated by the C compiler. Even slight moderations are already enough.
If you want to make it (virtually) impossible to even disassemble the machine code, you could encrypt your binary itself except for a small bootstrap that will unencrypt the remainder of the binary when it runs.
Obfuscating C code shouldn't have any bearing on the decompilability of the output.
> If you want to make it (virtually) impossible to even disassemble the machine code, you could encrypt your binary itself except for a small bootstrap that will unencrypt the remainder of the binary when it runs.
Unencrypting the binary at startup is somewhat easy to hook into. It's harder to decrypt each individual function when that function is called and then re-encrypt it after the function ends. Bonus points if you re-encrypt after each `CALL`.
This is stuff which was available back in 2003 -- that's when I first used techniques.
It was available already in the 1980's, so I learned at the time when I was manually disassembling computer games hoping to be able to crack them.
This is the entire point of obfuscation and it absolutely does affect how easy the code is to reverse engineer. If it didn’t, there wouldn’t be a market for obfuscators.