#define WIN32_LEAN_AND_MEAN
#include
#include
#include
#if _UNICODE
#define cout wcout
#endif
using namespace std;
void WriteLastError()
{
DWORD dw = GetLastError();
TCHAR szBuf[80];
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR) &lpMsgBuf,
0, NULL );
wsprintf(szBuf,
_T("ERROR(%d): %s"),
dw, lpMsgBuf);
wcout << szBuf;
LocalFree(lpMsgBuf);
}
int _tmain()
{
unsigned char matrix[6];
unsigned char redpill[] =
"\x0f\x01\x0d\x00\x00\x00\x00\xc3";
HANDLE hProcess = GetCurrentProcess();
LPVOID lpAddress = NULL;
PDWORD lpflOldProtect = NULL;
try
{
DWORD dw;
*((unsigned*)&redpill[3]) = (unsigned)matrix;
lpAddress = VirtualAllocEx(hProcess, NULL,
6, MEM_RESERVE|MEM_COMMIT , PAGE_EXECUTE_READWRITE);
if(lpAddress == NULL)
{
WriteLastError();
}
BOOL success = VirtualProtectEx(
hProcess, lpAddress, 6, PAGE_EXECUTE_READWRITE , lpflOldProtect);
dw = GetLastError();
if(success != 0)
{
WriteLastError();
}
memcpy(lpAddress, redpill, 8);
((void(*)())lpAddress)();
if (matrix[5]>0xd0)
{
wcout << _T("Inside Matrix!\n");
return 1;
}
else
{
wcout << _T("Not in Matrix.\n");
return 0;
}
}
finally
{
VirtualFreeEx(hProcess, lpAddress, 0, MEM_RELEASE);
}
}