21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

12.5 Performing Constant Transforms on<br />

Variables<br />

<strong>Problem</strong><br />

Variables used frequently—such as in loops or counters—are difficult to obfuscate<br />

without impacting the performance of the program.<br />

Solution<br />

Change variables by a constant value.<br />

Discussion<br />

Changing variables by a constant value is a trivial form of obfuscation; however, it is<br />

fast and easy to implement, and it can be combined with other obfuscation methods.<br />

Here is an example of the obfuscation:<br />

#define SET_VAR(var) (((var) * 3) + 0x01040200)<br />

#define GET_VAR(var) (((var) - 0x01040200) / 3)<br />

The macros can be applied to any usage of an integer:<br />

for (i = SET_VAR(0); GET_VAR(i) < 10; i = SET_VAR(j + 1)) {<br />

j = GET_VAR(i);<br />

printf("2 + %d = %d\n", i, 2 + GET_VAR(i));<br />

}<br />

Constant transforms are useful only if the SET_VAR and GET_VAR macros are used far<br />

apart; otherwise, the transform is immediately obvious. Transformations that are<br />

more robust can be created that use different mathematical operations in each of the<br />

SET_VAR and GET_VAR macros so that different constants are used in the expansion of<br />

each macro. Note that the SET_VAR macro can be used in the initialization of a variable,<br />

which will obfuscate the value of the variable at compile time.<br />

12.6 Merging Scalar Variables<br />

<strong>Problem</strong><br />

Scalar variables with constant or initialized values disclose information about ranges<br />

of values.<br />

This is the Title of the Book, eMatter Edition<br />

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.<br />

Merging Scalar Variables | 667

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!