What code obfuscation can and cannot do
Obfuscation buys time and raises the cost of an attack. It does not make a secret safe, and it has a price of its own.
Các bài viết được đăng bằng tiếng Anh.
Every program you ship can be read. Compiled code is harder to read than source code, but tools such as Ghidra turn machine code back into something close to the original logic. Obfuscation makes that output expensive to understand.
The main techniques
Renaming. Function and variable names are replaced with meaningless ones. It is cheap and effective in languages that keep names in the build, such as Java, C# and JavaScript. Stripping symbols does the same for native code.
String encryption. Text constants are stored encrypted and decoded when needed. Without it, a search for a message like “licence expired” leads an attacker straight to the check.
Control-flow flattening. Ordinary branches are replaced by a dispatcher that jumps between blocks based on a state variable. The logic stays the same, but the graph an analyst sees no longer shows its shape.
Virtualisation. Selected functions are compiled to bytecode for a custom virtual machine embedded in the program. An attacker has to understand the virtual machine before reading the function. This is the strongest technique and the most expensive to run.
What it does not do
It does not protect secrets. An API key or encryption key inside the application will be found, because the program has to use it. At the moment of use it sits in memory in plain form. Secrets belong on a server.
It does not stop a patch. Obfuscation makes the right place harder to find. Integrity checks and tamper responses are what make a modified build misbehave.
It does not last. Given enough time and motivation, any client-side protection is defeated. The aim is to make the attack cost more than it is worth, and to get past the period when your product is most valuable to copy.
What it costs
Flattening and virtualisation can slow a function by a large factor, so apply them to the code that matters, such as licence checks and your core algorithms, and leave the performance-critical loops alone. Measure before and after.
Crash reports become unreadable unless the build keeps a private map of the original names, and that map must be stored as carefully as the source code.
Some antivirus products treat heavily obfuscated programs as suspicious. Test your protected build against common products before release, and sign it with a code-signing certificate.
A sensible order of work
- Move what you can to the server.
- Remove names, debug information and readable strings.
- Harden the few functions that really matter.
- Add integrity checks that protect the hardening.
- Pay someone to attack the result, and read the report.
Do đội ngũ kỹ sư của Avtim viết. Đây là thông tin chung; hãy đối chiếu với hệ thống của bạn trước khi dựa vào.