title: Injecting .dll in windows applications on linux
body: <p>Hello stackoverflow community,</p>
  
  <p>recently I have switched from Windows to Linux so did all my applications and projects. I think it's the best choice I've ever made but I'm not sure if it's also the case for injecting Windows DLLs into Windows programs that run with Wine. </p>
  
  <p>I'm aware that .so is the shared library format for Linux but I can't find an equivalent port of that dll... I have tried to run Extreme Injector, Xenos injector and also my own written one with Wine which works flawlessly in Windows  but that gave me a load of errors and didn't even start those injectors. </p>
  
  <p>The injector i compiled under Windows:</p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;Windows.h&gt;
  #include &lt;TlHelp32.h&gt;
  
  DWORD GetProcId(const char* procName)
  {
      DWORD procId = 0;
      HANDLE hSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
  
      if (hSnap != INVALID_HANDLE_VALUE)
      {
          PROCESSENTRY32 procEntry;
          procEntry.dwSize = sizeof(procEntry);
  
          if (Process32First(hSnap, &amp;procEntry))
          {
              do
              {
                  if (!_stricmp(procEntry.szExeFile, procName))
                  {
                      procId = procEntry.th32ProcessID;
                      break;
                  }
              } while (Process32Next(hSnap, &amp;procEntry));
          }
      }
      CloseHandle(hSnap);
      return procId;
  }
  
  int main()
  {
      const char* dllPath = "mydll.dll";
      const char* procName = "program.exe";
      DWORD procId = 0;
  
      while (!procId)
      {
          procId = GetProcId(procName);
          Sleep(30);
      }
  
      HANDLE hProc = OpenProcess(PROCESS_ALL_ACCESS, 0, procId);
  
      if (hProc &amp;&amp; hProc != INVALID_HANDLE_VALUE)
      {
          void* loc = VirtualAllocEx(hProc, 0, MAX_PATH, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
  
          WriteProcessMemory(hProc, loc, dllPath, strlen(dllPath) + 1, 0);
  
          HANDLE hThread = CreateRemoteThread(hProc, 0, 0, (LPTHREAD_START_ROUTINE)LoadLibraryA, loc, 0, 0);
  
          if (hThread)
          {
              CloseHandle(hThread);
          }
      }
  
      if (hProc)
      {
          CloseHandle(hProc);
      }
      return 0;
  }
  
  
  </code></pre>
  
  <p>Why won't in particular my injector work under Wine (and the other ones)? I guess that's a more complicated question than it seems to be at first but maybe someone knows the answer to that.</p>
  
  <p>I'm just looking for a simple method to inject Windows DLLs into Windows applications running on Linux with Wine. Is there a way to do that? Also if someone knows how to modify the simple injector under Windows code to make it work with Wine and explain why those particular modifications have to be in place to make it work it'd be very appreciated. </p>
  
  <p>Thank You for your time.</p>
  
  <p>Greetings</p>