<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>born2c0de's Blog &#187; secrets</title>
	<atom:link href="http://www.sanchitkarve.com/blog/tag/secrets/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sanchitkarve.com/blog</link>
	<description>Demystifying Code Internals, Secrets and more…</description>
	<lastBuildDate>Sat, 07 Aug 2010 16:49:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>The Windows Green-Screen</title>
		<link>http://www.sanchitkarve.com/blog/2009/01/the-windows-green-screen/</link>
		<comments>http://www.sanchitkarve.com/blog/2009/01/the-windows-green-screen/#comments</comments>
		<pubDate>Sat, 17 Jan 2009 16:28:58 +0000</pubDate>
		<dc:creator>born2c0de</dc:creator>
				<category><![CDATA[Code Internals]]></category>
		<category><![CDATA[green screen]]></category>
		<category><![CDATA[secrets]]></category>
		<category><![CDATA[video playback internal design]]></category>
		<category><![CDATA[videos within images]]></category>
		<category><![CDATA[windows xp]]></category>

		<guid isPermaLink="false">http://www.sanchitkarve.com/blog/?p=59</guid>
		<description><![CDATA[I wanted to post this a few years back but I just didn&#8217;t have the time. This is something really interesting and it seems that nobody else has come across this little secret. Many members from dreamincode.net Forums asked me how I could make my signature show videos running in the background and I&#8217;ve finally [...]]]></description>
			<content:encoded><![CDATA[<p>I wanted to post this a few years back but I just didn&#8217;t have the time.</p>
<p>This is something really interesting and it seems that nobody else has come across this little secret.</p>
<p>Many members from <a title="dream.in.code" href="http://www.dreamincode.net" target="_blank">dreamincode.net Forums</a> asked me <strong>how I could make my signature show videos running in the background</strong> and I&#8217;ve finally found time to explain how.</p>
<p>This is how my Forum Signature looks like (or looked like when I was writing this post) :<img class="size-full wp-image-62  alignleft" title="b2c_sig" src="http://www.sanchitkarve.com/blog/wp-content/uploads/2009/01/b2c_sig.png" alt="b2c_sig" width="350" height="80" /></p>
<p style="text-align: left;">
<p style="text-align: left;">
<p style="text-align: left;">
<p style="text-align: left;">
<p>To see how this works, follow these steps:</p>
<ol>
<li style="text-align: left;">Open your favourite media player and play any video file.</li>
<li>Ensure that the media player window is covering the image above.</li>
<li>Now, minimize the media player.</li>
<li>You should now see a portion of the video being played on the image as if the image itself were a media player.</li>
</ol>
<p>Awesome, isn&#8217;t it?</p>
<p>I figured this out while I was experimenting with an application of mine which tried to modify Media Player Classic on-the-fly.</p>
<p>It seems that in Windows XP (might also be true for other windows OSes and other OSes), Video files can only be displayed on a portion of the screen that has a particular colour. The video can only be displayed on a portion of the screen which is currently displaying a specific colour.</p>
<p><strong>That specific colour is RGB(16,0,16).</strong></p>
<p>Try it out for yourself. Create an image with a background colour of RGB(16,0,16) like this:<img class="alignnone size-full wp-image-64" title="b2c_test_screen" src="http://www.sanchitkarve.com/blog/wp-content/uploads/2009/01/b2c_test_screen.png" alt="b2c_test_screen" width="640" height="480" /></p>
<p>Now play any video over this image and minimize the video player. The video should now be visible on the image.</p>
<p>My guess as to why this works is that Windows (or other OSes) needs to be able to figure out where a video should be displayed when a media player requests for playback. According to me, this has been <strong>intentionally included</strong> in the video playback design.</p>
<p><strong>If the media player just provided co-ordinates of a rectangle</strong> to the OS for displaying the video, that would mean that if any other application was placed on top of the media player window, the video would be displayed over the application&#8217;s interface which would not allow the user to see the application&#8217;s user interface (forms, controls etc.)</p>
<p>Here&#8217;s what I think they did to fix the problem.</p>
<p>The principle behind this design could have been that &#8220;<em>if a video could be displayed only within a rectangle that displayed only a specific colour, no overlapping application would be affected.</em>&#8221;</p>
<p>But which colour would be best suitable for this purpose? Black is the first colour that comes to my mind for obvious reasons but black is a common colour and is used frequently in desktop wallpapers or in user interface elements.</p>
<p>Hence they chose a colour that&#8217;s <strong>technically not black but would look just like black</strong> and hence they must have come up with the colour RGB(16,0,16)</p>
<p>My reasoning probably isn&#8217;t correct but I&#8217;m pretty sure that the real reason is based somewhere along the lines.</p>
<p><strong>I just find it ironic that something that behaves just like a green screen doesn&#8217;t even have a hint of green in its colour code </strong>(<em>its <strong>16,0,16</strong></em><em> in </em><em><strong>RGB</strong></em>) <img src='http://www.sanchitkarve.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>As I&#8217;m still not sure if this works on other operating systems, I&#8217;d appreciate it if you could test this on your operating system and post the result as a comment to this post. Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sanchitkarve.com/blog/2009/01/the-windows-green-screen/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Visual Basic 6 Internal Event Handling</title>
		<link>http://www.sanchitkarve.com/blog/2009/01/visual-basic-6-internal-event-handling/</link>
		<comments>http://www.sanchitkarve.com/blog/2009/01/visual-basic-6-internal-event-handling/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 07:49:34 +0000</pubDate>
		<dc:creator>born2c0de</dc:creator>
				<category><![CDATA[Code Internals]]></category>
		<category><![CDATA[secrets]]></category>
		<category><![CDATA[vb6]]></category>
		<category><![CDATA[visual basic]]></category>

		<guid isPermaLink="false">http://www.sanchitkarve.com/blog/?p=48</guid>
		<description><![CDATA[VB6 calls control events in a very specific way. It&#8217;s impressive but the design of event handling results in losing a certain number of guaranteed bytes per control used. By losing bytes, I am referring to the addition of redundant bytes in the executable code. I studied the entire structure with Disassemblers and debuggers and [...]]]></description>
			<content:encoded><![CDATA[<p>VB6 calls control events in a very specific way. It&#8217;s impressive but the design of event handling results in losing a certain number of guaranteed bytes per control used. By losing bytes, I am referring to the addition of redundant bytes in the executable code.</p>
<p>I studied the entire structure with Disassemblers and debuggers and found out that the total number of redundant bytes is  governed by the following formula:</p>
<p><strong>Total Redundant Bytes = SUMMATION OF (4 x (Number_Of_Events + 6 &#8211; Events_Used) ) FROM 1 TO N</strong></p>
<p><em>where:<br />
<strong>N</strong> = Total Number of Controls Used<br />
<strong>Number_Of_Events</strong> = Total Number Events Supported by a Control (Different for each control)<br />
<strong>Events_Used</strong> = Number of Events Used for each control.</em></p>
<p>So Imagine a simple form having two text boxes and 1 command button for a simple login box, considering that only the following events are used:<br />
<em>Form_Load()<br />
Command1_Click()</em><br />
The Total number of Redundant Bytes is:<br />
(4*(31+6-1)) + 2*(4*(24+6)) + (4*(17+6-1)) = 472<br />
1 FORM + 2 TEXT BOXES + 1 CMD BTN</p>
<p>That&#8217;s <strong>472 unnecessary bytes</strong> just for a simple login box using absolutely no user-written code.</p>
<p>Many people refer to VB6 as Visual Bloatware, and you now know why <img src='http://www.sanchitkarve.com/blog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.sanchitkarve.com/blog/2009/01/visual-basic-6-internal-event-handling/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Does Minesweeper Cheat?</title>
		<link>http://www.sanchitkarve.com/blog/2009/01/does-minesweeper-cheat/</link>
		<comments>http://www.sanchitkarve.com/blog/2009/01/does-minesweeper-cheat/#comments</comments>
		<pubDate>Fri, 16 Jan 2009 07:21:32 +0000</pubDate>
		<dc:creator>born2c0de</dc:creator>
				<category><![CDATA[Myths]]></category>
		<category><![CDATA[minesweeper]]></category>
		<category><![CDATA[secrets]]></category>

		<guid isPermaLink="false">http://www.sanchitkarve.com/blog/?p=46</guid>
		<description><![CDATA[I&#8217;ve come across a few people who believe that minesweeper lays down only half the number of bombs and only adds the other half on the board as the game progresses. I debugged the game myself and have found that it is completely false. However, the game ensures that you don&#8217;t click a bomb on [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve come across a few people who believe that minesweeper lays down only half the number of bombs and only adds the other half on the board as the game progresses.</p>
<p>I debugged the game myself and have found that it is completely false. However, the game ensures that you don&#8217;t click a bomb on the first click. Hence, if the first click is a bomb, <strong>it is removed from the grid and placed at the first empty location from the coordinate (0,0) i.e. the top-left location</strong>.</p>
<p>Hence, if you clicked on (3,2) which originally had a bomb, it would be removed from (3,2) and placed at (0,0) if that location were empty.</p>
<p>This can also be verified without using a debugger. Use the xyzzy cheat to enable the white pixel at the top-left corner of the screen. Then, find a location which contains a bomb (ie. black pixel at top-left corner of the screen) but don&#8217;t click it. Now, move your cursor to the top-left corner of the screen and check if it has a bomb.</p>
<p>Now click on the previous location which had a bomb and you&#8217;ll notice that there isn&#8217;t a bomb once you click it. Then move your cursor to the top-left corner of the board and you&#8217;ll notice that the bomb has been shifted to the top-left location.</p>
<p>Minesweeper cheats FOR you and not against you to ensure that you can start the game without clicking a bomb everytime.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sanchitkarve.com/blog/2009/01/does-minesweeper-cheat/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Microsoft does it differently</title>
		<link>http://www.sanchitkarve.com/blog/2009/01/microsoft-does-it-differently/</link>
		<comments>http://www.sanchitkarve.com/blog/2009/01/microsoft-does-it-differently/#comments</comments>
		<pubDate>Thu, 08 Jan 2009 22:34:32 +0000</pubDate>
		<dc:creator>born2c0de</dc:creator>
				<category><![CDATA[Code Internals]]></category>
		<category><![CDATA[secrets]]></category>
		<category><![CDATA[strings]]></category>
		<category><![CDATA[visual basic]]></category>

		<guid isPermaLink="false">http://www.sanchitkarve.com/blog/?p=12</guid>
		<description><![CDATA[A while back I was studying the Len() function of VB6 and I came across something interesting. Contrary to our belief that this function counts the number of characters in a string and returns it, it actually does something totally different. Here’s how it works. When any string is stored in VB, it is automatically [...]]]></description>
			<content:encoded><![CDATA[<p>A while back I was studying the Len() function of VB6 and I came across something interesting.</p>
<p>Contrary to our belief that this function counts the number of characters in a string and returns it, it actually does something totally different.</p>
<p>Here’s how it works.</p>
<p>When any string is stored in VB, it is automatically stored in this format (in unicode):</p>
<p>Suppose the String is “ABC”:</p>
<p><span style="font-family: &quot;Courier New&quot;;">06 00 00 00 41 00 42 00 43 00</span></p>
<p>The 41 to 43 part is a typical unicode style of storing strings, but 2 unicode characters before that, the number of bytes occupied by the string (including zeros) is stored (which is similar to Pascal style strings).<br />
Hence 06 stands for 6 bytes occupied by “ABC” (since it’s stored as A,0,B,0,C,0)</p>
<p><strong>So all that the Len() does is read 4 bytes before the beginning of the string and return that value itself, instead of calculating the length of the string.<br />
</strong></p>
<p>So actually, the Len Function does nothing except read the length from the string format and return it.<br />
Want to see how they do it?<br />
Here’s the Disassembled Listing of the Len() Function MSVBVM60.DLL DLL File.</p>

<div class="wp_syntax"><div class="code"><pre class="asm" style="font-family:monospace;">__vbaLenBstr <span style="color: #000000; font-weight: bold;">proc</span> <span style="color: #000000; font-weight: bold;">near</span>
   string = <span style="color: #000000; font-weight: bold;">dword</span> <span style="color: #000000; font-weight: bold;">ptr</span> 4
&nbsp;
   <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">esp</span><span style="color: #339933;">+</span>string<span style="color: #009900; font-weight: bold;">&#93;</span> <span style="color: #666666; font-style: italic;">; eax points to string</span>
   <span style="color: #00007f; font-weight: bold;">test</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #00007f;">eax</span> <span style="color: #666666; font-style: italic;">; ZF,SF,PF = EAX and EAX</span>
   <span style="color: #00007f; font-weight: bold;">jz</span> <span style="color: #000000; font-weight: bold;">short</span> <span style="color: #000000; font-weight: bold;">break</span> <span style="color: #666666; font-style: italic;">; If String is Null then break from loop</span>
   <span style="color: #00007f; font-weight: bold;">mov</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">&#91;</span><span style="color: #00007f;">eax</span><span style="color: #339933;">-</span><span style="color: #0000ff;">4</span><span style="color: #009900; font-weight: bold;">&#93;</span> <span style="color: #666666; font-style: italic;">; Gets Unicode Length stored before string.</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">; Here’s how Text from textbox is stored internally:</span>
   <span style="color: #666666; font-style: italic;">; If text is born2c0de then in memory:</span>
   <span style="color: #666666; font-style: italic;">; (0×12 0×00) 0×00 0×00 (0×62 0×00 …)</span>
   <span style="color: #666666; font-style: italic;">; ie. length of string in bytes(unicode) (here 18 bytes)</span>
   <span style="color: #666666; font-style: italic;">; followed by a Unicode 0 (0×00 0×00)</span>
   <span style="color: #666666; font-style: italic;">; followed by the actual string in unicode</span>
   <span style="color: #666666; font-style: italic;">; (’b’ 00 ‘o’ 00 … ‘e’ 00)</span>
   <span style="color: #666666; font-style: italic;">; So [eax-4] just gets the unicode length of</span>
   <span style="color: #666666; font-style: italic;">; string which already is stored when a</span>
   <span style="color: #666666; font-style: italic;">; string is taken as input from keyboard.</span>
&nbsp;
   <span style="color: #666666; font-style: italic;">; The Len() function doesn’t even calculate length!!!</span>
   <span style="color: #00007f; font-weight: bold;">shr</span> <span style="color: #00007f;">eax</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">1</span> <span style="color: #666666; font-style: italic;">; Divides Length by 2 to get Actual Length.</span>
   <span style="color: #666666; font-style: italic;">; Uses eax so it can be used as a return value.</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">break</span><span style="color: #339933;">:</span>
   <span style="color: #00007f; font-weight: bold;">retn</span> 4
__vbaLenBstr <span style="color: #000000; font-weight: bold;">endp</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.sanchitkarve.com/blog/2009/01/microsoft-does-it-differently/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
