-------------------------------------------------------------------------
| 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 | } |
no outgoing calls
no test coverage detected