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.

Comparing the assembly code generated for the integer test and the float test clearly<br />

illustrates the difference between the two from a code obfuscation standpoint:<br />

; First, the integer test: if (value) ...<br />

8048346: 8b 45 fc mov 0xfffffffc(%ebp),%eax<br />

8048349: 85 c0 test %eax,%eax<br />

804834b: 74 10 je 804835d <br />

; Compare with the float test: if (value = = 1.0) ...<br />

804835d: d9 45 f8 flds<br />

8048360: d9 e8 fld1<br />

8048362: d9 c9 fxch %st(1)<br />

8048364: da e9 fucompp<br />

8048366: df e0 fnstsw %ax<br />

8048368: 80 e4 45 and $0x45,%ah<br />

804836b: 80 fc 40 cmp $0x40,%ah<br />

804836e: 74 02 je 8048372 <br />

When a constant value is used in a comparison, it can be increased or decreased as<br />

long as value is adjusted by the same amount:<br />

if ((value + 8) 8) {<br />

; /* this will never be true */<br />

}<br />

The volatile keyword is used here to prevent the compiler from optimizing the else<br />

if block out of existence; many “dead code” obfuscations will be recognized as such<br />

and discarded by an optimizing compiler. See Recipe 13.2 for a more in-depth discussion<br />

of compiler dead-code elimination optimizations.<br />

The best type of bogus condition involves entirely unrelated data, thereby implying<br />

that a connection exists between the data in the real and the bogus conditions. Function<br />

pointers are ideal candidates for this type of obfuscation:<br />

volatile int const_value = (int) printf;<br />

if (value = = MAGIC_CONSTANT && (const_value & 0xFFFF0000)) {<br />

; /* success-handling code here */<br />

}<br />

662 | Chapter 12: Anti-Tampering<br />

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

Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.

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

Saved successfully!

Ooh no, something went wrong!