内存加载分析(cs模块)















最后更新于
#include <iostream>
#include <windows.h>
using namespace std;
int main(int argc, const char **argv)
{
wcout << "Connecting to pipe..." << endl;
HANDLE pipe = CreateFile(
"\\\\.\\pipe\\screenshot",
GENERIC_READ,
0,
NULL,
OPEN_EXISTING,
0,
NULL
);
if (pipe == INVALID_HANDLE_VALUE) {
wcout << "Failed to connect to pipe." << endl;
system("pause");
return 1;
}
wcout << "Reading data from pipe..." << endl;
DWORD size;
DWORD numBytesRead = 0;
BOOL result = ReadFile(
pipe,
&size,
4,
&numBytesRead,
NULL
);
Sleep(5000);
char* lpbuf = (char*)VirtualAlloc(NULL, size, MEM_COMMIT, PAGE_READWRITE);
if (result) {
ReadFile(
pipe,
lpbuf,
size,
&numBytesRead,
NULL
);
CloseHandle(pipe);
DWORD dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
DWORD dwShareMode = 0;
LPSECURITY_ATTRIBUTES lpSecurityAttributes = NULL;
DWORD dwCreationDisposition = OPEN_ALWAYS;
DWORD dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL;
HANDLE hTemplateFile = NULL;
HANDLE handle = CreateFile("test.jpg", dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile);
WriteFile(handle, lpbuf, size, &numBytesRead, NULL);
CloseHandle(handle);
}
else {
wcout << "Failed to read data from the pipe." << endl;
}
return 0;
}