MCPcopy Create free account
hub / github.com/OpenCppCoverage/OpenCppCoverage / WriteProcessMemory

Function WriteProcessMemory

Tools/ProcessMemory.cpp:64–91  ·  view source on GitHub ↗

-------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

62
63 //-------------------------------------------------------------------------
64 void WriteProcessMemory(HANDLE hProcess,
65 void* address,
66 void* buffer,
67 size_t size)
68 {
69 SIZE_T totalWritten = 0;
70 SIZE_T written = 0;
71
72 while (totalWritten < size)
73 {
74 auto startBuffer = static_cast<char*>(buffer) + totalWritten;
75 if (!::WriteProcessMemory(hProcess,
76 address,
77 startBuffer,
78 size - totalWritten,
79 &written))
80 {
81 LOG_ERROR << "Cannot write memory:";
82 }
83
84 if (written == 0)
85 THROW("Cannot write process memory");
86
87 if (!FlushInstructionCache(hProcess, startBuffer, written))
88 THROW("Cannot flush memory:");
89 totalWritten += written;
90 }
91 }
92}

Callers 2

SetBreakPointsRangeFunction · 0.85
RemoveBreakPointMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected