21.03.2013 Views

Problem - Kevin Tafuro

Problem - Kevin Tafuro

Problem - Kevin Tafuro

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

encoded as a series of 32 Obcode bits. Operations on Obcode values do not decode<br />

the values, but rather work on the encoded versions; therefore, the C statement:<br />

x = y ^ z;<br />

would be implemented as:<br />

int i;<br />

for (i = 0; i < 8; i++) {<br />

if (obit_get(y.s[i]) = = obit_get(z.s[i])) x.s[i] = obit_set(0);<br />

else x.s[i] = obit_set(1);<br />

}<br />

where x, y, and z are Obcode bytes, obit_get( ) returns 0 if the Obcode bit argument<br />

is odd and 1 if the argument is even, and obit_set( ) returns an Obcode bit<br />

representation of the argument. The values of x, y, and z are randomly determined at<br />

runtime.<br />

The Obcode API is defined in the file obcode.h:<br />

/* obcode.h */<br />

struct obyte {<br />

unsigned char s[8];<br />

};<br />

struct obint {<br />

unsigned char s[32];<br />

};<br />

extern void obcode_init(unsigned char key);<br />

extern void obcode_finish(void);<br />

extern unsigned char obit_set(int b);<br />

extern unsigned char obit_get(unsigned char b);<br />

extern void obyte_set(struct obyte *b, unsigned char c);<br />

extern unsigned char obyte_get(struct obyte *b);<br />

extern void obit_xor(unsigned char *b1, unsigned char *b2, unsigned char *b3);<br />

extern void obyte_xor(struct obyte *ob1, struct obyte *ob2, struct obyte *ob3);<br />

extern void obit_or(unsigned char *b1, unsigned char *b2, unsigned char *b3);<br />

extern void obit_and(unsigned char *b1, unsigned char *b2, unsigned char *b3);<br />

extern void obit_not(unsigned char *b1, unsigned char *b2);<br />

extern void obyte_add(struct obyte *ob1, struct obyte *ob2, struct obyte *ob3);<br />

extern void obyte_copy(struct obyte *dst, struct obyte *src);<br />

extern void obyte_swap(struct obyte *ob1, struct obyte *ob2);<br />

The following program demonstrates the basic usage of the Obcode library: the first<br />

argument passed to the program is XOR’d with a key, then used as an index into a<br />

table of function pointers.<br />

#include <br />

#include <br />

#include <br />

Performing Bit and Byte Obfuscation | 665<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!