<?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[Pufferüberlaufproblemen]]></title><description><![CDATA[<p>Immer wenn ich mein Projekt laufen lasse bekomme ich folgende Meldung:</p>
<blockquote>
<p>Durch einen Pufferüberlauf in PCFix.exe wurde der interne Programmzustand beschädigt. Klicken Sie auf &quot;Unterbrechen&quot;, um das Programm zu debuggen, oder auf &quot;Weiter&quot;, um es zu beenden.</p>
<p>Weitere Informationen finden Sie im Hilfethema &quot;Gewusst wie: Debugging von Pufferüberlaufproblemen&quot;.</p>
</blockquote>
<p>Hier der Code:</p>
<pre><code class="language-cpp">aus sicherheitsgründen entfernt
</code></pre>
<p>Wenn ich beide Teile laufen lasse bekomme ich den Fehler. Sobald ich ein Teil auskommentiere geht das Programm ohne Fehlermeldung durch.<br />
Hoffe jemand sieht wo der Fehler ist, denn ich starre schon seit 2 Tagen auf den Code, kann den Fehler aber leide nicht ausmachen.</p>
<p>Mit freundlich Grüßen<br />
pc-jedi</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/271062/pufferüberlaufproblemen</link><generator>RSS for Node</generator><lastBuildDate>Sat, 29 Aug 2026 11:19:27 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/271062.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 22 Jul 2010 17:51:14 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Mon, 21 Mar 2011 14:45:47 GMT]]></title><description><![CDATA[<p>Immer wenn ich mein Projekt laufen lasse bekomme ich folgende Meldung:</p>
<blockquote>
<p>Durch einen Pufferüberlauf in PCFix.exe wurde der interne Programmzustand beschädigt. Klicken Sie auf &quot;Unterbrechen&quot;, um das Programm zu debuggen, oder auf &quot;Weiter&quot;, um es zu beenden.</p>
<p>Weitere Informationen finden Sie im Hilfethema &quot;Gewusst wie: Debugging von Pufferüberlaufproblemen&quot;.</p>
</blockquote>
<p>Hier der Code:</p>
<pre><code class="language-cpp">aus sicherheitsgründen entfernt
</code></pre>
<p>Wenn ich beide Teile laufen lasse bekomme ich den Fehler. Sobald ich ein Teil auskommentiere geht das Programm ohne Fehlermeldung durch.<br />
Hoffe jemand sieht wo der Fehler ist, denn ich starre schon seit 2 Tagen auf den Code, kann den Fehler aber leide nicht ausmachen.</p>
<p>Mit freundlich Grüßen<br />
pc-jedi</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930204</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930204</guid><dc:creator><![CDATA[pc-jedi]]></dc:creator><pubDate>Mon, 21 Mar 2011 14:45:47 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Thu, 22 Jul 2010 18:08:29 GMT]]></title><description><![CDATA[<p>Schwer zu sagen. Entweder läuft in FindFileswithoutSubFolder etwas falsch, oder g_pLogfile-&gt;fTextout wird falsch aufgerufen - ich habe Letzteres im Verdacht; der C-Format-String lässt mich vermuten, dass die Parameter schlussendlich in eine *printf-Funktion geschmissen wird, und std::string lässt sich nicht in %s quetschen.</p>
<p>Allerdings kann ich das ohne den betreffenden Code nicht mit Sicherheit sagen; meine Kristallkugel ist in Reparatur.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930207</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930207</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Thu, 22 Jul 2010 18:08:29 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Thu, 22 Jul 2010 18:20:06 GMT]]></title><description><![CDATA[<blockquote>
<p>ich habe Letzteres im Verdacht; der C-Format-String lässt mich vermuten, dass die Parameter schlussendlich in eine *printf-Funktion geschmissen wird, und std::string lässt sich nicht in %s quetschen.</p>
<p>Allerdings kann ich das ohne den betreffenden Code nicht mit Sicherheit sagen; meine Kristallkugel ist in Reparatur.</p>
</blockquote>
<p>g_pLogfile-&gt;fTextout erwartet einen char und schreibt diesen dann in die Logfile.txt</p>
<pre><code class="language-cpp">void CLogfile::Textout (const char *Text)
{
	// Text schreiben und flushen
	fprintf (m_Logfile, Text);
	fflush (m_Logfile);

} // Textout (schwarz)
</code></pre>
<p>Und so wird das Logfile erstellt.</p>
<pre><code class="language-cpp">void CLogfile::CreateLogfile (const string LogName, const string Version)
{
	// Logfile leeren und Kopf schreiben
	m_Logfile = fopen (LogName.c_str(), &quot;w&quot;);

	// Aktuelle Build-Konfiguration ausgeben
	#ifdef _DEBUG
	Textout (&quot;BUILD: DEBUG\n&quot;);
	#else
	Textout (&quot;BUILD: RELEASE\n&quot;);
	#endif

	// Logfile schließen und mit append wieder öffnen
	fclose (m_Logfile);
	m_Logfile = fopen (LogName.c_str(), &quot;a&quot;);

} // CreateLogfile
</code></pre>
<p>Und hier der FindFileswithSubFolder und FindFileswithoutSubFolder.<br />
Der Code ist vl. ein wenig umständlich, aber tut was er soll.</p>
<pre><code class="language-cpp">list&lt;string&gt; FindFileswithSubFolder(const string FileLocation)
{
	HANDLE fHandle;
	WIN32_FIND_DATA wfd;
	list&lt;string&gt; Result;
	list&lt;string&gt;::const_iterator i;
	list&lt;string&gt; Temp;

	fHandle = FindFirstFile((FileLocation + &quot;\\*&quot;).c_str(),&amp;wfd);
	if ( fHandle != INVALID_HANDLE_VALUE)
	{
		do 
		{
			// Eintrag nur behandeln, wenn es nicht . oder .. ist (werden nur bei Unterverzeichnissen mit zurückgeliefert)
			// hier könnte man z.B. auch mit lstrcmp auf . und .. vergleichen, was allerdings nicht ganz so effizient ist
			if (!( (wfd.cFileName[0]=='.') &amp;&amp; ( (wfd.cFileName[1]=='.' &amp;&amp; wfd.cFileName[2]==0) || wfd.cFileName[1]==0 ) ))
			{
				if (wfd.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY)
				{
					Temp = FindFileswithSubFolder(FileLocation + &quot;\\&quot; + wfd.cFileName);
				}
				else
				{
					Result.push_back(FileLocation + &quot;\\&quot; + wfd.cFileName);
				} 
			}
			for(i = Temp.begin(); i != Temp.end(); i++)
			{
				Result.insert(Result.end(),(*i));
			}
			Temp.clear();
		}
		while (FindNextFile(fHandle,&amp;wfd));
	}
	else
	{
		printf(&quot;%#x&quot;,GetLastError());
	}
	FindClose(fHandle);
	return Result;
}

list&lt;string&gt; FindFileswithoutSubFolder(const string FileLocation)
{
	HANDLE fHandle;
	WIN32_FIND_DATA wfd;
	list&lt;string&gt; Result;

	fHandle = FindFirstFile((FileLocation + &quot;\\*&quot;).c_str(),&amp;wfd);
	if ( fHandle != INVALID_HANDLE_VALUE)
	{
		do 
		{
			// Eintrag nur behandeln, wenn es nicht . oder .. ist (werden nur bei Unterverzeichnissen mit zurückgeliefert)
			// hier könnte man z.B. auch mit lstrcmp auf . und .. vergleichen, was allerdings nicht ganz so effizient ist
			if (!( (wfd.cFileName[0]=='.') &amp;&amp; ( (wfd.cFileName[1]=='.' &amp;&amp; wfd.cFileName[2]==0) || wfd.cFileName[1]==0 ) ))
			{
				if (!(wfd.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY))
				{
					Result.push_back(FileLocation + &quot;\\&quot; + wfd.cFileName);
				}
			}
		}
		while (FindNextFile(fHandle,&amp;wfd));
	}
	else
	{
		printf(&quot;%#x&quot;,GetLastError());
	}
	FindClose(fHandle);
	return Result;
}
</code></pre>
<p>Die Fehler Meldung kommt erst am Ende des Programms, wenn es die 5sek Slepp abgewartet hat.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930209</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930209</guid><dc:creator><![CDATA[pc-jedi]]></dc:creator><pubDate>Thu, 22 Jul 2010 18:20:06 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Thu, 22 Jul 2010 18:43:28 GMT]]></title><description><![CDATA[<p>Es geht mir um fTextout, nicht um Textout, diese muss anders aussehen, denn sonst würde</p>
<pre><code class="language-cpp">g_pLogfile-&gt;fTextout (&quot;%s\n&quot;, (*iL));
</code></pre>
<p>nicht kompilieren (*iL ist vom Typ string, nicht char const *).</p>
<p>FindFileswithoutSubFolder sieht größtenteils in Ordnung aus, obwohl ich mir gerade nicht sicher bin, wie FindClose(INVALID_HANDLE_VALUE) reagiert. Du solltest den FindClose-Aufruf fünf Zeilen nach oben verlegen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930216</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930216</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Thu, 22 Jul 2010 18:43:28 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Thu, 22 Jul 2010 18:50:20 GMT]]></title><description><![CDATA[<p>Ok werde FindClose nach oben setzten.</p>
<p>Hier fTextout:</p>
<pre><code class="language-cpp">// fTextout
//
// Aufgabe: formatierten Text ins Logfile schreiben (schwarz)
//
void CLogfile::fTextout (const char *Text, ...)
{
	TCHAR buffer[MAX_BUFFER];  // char-Buffer
	va_list pArgList;          // Liste der übergebenen Argumente

	// String aus den Argumenten erstellen
	va_start (pArgList, Text);
	vsprintf (buffer, Text, pArgList);
	va_end (pArgList);

	// Erzeugten String schreiben
	Textout (buffer);

} // fTextout (schwarz)

// fTextout
//
// Aufgabe: formatierten Text ins Logfile schreiben (farbig)
//
void CLogfile::fTextout (int Color, const char *Text, ...)
{
	TCHAR buffer[MAX_BUFFER];  // char-Buffer
	va_list pArgList;          // Liste der übergebenen Argumente

	// String aus den Argumenten erstellen
	va_start (pArgList, Text);
	vsprintf (buffer, Text, pArgList);
	va_end (pArgList);

	// Erzeugten String schreiben
	Textout (Color, buffer);

} // fTextout (farbig)

// fTextout
//
// Aufgabe: formatierten Text ins Logfile schreiben (farbig, Liste)
//
void CLogfile::fTextout (int Color, bool List,const char *Text, ...)
{
	TCHAR buffer[MAX_BUFFER];  // char-Buffer
	va_list pArgList;          // Liste der übergebenen Argumente

	// String aus den Argumenten erstellen
	va_start (pArgList, Text);
	vsprintf (buffer, Text, pArgList);
	va_end (pArgList);

	// Erzeugten String schreiben
	Textout (Color, List, buffer);

} // fTextout (farbig, Liste)
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1930222</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930222</guid><dc:creator><![CDATA[pc-jedi]]></dc:creator><pubDate>Thu, 22 Jul 2010 18:50:20 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Thu, 22 Jul 2010 19:07:08 GMT]]></title><description><![CDATA[<p>Ja, da sieht man's. fTextOut ist dein Problem (bzw. der Aufruf). So müsste es gehen:</p>
<pre><code class="language-cpp">g_pLogfile-&gt;fTextout (&quot;%s\n&quot;, iL-&gt;c_str());
</code></pre>
<p>...wobei das ganze Konzept nicht besonders hübsch ist. Spricht etwas dagegen, ganz normal auf std::ostream aufzusetzen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930231</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930231</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Thu, 22 Jul 2010 19:07:08 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Thu, 22 Jul 2010 19:10:40 GMT]]></title><description><![CDATA[<blockquote>
<p>..wobei das ganze Konzept nicht besonders hübsch ist.</p>
</blockquote>
<p>Was meinst du mit Konzept?</p>
<blockquote>
<p>Spricht etwas dagegen, ganz normal auf std::ostream aufzusetzen?</p>
</blockquote>
<p>Nein spricht nichts dagegen. Würde nur gerne die Vorteile von ostream wissen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930234</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930234</guid><dc:creator><![CDATA[pc-jedi]]></dc:creator><pubDate>Thu, 22 Jul 2010 19:10:40 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Thu, 22 Jul 2010 22:13:04 GMT]]></title><description><![CDATA[<p>Ich meine das Konzept, Variablen per Ellipse an C-I/O-Funktionen durchzureichen. Komplexe Datentypen kriegst du so überhaupt nicht behandelt, und Typsicherheit ist nicht gegeben - beides hast du ja gerade am eigenen Leib erfahren.</p>
<p>Das wären auch die Vorteile von C++-Streams.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930337</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930337</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Thu, 22 Jul 2010 22:13:04 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Fri, 23 Jul 2010 00:11:26 GMT]]></title><description><![CDATA[<p>Vielen Danke für die Info. Werde das dann mal ausprobieren und mich dann wieder melden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930355</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930355</guid><dc:creator><![CDATA[pc-jedi]]></dc:creator><pubDate>Fri, 23 Jul 2010 00:11:26 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Mon, 21 Mar 2011 14:46:45 GMT]]></title><description><![CDATA[<p>So habe jetzt umgeschrieben und fTextout raus genommen. Benutze nur noch Textout und die sieht jetzt wie folgt aus:</p>
<pre><code class="language-cpp">aus Sicherheitsgründen entfernt
</code></pre>
<p>Bekomme ich immer noch die Fehlermeldung mit Pufferüberlauf</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930896</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930896</guid><dc:creator><![CDATA[pc-jedi]]></dc:creator><pubDate>Mon, 21 Mar 2011 14:46:45 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Fri, 23 Jul 2010 20:30:47 GMT]]></title><description><![CDATA[<p>Mit</p>
<pre><code class="language-cpp">Textout (&quot;PCFix &quot; + Version + &quot; - http://www.christian.duefel.de\nScan &quot;);
</code></pre>
<p>kann das aber nicht die Textout-Funktion sein, die du hier beschrieben hast - der Ausdruck ist vom Typ std::string, nicht char const *.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930898</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930898</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Fri, 23 Jul 2010 20:30:47 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Fri, 23 Jul 2010 20:32:49 GMT]]></title><description><![CDATA[<p>Doch ist sie und funktioniert auch. Da char in string einfach umgewandelt wird.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930901</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930901</guid><dc:creator><![CDATA[pc-jedi]]></dc:creator><pubDate>Fri, 23 Jul 2010 20:32:49 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Fri, 23 Jul 2010 20:39:36 GMT]]></title><description><![CDATA[<p>Ah, ich hab die Definition weiter unten übersehen; dachte, du nimmst noch die alte.</p>
<p>Folgendes:</p>
<pre><code class="language-cpp">ostream os(&amp;m_fb);
</code></pre>
<p>wird vermutlich danebengehen; std::ostreams Konstruktor nimmt als Parameter nur einen Streambuffer. Aber da m_fb schon ein std::ostream ist, kannst du einfach</p>
<pre><code class="language-cpp">m_fb &lt;&lt; Text &lt;&lt; &quot;\n&quot;;
</code></pre>
<p>schreiben. Kompiliert der Konstruktoraufruf oben überhaupt?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930904</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930904</guid><dc:creator><![CDATA[seldon]]></dc:creator><pubDate>Fri, 23 Jul 2010 20:39:36 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Fri, 23 Jul 2010 20:45:56 GMT]]></title><description><![CDATA[<p>m_fb ist ein filebuf. Deshalb kann folgendes:</p>
<pre><code class="language-cpp">m_fb &lt;&lt; Text &lt;&lt; &quot;\n&quot;;
</code></pre>
<p>nicht gehen</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930905</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930905</guid><dc:creator><![CDATA[pc-jedi]]></dc:creator><pubDate>Fri, 23 Jul 2010 20:45:56 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Fri, 23 Jul 2010 21:00:06 GMT]]></title><description><![CDATA[<p>va_list sind nicht typsicher und sind eigentlich C Code.</p>
<p>Wie wäre es mit etwas C++0x:</p>
<pre><code class="language-cpp">namespace variadic {
	void print() {
		std::cout &lt;&lt; std::endl;	
	}
	template&lt;typename Arg, typename ... Remains&gt;
	void print(const Arg&amp; arg, const Remains&amp;... remains) {
		std::cout &lt;&lt; arg;
		print(remains...);
	}	
}
</code></pre>
<p>Sollte so passen. Erfordert aber ein --std=c++0x beim Kompilieren.</p>
<p>Und so tust du's anwenden:</p>
<pre><code class="language-cpp">variadic::print(&quot;Test &quot;, 1, 2, 3, &quot; okay es funktioniert!&quot;);
</code></pre>
]]></description><link>https://www.c-plusplus.net/forum/post/1930907</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930907</guid><dc:creator><![CDATA[Mentras]]></dc:creator><pubDate>Fri, 23 Jul 2010 21:00:06 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Fri, 23 Jul 2010 21:09:28 GMT]]></title><description><![CDATA[<p>Ja das ist zum anzeigen in der Konsole sehr schön, aber ich möchte den Kram in eine Datei schreiben.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930908</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930908</guid><dc:creator><![CDATA[pc-jedi]]></dc:creator><pubDate>Fri, 23 Jul 2010 21:09:28 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Fri, 23 Jul 2010 21:18:22 GMT]]></title><description><![CDATA[<p>ok..</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930910</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930910</guid><dc:creator><![CDATA[Mentras]]></dc:creator><pubDate>Fri, 23 Jul 2010 21:18:22 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Fri, 23 Jul 2010 21:14:46 GMT]]></title><description><![CDATA[<p>Das war jetzt nicht böse gemeint.<br />
Habe die Funktion mit den Argument entfernt. Habe jetzt nur noch eine ganz einfach Funktion die einen String über ostream in eine Datei schreibt. Nur kommt es irgendwo, zu einem Pufferüberlauf, den ich mir nicht erklären kann.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1930911</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1930911</guid><dc:creator><![CDATA[pc-jedi]]></dc:creator><pubDate>Fri, 23 Jul 2010 21:14:46 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Tue, 27 Jul 2010 12:11:47 GMT]]></title><description><![CDATA[<p>Keiner mehr eine Idee?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1932551</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1932551</guid><dc:creator><![CDATA[pc-jedi]]></dc:creator><pubDate>Tue, 27 Jul 2010 12:11:47 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Tue, 27 Jul 2010 12:37:55 GMT]]></title><description><![CDATA[<p>Und der Überlauf kommt beim Schreiben in die Datei ?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1932563</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1932563</guid><dc:creator><![CDATA[scrabbl]]></dc:creator><pubDate>Tue, 27 Jul 2010 12:37:55 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Tue, 27 Jul 2010 12:44:50 GMT]]></title><description><![CDATA[<p>Der Pufferüberlauf kommt am Ende des Programms, wenn alles erledigt ist. Erst kommt 10sec Sleep und wenn ich den 10sec Sleep das Programm per Alt + F4 oder einfach mit X beende kommt kein Pufferüberlauf, aber wenn es sich selbst beendet entsteht ein Pufferüberlauf.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1932567</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1932567</guid><dc:creator><![CDATA[pc-jedi]]></dc:creator><pubDate>Tue, 27 Jul 2010 12:44:50 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Tue, 27 Jul 2010 22:38:46 GMT]]></title><description><![CDATA[<p>Update: Problem hat sich verschoben<br />
ausschnitt aus main.cpp</p>
<pre><code class="language-cpp">// Überschrift erzeugen
	g_pLogfile-&gt;WriteTopic (&quot;Test&quot;);

	// Allocate array for getting ImageBase addresses of
    // all drivers present in system.
    DWORD dwBufferLen = GetImageBaseAddrArrayLen();
    LPVOID* pImageBaseAddrArray = (LPVOID*)new BYTE[ dwBufferLen ];

    DWORD dwBytesReturned = 0;
    // Get the ImageBaseAddresses of all drivers.
    EnumDeviceDrivers( pImageBaseAddrArray,  // array of load addresses
                       dwBufferLen,  // size of array as 0.
                       &amp;dwBytesReturned );

    // Get the total number of drivers. calculate it by
    // total size in bytes/sizeof(void*)
    DWORD nDrivers = dwBufferLen / sizeof(LPVOID);

	PVOID OldValue = NULL;

	for( DWORD Index = 0; Index &lt; nDrivers; ++Index )
    {
        // Get Device Driver informations.
        string sDriverBaseName;
        string sDriverFileName;
        GetDriverInfo( pImageBaseAddrArray[ Index], sDriverBaseName, sDriverFileName );

		// \??\ /
		int iFindIdxMD5Question = sDriverFileName.find( &quot;\\??\\&quot; );
		int iExistQuestion = 0;
		if ( iFindIdxMD5Question != -1 )
		{
			sDriverFileName.erase( 0, 4 );
			iExistQuestion = 1;
		}
		// \Windows\System32
		int iFindIdxMD5Win = sDriverFileName.find( &quot;\\Windows\\System32&quot; );
		if ( iFindIdxMD5Win != -1 )
			sDriverFileName.replace( iFindIdxMD5Win, 17, sSysDir );
		// \WINDOWS\System32
		int iFindIdxMD5Win2 = sDriverFileName.find( &quot;\\WINDOWS\\System32&quot; );
		if ( iFindIdxMD5Win2 != -1 )
			sDriverFileName.replace( iFindIdxMD5Win, 17, sSysDir );
		// \SystemRoot\System32
		int iFindIdxMD5SysRoot = sDriverFileName.find( &quot;\\SystemRoot\\System32&quot; );
		if ( iFindIdxMD5SysRoot != -1 )
			sDriverFileName.replace( iFindIdxMD5SysRoot, 20, sSysDir );
		// \SystemRoot\system32
		int iFindIdxMD5SysRoot2 = sDriverFileName.find( &quot;\\SystemRoot\\system32&quot; );
		if ( iFindIdxMD5SysRoot2 != -1 )
			sDriverFileName.replace( iFindIdxMD5SysRoot2, 20, sSysDir );
		// \SystemRoot\SysWOW64
		int iFindIdxMD5SysWOW64 = sDriverFileName.find( &quot;\\SystemRoot&quot; );
		if ( iFindIdxMD5SysWOW64 != -1 )
			sDriverFileName.replace( iFindIdxMD5SysWOW64, 11, sWinDir );
		// C:\Windows\SysWOW64
		int iFindIdxMD5C = sDriverFileName.find( &quot;C:\\&quot; );
		if ( iFindIdxMD5C == -1 )
			sDriverFileName.insert( 0, &quot;C:\\&quot; );

		// calculating MD5
		HANDLE hFile;
		DWORD dwNumRead = -1;

		if(IsWow64())
			if (!WOW64DisableFsRedirection(&amp;OldValue))
				printf(&quot;WOW64DisableFsRedirection doesn´t work\n&quot;);

		hFile = CreateFile(sDriverFileName.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL);

		if (!WOW64RevertFsRedirection(OldValue))
			printf(&quot;WOW64RevertFsRedirection doesn´t work\n&quot;);

		if(hFile == INVALID_HANDLE_VALUE)
		{
			g_pLogfile-&gt;Textout (&quot;ERROR: INVALID_HANDLE_VALUE&quot; + sDriverFileName);
		}
		else
		{
			//GetFileSize to determine size of buffer for ReadFile
			DWORD BufferSize = GetFileSize(hFile,NULL);

			cout &lt;&lt; &quot;Buffer: &quot; &lt;&lt; BufferSize &lt;&lt;endl;

			char* ReadBuffer = new char [BufferSize];// create a new char * to hold the buffer using the filesize

			//Read from the file:
			if(!ReadFile(hFile, ReadBuffer,BufferSize+1,&amp;dwNumRead,NULL))
			{
				printf (&quot;ReadFile Fail&quot;);
				return 1;
			}

			//To close the file:
			CloseHandle(hFile);

			char hash[32];
			MD5Hash((BYTE*)ReadBuffer,BufferSize,hash);
			free(ReadBuffer);
			if ( iExistQuestion == 1)
			sDriverFileName.insert( 0, &quot;\\??\\&quot;);

			g_pLogfile-&gt;Textout (sDriverBaseName + &quot; : &quot; + sDriverFileName + &quot; : &quot; + hash);

		}
    }
</code></pre>
<p>MD5.cpp</p>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#include &lt;wincrypt.h&gt;
#include &lt;fstream&gt;

using namespace std;

#define MD5LEN  16

void MD5Hash(BYTE hash[],int sz,char sec[])
{
    HCRYPTPROV hProv = 0,hHash = 0;
    BYTE rgbHash[MD5LEN];
    DWORD cbHash = 0;
    char finalhash[32], dig[] = &quot;0123456789abcdef&quot;;
    unsigned int l = 0;

    CryptAcquireContext(&amp;hProv, NULL,NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
    CryptCreateHash(hProv, CALG_MD5, 0, 0, &amp;hHash);
    CryptHashData(hHash, hash, sz, 0);
    cbHash = MD5LEN;
    CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &amp;cbHash, 0);

    for(DWORD i = 0; i &lt; cbHash; i++){
        finalhash[l] = dig[rgbHash[i] &gt;&gt; 4];
        l++;
        finalhash[l] = dig[rgbHash[i] &amp; 0xf];
        l++;
    }

    for(l = 32; l &lt; strlen(finalhash); l++) finalhash[l] = 0;
    strcpy_s(sec, 33, finalhash);
    CryptDestroyHash(hHash);
    CryptReleaseContext(hProv, 0);
}
</code></pre>
<p>DLL_LoadFunction.h</p>
<pre><code class="language-cpp">#include &lt;windows.h&gt;

typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
typedef BOOL (WINAPI *LPFN_WOW64DISABLEWOW64FSREDIRECTION) (PVOID*);
typedef BOOL (WINAPI *LPFN_WOW64REVERTWOW64FSREDIRECTION) (PVOID);

BOOL IsWow64();
BOOL WOW64DisableFsRedirection(PVOID *OldValue);
BOOL WOW64RevertFsRedirection(PVOID OldValue);
</code></pre>
<p>DLL_LoadFunction.cpp</p>
<pre><code class="language-cpp">#include &quot;DLL_LoadFunction.h&quot;

LPFN_ISWOW64PROCESS fnMyIsWow64Process;
LPFN_WOW64DISABLEWOW64FSREDIRECTION fnMyWow64DisableWow64FsRedirection;
LPFN_WOW64REVERTWOW64FSREDIRECTION fnMyWow64RevertWow64FsRedirection;

BOOL IsWow64()
{
    BOOL bIsWow64 = FALSE;

    //IsWow64Process is not available on all supported versions of Windows.
    //Use GetModuleHandle to get a handle to the DLL that contains the function
    //and GetProcAddress to get a pointer to the function if available.

    fnMyIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(
        GetModuleHandle(TEXT(&quot;kernel32&quot;)),&quot;IsWow64Process&quot;);

    if(NULL != fnMyIsWow64Process)
    {
        if (!fnMyIsWow64Process(GetCurrentProcess(),&amp;bIsWow64))
        {
            //handle error
        }
    }
    return bIsWow64;
}

BOOL WOW64DisableFsRedirection(PVOID *OldValue)
{
	fnMyWow64DisableWow64FsRedirection = (LPFN_WOW64DISABLEWOW64FSREDIRECTION) GetProcAddress(
		GetModuleHandle(TEXT(&quot;kernel32&quot;)),&quot;Wow64DisableWow64FsRedirection&quot;);

	if(NULL != fnMyWow64DisableWow64FsRedirection)
	{
		if (!fnMyWow64DisableWow64FsRedirection(OldValue))
		{
			// handel error
			return false;
		}
		else
		{
			return true;
		}
	}
	return false;
}

BOOL WOW64RevertFsRedirection(PVOID OldValue)
{
	fnMyWow64RevertWow64FsRedirection = (LPFN_WOW64REVERTWOW64FSREDIRECTION) GetProcAddress(
		GetModuleHandle(TEXT(&quot;kernel32&quot;)),&quot;Wow64RevertWow64FsRedirection&quot;);

	if(NULL != fnMyWow64RevertWow64FsRedirection)
	{
		if (!fnMyWow64RevertWow64FsRedirection(OldValue))
		{
			// handel error
			return false;
		}
		else
		{
			return true;
		}
	}
	return false;
}
</code></pre>
<p>Wenn wer Fehler oder Optimierungsbedarf sieht immer her damit <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/1932845</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1932845</guid><dc:creator><![CDATA[pc-jedi]]></dc:creator><pubDate>Tue, 27 Jul 2010 22:38:46 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Tue, 27 Jul 2010 23:52:29 GMT]]></title><description><![CDATA[<p>Der ganze Code ist mir zu gross, aber ein paar Dinge:</p>
<pre><code class="language-cpp">LPVOID* pImageBaseAddrArray = (LPVOID*)new BYTE[ dwBufferLen ];
</code></pre>
<p>Wo gibst du den Speicher frei? Vergiss nicht, ihn vor dem <code>delete[]</code> in <code>BYTE*</code> zu casten.</p>
<pre><code class="language-cpp">int iFindIdxMD5Win = sDriverFileName.find( &quot;\\Windows\\System32&quot; );
if ( iFindIdxMD5Win != -1 ) 
            sDriverFileName.replace( iFindIdxMD5Win, 17, sSysDir ); 
// [Noch 5 Mal Codeduplikation]
</code></pre>
<p>Auslagern in Funktionen wäre angebracht.</p>
<pre><code class="language-cpp">char* ReadBuffer = new char [BufferSize];
// [...]
free(ReadBuffer);
</code></pre>
<p>Das resultiert in undefiniertem Verhalten. <strong>Niemals</strong> <code>new</code> / <code>delete</code> mit <code>malloc()</code> / <code>free()</code> mischen**!** <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/26a0.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--warning"
      title=":warning:"
      alt="⚠"
    /></p>
<p>In C++ solltest du primär <code>new</code> / <code>delete</code> bzw. <code>new[]</code> / <code>delete[]</code> verwenden. Noch besser wäre natürlich automatische Speicherverwaltung mittels RAII. Gut möglich, dass hier auch dein Fehler liegt.</p>
<pre><code class="language-cpp">#define MD5LEN  16
</code></pre>
<p>Ziehe für Konstanten <code>const typ</code> einem <code>#define</code> vor.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1932861</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1932861</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Tue, 27 Jul 2010 23:52:29 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Wed, 28 Jul 2010 07:21:46 GMT]]></title><description><![CDATA[<p>Hi</p>
<p>Vielen Dank für deine Hilfe, Nexus <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>
<p>Jetzt bekomme ich folgende Fehlermeldung:</p>
<blockquote>
<p>Run-Time Check Failure #2 - Stack around the variable 'finalhash' was corrupted.</p>
</blockquote>
<pre><code class="language-cpp">#include &lt;iostream&gt;
#include &lt;windows.h&gt;
#include &lt;wincrypt.h&gt;
#include &lt;fstream&gt;

using namespace std;

const int MD5LEN = 16;

void MD5Hash(BYTE hash[],int sz,char sec[])
{
    HCRYPTPROV hProv = 0,hHash = 0;
    BYTE rgbHash[MD5LEN];
    DWORD cbHash = 0;
    char finalhash[32], dig[] = &quot;0123456789abcdef&quot;;
    unsigned int l = 0;

    CryptAcquireContext(&amp;hProv, NULL, NULL, PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
    CryptCreateHash(hProv, CALG_MD5, 0, 0, &amp;hHash);
    CryptHashData(hHash, hash, sz, 0);
    cbHash = MD5LEN;
    CryptGetHashParam(hHash, HP_HASHVAL, rgbHash, &amp;cbHash, 0);

    for(DWORD i = 0; i &lt; cbHash; i++){
        finalhash[l] = dig[rgbHash[i] &gt;&gt; 4];
        l++;
        finalhash[l] = dig[rgbHash[i] &amp; 0xf];
        l++;
    }

    for(l = 32; l &lt; strlen(finalhash); l++) finalhash[l] = 0;
    strcpy_s(sec, 33, finalhash);
    CryptDestroyHash(hHash);
    CryptReleaseContext(hProv, 0);
}
</code></pre>
<p>Ich hoffe hier kann mir auch nochmal wer auf die Sprünge helfen <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/1932916</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1932916</guid><dc:creator><![CDATA[pc-jedi]]></dc:creator><pubDate>Wed, 28 Jul 2010 07:21:46 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Wed, 28 Jul 2010 08:09:37 GMT]]></title><description><![CDATA[<p>Das sieht doch stark danach aus als würdest du irgendwo über das charArray finalhash rausschreiben. Wäre zumindest ein typischer Grund für die Fehlermeldung.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1932925</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1932925</guid><dc:creator><![CDATA[gnarf88]]></dc:creator><pubDate>Wed, 28 Jul 2010 08:09:37 GMT</pubDate></item><item><title><![CDATA[Reply to Pufferüberlaufproblemen on Wed, 28 Jul 2010 08:59:54 GMT]]></title><description><![CDATA[<p>Die ganzen rohen Arrays und C-Strings sind eben schon fehleranfällig. Ein etwas idiomatischeres C++ könnte dir nicht schaden. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f609.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--winking_face"
      title=";)"
      alt="😉"
    /></p>
<p>Für Arrays konstanter Grösse könntest du z.B. <code>std::tr1::array</code> nehmen (falls du TR1 hast, sonst gäbe es das auch in Boost). Ist im Release-Modus genauso schnell wie ein C-Array, aber prüft im Debug-Modus Indizes und spart viel Debugzeit. Hat auch nützliche Methoden wie <code>size()</code> , sodass die Grösse nicht immer separat abgespeichert werden muss. Für dynamische Puffer kannst du statt mit <code>new[]</code> und <code>delete[]</code> selbst was zu basteln Containerklassen wie <code>std::vector</code> nehmen. Die Schnittstelle ist bei <code>array</code> und <code>vector</code> weitgehend einheitlich.</p>
<pre><code class="language-cpp">// std::vector für dynamisches Array, als Beispiel
    std::vector&lt;BYTE&gt; hash;

    // std::tr1::array für statisches Array
    std::tr1::array&lt;char, 32&gt; finalhash;

    hash[index]; // zugreifen auf Elemente (beide Container)
    &amp;hash[0]; // erhalten eines C-Strings für WinAPI-Interoperabilität

    // Statt deiner Schleife, nimm sowas (hat auch nicht quadratische Laufzeit):
    // Variablen wie l erst wenn nötig deklarieren!
    for(unsigned int l = 0; l &lt; finalhash.size(); ++l)
		finalhash[l] = 0;

    // Oder gleich so:
    std::fill(finalhash.begin(), finalhash.end(), 0);    

    // Statt strcpy_s kannst du z.B. std::copy() nehmen
    std::copy(finalhash.begin(), finalhash.end(), sec.begin());

    // Oder meinetwegen auch so, ohne hardgecodete Literale wie 33
    strcpy_s(&amp;sec[0], sec.size(), finalhash);
</code></pre>
<p>Lies dich vielleicht auf <a href="http://www.cplusplus.com" rel="nofollow">www.cplusplus.com</a> in die Dokumentation der STL-Container und -Algorithmen etwas ein. Einen schönen Artikel findest du auch <a href="http://magazin.c-plusplus.net/artikel/Aufbau%20der%20STL%20-%20Teil%201%3A%20Container" rel="nofollow">hier</a>.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1932953</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1932953</guid><dc:creator><![CDATA[Nexus]]></dc:creator><pubDate>Wed, 28 Jul 2010 08:59:54 GMT</pubDate></item></channel></rss>