<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[DLL-Injection ohne Fehler ... und ohne Erfolg!]]></title><description><![CDATA[<p>Hi,<br />
ich bin grade dabei eine Funktion zur Automatischen DLL-Injection zu schreiben,hab<br />
jetzt schon ein paar Tutorials/Sources gelesen,<br />
der folgende Code baut also auf diesen Quellen auf.</p>
<p>Aber erst mal will ich euch das Problem erklären:</p>
<p>Alles schein prima zu klappen,er compiliert und führt das Programm aus,nur es<br />
tut sich nichts,die DLL wird nicht geladen...<br />
An der DLL und an get_handle liegts nicht ,hab ich beides gecheckt.<br />
Außerdem scheinen alle genutzten Funktionen richtig ausgeführt zu werden (wird im Code gecheckt).<br />
Ich finde einfach keinen Fehler <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Hoffe ihr könnt mir helfen.<br />
Schon mal vielen Dank</p>
<p>Hier der Code:</p>
<pre><code class="language-cpp">#define _WIN32_WINNT 0x500
#include &lt;windows.h&gt;
#include &lt;tlhelp32.h&gt;
#include &lt;iostream&gt;
using namespace std;

HANDLE get_handle(char* ); 
int InjectDll(HANDLE ,char* );

int main(void)
{
  if(InjectDll(get_handle(&quot;notepad.exe&quot;),&quot;test.dll&quot;) == -1)
   cout &lt;&lt; &quot;return = -1&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;return = 0&quot; &lt;&lt; endl; 
  system(&quot;PAUSE&quot;); 
  return 1;  
}

/********************************************************************/

HANDLE get_handle(char* exe_name)         
{
  HANDLE hProcessSnap;
  HANDLE hProcess;
  PROCESSENTRY32 pe32;
  DWORD dwPriorityClass;

  hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
  pe32.dwSize = sizeof( PROCESSENTRY32 );

  do
  {
    if (strcmp(pe32.szExeFile,exe_name) == 0 )
    {
     hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID );
     CloseHandle( hProcessSnap );
     return hProcess;
    }
  } while( Process32Next( hProcessSnap, &amp;pe32 ) );

}

/********************************************************************/

int InjectDll(HANDLE hProcess,char* dll_to_inject)
{
        LPVOID VirtualMem;
        LPTHREAD_START_ROUTINE ThreadAddr;
        HMODULE KernelModul;
        DWORD rw = 0; 

        VirtualMem = VirtualAllocEx(hProcess,NULL,sizeof(dll_to_inject),MEM_COMMIT,PAGE_READWRITE);
        if(!VirtualMem)      
            return -1;

        KernelModul = GetModuleHandle(&quot;Kernel32&quot;);
        if(!KernelModul)      
            return -1;

        ThreadAddr = (LPTHREAD_START_ROUTINE) GetProcAddress(KernelModul,&quot;LoadLibraryA&quot;);
        if(!ThreadAddr)      
            return -1;

        if(!WriteProcessMemory(hProcess,
                           VirtualMem,
                           (LPVOID)dll_to_inject,
                           sizeof(dll_to_inject),
                           &amp;rw))
            return -1;

        if(!CreateRemoteThread(hProcess,
                              NULL,
                              0,
                              ThreadAddr,
                              VirtualMem,
                              0,
                              NULL))
            return -1;
return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/153962/dll-injection-ohne-fehler-und-ohne-erfolg</link><generator>RSS for Node</generator><lastBuildDate>Thu, 23 Jul 2026 09:38:16 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/153962.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 22 Jul 2006 17:18:16 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to DLL-Injection ohne Fehler ... und ohne Erfolg! on Sat, 22 Jul 2006 17:18:16 GMT]]></title><description><![CDATA[<p>Hi,<br />
ich bin grade dabei eine Funktion zur Automatischen DLL-Injection zu schreiben,hab<br />
jetzt schon ein paar Tutorials/Sources gelesen,<br />
der folgende Code baut also auf diesen Quellen auf.</p>
<p>Aber erst mal will ich euch das Problem erklären:</p>
<p>Alles schein prima zu klappen,er compiliert und führt das Programm aus,nur es<br />
tut sich nichts,die DLL wird nicht geladen...<br />
An der DLL und an get_handle liegts nicht ,hab ich beides gecheckt.<br />
Außerdem scheinen alle genutzten Funktionen richtig ausgeführt zu werden (wird im Code gecheckt).<br />
Ich finde einfach keinen Fehler <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f61e.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--disappointed_face"
      title=":("
      alt="😞"
    /></p>
<p>Hoffe ihr könnt mir helfen.<br />
Schon mal vielen Dank</p>
<p>Hier der Code:</p>
<pre><code class="language-cpp">#define _WIN32_WINNT 0x500
#include &lt;windows.h&gt;
#include &lt;tlhelp32.h&gt;
#include &lt;iostream&gt;
using namespace std;

HANDLE get_handle(char* ); 
int InjectDll(HANDLE ,char* );

int main(void)
{
  if(InjectDll(get_handle(&quot;notepad.exe&quot;),&quot;test.dll&quot;) == -1)
   cout &lt;&lt; &quot;return = -1&quot; &lt;&lt; endl;
  cout &lt;&lt; &quot;return = 0&quot; &lt;&lt; endl; 
  system(&quot;PAUSE&quot;); 
  return 1;  
}

/********************************************************************/

HANDLE get_handle(char* exe_name)         
{
  HANDLE hProcessSnap;
  HANDLE hProcess;
  PROCESSENTRY32 pe32;
  DWORD dwPriorityClass;

  hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
  pe32.dwSize = sizeof( PROCESSENTRY32 );

  do
  {
    if (strcmp(pe32.szExeFile,exe_name) == 0 )
    {
     hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID );
     CloseHandle( hProcessSnap );
     return hProcess;
    }
  } while( Process32Next( hProcessSnap, &amp;pe32 ) );

}

/********************************************************************/

int InjectDll(HANDLE hProcess,char* dll_to_inject)
{
        LPVOID VirtualMem;
        LPTHREAD_START_ROUTINE ThreadAddr;
        HMODULE KernelModul;
        DWORD rw = 0; 

        VirtualMem = VirtualAllocEx(hProcess,NULL,sizeof(dll_to_inject),MEM_COMMIT,PAGE_READWRITE);
        if(!VirtualMem)      
            return -1;

        KernelModul = GetModuleHandle(&quot;Kernel32&quot;);
        if(!KernelModul)      
            return -1;

        ThreadAddr = (LPTHREAD_START_ROUTINE) GetProcAddress(KernelModul,&quot;LoadLibraryA&quot;);
        if(!ThreadAddr)      
            return -1;

        if(!WriteProcessMemory(hProcess,
                           VirtualMem,
                           (LPVOID)dll_to_inject,
                           sizeof(dll_to_inject),
                           &amp;rw))
            return -1;

        if(!CreateRemoteThread(hProcess,
                              NULL,
                              0,
                              ThreadAddr,
                              VirtualMem,
                              0,
                              NULL))
            return -1;
return 0;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1102316</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1102316</guid><dc:creator><![CDATA[DLL__]]></dc:creator><pubDate>Sat, 22 Jul 2006 17:18:16 GMT</pubDate></item><item><title><![CDATA[Reply to DLL-Injection ohne Fehler ... und ohne Erfolg! on Mon, 24 Jul 2006 13:19:43 GMT]]></title><description><![CDATA[<p>*push*<br />
Kann mir keiner Helfen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1103164</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1103164</guid><dc:creator><![CDATA[DLL__]]></dc:creator><pubDate>Mon, 24 Jul 2006 13:19:43 GMT</pubDate></item><item><title><![CDATA[Reply to DLL-Injection ohne Fehler ... und ohne Erfolg! on Mon, 24 Jul 2006 14:38:19 GMT]]></title><description><![CDATA[<p>LoadLibraryA schlaegt wahrscheinlich fehl. Du ueberpruefst ja auch nicht den rueckgabewert des von dir erstellten threads sonst haettest du das gesehen!<br />
Und warum schlaegt LoadLibrary fehl?<br />
... weil du mit sizeof nicht die groese des speicherbereiches herausbekommen auf den ein pointer zeigt! Konkret is das hier falsch:</p>
<pre><code class="language-cpp">VirtualMem = VirtualAllocEx(hProcess,NULL,sizeof(dll_to_inject),MEM_COMMIT,PAGE_READWRITE);
...
if(!WriteProcessMemory(hProcess, VirtualMem, (LPVOID)dll_to_inject, sizeof(dll_to_inject), &amp;rw))
</code></pre>
<p>sizeof gibt hier 4 zurueck (weil ein zeiger auf 4bytes gross ist)! und weil in deinen 4 bytes natuerlich nicht der ganze pfad zur dll steht wird LoadLibrary bestimmt &quot;file not found&quot; zurueckgeben.</p>
<p>also ersetz die beiden &quot;sizeof's&quot; jeweils durch strlen(...)+1</p>
<p>obs dann geht weis ich auch nicht aber die chancen stehen schonmal besser <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f642.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--slightly_smiling_face"
      title=":)"
      alt="🙂"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1103220</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1103220</guid><dc:creator><![CDATA[zeiger]]></dc:creator><pubDate>Mon, 24 Jul 2006 14:38:19 GMT</pubDate></item></channel></rss>