Linux process writing to Windows process memory running in Wine

Questions about Wine on Linux
Locked
Remdul
Level 1
Level 1
Posts: 9
Joined: Thu Nov 08, 2018 11:15 am

Linux process writing to Windows process memory running in Wine

Post by Remdul »

I have two applications running on my Linux machine, one a Window process running in Wine, another a native Linux process. From the Linux process I can read() from /proc/#/mem and retrieve the information I need, but I'd also like to write to it. I'm not particularly concerned about memory corruption or race conditions or the correctness of it.
Currently the Windows process crashes as soon as I write to the chunk of memory with 'invalid page fault' (Wine doesn't seem to complain or interfere), and the Linux application keeps running just fine.

This is what I'm supposed to do on Windows:

Code: Select all

 DWORD tmp;
 if (!VirtualProtectEx(processHandle, dataAdress, dataSize, PAGE_EXECUTE_READWRITE, &tmp)) {
  printf("error changing memory protection\n");
  return false;
 }
 
 if (!WriteProcessMemory(processHandle, dataAdress, &newData, dataSize, NULL)) {
  printf("error writing memory\n");
  return false;
 }
This is the Linux app equivalent:

Code: Select all

 // open process memory
 char path[80];
 snprintf(path, 80, "/proc/%d/mem", pid);
 int fd_procmem = open(path, O_RDWR);
 if (fd_procmem == -1) {
  printf("could not open \"%s\" (%i): %s\n", path, errno, strerror(errno) );
  return false;
 }
 
 // write data
 long int addr = 0x98FCC500;
 lseek(fd_procmem, addr, SEEK_SET);
 int r = write(fd_procmem, data, dataSize);
 if (r != 64) {
  printf("error while writing\n");
  return false;
 }
Is there a Wine Win32 library exposed that I can access from a Linux app to invoke Win32 API calls within a running Wine prefix instance?
Locked