Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save angelorodem/fd3f074a27ddf2708ee74a5ad32704d9 to your computer and use it in GitHub Desktop.
Save angelorodem/fd3f074a27ddf2708ee74a5ad32704d9 to your computer and use it in GitHub Desktop.
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