r/C_Programming • • Sep 02 '26

Protecting source code from reverse engineering

Hi everyone,
I am looking to provide a compiled version of our physics solver to our customers. I understand there are many obfuscation techniques to protect source code but I am wondering if there are some smarter ways?

We already cloud computing, the issue is we have customers that are in locations without internet/need realtime solving.

0 Upvotes

36 comments sorted by

55

u/apnorton Sep 02 '26

Like the advice that was given to you over in r/rust, for a B2B piece of software, the way you can protect against reverse engineering is by creating a contract with strong legal penalties for reverse-engineering your software.

Technical means of reverse engineering prevention is a band-aid fix at this time; outside of significant advances in homomorphic encryption schemes (to bring it to a reasonable speed) and having your code execute within a secure enclave, your adversary has the advantage.

14

u/DamienTheUnbeliever Sep 02 '26

The engineering effort you expend in trying to protect your code produces *zero* value that your paying customers care about. Try to bear that in mind.

And also bear in mind that the *entire games industry* couldn't solve piracy without introducing an always-connected model where some of the IP stays on machines they own. So ask yourself why you think you'll be able to solve a problem they could not?

1

u/ConsciousBath5203 Sep 02 '26

And keep in mind, people do far more and are far more passionate about their pixel elf simulators than they are about something that is used for business.

If someone wanted to recreate the physics sim themselves, it would actually be easier to look up the formulas online and build their own from scratch.

20

u/siliconlore Sep 02 '26

Find another way. A smart dedicated reverse engineer will eventually crack whatever scheme you come up with. You would need to embed your code in a cryptographically secure hardware module with some kind of access key where the only thing the module outputs is solution data.

14

u/sol_hsa Sep 02 '26

That sounds like a contract issue, not a technical one.

6

u/xtopspeed Sep 02 '26 edited Sep 02 '26

I used to work for a somewhat large corporation back in the day that, e.g., manufactures cell phones, and their gist was always that it's more trouble than it's worth and that source code isn’t all that valuable, anyway. Time is much better spent improving the codebase than trying to protect what is already written.

1

u/realdreamer1993 Sep 07 '26

is there any big name software(non free) that not using cloud protection ? MS Windows are crackable..

1

u/realdreamer1993 Sep 07 '26

"spent improving the codebase" actually tend to agree with this, if code base is small and already finished then maybe the program is trivia. if program is big and involving many domain then it very difficult to crack. e.g Mikrotik, Cisco, Juniper etc..

5

u/stjarnalux Sep 02 '26

There's always somebody (me, lol) that can, worst case, even without any readable source, dump the asm out of memory and largely figure out what's going on, especially if you already have some clue what it's supposed to do. I spent years of my career dealing with secretive recalcitrant Big Networking vendors who would send us obfuscated code for performance analysis and fundamentally it hid nothing. It's non-trivial, but people who specialize in this are usually quite skilled.

4

u/GameskoTV Sep 02 '26

Not possible

1

u/realdreamer1993 Sep 07 '26

Example: MS Windows ?

2

u/eteran Sep 02 '26

My job used to be reverse engineering and gotta be honest. There's nothing that you can do that will be 100% effective.

Especially in the age of AI, things are much more accelerated.

Go the legal enforcement route if this actually matters to you.

3

u/ReallyEvilRob Sep 02 '26

If someone already has the source code, there isn't anything to reverse engineer. If you want to protect it, then don't release it.

1

u/realdreamer1993 Sep 07 '26

I think the OP will not share the source code. For reverse engineering, the object would be the binary.

1

u/ReallyEvilRob Sep 07 '26

That would make sense, but the OP's title specifically asks about protecting the source code and not the compiled binary.

2

u/flyingron Sep 02 '26

The first step is always to remove any symbol information from your distributed materials. If this involves a linkable library, you'll have to avail yourself possibly of some platform specific tools. It might be sufficient to just declare everything but the interfaces you want to expose static, though there's no guarantees (nor is it guarantee to be possible).

As for general disassembly, that's harder (especially with more modern tools) to stop. While they may not get your actual "source" code, they will see your algorithms. You can try to confuse things by wasting time doing steps unrelated to the problem being solved, but that has its own slew of problems (notably the lack of efficiency).

Obfuscation is more of a thing for stuff like the CLR (.NET) stuff that preserves a lot of the source information in the intermediate code.

Some programs (notably embedded stuff) store the program encrypted and decrypt on the fly, but again this is fraught with efficiency and other perils. On most sane general platforms, you can't execute into code you could write as data.

1

u/musbur Sep 04 '26

If this is a B2B situation, you might as well give the entire source code to your customer. The reason they're buying your product is that you deliver good value at a good price. As long as you keep providing that, they have no incentive to spend resources of their own to work on your code. I work in a large company that buys bespoke software from contractors, and nobody would ever look at a single line of code even if they could. There's no business case.

1

u/limitless_grow Sep 17 '26

In the end you can't only make it more expensive to understand what the binary does.

Once you are stripping the debug information than most of the code is gone, but the binary still does, what the code says and still contains all constants and all of that can be figured out. However you can make right that a little bit harder.

You could replace all string functions und common standard library functions using your own wrappers, prepend allocated memory with additional junk, remove 3rd party libraries because the interfaces may tell what your code does, remove logging and error messages from release versions, call invalid functions if there are huge time delays during the initialization because your program is debugged aso.

A total protection is impossible because your program has always to do what it should do but you can make the reverse engineering several times harder and much more expensive than rewriting your software. That way it becomes unattractive for others. However, if the calculations of the program itself are a total secret than you should execute those remote in a protected system that nobody else but you has physical access to.

1

u/ThatIsATastyBurger12 Sep 02 '26

Licenses and legal action are your best bet. Nothing is foolproof. But realistically, is this an actual problem you have? Do you have any reason to believe that your customers are decompiling and redistributing your solver, or doing anything to infringe on your intellectual property in any way? Even if they are reverse engineering your solver for their own benefit, they still probably rely on you for support and updates. There aren’t that many people who are good at reverse engineering assembly code AND understanding commercial physics solvers.

1

u/Drach88 Sep 02 '26

Especially in the age of AI, reverse engineering a compiled binary is not very difficult. Even with obfuscation methods, if someone wants to reverse engineer your methodology, they will.

I used to have to reverse-engineer minified and mangled JavaScript for work, and I have experience reverse-engineering malware. To someone with a bit of experience, getting around obfuscation techniques are just a matter of applying the skills and domain knowledge they are already well versed in.

0

u/runningOverA Sep 02 '26

I was planning to say that those assembly reverse engineers have grown gray beards and most are dead. So don't worry. The few that are still alive don't have time for this.

Then realized, AI has replaced them and they are better than ever.

2

u/ConsciousBath5203 Sep 02 '26

I don't think you realize just how popular (or profitable) cheating in video games is... Or that the NSA distributes reverse engineering software that makes the whole process really easy, especially once you start figuring stuff out.

2

u/RappyPhan Sep 02 '26

There are plenty of young assembly reverse engineers who don't use LLMs.

0

u/tobdomo Sep 02 '26

Strip your binary from all symbolic information. Depending on your host platform and toolchain, e.g. use strip on Linux (see man strip). Use static linking, full optimization (including linker optimization). That is nowhere foolproof, but it makes things a lot harder to begin with.

Then use DRM and Licensing software. This will encrypt and decrypt on the fly. Wibu-Systems for example makes a tool called CodeMeter. Using this software, you can tie and encrypt the binary to a specific machine or a out-of-band key vault (e.g. a USB key or a license file).

0

u/BarracudaDefiant4702 Sep 02 '26

Your two biggest options are you make it difficult by layering black boxes. The more effective you are the more It will eat into performance. The most effective option is to host the part you are most concerned about behind an api. It will mean the app (or at least that part of the app) will not function if offline. Many places don't like that, but many companies are starting to sell their products as cloud only.

0

u/Dangerous_Region1682 Sep 02 '26

If you are trying to preserve your algorithm against state sponsored actors there isn’t much you can do, they have the business, hardware and software means, along with the expertise to do so.

If you are protecting yourself against more commercial or user level theft then common obfuscation and licensing methods are probably sufficient. At some stage you have to say are certain customers unwilling or unable to use a cloud environment worth the risk?

0

u/jeffbell Sep 02 '26

Self modifying code is hard but modifying a table of callbacks is straightforward. 

A buffer overrun to change your return address is fun. 

0

u/lucasxi Sep 02 '26

No matter how much you try, someone who is determined enough will bypass any attempts at obfuscation. This is a known issue when distributing software and needs a legal solution.

0

u/emedan_mc Sep 02 '26

You can delay, never protect. Cloud based code with api calls is protected.

0

u/sciencekm Sep 03 '26

As long as the binary is there, anyone can reverse engineer that. You can however make it more difficult with self-modifying code and assembly tricks. Don't bother with high level languages as the output is predictable.

0

u/Daveinatx Sep 03 '26

All code can be decompiled with IDA pro or ghidra. That said, there are ways to try to hide it. Usually you would want to use encryption over essential code, whether it's the application, libraries, or sections of runtime code. Even then, good hackers know what they're looking for at run time even within cache.

Your absolute best way though, is to use keys that are hidden either behind an fpga, USB fob, or possibly within a TPM for key wrapping. Once pages are needed, force it within the cache before decryption. Zero out keys after usage.

I used to get paid a lot for doing this, it's complex to do right. So, it all depends on what level you or your customer wants. But the rest of the details are for you to research.

-1

u/Stickhtot Sep 02 '26

Not necessarily smart but I know that setting the optimization levels to the highest would remove symbols in the assembly which would probably make it harder to reverse engineer

0

u/lucasxi Sep 02 '26

Less code makes it easier to reverse engineer, a main component of obfuscation is to bloat the binary with junk to make a reverse engineer waste time.

1

u/Super-Complaint-3289 2d ago

I use strong words on my obfuscated code relationed to multilation, mass killing and other trigger words to trigger the ai filter