Skip to content

Instantly share code, notes, and snippets.

  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Run shellcode (machinecode) from c++ on windows mingw gcc
#include <windows.h>
#include <iostream>
int main(){
//code that just returns 5+5 (10)
static const int code_lenght = 44;
unsigned char opcodes[code_lenght] = "\x55\x48\x89\xe5\xb8\x0a\x00\x00\x00\x5d\xc3";
HANDLE mem_handle = CreateFileMappingA( INVALID_HANDLE_VALUE, NULL, PAGE_EXECUTE_READWRITE, 0, code_lenght, NULL);
void* mem_map = MapViewOfFile( mem_handle, FILE_MAP_ALL_ACCESS | FILE_MAP_EXECUTE, 0x0, 0x0, code_lenght);
memcpy(mem_map, opcodes, sizeof(opcodes));
std::cout << (( int(*)() )mem_map)() << std::endl;
return 0;
}
@rrifi
Copy link

rrifi commented Apr 18, 2021

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment