kalkanistovinko
kalkanistovinko

Reputation: 97

Shell code: access violation exception for no obvious reason

In VS2012 I wrote:

int main(){
    char *myshell = 
    "\x50"  // push eax
    "\x58"  // pop eax
    "\xC3"; //ret

    __asm call myshell

    return 0;
}

I followed the debugger line by line, and when the CPU attempts to execute "push eax", or anything else I decide to change it to for that matter, it fires a failing exception, saying:

Unhandled exception at 0x00265858 in ConsoleApplication8.exe: 0xC0000005: Access violation executing location 0x00265858.

Why is that?

Upvotes: 0

Views: 1281

Answers (1)

David Skuza
David Skuza

Reputation: 140

Google points here.

You can use VirtualProtect before calling.

DWORD oldProtection = 0;
VirtualProtect((void*)myshell, 3, PAGE_EXECUTE_READWRITE, &oldProtection);

Upvotes: 2

Related Questions