简体   繁体   中英

How can I change text that is read via ReadFile function

How can I change text that is read via ReadFile function? I'm using detour to hook ReadFile functions calls. 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.

error 2: you missed to fill lpNumberOfBytesRead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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