#include<iostream> #include<cstdlib> #include<fstream>#include<Windows.h>#include<stdio.h>usingnamespacestd;intmain(intargc,char*argv[]){HANDLEhFile;DWORDdwFileSize;DWORDbaseAddres=0;BOOLreadSuccess;DWORDbytesRead=0;if(argc==1){cout<<"\tArugments: execute_sc.exe sc.bin offset (optional)"<<endl;return0;}// Open up file passed as an argument hFile=CreateFile(argv[1],// name of the writeGENERIC_READ,// open for writingFILE_SHARE_READ,// do not shareNULL,// default securityOPEN_EXISTING,// create new file onlyFILE_ATTRIBUTE_NORMAL,// normal fileNULL);// no attr. template// check if handle is valid if(hFile!=INVALID_HANDLE_VALUE){if(argc>=3){baseAddres=std::strtoul(argv[2],0,16);}dwFileSize=GetFileSize(hFile,NULL);void*exec=VirtualAlloc((LPVOID)baseAddres,dwFileSize,MEM_COMMIT,PAGE_EXECUTE_READWRITE);cout<<"Allocated at "<<std::hex<<exec<<endl;if(exec!=NULL){readSuccess=ReadFile(hFile,exec,dwFileSize,&bytesRead,NULL);if(readSuccess==TRUE)((void(*)())exec)();elsecout<<"ERROR: ReadFile Failed Error: "<<endl;}elsecout<<"ERROR: VirtualAlloc Failed"<<endl;CloseHandle(hFile);}return0;}
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.