Control Flow Flattening Using Pre-calculated Mask Values

Resolve Bottlenecks,
Find Innovative Solutions
Generate 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

VSEngineering 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

Engineering Contradiction:
Improvecode obfuscation effectivenessVSAvoidexecution time overhead
Core Design Contradiction:
Difficulty of detecting and measuringVSLoss of time

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.

Inventive Principle:
Principle #10Preliminary action

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.

Inventive Principle:
Principle #35Parameter changes

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

Engineering Contradiction:
Improveaccuracy of next basic block determinationVSAvoidcode size
Core Design Contradiction:
Measurement precisionVSDevice complexity

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.

Inventive Principle:
Principle #2Taking out (Extraction)

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

Engineering Contradiction:
Improveprecision of mask value calculationVSAvoidcomputational cost
Core Design Contradiction:
Measurement precisionVSPower

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.

Inventive Principle:
Principle #10Preliminary action

Data Source

PatentUS10599820B2Control flow flattening for code obfuscation where the next block calculation needs run-time information
Publication Date: 2020.03.24 NXP BV
  • US10599820B2 patent drawing

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.