A proper debugger will tell you what is going wrong. I can only guess that your code is causing an access violation because the buffer you want to go to is not executable.
You are probably the default DEP system, such as Vista or 7, so you need to make sure your shellcode is executable. To do this, first use VirtualAlloc
to select a new, executable buffer and copy your shellcode to it, then execute it :
void *exec = VirtualAlloc(0, sizeof b, MEM_COMMIT, PAGE_EXECUTE_READWRITE); memcpy(exec, b, sizeof b); ((void(*)())exec)();
By the way, you do not need to null-terminate the shellcode (C ++ automatically terminates the string literal, but this is optional). You also do not need to specify the size:
unsigned char b[] = "\xcc";
source share