<?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[LPVOID konvertieren in char[]?]]></title><description><![CDATA[<p>Hallo</p>
<p>ich programmiere Trainer für PC Games und habe ein Problem mit dem Konvertieren von LPVOID ein eine Zeichenkette. Ich benötige in der Funktion TrainerBegin() einen Vergleich zwischen den in &quot;readbuf&quot; gespeicherten Werten und Hack[0].defbytes. Das Programm funktioniert zwar auch so ist aber relativ unsicher, weil wenn jemand eine andere Spielversion benutzt für die der Trainer nicht ausgelegt ist werden willkürlich die Hack[0].hackbytes werte in den Prozess geschrieben ohne -&gt; Spiel würde warscheinlich abstürzen.</p>
<pre><code class="language-cpp">// Godmodehack
	TrainerStoreHack(0,
					0x049c0ab8,&quot;\x90\x90\x90\x90\x90\x90&quot;,&quot;\x89\x86\x10\x02\x00\x00&quot;,
					0x049cc5c9,&quot;\x90\x90\x90\x90\x90\x90&quot;,&quot;\x89\x87\x10\x02\x00\x00&quot;,
					0,0,0);
</code></pre>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &quot;Trainer.h&quot;

HWND   Wnd;
HANDLE Hproc;
bool   TrainerInitdone=false;

struct SHack
{
	DWORD addr1;
	DWORD addr2;
	DWORD addr3;
	LPVOID hackbytes1;	// Die manipulierten Werte
	LPVOID hackbytes2;
	LPVOID hackbytes3;
	LPVOID defbytes1;	// In Defbytes stehen die Originalwerte aus dem Spiel
	LPVOID defbytes2;
	LPVOID defbytes3;
};

SHack Hack[16];

void TrainerStoreHack(int array_nr, 
					  DWORD processmemoryadr1, LPVOID enablebytes1, LPVOID disablebytes1,
					  DWORD processmemoryadr2, LPVOID enablebytes2, LPVOID disablebytes2,
					  DWORD processmemoryadr3, LPVOID enablebytes3, LPVOID disablebytes3)
{
	Hack[array_nr].addr1=processmemoryadr1;
	Hack[array_nr].hackbytes1=enablebytes1;
	Hack[array_nr].defbytes1=disablebytes1;

	Hack[array_nr].addr2=processmemoryadr2;
	Hack[array_nr].hackbytes2=enablebytes2;
	Hack[array_nr].defbytes2=disablebytes2;

	Hack[array_nr].addr3=processmemoryadr3;
	Hack[array_nr].hackbytes3=enablebytes3;
	Hack[array_nr].defbytes3=disablebytes3;
}

int TrainerBegin(char *proc)
{
	Wnd = FindWindow(NULL, proc);	// retrieves a handle to the top-level window with the name 'proc' and store it in 'Wnd'
	if (Wnd)							// If no window was found Wnd will be 0, return 0
	{
		LPDWORD PID;
		if (GetWindowThreadProcessId(Wnd,(LPDWORD) &amp;PID))	// retrieves identifier of the process that created the specified window (stored in PID)
		{
			Hproc= OpenProcess(PROCESS_ALL_ACCESS,NULL,(DWORD)PID);	// get handle to the process
			if(Hproc)												// If no process was found the handle will be 0, return 0
			{
				LPVOID readbuf=0;
				if (!ReadProcessMemory(Hproc, (void*)Hack[0].addr1, &amp;readbuf, 6,0) ) // read 0x049c0ab8,  [&quot;\x89\x86\x10\x02\x00\x00&quot;]
				{
					MessageBox(0,&quot;ReadProcessMemory() failed&quot;,errmsg,MB_OK);
					CloseHandle(Hproc);
					return 0;
				}

                // HIER BRAUCHE ICH EINEN VERGLEICH readbuf / Hack[0].defbytes1
                // if (*readbuf* == *Hack[0].defbytes1)
                // {
                //     TrainerInitdone=true;
                //     return 1;	
                // }
			}
			else
			{
				TrainerInitdone=false;
				MessageBox(0,&quot;OpenProcess() failed&quot;,errmsg,MB_OK);
				return 0;
			}
		}
		else
		{
			TrainerInitdone=false;
			MessageBox(0,&quot;GetWindowThreadProcessId() failed&quot;,errmsg,MB_OK);
			return 0;
		}
	}
	else
	{
		TrainerInitdone=false;
		MessageBox(0,&quot;FindWindow() failed - did you start the game?&quot;,errmsg,MB_OK);
		return 0;
	}
	return 0;
}

void TrainerEnd()
{
	if(Hproc)	// did we have a handle?
		CloseHandle(Hproc);
}

bool TrainerWrite(DWORD addr, LPVOID newbyte)
{
	if(Hproc)												// If no process was found the handle will be 0, return 0
	{
		bool suspended=false;
		if (SuspendThread(Hproc) != (DWORD) -1)				// try to stop Thread - it is safer
		suspended=true;										// on succes save this to suspended
		DWORD nbyte=strlen((char*)newbyte);					// by checking our string 'newbyte' we can find out how many bytes we want to write
		FlushInstructionCache(Hproc, (LPVOID)addr , nbyte);	// flush the instruction cache (for safety)
		DWORD ByteWriten;
		if ( (WriteProcessMemory (Hproc, (LPVOID)addr, newbyte, nbyte, &amp;ByteWriten)) &amp;&amp; ByteWriten == nbyte) // write to process
		{
			if(suspended)									// If we have suspended our thread...
				ResumeThread(Hproc);						// ...resume it
			return true;
		}
		else
		{
			MessageBox(0,&quot;WriteProcessMemory () failed&quot;,errmsg,MB_OK);
			return false;
		}
	}
	MessageBox(0,&quot;Hproc invalid&quot;,errmsg,MB_OK);
	return false;	
}

bool TrainerEnableHack(int nhack)
{
	bool status=false;
	if (Hack[nhack].addr1!=0)
	{
		if (!TrainerWrite(Hack[nhack].addr1, Hack[nhack].hackbytes1))
			return status;
	}
	if (Hack[nhack].addr2!=0)
	{
		if(!TrainerWrite(Hack[nhack].addr2, Hack[nhack].hackbytes2))
			return status;
	}
	if (Hack[nhack].addr3!=0)
	{
		if(!TrainerWrite(Hack[nhack].addr3, Hack[nhack].hackbytes3))
			return status;
	}
	return status;
}

bool TrainerDisableHack(int nhack)
{
	bool status=false;
	if (Hack[nhack].addr1!=0)
	{
		TrainerWrite(Hack[nhack].addr1, Hack[nhack].defbytes1);
	}
	if (Hack[nhack].addr2!=0)
		TrainerWrite(Hack[nhack].addr2, Hack[nhack].defbytes2);
	if (Hack[nhack].addr3!=0)
		TrainerWrite(Hack[nhack].addr3, Hack[nhack].defbytes3);
	return status;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/topic/193054/lpvoid-konvertieren-in-char</link><generator>RSS for Node</generator><lastBuildDate>Sun, 27 Sep 2026 18:41:05 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/193054.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 21 Sep 2007 12:40:51 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to LPVOID konvertieren in char[]? on Fri, 21 Sep 2007 12:40:51 GMT]]></title><description><![CDATA[<p>Hallo</p>
<p>ich programmiere Trainer für PC Games und habe ein Problem mit dem Konvertieren von LPVOID ein eine Zeichenkette. Ich benötige in der Funktion TrainerBegin() einen Vergleich zwischen den in &quot;readbuf&quot; gespeicherten Werten und Hack[0].defbytes. Das Programm funktioniert zwar auch so ist aber relativ unsicher, weil wenn jemand eine andere Spielversion benutzt für die der Trainer nicht ausgelegt ist werden willkürlich die Hack[0].hackbytes werte in den Prozess geschrieben ohne -&gt; Spiel würde warscheinlich abstürzen.</p>
<pre><code class="language-cpp">// Godmodehack
	TrainerStoreHack(0,
					0x049c0ab8,&quot;\x90\x90\x90\x90\x90\x90&quot;,&quot;\x89\x86\x10\x02\x00\x00&quot;,
					0x049cc5c9,&quot;\x90\x90\x90\x90\x90\x90&quot;,&quot;\x89\x87\x10\x02\x00\x00&quot;,
					0,0,0);
</code></pre>
<pre><code class="language-cpp">#include &lt;windows.h&gt;
#include &quot;Trainer.h&quot;

HWND   Wnd;
HANDLE Hproc;
bool   TrainerInitdone=false;

struct SHack
{
	DWORD addr1;
	DWORD addr2;
	DWORD addr3;
	LPVOID hackbytes1;	// Die manipulierten Werte
	LPVOID hackbytes2;
	LPVOID hackbytes3;
	LPVOID defbytes1;	// In Defbytes stehen die Originalwerte aus dem Spiel
	LPVOID defbytes2;
	LPVOID defbytes3;
};

SHack Hack[16];

void TrainerStoreHack(int array_nr, 
					  DWORD processmemoryadr1, LPVOID enablebytes1, LPVOID disablebytes1,
					  DWORD processmemoryadr2, LPVOID enablebytes2, LPVOID disablebytes2,
					  DWORD processmemoryadr3, LPVOID enablebytes3, LPVOID disablebytes3)
{
	Hack[array_nr].addr1=processmemoryadr1;
	Hack[array_nr].hackbytes1=enablebytes1;
	Hack[array_nr].defbytes1=disablebytes1;

	Hack[array_nr].addr2=processmemoryadr2;
	Hack[array_nr].hackbytes2=enablebytes2;
	Hack[array_nr].defbytes2=disablebytes2;

	Hack[array_nr].addr3=processmemoryadr3;
	Hack[array_nr].hackbytes3=enablebytes3;
	Hack[array_nr].defbytes3=disablebytes3;
}

int TrainerBegin(char *proc)
{
	Wnd = FindWindow(NULL, proc);	// retrieves a handle to the top-level window with the name 'proc' and store it in 'Wnd'
	if (Wnd)							// If no window was found Wnd will be 0, return 0
	{
		LPDWORD PID;
		if (GetWindowThreadProcessId(Wnd,(LPDWORD) &amp;PID))	// retrieves identifier of the process that created the specified window (stored in PID)
		{
			Hproc= OpenProcess(PROCESS_ALL_ACCESS,NULL,(DWORD)PID);	// get handle to the process
			if(Hproc)												// If no process was found the handle will be 0, return 0
			{
				LPVOID readbuf=0;
				if (!ReadProcessMemory(Hproc, (void*)Hack[0].addr1, &amp;readbuf, 6,0) ) // read 0x049c0ab8,  [&quot;\x89\x86\x10\x02\x00\x00&quot;]
				{
					MessageBox(0,&quot;ReadProcessMemory() failed&quot;,errmsg,MB_OK);
					CloseHandle(Hproc);
					return 0;
				}

                // HIER BRAUCHE ICH EINEN VERGLEICH readbuf / Hack[0].defbytes1
                // if (*readbuf* == *Hack[0].defbytes1)
                // {
                //     TrainerInitdone=true;
                //     return 1;	
                // }
			}
			else
			{
				TrainerInitdone=false;
				MessageBox(0,&quot;OpenProcess() failed&quot;,errmsg,MB_OK);
				return 0;
			}
		}
		else
		{
			TrainerInitdone=false;
			MessageBox(0,&quot;GetWindowThreadProcessId() failed&quot;,errmsg,MB_OK);
			return 0;
		}
	}
	else
	{
		TrainerInitdone=false;
		MessageBox(0,&quot;FindWindow() failed - did you start the game?&quot;,errmsg,MB_OK);
		return 0;
	}
	return 0;
}

void TrainerEnd()
{
	if(Hproc)	// did we have a handle?
		CloseHandle(Hproc);
}

bool TrainerWrite(DWORD addr, LPVOID newbyte)
{
	if(Hproc)												// If no process was found the handle will be 0, return 0
	{
		bool suspended=false;
		if (SuspendThread(Hproc) != (DWORD) -1)				// try to stop Thread - it is safer
		suspended=true;										// on succes save this to suspended
		DWORD nbyte=strlen((char*)newbyte);					// by checking our string 'newbyte' we can find out how many bytes we want to write
		FlushInstructionCache(Hproc, (LPVOID)addr , nbyte);	// flush the instruction cache (for safety)
		DWORD ByteWriten;
		if ( (WriteProcessMemory (Hproc, (LPVOID)addr, newbyte, nbyte, &amp;ByteWriten)) &amp;&amp; ByteWriten == nbyte) // write to process
		{
			if(suspended)									// If we have suspended our thread...
				ResumeThread(Hproc);						// ...resume it
			return true;
		}
		else
		{
			MessageBox(0,&quot;WriteProcessMemory () failed&quot;,errmsg,MB_OK);
			return false;
		}
	}
	MessageBox(0,&quot;Hproc invalid&quot;,errmsg,MB_OK);
	return false;	
}

bool TrainerEnableHack(int nhack)
{
	bool status=false;
	if (Hack[nhack].addr1!=0)
	{
		if (!TrainerWrite(Hack[nhack].addr1, Hack[nhack].hackbytes1))
			return status;
	}
	if (Hack[nhack].addr2!=0)
	{
		if(!TrainerWrite(Hack[nhack].addr2, Hack[nhack].hackbytes2))
			return status;
	}
	if (Hack[nhack].addr3!=0)
	{
		if(!TrainerWrite(Hack[nhack].addr3, Hack[nhack].hackbytes3))
			return status;
	}
	return status;
}

bool TrainerDisableHack(int nhack)
{
	bool status=false;
	if (Hack[nhack].addr1!=0)
	{
		TrainerWrite(Hack[nhack].addr1, Hack[nhack].defbytes1);
	}
	if (Hack[nhack].addr2!=0)
		TrainerWrite(Hack[nhack].addr2, Hack[nhack].defbytes2);
	if (Hack[nhack].addr3!=0)
		TrainerWrite(Hack[nhack].addr3, Hack[nhack].defbytes3);
	return status;
}
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1370121</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1370121</guid><dc:creator><![CDATA[run32.dll]]></dc:creator><pubDate>Fri, 21 Sep 2007 12:40:51 GMT</pubDate></item></channel></rss>