MCPcopy Create free account
hub / github.com/dobin/RedEdr / GetRemoteUnicodeStr

Function GetRemoteUnicodeStr

RedEdrShared/process_query.cpp:487–519  ·  view source on GitHub ↗

Gets a UNICODE_STRING content in a remote process as wstring

Source from the content-addressed store, hash-verified

485
486// Gets a UNICODE_STRING content in a remote process as wstring
487std::string GetRemoteUnicodeStr(HANDLE hProcess, UNICODE_STRING* u) {
488 if (!hProcess || hProcess == INVALID_HANDLE_VALUE || !u) {
489 LOG_A(LOG_ERROR, "GetRemoteUnicodeStr: Invalid parameters");
490 return std::string();
491 }
492
493 if (!u->Buffer || u->Length == 0) {
494 return std::string(); // Empty string is valid
495 }
496
497 // Sanity check for reasonable string length (64KB limit)
498 if (u->Length > 65536) {
499 LOG_A(LOG_WARNING, "GetRemoteUnicodeStr: String length too large: %u", u->Length);
500 return std::string();
501 }
502
503 std::wstring s;
504 //std::vector<wchar_t> commandLine(u->Length / sizeof(wchar_t));
505 std::vector<wchar_t> uni(u->Length / sizeof(wchar_t) + 1, L'\0'); // Add space for null terminator
506
507 if (!ReadProcessMemory(hProcess, u->Buffer, uni.data(), u->Length, NULL)) {
508 LOG_A(LOG_ERROR, "ProcessQuery: Could not ReadProcessMemory error: %lu", GetLastError());
509 return std::string();
510 }
511 else {
512 // Ensure null termination
513 uni[u->Length / sizeof(wchar_t)] = L'\0';
514 s.assign(uni.begin(), uni.end() - 1); // Exclude the manually added null terminator
515 }
516
517 std::string str = wstring2string(s);
518 return str;
519}
520
521
522wchar_t* GetFileNameFromPath(wchar_t* path) {

Callers 1

ProcessPebInfoFunction · 0.85

Calls 6

stringFunction · 0.85
wstring2stringFunction · 0.85
LOG_AFunction · 0.50
dataMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected