#include #include #include char check_for_byte(uint8_t code, void *function) { char result = 0; asm("mov $0xfff,%%ecx \n\t" "repnz scasb \n\t" // repnz scas %es:(%edi),%al "setz %0 \n\t" :"=r"(result):"a"(code),"D"(function)); return result; } char check_for_word(uint16_t code, void *function) { char result = 0; asm("mov $0xfff,%%ecx \n\t" "repnz scasw \n\t" // repnz scas %es:(%edi),%al "setz %0 \n\t" :"=r"(result):"a"(code),"D"(function)); return result; } int main(int argc, char **argv) { const uint8_t byte[] = {0xcc}; const uint16_t word[] = {0xcd03, 0xcd2d}; void *function[] = {check_for_byte, check_for_word, main}; char *name[] = {"check_for_byte", "check_for_word", "main"}; for(size_t f = 0; f < 3; ++f) { for(size_t b = 0; b < 1; ++b) if (check_for_byte(byte[b], function[f])) { printf("0x%x found in %s\n", byte[b] & 0xff, name[f]); // exit(0); } for(size_t w = 0; w < 2; ++w) if (check_for_word(word[w], function[f])) { printf("0x%x found in %s\n", word[w] & 0xffff, name[f]); // exit(0); } } puts("debugger not detected!!!"); }