MCPcopy Create free account
hub / github.com/DFIR-ORC/dfir-orc / LoadResourceData

Function LoadResourceData

src/OrcCapsule/Utilities/Resource.cpp:34–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32} // namespace
33
34std::error_code LoadResourceData(HMODULE hModule, const std::wstring& name, LPCWSTR type, std::vector<uint8_t>& output)
35{
36 std::error_code ec;
37
38 HRSRC hResource = FindResourceW(hModule, name.c_str(), type);
39 if (!hResource)
40 {
41 ec = LastWin32Error();
42 Log::Debug(L"Failed FindResourceW (name: {}) [{}]", name, ec);
43 return ec;
44 }
45
46 HGLOBAL hLoaded = LoadResource(hModule, hResource);
47 if (!hLoaded)
48 {
49 ec = LastWin32Error();
50 Log::Debug(L"Failed LoadResource (name: {}, type: {}) [{}]", name, type, ec);
51 return ec;
52 }
53
54 DWORD size = SizeofResource(hModule, hResource);
55 if (size == 0)
56 {
57 ec = LastWin32Error();
58 Log::Debug(L"Failed SizeofResource (name: {}) [{}]", name, type, ec);
59 return ec;
60 }
61
62 const void* pData = LockResource(hLoaded);
63 if (!pData)
64 {
65 return std::make_error_code(std::errc::bad_address);
66 }
67
68 const auto* bytePtr = static_cast<const uint8_t*>(pData);
69 output.assign(bytePtr, bytePtr + size);
70 return {};
71}
72
73std::error_code
74LoadResourceData(const fs::path& path, const std::wstring& name, LPCWSTR type, std::vector<uint8_t>& output)

Callers 3

ExtractResourceFunction · 0.85
GetRunnerSlotInfoFunction · 0.85
LaunchRunnerProcessFunction · 0.85

Calls 5

c_strMethod · 0.80
LastWin32ErrorFunction · 0.70
DebugFunction · 0.70
assignMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected