<?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[Probleme mit Dll Injection]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich versuche gerade testweise eine Dll in mein eigenes Programm zu laden. Es scheint auch alles zu klappen bis zum Aufruf einer Funktion aus der Dll:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

__declspec(dllexport) int __stdcall Funktion(DWORD) {
	MessageBox(0, &quot;Hallo&quot;, &quot;&quot;, 0);
	return 0;
}

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved) {	
    return TRUE;
}
</code></pre>
<p>Wie gesagt, Prozess öffnen und in den &quot;fremden&quot; Prozess schreiben funktioniert. In dem folgenden struct speicher ich die Adressen der Funktionen, den Dll-Namen<br />
und den Namen der Funktion die aufgerufen werden soll.</p>
<pre><code class="language-cpp">struct injection_data {
	HMODULE (WINAPI *fpLoadLibrary)(LPCSTR);
	FARPROC (WINAPI *fpGetProcAddress)(HMODULE, LPCSTR);
	BOOL    (WINAPI *fpFreeLibrary)(HMODULE);

	char    dllpath[256];
	char    entrypoint[256];
	DWORD   dwErrLine;	
	DWORD   entryparam;
};

injection_data IData;

IData.fpLoadLibrary = (HMODULE (WINAPI *)(LPCSTR)) GetProcAddress(hModule, &quot;LoadLibraryA&quot;);
IData.fpGetProcAddress = (FARPROC (WINAPI *)(HMODULE, LPCSTR)) GetProcAddress(hModule, &quot;GetProcAddress&quot;);
IData.fpFreeLibrary = (BOOL (WINAPI *)(HMODULE)) GetProcAddress(hModule, &quot;FreeLibrary&quot;);
strcpy(IData.dllpath, &quot;dll.dll&quot;);
strcpy(IData.entrypoint, &quot;Funktion&quot;);

/* ... */
</code></pre>
<p>Das ist die Funktion, die im fremden Prozess aufgerufen wird:</p>
<pre><code class="language-cpp">static int __stdcall injection_sub(struct injection_data *idata) {
	HINSTANCE hLibrary = idata-&gt;fpLoadLibrary(idata-&gt;dllpath);

	if(hLibrary == 0) { 
		idata-&gt;dwErrLine = __LINE__ - 1; 
		return -1; 
	}

	int (WINAPI *fpEntryFunc)(DWORD);
	fpEntryFunc = (int (__stdcall *)(DWORD)) idata-&gt;fpGetProcAddress(hLibrary, idata-&gt;entrypoint);

	/* Hier ist der Fehler, fpEntryFunc = 0 */

	if (fpEntryFunc == 0) { 
		idata-&gt;dwErrLine = __LINE__ - 1;
		return -1;
	}

	int rc = fpEntryFunc(idata-&gt;entryparam);

	idata-&gt;fpFreeLibrary(hLibrary);

	return rc;
}
</code></pre>
<p>Weiß von euch jemand wieso GetProcAdress da nicht klappt?</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/184549/probleme-mit-dll-injection</link><generator>RSS for Node</generator><lastBuildDate>Mon, 06 Jul 2026 06:12:34 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/184549.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 16 Jun 2007 13:44:08 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Probleme mit Dll Injection on Sat, 16 Jun 2007 13:44:08 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>ich versuche gerade testweise eine Dll in mein eigenes Programm zu laden. Es scheint auch alles zu klappen bis zum Aufruf einer Funktion aus der Dll:</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

__declspec(dllexport) int __stdcall Funktion(DWORD) {
	MessageBox(0, &quot;Hallo&quot;, &quot;&quot;, 0);
	return 0;
}

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved) {	
    return TRUE;
}
</code></pre>
<p>Wie gesagt, Prozess öffnen und in den &quot;fremden&quot; Prozess schreiben funktioniert. In dem folgenden struct speicher ich die Adressen der Funktionen, den Dll-Namen<br />
und den Namen der Funktion die aufgerufen werden soll.</p>
<pre><code class="language-cpp">struct injection_data {
	HMODULE (WINAPI *fpLoadLibrary)(LPCSTR);
	FARPROC (WINAPI *fpGetProcAddress)(HMODULE, LPCSTR);
	BOOL    (WINAPI *fpFreeLibrary)(HMODULE);

	char    dllpath[256];
	char    entrypoint[256];
	DWORD   dwErrLine;	
	DWORD   entryparam;
};

injection_data IData;

IData.fpLoadLibrary = (HMODULE (WINAPI *)(LPCSTR)) GetProcAddress(hModule, &quot;LoadLibraryA&quot;);
IData.fpGetProcAddress = (FARPROC (WINAPI *)(HMODULE, LPCSTR)) GetProcAddress(hModule, &quot;GetProcAddress&quot;);
IData.fpFreeLibrary = (BOOL (WINAPI *)(HMODULE)) GetProcAddress(hModule, &quot;FreeLibrary&quot;);
strcpy(IData.dllpath, &quot;dll.dll&quot;);
strcpy(IData.entrypoint, &quot;Funktion&quot;);

/* ... */
</code></pre>
<p>Das ist die Funktion, die im fremden Prozess aufgerufen wird:</p>
<pre><code class="language-cpp">static int __stdcall injection_sub(struct injection_data *idata) {
	HINSTANCE hLibrary = idata-&gt;fpLoadLibrary(idata-&gt;dllpath);

	if(hLibrary == 0) { 
		idata-&gt;dwErrLine = __LINE__ - 1; 
		return -1; 
	}

	int (WINAPI *fpEntryFunc)(DWORD);
	fpEntryFunc = (int (__stdcall *)(DWORD)) idata-&gt;fpGetProcAddress(hLibrary, idata-&gt;entrypoint);

	/* Hier ist der Fehler, fpEntryFunc = 0 */

	if (fpEntryFunc == 0) { 
		idata-&gt;dwErrLine = __LINE__ - 1;
		return -1;
	}

	int rc = fpEntryFunc(idata-&gt;entryparam);

	idata-&gt;fpFreeLibrary(hLibrary);

	return rc;
}
</code></pre>
<p>Weiß von euch jemand wieso GetProcAdress da nicht klappt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1307217</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1307217</guid><dc:creator><![CDATA[Konrad]]></dc:creator><pubDate>Sat, 16 Jun 2007 13:44:08 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Dll Injection on Sat, 16 Jun 2007 14:22:59 GMT]]></title><description><![CDATA[<p>Prüf mal, welchen Exportnamen &quot;Funktion&quot; in der DLL hat.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1307245</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1307245</guid><dc:creator><![CDATA[[[global:guest]]]]></dc:creator><pubDate>Sat, 16 Jun 2007 14:22:59 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Dll Injection on Sat, 16 Jun 2007 15:40:00 GMT]]></title><description><![CDATA[<p>Hallo,</p>
<p>danke für den Tipp, das war der Fehler. Die Funktion heißt &quot;_Z8Funktionm@4&quot;.<br />
Kann ich auf den Funktionsnamen denn irgendwie Einfluss nehmen?</p>
<p>2. Frage<br />
Wenn ich MessageBox innerhalb der DllMain() aufrufe - wieso wird die dann beim laden nicht angezeigt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1307302</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1307302</guid><dc:creator><![CDATA[Konrad]]></dc:creator><pubDate>Sat, 16 Jun 2007 15:40:00 GMT</pubDate></item><item><title><![CDATA[Reply to Probleme mit Dll Injection on Sat, 16 Jun 2007 16:17:18 GMT]]></title><description><![CDATA[<p><a href="http://www.codeproject.com/dll/SimpleDllP3.asp" rel="nofollow">http://www.codeproject.com/dll/SimpleDllP3.asp</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1307336</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1307336</guid><dc:creator><![CDATA[1.]]></dc:creator><pubDate>Sat, 16 Jun 2007 16:17:18 GMT</pubDate></item></channel></rss>