Created
April 2, 2012 13:56
-
-
Save yutopp/2283586 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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