Here is an obfuscating technique, where a conditional jump is replaced by a jump table. Each array contains only one valid function pointer, which are called based on a crc value. I kept only a single array of function pointers
#include <stdio.h>
#include <inttypes.h>
typedef void (*crc_check_fn)(uint32_t *);
static void crc_nib2 (uint32_t *crc) { printf("OK\n"); }
crc_check_fn b1[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, crc_nib2, 0, 0, 0 };
int main(){
uint32_t crc = 0xFFF7FB7C;
int index = crc & 0x0F;
(*b1[index])(&crc);
}
I have several questions:
Can this array located in the assembly of the binary? I do not know well assembly, so checking it I was unable to tell this.
I assume the answer to the previous question is yes, because the original post recommends initializng
b1like{ ..., crc_nib2-8, crc_nib2, crc_ni2+8, ... };. Is this safer? Isn't it possible to tell that these are invalid pointers? Shouldn't be a better option to implement a lot of real dummy functions?Compiling with
gcc -SI gotb1: ...
.quad 0
.quad crc_nib2 .quad 0
...
Running objdump -d on the binary produces an assembly without the above lines. Why are the assemblies different? I have not stripped off symbols.
objdump -d, elf splitited on sections, .text (with code), '.rodata' constants and so on,objdump -ddisassemble only '.text' section, while your data may be in another sections.