Protecting C and C++ code only in marked sections of code

Introduction to support for obfuscation of C/C++ code surrounded by delimiters

Stunnix CXX-Obfus can obfuscate C/C++ code only between certain strings. This is useful if you wish to keep some parts of your code totally unchanged, or if your C/C++ is intermixed with some other high-level language.

When such support for delimiters is enabled, Stunnix CXX-Obfus scans input file for code start delimiter, and protects the C/C++ till it encounters end delimiter.

You can define several different strings as start delimiter; also you can define several different strings as end delimiter. Once Stunnix CXX-Obfus encounters any variant of start delimiter, it will start protecting C/C++ code, and it will stop mangling C/C++ code once it encounters any version of end delimiter.

Start/end delimiter can be arbitrary sequence of characters except newline; it can contain spaces, characters used for operators or characters that mark up the comment. It is common practice to make start delimiter and end delimiter a single-line comment containg some keyword, so delimited code would look like this:

//CODESTART
  abc=def+42;
//CODEEND

- this way, code with delimiters will still be syntactically correct C/C++ code.

Configuring project for obfuscating C/C++ code surrounded by delimiters

Let's create a new processing mode that will enable protection of C/C++ code only surrounded by delimiters. We'll assign that mode to files we are interested in using Settings ⇒ "For files" - by putting checkbox near those files, selecting the newly-created mode from dropdown list and then clicking on "Assign Processing Mode" button.

To create new mode, go to Settings ⇒ Edit modes, click on "Create new mode" button. Enter title "delimited" or the next screen. Select "Standard: treat as raw code" as PARENT mode from dropdown list. Scroll down to section "Meta-language in input files", Select "Code is protected only between delimiters", and check a checkbox to the left of dropdown list. Put checkboxes to the left of textfields with titles "Name of file containing strings that mark start of piece of code" and "Name of file containing strings that mark end of piece of code". Put "start-delimiters.txt" (without quotes) into "Name of file containing strings that mark start of piece of code" and put "end-delimiters.txt" (without quotes) "Name of file containing strings that mark end of piece of code". Click Save at the bottom of the page.

After that, put files with names "start-delimiters.txt" and "end-delimiters.txt" into your Project's input directory; list your start delimiters, one per line in the former and list your end delimiters into the later.

After that go to Settings ⇒ "For files", select files where start/end delimiters are present, select "delimited" from dropdown list and click on "Assign Processing Mode" button.

Possible applications

You can use this functionality to obfuscate only some portions of the C/C++ file. Also if you have C/C++ code emebded in some XML file, you can use this functionality to obfuscate code inside such XML file without affecting the XML markup around the code.