Control Flow Flattening Using Pre-calculated Mask Values
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing code obfuscation techniques are inefficient in preventing reverse engineering, especially when multiple predecessor basic blocks complicate the computation of the next basic block ID, leading to increased execution time overhead and code size.
Innovation Solution
A method involving determining a mask value by bit-wise operations on the IDs of predecessor basic blocks, using this mask to calculate the next basic block ID based on conditionals, and inserting instructions to obscure the control flow, allowing the next basic block ID to be determined at runtime.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Difficulty of detecting and measuring
If control flow flattening is implemented to obfuscate code, then code obfuscation effectiveness is improved, but execution time overhead increases
Solution Approach 1:
The mask value is pre-calculated during code compilation based on the IDs of predecessor basic blocks. This preliminary computation stores the common bit pattern that will be used at runtime to determine the next basic block, eliminating the need for complex runtime analysis of multiple predecessor blocks and reducing execution time overhead.
Solution Approach 2:
The invention changes the parameter representation by using a mask value that captures the common bits of predecessor block IDs. Instead of storing or comparing full IDs at runtime, the system transforms the problem into comparing and operating on mask values, which reduces computational complexity and execution time while maintaining obfuscation effectiveness.
2Measurement precision
If multiple predecessor basic blocks are handled with detailed computation, then accuracy of next basic block determination is improved, but code size increases
Solution Approach 1:
The invention extracts only the essential information needed for control flow determination by calculating a mask value that represents the common bits of predecessor block IDs. This extracted mask value is stored instead of the full computation logic, reducing code size while maintaining the ability to accurately determine the next basic block at runtime.
3Measurement precision
If complex bit-wise operations are performed on predecessor block IDs, then precision of mask value calculation is improved, but computational cost increases
Solution Approach 1:
The complex bit-wise operations (AND, OR, NOT) are performed during code compilation rather than at runtime. The mask value is pre-calculated by combining the IDs of all predecessor basic blocks using these operations, storing the result for efficient runtime use and avoiding repeated computational expense.
Data Source
AI summary
A method of obscuring software code including a plurality of basic blocks wherein the basic blocks have an associated identifier (ID), including: determining, by a processor, for a first basic block first predecessor basic blocks, wherein first predecessor basic blocks jump to the first basic block and the first basic block jumps to a next basic block based upon a next basic block ID; producing, by the processor, a mask value based upon the IDs of first predecessor basic blocks, wherein the mask value identifies common bits of the IDs of the first predecessor basic blocks; and inserting, by the processor, an instruction in the first basic block to determine a next basic block ID based upon the mask value and an ID of one of the first predecessor basic blocks.
