简体   繁体   English

如何更改通过ReadFile函数读取的文本

[英]How can I change text that is read via ReadFile function

How can I change text that is read via ReadFile function? 如何更改通过ReadFile函数读取的文本? I'm using detour to hook ReadFile functions calls. 我正在使用弯路来钩住ReadFile函数调用。 It works ok (I think so because of debug message boxes), but I can't change text that is read from the file. 它可以正常工作(由于调试消息框,我认为是这样),但是我无法更改从文件读取的文本。

static BOOL(WINAPI * true_read_file)(
  HANDLE hFile
  , LPVOID lpBuffer
  , DWORD nNumberOfBytesToRead
  , LPDWORD lpNumberOfBytesRead
  , LPOVERLAPPED lpOverlapped) = ReadFile;

BOOL WINAPI my_read_file(
  HANDLE hFile
  , LPVOID lpBuffer
  , DWORD nNumberOfBytesToRead
  , LPDWORD lpNumberOfBytesRead
  , LPOVERLAPPED lpOverlapped)
{
  MessageBoxA(NULL, "my_read_file", "Some caption", MB_OK);
  std::strcpy((char*)lpBuffer, "str"); // It doesn't work
  return TRUE;
}

What am I doing wrong? 我究竟做错了什么? How can I fix it? 我该如何解决?

Thanks in advance. 提前致谢。

error 1: you should check nNumberOfBytesToRead, it's possible 1, so you code overrun the buffer. 错误1:您应该检查nNumberOfBytesToRead,可能为1,因此您代码溢出了缓冲区。

error 2: you missed to fill lpNumberOfBytesRead. 错误2:您错过填写lpNumberOfBytesRead。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM