I have been attempting to write strings in Kernel Memory for some time now. I have been able to read strings, however I have no luck with writing them. I can write regular things such as a DWORD. I keep getting stuck on casting a string to a UINT_PTR. Any help is appreciated and here is my code for reading strings:
std::string ReadString(UINT_PTR ProcessId, UINT_PTR ReadAddress, SIZE_T Size) {
if (hDriver == INVALID_HANDLE_VALUE) {
return {};
}
DWORD64 Bytes;
KERNEL_READ_REQUEST ReadRequest{};
std::vector<char> buffer(Size, char{ 0 });
ReadRequest.ProcessId = ProcessId;
ReadRequest.Address = ReadAddress;
ReadRequest.Size = buffer.size();
ReadRequest.Output = static_cast<void*>(&buffer[0]);
if (DeviceIoControl(hDriver, IO_READ_REQUEST, &ReadRequest, sizeof(ReadRequest), &ReadRequest, sizeof(ReadRequest), 0, 0)) {
return std::string(buffer.data());
}
else {
return {};
}
}
What I have tried:
std::vector<char> buffer(Size, char{ 0 });
I have also tried:
std::string WriteString(UINT_PTR ProcessId, UINT_PTR WriteAddress, UINT_PTR WriteValue, SIZE_T Size) {
if (hDriver == INVALID_HANDLE_VALUE) {
return {};
}
DWORD64 Bytes;
KERNEL_WRITE_REQUEST WriteRequest{};
std::vector<char> buffer(Size, char{ 0 });
WriteRequest.ProcessId = ProcessId;
WriteRequest.Address = WriteAddress;
WriteRequest.Size = buffer.size();
WriteRequest.Value = WriteValue;
if (DeviceIoControl(hDriver, IO_WRITE_REQUEST, &WriteRequest, sizeof(WriteRequest), 0, 0, 0, 0)) {
return {};
}
else {
return {};
}
}