Loop Unrolling Transformation: Difference between revisions

Jump to navigation Jump to search
no edit summary
(Created page with "Obfuscation is a code transformation technique used to make source code difficult to read and understand while preserving its functionality. This process typically involves renaming identifiers, restructuring code, or inserting misleading elements to obscure the original logic. Obfuscation is often used to protect intellectual property, prevent reverse engineering, or secure sensitive logic in software. While the transformed code remains executable, it becomes significan...")
 
No edit summary
Line 1: Line 1:
Obfuscation is a code transformation technique used to make source code difficult to read and understand while preserving its functionality. This process typically involves renaming identifiers, restructuring code, or inserting misleading elements to obscure the original logic. Obfuscation is often used to protect intellectual property, prevent reverse engineering, or secure sensitive logic in software. While the transformed code remains executable, it becomes significantly harder for humans to analyze, ensuring that key implementation details are concealed without altering program behavior.
Loop unrolling is an optimization technique that reduces the number of iterations in a loop by expanding its body to process multiple elements per iteration. This transformation decreases loop overhead, improves execution efficiency, and can enhance opportunities for parallelization. By reducing control flow instructions, loop unrolling minimizes branching and increases instruction-level parallelism, making it particularly useful for performance-critical applications. While it can lead to larger code size, the trade-off often results in significant runtime improvements.
==Obfuscation Transformation in emmtrix Studio==
==Loop Unrolling Transformation in emmtrix Studio==
emmtrix Studio implements obfuscation using #pragma directives or via the GUI. Obfuscation is a transformation that renames identifiers so that they become obscure. This feature is typically used to ensure that the code is unrecognizable. Functionality of the code and its original structure are preserved. The algorithms used are Secure Hash Algorithms SHA-1 and SHA-256.
emmtrix Studio implements loop unrolling using #pragma directives or via the GUI. Unrolling will reduce the iteration count and increase the body of the loop, processing statements from multiple iteration steps in a single iteration.
===Typical Usage and Benefits===
===Typical Usage and Benefits===
The transformation is used make the source code hard to understand for humans while still preserving the original structure of the source code. It is meant for cases where the source code needs to be shared (e.g. for debugging) but no intellectual property should be shown.The transformation can be applied only to functions.
Loop unrolling is used to reduce the overhead of the loops and to exploit parallelization on coarser parts.
 
Even though the transformation is selectable only for functions, it can affect other identifiers, as well, depending on the user settings. In its full scope, obfuscation affects all identifiers, including:
*functions and their parameters
*global and local variables
*user-defined types
*structs and unions
*enumerators
*file names
===Example===
===Example===
{| class="wikitable"
{| class="wikitable"
|-
|-
|<syntaxhighlight lang="c">
|<syntaxhighlight lang="c">
/* The following code tests obfuscation transformation applied to main function with default parameters.
/* The following code tests LoopUnroll transformation applied to a for loop: */   
* According to the default settings, all identifiers except for the external definitions and the main func-
  tion, shall be renamed and become obscure.
* In the current code example the identifiers with the suffix _obfu are renamed.
* Other identifiers include printf and main functions and they remain unmodified.
*/   


const int g_obfu = 10;
int main(void) {
void print_obfu(int a_obfu) {
     int i;
     printf(” % d\ n”, a_obfu);
    int a[4];
}
    #pragma EMX_TRANSFORMATION LoopUnroll {
#pragma EMX_TRANSFORMATION ObfuscateIdentifiers
        ”
int main() {
        unrollfactor”: 4
     int l_obfu = 1;
     }
     print_obfu(l_obfu);
     for (i = 0; i < 4; i++) {
     print_obfu(g_obfu);
        a[i] = i;
     }
     return 0;
     return 0;
}
}
</syntaxhighlight>
</syntaxhighlight>
|<syntaxhighlight lang="c">
|<syntaxhighlight lang="c">
/* The following code is the generated code after the transformation has been applied.
/* The generated code includes all four iterations of the loop transformed into four separate statements.
* The loop unrolling is full and the loop is removed.
  */
  */


const int var_ee832f = 10;
int main(void) {
void func_3db980(int var_e86e08) {
     int i;
     printf(” % d\ n”, var_e86e08);
    int a[4];
}
    i = 0;
void func_baf390(int var_e86e08) {
    {
     printf(” % d\ n”, var_e86e08);
        a[i] = i;
}
     } {
int main() {
        a[i + 1 * 1] = i + 1 * 1;
    int var_32bc72 = 1;
    } {
     func_baf390(var_32bc72);
        a[i + 1 * 2] = i + 1 * 2;
     func_3db980(var_ee832f);
     } {
        a[i + 1 * 3] = i + 1 * 3;
     }
     return 0;
     return 0;
}
}
</syntaxhighlight>
</syntaxhighlight>
|}Along with the transformed code, a mapping between the old and the new identifiers is created. It is stored in a CSV file obfuscation_mapping.csv.<syntaxhighlight lang="c">
|}
file_b93f1b;test_obfuscation00
func_3db980;print_obfu
func_baf390;print_obfu_duplicate2
var_e86e08;a_obfu
var_ee832f;g_obfu
var_32bc72;l_obfu
</syntaxhighlight>
===Parameters===
===Parameters===
Following parameters can be set (each description is followed by keyword in pragma-syntax and default value):
Following parameters can be set (each description is followed by keyword in pragma-syntax and default value):
Line 69: Line 53:
!Description
!Description
|-
|-
|<code>all</code>
|<code>unrollfactor</code>
|true
|max_unrollfactor
|'''Whole Project''' - apply obfuscation on all translation units across project
|'''Unroll factor''' - divide iteration count & multiply iterating variable. If equal to total number of iterations, loop-construct will be removed from code. If not integer divisor of total number of iterations, additional loop
|-
processing last iterations will be added
|<code>external</code>
|false
|'''External definitions''' - apply obfuscation on identifiers in header files; use with caution, since it affects used system identifiers and produces uncompilable code
|-
|<code>output</code>
|true
|'''Output identifiers''' - generate CSV file containing mapping of old and new names
|-
|<code>seed</code>
|enc1
|'''Seed for hash-function''' - arbitrary string used as input for hashing algorithms
|-
|<code>n</code>
|6
|'''Hash-length''' - length of hash code in obfuscated identifiers
|}
|}
===Note===
[[Category:Code Transformation]]
*For same seeds and hash-lengths, obfuscation is deterministic.
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu