Skip to content

Instantly share code, notes, and snippets.

@yutopp
Created April 2, 2012 13:56
Show Gist options
  • Save yutopp/2283586 to your computer and use it in GitHub Desktop.
Save yutopp/2283586 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <Windows.h>
int main() {
typedef unsigned char byte_t;
byte_t* const p = reinterpret_cast<byte_t*>( ::VirtualAlloc( NULL, 1024, MEM_COMMIT, PAGE_EXECUTE_READWRITE ) );
if ( p == NULL )
return -1;
p[0] = 0x55; // push ebp;
p[1] = 0xB8; // mov eax, 72
p[2] = 0x72;
p[3] = 0;
p[4] = 0;
p[5] = 0;
p[6] = 0x5d; // pop ebp;
p[7] = 0xc3; // ret 0;
typedef int(*func_t)();
int const i = (reinterpret_cast<func_t>( p ))();
std::cout << std::hex << i << std::endl;
::VirtualFree( p, 0, MEM_RELEASE );
{ char c; std::cin >> c; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment