Some code to obfuscate conditional branches in a dissassembler
The "Secure Programming Cookbook for C and C++" proposed the following
code to obfuscate conditional branches in a dissassembler:
#define IF_ZERO(val) \
asm(" xorl %%ebx, %%ebx\n\t" \
" negl %%eax\n\t" \
" rcl $3, %%ebx\n\t" \
" movl 0f( , %%ebx ), %%eax \n\t" \
" jmp *%%eax \n" \
"0: \n\t" \
" .long 1f\n\t" \
" .long 2f\n" \
"1: \n" \
: : "a" (val) : "%ebx");
#define ELSE \
asm(" jmp 3f\n\t" \
"2: \n");
#define ENDIF \
asm("3: \n");
The IF_ZERO macro places the value to be tested in the eax register, then
uses the negl instruction to set the carry flag if the value in the eax
register is nonzero. The carry flag is then rotated into a register and
used as an index into a jump table. The macro can be used to test for
equality by subtracting one value from another and passing it the result.
The problem is that GCC (version 3.3.5, Debian GNU/Linux Sarge) says
"Error: local label `"2" (instance number 1 if a fb label)' is not
defined". I'm not strong in assembly yes, what is wrong there? Thanks.
Best regards,
Andrew Pogrebennyk
|