<?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[Auslesen einer Datei mit 0-Byte Zeichen]]></title><description><![CDATA[<p>Hallo.<br />
Ich versuche gerade den Inhalt einer PNG-Datei auszulesen. fstream erkennt die Länge der Datei richtig, nämlich genau 7043 Zeichen. Wenn ich den Inhalt nun mit fstream::read in einen Char-Array kopiere, so wird dieser ja nur bis zum 1. Vorkommen eines 0-Byte Zeichens kopiert. strlen(str) gibt 7 aus. Also ist das erste 0 Byte Zeichen beim 6. Index was so auch stimmt. Aber wie gehe ich damit nun um? Der letzte Teil der Datei hat den Inhalt &quot;Restrictor_Encrypted_001&quot; den ich manuell mit Notepad++ reineditiert habe. Wenn ich nun aber das 4. letzte Zeichen ausgeben will, also den Unterstrich, kommt nur ein Null Byte Zeichen. Also str[length - 4] == '\0'. Woran liegt das? Ich dachte, dass die Strings durch Funktionen wie strlen, strcpy und strstr gekürzt werden, aber das ist wohl nicht so.</p>
<p>Hier ist mein Code zum auslesen des Inhalts. Ich hoffe ihr könnt mir Tipps dazu geben.</p>
<pre><code class="language-cpp">Validate_t CRestrictor::validate(Type_t *Type)
{
	this-&gt;m_pStream = new fstream(this-&gt;m_pszPath, ios::in | ios::out);

	if (!this-&gt;m_pStream || !this-&gt;m_pStream-&gt;is_open())
	{
		return FileNotExists;
	}

	this-&gt;m_pStream-&gt;seekg(0, fstream::end);
	this-&gt;m_iLength = this-&gt;m_pStream-&gt;tellg();
	this-&gt;m_pStream-&gt;seekg(0, fstream::beg);
	this-&gt;m_pszSource = new char[this-&gt;m_iLength];
	this-&gt;m_pStream-&gt;read(this-&gt;m_pszSource, this-&gt;m_iLength);

	cout &lt;&lt; this-&gt;m_pszSource[1]; // P (stimmt)
	cout &lt;&lt; this-&gt;m_pszSource[this-&gt;m_iLength - 4]; // Null Byte (stimmt nicht, sollte _ sein)
	cout &lt;&lt; strlen(this-&gt;m_pszSource); // 7 (stimmt nicht, in echt 7043)

	if (strstr(this-&gt;m_pszSource, PROT_HEADER&quot;_&quot;PROT_VERSION))
	{
		this-&gt;m_Type = *Type = Encrypted;
		return PasswordNeeded;
	}
	else if (strstr(this-&gt;m_pszSource, PROT_HEADER&quot;_&quot;))
	{
		return FileOutdated;
	}

	this-&gt;m_Type = *Type = Decrypted;
	return PasswordNeeded;
}
</code></pre>
<p>Gruß</p>
<p>(Und bitte nicht denken dass ich hier irgendwas knacken will, ich versuche mich an einem eigenen Dateischutz ;))</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/250403/auslesen-einer-datei-mit-0-byte-zeichen</link><generator>RSS for Node</generator><lastBuildDate>Wed, 16 Sep 2026 01:31:14 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/250403.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 17 Sep 2009 14:24:13 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Auslesen einer Datei mit 0-Byte Zeichen on Thu, 17 Sep 2009 14:24:13 GMT]]></title><description><![CDATA[<p>Hallo.<br />
Ich versuche gerade den Inhalt einer PNG-Datei auszulesen. fstream erkennt die Länge der Datei richtig, nämlich genau 7043 Zeichen. Wenn ich den Inhalt nun mit fstream::read in einen Char-Array kopiere, so wird dieser ja nur bis zum 1. Vorkommen eines 0-Byte Zeichens kopiert. strlen(str) gibt 7 aus. Also ist das erste 0 Byte Zeichen beim 6. Index was so auch stimmt. Aber wie gehe ich damit nun um? Der letzte Teil der Datei hat den Inhalt &quot;Restrictor_Encrypted_001&quot; den ich manuell mit Notepad++ reineditiert habe. Wenn ich nun aber das 4. letzte Zeichen ausgeben will, also den Unterstrich, kommt nur ein Null Byte Zeichen. Also str[length - 4] == '\0'. Woran liegt das? Ich dachte, dass die Strings durch Funktionen wie strlen, strcpy und strstr gekürzt werden, aber das ist wohl nicht so.</p>
<p>Hier ist mein Code zum auslesen des Inhalts. Ich hoffe ihr könnt mir Tipps dazu geben.</p>
<pre><code class="language-cpp">Validate_t CRestrictor::validate(Type_t *Type)
{
	this-&gt;m_pStream = new fstream(this-&gt;m_pszPath, ios::in | ios::out);

	if (!this-&gt;m_pStream || !this-&gt;m_pStream-&gt;is_open())
	{
		return FileNotExists;
	}

	this-&gt;m_pStream-&gt;seekg(0, fstream::end);
	this-&gt;m_iLength = this-&gt;m_pStream-&gt;tellg();
	this-&gt;m_pStream-&gt;seekg(0, fstream::beg);
	this-&gt;m_pszSource = new char[this-&gt;m_iLength];
	this-&gt;m_pStream-&gt;read(this-&gt;m_pszSource, this-&gt;m_iLength);

	cout &lt;&lt; this-&gt;m_pszSource[1]; // P (stimmt)
	cout &lt;&lt; this-&gt;m_pszSource[this-&gt;m_iLength - 4]; // Null Byte (stimmt nicht, sollte _ sein)
	cout &lt;&lt; strlen(this-&gt;m_pszSource); // 7 (stimmt nicht, in echt 7043)

	if (strstr(this-&gt;m_pszSource, PROT_HEADER&quot;_&quot;PROT_VERSION))
	{
		this-&gt;m_Type = *Type = Encrypted;
		return PasswordNeeded;
	}
	else if (strstr(this-&gt;m_pszSource, PROT_HEADER&quot;_&quot;))
	{
		return FileOutdated;
	}

	this-&gt;m_Type = *Type = Decrypted;
	return PasswordNeeded;
}
</code></pre>
<p>Gruß</p>
<p>(Und bitte nicht denken dass ich hier irgendwas knacken will, ich versuche mich an einem eigenen Dateischutz ;))</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1780543</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1780543</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Thu, 17 Sep 2009 14:24:13 GMT</pubDate></item><item><title><![CDATA[Reply to Auslesen einer Datei mit 0-Byte Zeichen on Thu, 17 Sep 2009 14:26:33 GMT]]></title><description><![CDATA[<p>ios::binary</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1780546</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1780546</guid><dc:creator><![CDATA[Leprechaun]]></dc:creator><pubDate>Thu, 17 Sep 2009 14:26:33 GMT</pubDate></item><item><title><![CDATA[Reply to Auslesen einer Datei mit 0-Byte Zeichen on Thu, 17 Sep 2009 14:35:03 GMT]]></title><description><![CDATA[<p>Hi.<br />
Danke - so easy!<br />
Aber dennoch bleibt das Problem mit strstr - wie kann ich das nun Anwenden? Wenn nichts anderes üblicht bleibt kann ich ja aber selber so etwas mit einer Schleife nachbasteln, so wäre es mir aber lieber.</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1780550</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1780550</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Thu, 17 Sep 2009 14:35:03 GMT</pubDate></item><item><title><![CDATA[Reply to Auslesen einer Datei mit 0-Byte Zeichen on Thu, 17 Sep 2009 14:57:35 GMT]]></title><description><![CDATA[<p>theliquidwave schrieb:</p>
<blockquote>
<p>Aber dennoch bleibt das Problem mit strstr - wie kann ich das nun Anwenden?</p>
</blockquote>
<p>Garnicht.<br />
Die Definition eines C Strings besagt nunmal dass 0 das Ende des Strings anzeigt. Ergo hast du keine C Strings und kannst also die C String Funktionen nicht verwenden.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1780568</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1780568</guid><dc:creator><![CDATA[Shade Of Mine]]></dc:creator><pubDate>Thu, 17 Sep 2009 14:57:35 GMT</pubDate></item><item><title><![CDATA[Reply to Auslesen einer Datei mit 0-Byte Zeichen on Thu, 17 Sep 2009 15:14:52 GMT]]></title><description><![CDATA[<p>Hi.<br />
Ok, danke dafür. Meine selbst geschrieben Funktion funktioniert auch ganz gut <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>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1780584</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1780584</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Thu, 17 Sep 2009 15:14:52 GMT</pubDate></item><item><title><![CDATA[Reply to Auslesen einer Datei mit 0-Byte Zeichen on Thu, 17 Sep 2009 15:18:37 GMT]]></title><description><![CDATA[<p>Wenn du Stringoperationen auf Zeichenketten mit Nullzeichen anwenden willst, dann nimm doch std::string.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1780588</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1780588</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 17 Sep 2009 15:18:37 GMT</pubDate></item><item><title><![CDATA[Reply to Auslesen einer Datei mit 0-Byte Zeichen on Thu, 17 Sep 2009 16:42:34 GMT]]></title><description><![CDATA[<p>Hi.<br />
Nein - ich bin kein Freund von std::string <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>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1780627</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1780627</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Thu, 17 Sep 2009 16:42:34 GMT</pubDate></item><item><title><![CDATA[Reply to Auslesen einer Datei mit 0-Byte Zeichen on Thu, 17 Sep 2009 17:21:44 GMT]]></title><description><![CDATA[<blockquote>
<p>Nein - ich bin kein Freund von std::string <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>
</blockquote>
<p>Und warum nicht, wenn man fragen darf? I wants to start a flamewar.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1780647</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1780647</guid><dc:creator><![CDATA[Cox]]></dc:creator><pubDate>Thu, 17 Sep 2009 17:21:44 GMT</pubDate></item><item><title><![CDATA[Reply to Auslesen einer Datei mit 0-Byte Zeichen on Thu, 17 Sep 2009 17:59:50 GMT]]></title><description><![CDATA[<p>Wieso willst du strings (also Zeichenketten) für den inhalt einer PNG-Datei (also reine aten-bytes) nehmen? Ich würd eher sowas wie std::vector&lt;unsigned char&gt; oder ähnliches nehmen.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1780667</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1780667</guid><dc:creator><![CDATA[pumuckl]]></dc:creator><pubDate>Thu, 17 Sep 2009 17:59:50 GMT</pubDate></item><item><title><![CDATA[Reply to Auslesen einer Datei mit 0-Byte Zeichen on Thu, 17 Sep 2009 18:22:51 GMT]]></title><description><![CDATA[<p>Hi.<br />
Ich möchte die Daten nur im String haben um später simpel mittels += Hash zu rechnen. Es ist also eine wirklich simple Lernaufgabe für mich selber.</p>
<p>@ Cox: Ich mag es halt einfach nicht. &quot;Native Typen&quot; wie Char-Arrays gefallen mir besser.</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1780676</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1780676</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Thu, 17 Sep 2009 18:22:51 GMT</pubDate></item><item><title><![CDATA[Reply to Auslesen einer Datei mit 0-Byte Zeichen on Thu, 17 Sep 2009 18:33:49 GMT]]></title><description><![CDATA[<p>theliquidwave schrieb:</p>
<blockquote>
<p>Hi.<br />
Ich möchte die Daten nur im String haben um später simpel mittels += Hash zu rechnen. Es ist also eine wirklich simple Lernaufgabe für mich selber.</p>
<p>@ Cox: Ich mag es halt einfach nicht. &quot;Native Typen&quot; wie Char-Arrays gefallen mir besser.</p>
<p>Gruß</p>
</blockquote>
<p>Ich wiederhole mich: Du wünscht dir Stringoperationen, warum nimmst du nicht std::string?</p>
<p>Das du kein Freund von std::string bist, heißt ja nur, dass du die privaten Elemente nicht benutzen darfst - aber das darf sowieso niemand. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1780681</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1780681</guid><dc:creator><![CDATA[SeppJ]]></dc:creator><pubDate>Thu, 17 Sep 2009 18:33:49 GMT</pubDate></item><item><title><![CDATA[Reply to Auslesen einer Datei mit 0-Byte Zeichen on Thu, 17 Sep 2009 18:58:15 GMT]]></title><description><![CDATA[<p>SeppJ schrieb:</p>
<blockquote>
<p>Das du kein Freund von std::string bist, heißt ja nur, dass du die privaten Elemente nicht benutzen darfst - aber das darf sowieso niemand. <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
</blockquote>
<p>Ich musste zwar 2mal drüber nachdenken, aber um so lustiger wars <img
      src="https://www.c-plusplus.net/forum/plugins/nodebb-plugin-emoji/emoji/emoji-one/1f603.png?v=ab1pehoraso"
      class="not-responsive emoji emoji-emoji-one emoji--grinning_face_with_big_eyes"
      title=":D"
      alt="😃"
    /></p>
]]></description><link>https://www.c-plusplus.net/forum/post/1780689</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1780689</guid><dc:creator><![CDATA[unskilled]]></dc:creator><pubDate>Thu, 17 Sep 2009 18:58:15 GMT</pubDate></item><item><title><![CDATA[Reply to Auslesen einer Datei mit 0-Byte Zeichen on Fri, 18 Sep 2009 06:04:18 GMT]]></title><description><![CDATA[<p>In der C-Standardbibliothek: str* -&gt; mem*</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1780788</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1780788</guid><dc:creator><![CDATA[LordJaxom]]></dc:creator><pubDate>Fri, 18 Sep 2009 06:04:18 GMT</pubDate></item><item><title><![CDATA[Reply to Auslesen einer Datei mit 0-Byte Zeichen on Fri, 18 Sep 2009 12:12:56 GMT]]></title><description><![CDATA[<p>@ LordJaxom: Wow - genial. Danke!<br />
@ andere: Ich möchte halt einfach nicht std::string benutzen. Auch wenn dort möglicherweise Vorteile vorhanden sind mag ich es so nun einmal lieber und funktionieren tut ja auch alles. Jedem das Seine!</p>
<p>Gruß</p>
]]></description><link>https://www.c-plusplus.net/forum/post/1780974</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/1780974</guid><dc:creator><![CDATA[theliquidwave]]></dc:creator><pubDate>Fri, 18 Sep 2009 12:12:56 GMT</pubDate></item></channel></rss>