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.

* typedefs for clarity */<br />

typedef unsigned char obit_t;<br />

typedef struct obyte obyte_t;<br />

typedef struct obint obint_t;<br />

int obytes_equal(obyte_t *a, obyt_t *b) {<br />

int i;<br />

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

if (obit_get(a.s[i]) != obit_get(b.s[i])) return 0;<br />

return 1;<br />

}<br />

/* do-nothing subroutines */<br />

void action_write(char *arg) { printf("write %s\n", arg); }<br />

void action_read(char *arg) { printf("read %s\n", arg); }<br />

void action_error(void) { printf("ERROR: Bad parameter\n"); }{<br />

int main(int argc, char *argv[ ]) {<br />

obyte_t input, read_val, write_val;<br />

unsigned char i;<br />

if (argc < 2) {<br />

fprintf(stderr, "Usage: %s num string\n", argv[0]);<br />

return 1;<br />

}<br />

/* initialize the obcode lib with a random key */<br />

obcode_init(0);<br />

/* obfuscate the first argument */<br />

obyte_set(&input, (unsigned char)atoi(argv[1]));<br />

/* obfuscate the values to compare it to--these should really be stored in<br />

* obfuscated form instead of generated<br />

*/<br />

obyte_set(&read_val, 63);<br />

obyte_set(&write_val, 112);<br />

/* perform comparisons */<br />

if (obytes_equal(&input, &read_val)) action_read(argv[2]);<br />

else if (obytes_equal(&input, &write_val)) action_write(argv[2]);<br />

else action_err( );<br />

/* cleanup */<br />

obcode_finish( );<br />

return 0;<br />

}<br />

See Also<br />

Obcode library by Pawel Krawczyk: http://echelon.pl/pubs/<br />

666 | 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!