<?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>Skypher &#187; SkyLined</title>
	<atom:link href="http://skypher.com/index.php/author/skylined/feed/" rel="self" type="application/rss+xml" />
	<link>http://skypher.com</link>
	<description>The blog for absolutely nothing!</description>
	<lastBuildDate>Sat, 25 Feb 2012 11:27:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Transformed polygons fractal rendering engine</title>
		<link>http://skypher.com/index.php/2011/11/19/transformed-polygons-fractal-rendering-engine/</link>
		<comments>http://skypher.com/index.php/2011/11/19/transformed-polygons-fractal-rendering-engine/#comments</comments>
		<pubDate>Sat, 19 Nov 2011 22:07:52 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Art]]></category>
		<category><![CDATA[Browsers]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming Languages]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=692</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve finally had some time to work on a project that renders fractals by repeatedly applying transformations to regular polygons. The code&#8217;s not in any state to release (and, sadly, probably will never be), but I did manage to get the kind of output I was hoping for. So, I&#8217;ve uploaded<br />
<a href="http://skylined.deviantart.com/art/Quasicrystal-3-269869870">a sample</a> to my Deviant Art page. The code is written in JavaScript and renders to the 2d canvas. This sample was rendered in Chrome in a few seconds.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2011/11/19/transformed-polygons-fractal-rendering-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript 1K poptart cat</title>
		<link>http://skypher.com/index.php/2011/05/05/javascript-1k-poptart-cat/</link>
		<comments>http://skypher.com/index.php/2011/05/05/javascript-1k-poptart-cat/#comments</comments>
		<pubDate>Thu, 05 May 2011 11:29:04 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[1k]]></category>
		<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Funny]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=678</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>I wrote another 1K JavaScript demo: <a href="http://skypher.com/SkyLined/demo/1K/poptartcat/">a 1k version of poptart cat</a>. See <a href="http://knowyourmeme.com/memes/nyan-cat-pop-tart-cat">this site</a> for more information about <a href="http://www.prguitarman.com/index.php?id=348">this meme</a>.</p>
<p><iframe style="width:420px; height: 420px; overflow: hidden; border: 0px;" src="http://skypher.com/SkyLined/demo/1K/poptartcat/"></iframe></p>
<p>Minimization tricks include:</p>
<ul>
<li>storing all sprites in a string by encoding each pixel in a sprite in 2 bits and storing 6 bits in each character. Each 2 bit chunk can have one of these values: 0=CR/lF (end of line/start of next line in sprite), 1=transparent (do not draw but move to next pixel), 2 = color 1, 3 = color 2. The colors are chosen from a palette, which is a string containing a number of RGB colors encoded in 3 hex chars (&#8216;fff&#8217;=white, &#8217;000&#8242;=black, &#8216;f00&#8242;=red, etc&#8230;). Each sprite has an associated palette based on the number of the sprite. Most sprites use one of two palettes: a one color palette (&#8216;fff&#8217;) for the background stars) or a two color palette (&#8217;999000&#8242;) for the cat&#8217;s face, paws and tail. A few other palettes are used for the poptart.</li>
<li>storing all sprite maps (meaning which sprites to draw where for each frame) in an array of 6 strings, one for each frame, by encoding each position and sprite number in 3 bits. The background stars are not included; their vertical position is based on their number, by multiplying the number of each star by a certain value. Their horizontal position is based on time, by multiplying the time by a certain value modulus the width of the image and adding a &#8220;random&#8221; value using the value of a different character from the sprites string for each star.</li>
<li>drawing squares instead of sprites to fill larger regions, as sprites need a lot more bytes to store when they get bigger then code to draw a single square does.
<li>using one function for two purposes: to draw a specific sprite at a specific location using a specific palette on the canvas, or to draw a square at a specific location, with specific dimensions and a specific color on the canvas. The function will draw a sprite if there are only 4 arguments provided and a square if there are 5.</li>
<li>using a bit of math to offset multiple sprites based on which frame is being drawn and adding sprites to the sprite. This is done to have the individual sprite maps for each frame contain the same information as much as possible, which makes them easier to compress.
</ul>
<p>I assumed it would be easy to code this one in 1K, but it turned out that it was pretty hard to minimize my code.</p>
<ul>
<li>I started with a large file that draw only the (animated) cat. This wasn&#8217;t optimized in any way: it used one big sprite for each frame, with each pixel being stored as byte containing a value 0-8, representing an index into a palette.</li>
<li>I then cut the cat into smaller individual sprites that I could reuse between frames (eg. the face is always the same, just at a different location). I stored a sprite mapping, meaning which sprite to draw where for each frame. I stored all this information in a string using values between 0-36 encoded using &#8216;[char] = [value].toString(36)&#8221; and read using &#8220;[value] = parseInt([char], 36)&#8221;.</li>
<li>I chose to give each sprite only two colors + transparent (3 values), so I can store each pixel in 2 bits (4 values) and use the unused value to signal &#8216;end of line&#8217; and using &#8216;end of line&#8217; twice for &#8216;end of sprite&#8217;. This meant I could store the entire sprite as 2 bit values. I encoded 3 of these 2 bit values per byte using &#8220;[char] = String.fromCharCode([values]+offset)&#8221; and red them using &#8220;[values] = [char].charCodeAt(0)-offset&#8221;.</li>
<li>I stored the values in the sprite maps as 3 bit values and encoded 2 of these 3 bit values per byte as well.</li>
<li>I wrote code that choses an &#8216;offset&#8217; to use in encoding sprites/sprite maps that caused the resulting string to contain as many of the same bytes as the code, which allows better compression.</li>
<li>At this point I was down to ~1.2K compressed. By reusing code for two purposes (eg. the &#8216;f&#8217; function) and rearranging/rewriting code to have it contain as many repeated strings as possible to allow better compression, I as able to get it down to ~1.01K.</li>
<li>Finally, I optimized my png compressor code to work together with the poptart cat code; eg. do not use &#8216;eval&#8217; to run the decompressed code, which then uses setTimeout to start the animation, but use &#8216;setTimeout&#8217; directly. This allowed me to squeeze everything into 1K.</li>
</ul>
<p>Because manually editing 2/3 bit values stored in 8 bit characters + offset is impractical, and because some of the values where calculated rather than hand-picked. I wrote  my development code to generate the final code and data automatically. This means I have a somewhat documented, readable version of the <a href="http://skypher.com/SkyLined/demo/1K/poptartcat/1knyan6.html">test container HTML</a> and the actual <a href="http://skypher.com/SkyLined/demo/1K/poptartcat/1knyan6.js">JavaScript</a> code. The test container will load the code, which will show the animation slowed down to 1 frame per second and output the final code below the animation. The final code is what I pumped through my to-be-released <a href="http://code.google.com/p/jssfx/">JsSfx</a> png compressor.</p>
<p>Afterwards, I realized that there are a few ways in which I could have improved on the code by doing a few things differently:</p>
<ul>
<li>Save data as unicode strings; this allows storing not 6 bits per byte, but (effectively) 16 per 2 bytes. This could reduce the size of the data by about 128 bytes, but would use more bytes to store the non-unicode characters outside of the strings.</li>
<li>Save each entry for each sprite map in a separate string, meaning store the x coordinates in one string, the y coordinates in another and the sprite number in a third. This should result in data that can be compressed better.</li>
<li>Use scaling for sprites to be able to draw the background, rainbow and body of poptart cat using sprites as well instead of separate code to draw squares. This would use less bytes than having code to draw the cat using both sprites and squares.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2011/05/05/javascript-1k-poptart-cat/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Mandelbrot fractal rendering engine</title>
		<link>http://skypher.com/index.php/2011/01/13/javascript-mandelbrot-fractal-rendering-engine/</link>
		<comments>http://skypher.com/index.php/2011/01/13/javascript-mandelbrot-fractal-rendering-engine/#comments</comments>
		<pubDate>Thu, 13 Jan 2011 00:33:59 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=668</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve put a few pieces of JavaScript together to create an interactive Mandelbrot fractal rendering engine <a href="http://skypher.com/SkyLined/demo/FractalZoomer/Mandel.html">here</a>. You can zoom into any area and adjust the number of iterations.</p>
<p>Suggestions and comments are appreciated; I have a few ideas of my own, such as allowing you to link to specific zoom settings, but I&#8217;m not sure when I&#8217;ll have time to add them.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2011/01/13/javascript-mandelbrot-fractal-rendering-engine/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Window Zoom Chrome Extension</title>
		<link>http://skypher.com/index.php/2011/01/02/window-zoom-chrome-extension/</link>
		<comments>http://skypher.com/index.php/2011/01/02/window-zoom-chrome-extension/#comments</comments>
		<pubDate>Sun, 02 Jan 2011 12:40:08 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Extensions]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming Languages]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=664</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve released my first <a href="https://chrome.google.com/extensions">Chrome Extension</a>, which allows you to zoom certain HTML element to full window size. This is especially useful with embedded videos: where you can normally choose between watching as a tiny element embedded in a website or watching full screen, this extension gives you a third option: full window.<br />
While viewing an element full window, you can resize the window and the element will be resized accordingly.</p>
<p>Source code <a href="http://code.google.com/p/chrome-window-zoom-extension/">here</a>, install it <a href="https://chrome.google.com/webstore/detail/mpgjeecnfhippncndbojafcnpocpekcj/">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2011/01/02/window-zoom-chrome-extension/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>w32 speaking shellcode &#8211; Pwn in style</title>
		<link>http://skypher.com/index.php/2010/12/31/w32-speaking-shellcode-pwn-in-style/</link>
		<comments>http://skypher.com/index.php/2010/12/31/w32-speaking-shellcode-pwn-in-style/#comments</comments>
		<pubDate>Fri, 31 Dec 2010 13:26:36 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Shellcode]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=659</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>Over the past few weeks I created a <a href="http://code.google.com/p/w32-speaking-shellcode/">new shellcode</a> that uses the <a href="http://msdn.microsoft.com/en-us/library/ee705648.aspx">Microsoft Speech API</a> to have the target computer say &#8220;You got pwned!&#8221; over the speakers. Needless to say, the practical applications are myriad, from impressing women in bars to expediting world peace. However, I expect that the most common application will be people impressing their friends with their 1337 hacker skills.</p>
<p>The size of the shellcode is 242 bytes (add 5 for stack alignment and 39 for EAT bypass). It has all the usual bells and whistles: OS/SP independent, null-free, optional stack alignment and EAT bypass and no register requires a specific value for it to run correctly. </p>
<p>Get the code <a href="http://code.google.com/p/w32-speaking-shellcode/downloads/detail?name=w32-speaking-shellcode.zip">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/12/31/w32-speaking-shellcode-pwn-in-style/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Merry Christmas and a Happy New Year!</title>
		<link>http://skypher.com/index.php/2010/12/22/merry-christmas-and-a-happy-new-year/</link>
		<comments>http://skypher.com/index.php/2010/12/22/merry-christmas-and-a-happy-new-year/#comments</comments>
		<pubDate>Wed, 22 Dec 2010 17:11:54 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Chrome]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=656</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>In case you don&#8217;t get my card: Merry Christmas and a Happy New Year, JavaScript style:<br />
<a href="http://skypher.com/SkyLined/demo/PerlinSimplexNoiseSnow/snow.html">http://skypher.com/SkyLined/demo/PerlinSimplexNoiseSnow/snow.html</a></p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/12/22/merry-christmas-and-a-happy-new-year/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JsSfx3.2 &#8211; JavaScript compression tool updated.</title>
		<link>http://skypher.com/index.php/2010/12/09/jssfx3/</link>
		<comments>http://skypher.com/index.php/2010/12/09/jssfx3/#comments</comments>
		<pubDate>Thu, 09 Dec 2010 20:46:06 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[demo]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Python]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=647</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://skypher.com/index.php/2010/11/28/perlin-flames/">previous post</a>, I explained how you can manually optimize JavaScript for size and/or create self-extracting compressed script using <a href="http://code.google.com/p/jssfx/">JsSfx</a>. Today I release an updated version of JsSfx, which compresses script to even smaller sizes than the previous version and, as far as I know, smaller sizes than any other JavaScript compressor.</p>
<p>JsSfx is designed for use in the <a href="http://www.scene.org/">demo scene</a>, where people often create <a href="http://pouet.net/prodlist.php?platform[]=JavaScript">JavaScript demos</a> in a very limited number of bytes (and often a power of 2, such as <a href="http://skypher.com/SkyLined/demo/256b/SkyLined%20-%20Ascii%20art%20Julia-set%20rotozoom%20(Thanks%20to%20shr%5EMolecoola).htm">256 bytes</a>, <a href="http://pouet.net/prodlist.php?type[]=512b&#038;platform[]=JavaScript">512 bytes</a>, <a href="http://skypher.com/SkyLined/demo/PerlinFlames/p4sfx.html">1Kb</a>, <a href="http://pouet.net/prodlist.php?type[]=4k&#038;platform[]=JavaScript">4Kb</a>, etc&#8230;). In August/September of 2010, a demo competition was held at <a href="http://js1k.com/">js1k.com</a>. Contestants were asked to submit JavaScript demos that were 1024 bytes or less in size. A few of the entries used compression to fit a larger script into 1k. One of the more complex entries, <a href="http://www.p01.org/releases/WOLF1K/js1k.htm">WOLF1k</a> by <a href="http://www.p01.org">p01</a>, uses <a href="http://benalman.com/">cowboy</a>&#8216;s <A href="https://github.com/cowboy/javascript-packify">packify</a> to compress 1370 bytes of script into <a href="http://www.p01.org/releases/WOLF1K/wolf1k.js">exactly 1024 bytes</a>. To see how well JsSfx was doing, I tested JsSfx1.2 on the 1370 uncompressed bytes of WOLF1k and found it reduced it to 1031 bytes. Obviously, I needed to improve on that, so I came up with an improved decoder for JsSfx3. The latest version compresses WOLF1k to 1013 bytes in utf-8 and 986 bytes using <a href="http://en.wikipedia.org/wiki/ISO/IEC_8859-1">ISO 8859-1</a> (aka. latin-1). However, it does take a while to find the best way to compress scripts. JsSfx3 was developed with size in mind and not speed: it takes a minute or two to compress scripts of a few kilobytes. Compressing large scripts such as <a href="http://jquery.com/">jQuery</a> is not practical: it would probably take days on a fast computer.</p>
<p>There&#8217;s another competition over at <a href="http://js1k.com/2010-xmas/">js1k.com</a> at the moment, but unfortunately compression is not allowed this time. <a href="http://twitter.com/js1k">Peter van der Zee</a>, who hosts the contest, seems to believe that using compression removes the need for &#8220;hand tuning&#8221; your script and that this removes the fun. I disagree and believe WOLF1k and my own Perlin Noise script prove that. Also, I can assure you that a lot of &#8220;hand tuning&#8221; went into JsSfx3.2.</p>
<p>Anyway, if you&#8217;re working on small JavaScript demos and would like to see how small you can get your script, please give the <a href="http://code.google.com/p/jssfx/downloads/detail?name=JsSfx.zip">new version</a> a try and let me know if it works for you!</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/12/09/jssfx3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>JavaScript Perlin flames source</title>
		<link>http://skypher.com/index.php/2010/11/30/javascript-perlin-flames-source/</link>
		<comments>http://skypher.com/index.php/2010/11/30/javascript-perlin-flames-source/#comments</comments>
		<pubDate>Tue, 30 Nov 2010 15:01:40 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[1k]]></category>
		<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Opera]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Safari]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=642</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>Many people have asked me for the uncompressed source of my <a href="http://skypher.com/index.php/2010/11/28/perlin-flames/">Perlin flames script</a>. At first I though about keeping it private, so people would have to reverse engineer the compressed code. After all, reverse engineering is how I learned the majority of what I know about programming today. But I realized that not everybody may have time to waste on such efforts when I wanted to have a copy of the original source of <a href="http://www.p01.org/releases/WOLF1K/wolf1k.js">WOLF1k</a> and couldn&#8217;t be bothered to decode it myself. So, I&#8217;ve made the uncompressed source available <a href="http://skypher.com/SkyLined/demo/PerlinFlames/p4.js">here</a>. This is the source after I manually optimized it for size and it doesn&#8217;t have any useful inline documentation: I found it much easier to memorize what each part of 1k of script does than continuously update documentation as I wrote it.</p>
<p>I still believe it is a good exercise to extract the source from the encoded version, as you learn a lot more that way, but I&#8217;ll leave that choose to you.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/11/30/javascript-perlin-flames-source/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript Perlin flames in 1k</title>
		<link>http://skypher.com/index.php/2010/11/28/perlin-flames/</link>
		<comments>http://skypher.com/index.php/2010/11/28/perlin-flames/#comments</comments>
		<pubDate>Sun, 28 Nov 2010 22:50:29 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[1k]]></category>
		<category><![CDATA[Browsers]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[demo]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=617</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p><a href="http://encyclopediadramatica.com/TL;DR">TL;DR</a> =&gt; see the Perlin noise flames script in action <a href="http://skypher.com/SkyLined/demo/PerlinFlames/p4sfx.html">here</a>. The rest of this article details how the script works and how I reduced its size to under 1k.</p>
<p>One of my side projects is creating JavaScript <a href="http://en.wikipedia.org/wiki/Demo_(computer_programming)">demos</a>. Unfortunately, I hardly ever find time to finish and <a href="http://pouet.net/user.php?who=24551">release</a> anything. You may recognize the following: I think of a new effect that would be really cool. I start working on some code and get a proof-of-concept working. The code proves how awesome the end result would be, but it&#8217;s nowhere near production quality. Then I waste a lot of time on fine-tuning some aspects of the code (size, speed, various design/implementation details). Finally I get bored with it and/or distracted by a new project. I have a zillion of such projects doing nothing on my harddrive.</p>
<p>Luckily, this is not always the case. I was going through some of the awesome codes of the <a href="http://js1k.com/">js1k</a> contest recently and got interested in <a href="http://en.wikipedia.org/wiki/Perlin_noise">Perlin noise</a>. I started working on my own version and after only a few iterations I had a pretty decent flame effect going. The amazing thing about Perlin noise is how easy it is to create a decent looking effect with very little effort.</p>
<p>The code starts by creating an array with <a href="http://en.wikipedia.org/wiki/Random_number_generation">random numbers</a>. The code needs to have a way of requesting the same random number twice and getting the same value and an array is the fasted way to do this. Using an index into the array as a seed, the code can read the same random number as often as it wants without changes. One side effect is that because the size of the array is limited, you will at some point have to reuse the same data. However, if you make sure the size of this array is sufficiently large (and a prime), this will not be noticed by the average user. Next the code creates three canvas elements. Two are used as off-screen buffers to generate the flames and smoke in, the third is visible and used to combine the two into the final effect. Two one dimentional arrays of perlin data are generated, one for the shape of the flames and one which is used as a <a href="http://en.wikipedia.org/wiki/Map_projection">projection map</a> for the movement of the flames. For each pixel, the projection map tells the code where in the shape map it should read a byte to use as the color value for that pixel. The color value is converted to an RGB value using two table, one for the flames and one for the smoke. The pixels are drawn at the bottom of the off-screen buffers and all pixels in these buffers are shifted upwards. For the flames, all pixels in the buffer are darkened, causing them to die out as the move up.</p>
<p>When I got his working, I got obsessed, as one does, with size and speed: I wanted to have it run at 60fps and shrink the size of the code to 1k or less. Guaranteeing the frame rate is hard to achieve because the effect needs a few CPU intensive operations to calculate each frame. I could reduce the quality to achieve a higher frame rate, but that would defeat the original goal of creating a nice looking effect. After a bit of tweaking, it is now running at 60fps on my machine without too much loss of quality. However, it may be less on older machines.</p>
<p>Shrinking the size of JavaScript is mostly about rewriting/rearranging your algorithms to be more size efficient. How to best do this depends on the algorithm and many such optimizations are one-offs: they apply only to that one code construct and you&#8217;ll probably never use the same trick again. However, there are a few tricks that I find I can commonly use on all scripts to reduce their size:</p>
<ol>
<li>Use one character, global variable and function names:
<ul>
<li>&quot;<strong>var iCounter = 0</strong>&quot; =&gt; &quot;<strong>i=0</strong>&quot;</li>
</ul>
</li>
<li>Do not use expensive keywords:
<ul>
<li>&quot;<strong>x=new Array();</strong>&quot; =&gt; &quot;<strong>x=[];</strong>&quot;</li>
<li>&quot;<strong>while(){}</strong>&quot;, &quot;<strong>do {} while ()</strong>&quot; =&gt; &quot;<strong>for(){}</strong>&quot;</li>
<li>&quot;<strong>x=Math.floor(x);</strong>&quot; =&gt; &quot;<strong>x=x&gt;&gt;0;</strong>&quot;</li>
<li>&quot;<strong>x=Math.round(x);</strong>&quot; =&gt; &quot;<strong>x=x-.5&gt;&gt;0;</strong>&quot;</li>
<li>&quot;<strong>x=Math.ceil(x);</strong>&quot; =&gt; &quot;<strong>x=x+.999&gt;&gt;0;</strong>&quot;
<div>(if you don&#8217;t mind rounding errors)</div>
</li>
<li>&quot;<strong>x=Math.pow(2,x);</strong>&quot; =&gt; &quot;<strong>x=1&lt;&lt;x;</strong>&quot;</li>
<li>&quot;<strong>x=x/256;</strong>&quot; =&gt; &quot;<strong>x=x>>8;</strong>&quot;
<div>(if you don&#8217;t mind the result being rounded down to an integer)</div>
</li>
</ul>
</li>
<li>Choose the most efficient notation for numbers:
<ul>
<li>&quot;<strong>0&#215;10</strong>&quot; =&gt; &quot;<strong>16</strong>&quot;</li>
<li>&quot;<strong>0&#215;20000</strong>&quot; =&gt; &quot;<strong>1&lt;&lt;17</strong>&quot;</li>
<li>&quot;<strong>1000</strong>&quot; =&gt; &quot;<strong>1e3</strong>&quot;</li>
<li>&quot;<strong>.0001</strong>&quot; =&gt; &quot;<strong>1e-4</strong>&quot;</li>
</ul>
</li>
<li>Optimize how you use the <a href="http://en.wikipedia.org/wiki/For_loop#Three-expression_for_loops">three-expression</a> in for-loops:
<ul>
<li>&quot;<strong>for(x=0;x&lt;50;x++){}</strong>&quot; =&gt; &quot;<strong>for(x=50;x&#8211;;){}</strong>&quot;</li>
<li>&quot;<strong>for(x=50;x&#8211;;){}y=5;</strong>&quot; =&gt; &quot;<strong>for(x=50;x&#8211;;y=5){}</strong>&quot;
<div>(this saves 1 semi-colon, but may slow your script down a little)</div>
</li>
</ul>
</li>
<li>Remove comments and unneeded curly braces, white-space and semi-colons:
<ul>
<li>&quot;<strong>for (&#8230;) { a+=b; c*=a; }</strong>&quot; =&gt; &quot;<strong>for(&#8230;)a+=b,c*=a;</strong>&quot;</li>
<li>&quot;<strong>function () {a+=b;}</strong>&quot; =&gt; &quot;<strong>function(){a+=b}</strong>&quot;</li>
</ul>
<div>(Some of this can be done automatically and I&#8217;ve recently added code to do this to <a href="http://code.google.com/p/jssfx/">JsSfx</a>)</div>
</li>
<li>Save often used complex values in variables:
<ul>
<li>&quot;<strong>x=document.createElement(&#8230;);document.body.appendchild(x);</strong>&quot; =&gt; &quot;<strong>d=document;x=d.createElement(&#8230;);d.body.appendchild(x);</strong>&quot;</li>
<li>&quot;<strong>y=x*x*x+x*x-4;z=x*x*x+x*x+5;</strong>&quot; =&gt; &quot;<strong>y=(q=x*x*x+x*x)-4;z=q+5;</strong>&quot;</li>
</ul>
</li>
<li>Combine setting values:
<ul>
<li>&quot;<strong>x=0;y=0;</strong>&quot; =&gt; &quot;<strong>x=y=0;</strong>&quot;</li>
<li>&quot;<strong>x=0;y=[0];</strong>&quot; =&gt; &quot;<strong>y=[x=0];</strong>&quot;</li>
</ul>
</li>
</ol>
<p>This list does not claim to be complete. If you feel that I have omitted something useful, please leave a comment.</p>
<p>After manual optimization of code size, you can probably shrink the size of you script a lot further using some form of compression and self-extraction. I <a href="http://skypher.com/index.php/2010/08/10/jssfx/">published</a> <a href="http://code.google.com/p/jssfx/">JsSfx</a>, which implements a custom compression and generates self-extracting JavaScript. I developed the compression technique it uses based on a number of assumptions:</p>
<ol>
<li>JavaScript often contains the same character sequence a number of times (eg. strings like &quot;<strong>for(</strong>&quot; will appear quite often)</li>
<li>JavaScript normally uses <a href="http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters">a small sub-set</a> of all the bytes <a href="http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf">valid in JavaScript</a>.</li>
<li>The size of the script to be compressed is assumed to be small. Therefore, compression can save only so many bytes and the size of the decoder will have a large impact on the size of the final script. A large decoder negates the benefit of a good compression ratio.</li>
</ol>
<p>The compression used in JsSfx works by replacing all instances of an often repeated string with one character that is not used in the script. It saves the character and the string it replaced as well. In a way this is similar to the manual step number 6 I explained above. Here&#8217;s an example:<br />
<code><br />
code="o = document.createElement('a');\r\ndocument.body.appendChild(o);"<br />
&nbsp;<br />
</code><br />
May be compressed as:<br />
<code><br />
keys="A"<br />
code="o = AcreateElement('a');\r\nAbody.appendChild(o);Adocument.";<br />
&nbsp;<br />
</code><br />
In the above example, &#8220;document.&#8221; was replaced by &#8220;A&#8221;. The keys variable contains the list of the characters used to replace strings (in this case only &#8220;A&#8221;). The code variable stores the original string, with the replacements, followed by the key and the replaced string. The original code can be restored by splitting the code string into sub-strings using the keys. In the above example this leads to an array of sub-strings like this:<br />
<code><br />
sub_string=["o = ", "createElement('a');\r\n", "body.appendChild(o);", "document."];<br />
&nbsp;<br />
</code><br />
By removing the last string from the array and joining the remaining strings back together using this string, the decoder can recreate the original.</p>
<p>The original Perlin noise flames script was about 3.2k in size (excluding comments and whitespace). I manually reduced this to ~1.2k (a lot of gain comes from replacing long variables names with one character). Using JsSfx, I got it just below 1k.</p>
<p>I&#8217;d like to thank the people at <a href="http://pouet.net/prod.php?which=56334">pouet.net</a> for feedback that allowed me to get this script to run on all browsers except MSIE. I&#8217;ve tested it on MSIE9 platform preview, but it doesn&#8217;t work (for unknown reasons).</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/11/28/perlin-flames/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Bypassing Export address table Address Filter (EAF)</title>
		<link>http://skypher.com/index.php/2010/11/17/bypassing-eaf/</link>
		<comments>http://skypher.com/index.php/2010/11/17/bypassing-eaf/#comments</comments>
		<pubDate>Wed, 17 Nov 2010 20:46:48 +0000</pubDate>
		<dc:creator>SkyLined</dc:creator>
				<category><![CDATA[Assembler]]></category>
		<category><![CDATA[PoC]]></category>
		<category><![CDATA[Programming Languages]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Shellcode]]></category>

		<guid isPermaLink="false">http://skypher.com/?p=605</guid>
		<description><![CDATA[<br />
<b>Warning</b>:  preg_split() [<a href='function.preg-split'>function.preg-split</a>]: Compilation failed: lookbehind assertion is not fixed length at offset 14 in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>77</b><br />
<br />
<b>Warning</b>:  Invalid argument supplied for foreach() in <b>/home/c3682jgn/domains/skypher.com/public_html/wp-content/themes/braille/options/plugins.php</b> on line <b>78</b><br />
]]></description>
			<content:encoded><![CDATA[<p>(An unfinished version of this blog post was accidentally published last week. In case you got a hold of a copy: I&#8217;ve made only small modifications, so no need to re-read the entire post. However, I did not released the source of my PoC shellcode earlier, so you may want to <a href="https://code.google.com/p/w32-msgbox-shellcode/source/diff?path=/trunk/w32-msgbox-shellcode.asm&#038;format=side&#038;r=4">check if out</a>).</p>
<p>In early September this year Microsoft released their <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=c6f0a6ee-05ac-4eb6-acd0-362559fd2f04">Enhanced Mitigation Experience Toolkit v2.0</a> (EMET), which includes a new &#8220;pseudo&#8221;-mitigation called Export address table Address Filter (EAF). I decided to have a look at how this mitigation attempts to prevent exploits from succeeding and how an attacker might bypass it. For people that suffer from <a href="http://encyclopediadramatica.com/TL;DR">tl;dr</a> syndrome, I&#8217;ve put my conclusion up front:</p>
<p><strong>It is my conclusion that EAF should be effective at preventing most current shellcode from executing and therefore a useful mitigation. However, it is relatively simple to bypass. Proof of concept code to do this can be found <a href="https://code.google.com/p/w32-msgbox-shellcode/">here</a>. I expect that if EAF becomes a common mitigation, attackers will update their shellcodes to bypass it. I cannot think of any effective way in which EAF can be updated that would not be relatively simple to bypass as well.</strong></p>
<p>EAF works by setting a <a href="http://en.wikipedia.org/wiki/Breakpoint#Hardware_implementation">hardware breakpoint</a> on the <a href="http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx">export address tables</a> of the ntdll.dll and kernel32.dll modules in a process. When the breakpoint is triggered, EAF determines if the code that is trying to access the export address table is valid code for that process or malicious code injected into the process through an exploit. Most exploits will at some point inject and run shellcode into the target process. One of the first thing most shellcodes do is determine where certain functions are loaded in memory. This is commonly and easiest done by going through the list of loaded modules and reading their export address tables. When shellcode reads the export address tables of ntdll.dll and/or kernel32.dll, EAF detects the shellcode and terminates the process, preventing the exploit from running successfully.</p>
<p>I tested EAF with<a href="https://code.google.com/p/w32-msgbox-shellcode/">one of my shellcodes</a> that shows a message in a popup window when it runs successfully. <a href="http://code.google.com/hosting/search?q=SkyLined+shellcode+win32">All my shellcodes</a> scan the export address tables of loaded modules to find certain functions. This is a common technique used by almost all shellcodes that EAF is designed to detect. So, enabling EAF should prevent my shellcode, and most others, from working.</p>
<p>I use <a href="http://code.google.com/p/testival/">testival</a> to test my shellcode because it makes things easy to automate and I can copy+paste the output into this blog to show you what is going on. When my shellcode is run, it shows a popup dialog box and then triggers an int3 debugger breakpoint. Here&#8217;s the output of w32-testival.exe for a successful run of my shellcode:<br />
<code><br />
C:\Dev\Shellcode\w32-msgbox-shellcode&gt;w32-testival [$]=ascii:w32-msgbox-shellcode.bin eip=$ --verbose --eh --eh<br />
Allocating 0x1000 bytes of memory... ok. (address: 0x00030000)<br />
Setting data and registers:<br />
  [0x00030000]              = 8C bytes of data.<br />
  eax                       = 0xDEADBEEF (default)<br />
  ecx                       = 0xDEADBEEF (default)<br />
  edx                       = 0xDEADBEEF (default)<br />
  ebx                       = 0xDEADBEEF (default)<br />
  esp                       = ??? (unmodified)<br />
  ebp                       = 0xDEADBEEF (default)<br />
  esi                       = 0xDEADBEEF (default)<br />
  edi                       = 0xDEADBEEF (default)<br />
  eip                       = 0x00030000 ($)<br />
Registering Structured Exception Handler (SEH)...ok.<br />
Registering Vectored Exception Handler (VEH)...ok.<br />
Executing shellcode by jumping to 0x00030000...First chance debugger breakpoint exception at 0x0003008B.<br />
Second chance debugger breakpoint exception at 0x0003008B.<br />
&nbsp;<br />
C:\Dev\Shellcode\w32-msgbox-shellcode&gt;<br />
&nbsp;<br />
</code><br />
Of course, you cannot see the popup dialog box in this output, but you can see that the int3 debugger breakpoint at the end of the shellcode was executed. This means that it ran successfully.</p>
<p>After enabling EAF I tried executing the shellcode again and found that it still worked. So either EAF was not working or I was doing something wrong. I contacted my friends at MS who developed the tool and asked them to help me find out what was going on. They explained that in order to install the EAF mitigation, EMET needs to create a new thread in the process first, which means the mitigation is not enabled immediately on startup. To make sure that the mitigation is installed, you need to wait a bit before running your shellcode. So, I added a new switch to testival that allows it to wait a given number of milliseconds before executing the shellcode. Using this new feature, I tried again and this time EAF successfully blocked my shellcode, as you can see here:</p>
<p><code><br />
C:\Dev\Shellcode\w32-msgbox-shellcode&gt;w32-testival [$]=ascii:w32-msgbox-shellcode.bin eip=$ --verbose --eh --eh --delay=1000<br />
Allocating 0x1000 bytes of memory... ok. (address: 0x00030000)<br />
Setting data and registers:<br />
  [0x00030000]              = 8C bytes of data.<br />
  eax                       = 0xDEADBEEF (default)<br />
  ecx                       = 0xDEADBEEF (default)<br />
  edx                       = 0xDEADBEEF (default)<br />
  ebx                       = 0xDEADBEEF (default)<br />
  esp                       = ??? (unmodified)<br />
  ebp                       = 0xDEADBEEF (default)<br />
  esi                       = 0xDEADBEEF (default)<br />
  edi                       = 0xDEADBEEF (default)<br />
  eip                       = 0x00030000 ($)<br />
Registering Structured Exception Handler (SEH)...ok.<br />
Registering Vectored Exception Handler (VEH)...ok.<br />
Waiting for 1000 milliseconds...ok.<br />
Executing shellcode by jumping to 0x00030000...First chance single step exception at 0x00030054: A trace trap or other single-instruction mechanism signaled that one instruction has been executed.<br />
Second chance exception 0xC0000409 at 0x00030054.<br />
&nbsp;<br />
C:\Dev\Shellcode\w32-msgbox-shellcode&gt;<br />
&nbsp;<br />
</code><br />
This time the process is terminated early by a single step exception. This is because the EAF mitigation has detect that the shellcode accessed the export address table and decided to terminate the application rather than allow the shellcode to continue executing. This shows that EAF should be able to detect and protect against exploits that use most common shellcode.</p>
<p>I decided not to reverse EAF in order to find out how it works, but rather try to guess how it works and guess how it might by bypassed and try if it works. I assumed that EAF works by checking the location of the instruction that is accessing the export address table: if it is located inside the code segment of a loaded module, EAF assumes it is valid code and allowed it to continue. Otherwise, EAF assumes it is malicious code and terminates the process. If my hypothesis is correct, it might be possible to have the shellcode use a sequence of instructions inside the code segment of a loaded module that can be used to read memory. Because in this case, EAF will assumes that valid code is attempting to read the export address table rather than my shellcode and allow the code to continue.</p>
<p>To test this, I created a modified version of my shellcode that works like this:</p>
<ul>
<li>First, the shellcode finds out where ntdll.dll is loaded in memory as usual.</li>
<li>Second, it finds out where the code segment for ntdll.dll is located.</li>
<li>Third, it scans the code segment for a specific instruction sequence that can be used to read arbitrary memory.</li>
<li>Finally, it calls this instruction sequence to read the export address table, rather than read it directly.</li>
</ul>
<p>This is effectively the same as doing a ret-into-libc attack, something which EAF is not designed to block and this should therefore be able to bypass it. It turns out that the RtlGetCurrentPeb function has a useful instruction sequence. This sequence is static across Windows versions and SPs and exactly 4 bytes long, which means it is easy to write code to find it:<br />
<code><br />
 ntdll32!RtlGetCurrentPeb:<br />
     64a118000000    mov     eax,dword ptr fs:[00000018h]<br />
     8b4030          mov     eax,dword ptr [eax+30h]<br />
     c3              ret<br />
&nbsp;<br />
</code><br />
By setting EAX to the memory address you want to read (minus 0&#215;30) and calling the second instruction, you can read arbitrary memory into EAX.</p>
<p>The first time I tested my code, it was blocked by EAF while scanning for the instruction sequence in the code segment. It turns out that the export address table is located at the start of the code segment of ntdll.dll, so my scan for the instruction sequence was accessing it and triggering EAF.  Luckily, the RtlGetCurrentPeb function is not located anywhere near the start of the code segment in any version of ntdll.dll, so it was relatively easy to avoid this by skipping over the first 0&#215;1000 bytes of the code segment.</p>
<p>Here is the result for my modified shellcode, which is only 30 bytes larger than the original:<br />
<code><br />
C:\Dev\Shellcode\w32-msgbox-shellcode&gt;w32-testival [$]=ascii:w32-msgbox-shellcode-eaf.bin eip=$ --verbose --eh --eh --delay=1000<br />
Allocating 0x1000 bytes of memory... ok. (address: 0x00030000)<br />
Setting data and registers:<br />
  [0x00030000]              = AB bytes of data.<br />
  eax                       = 0xDEADBEEF (default)<br />
  ecx                       = 0xDEADBEEF (default)<br />
  edx                       = 0xDEADBEEF (default)<br />
  ebx                       = 0xDEADBEEF (default)<br />
  esp                       = ??? (unmodified)<br />
  ebp                       = 0xDEADBEEF (default)<br />
  esi                       = 0xDEADBEEF (default)<br />
  edi                       = 0xDEADBEEF (default)<br />
  eip                       = 0x00030000 ($)<br />
Registering Structured Exception Handler (SEH)...ok.<br />
Registering Vectored Exception Handler (VEH)...ok.<br />
Waiting for 1000 milliseconds...ok.<br />
Executing shellcode by jumping to 0x00030000...First chance single step exception at 0x76FBA045: A trace trap or other single-instruction mechanism signaled that one instruction has been executed.<br />
First chance single step exception at 0x76FAFFCE: A trace trap or other single-instruction mechanism signaled that one instruction has been executed.<br />
First chance single step exception at 0x76FAFFCE: A trace trap or other single-instruction mechanism signaled that one instruction has been executed.<br />
First chance single step exception at 0x76FAFFCE: A trace trap or other single-instruction mechanism signaled that one instruction has been executed.<br />
&lt;snip&gt;(Many more single step exceptions)&lt;snip&gt;<br />
First chance single step exception at 0x76FAFFCE: A trace trap or other single-instruction mechanism signaled that one instruction has been executed.<br />
First chance debugger breakpoint exception at 0x000300AA.<br />
Second chance debugger breakpoint exception at 0x000300AA.<br />
&nbsp;<br />
C:\Dev\Shellcode\w32-msgbox-shellcode&gt;<br />
&nbsp;<br />
</code><br />
Every time the export address table is accessed, the hardware breakpoint is triggered and EAF checks to see if shellcode is attempting to access it. This is why you are seeing so may first change single step exceptions. However, because I am using the instruction sequence in ntdll.dll to access the address table, EAF allows the code to continue. The shellcode runs successfully and the process terminates when the shellcode executes the int3 debugger breakpoint as before.</p>
<p>Have a look at <a href="https://code.google.com/p/w32-msgbox-shellcode/source/diff?path=/trunk/w32-msgbox-shellcode.asm&#038;format=side&#038;r=4">the changes</a> I made to my shellcode to make this work. They are relatively minor and it should be possible to apply this technique to any shellcode, which reduces the usefulness of EAF in the long run.</p>
<p>I thought about possibilities to prevent or detect this bypass.  Unfortunately, I could not think of anything that would be effective. Here are some of my ideas and why I think they won&#8217;t work:<br />
- EAF could check for this specific instruction sequence. However, shellcode could scan for other sequences in ntdll.dll (or even in other modules) that can be used to achieve the same.<br />
- EAF could &#8220;walk the stack&#8221; and check that all return addresses are valid. However, the shellcode could construct a ret-into-libc stack with only valid return addresses, where the first call reads the export address table and the next call modifies the return address for the third return address to point to the shellcode again.<br />
- EAF could set additional hardware breakpoints on structures that can be used to find the locations of modules, in an attempt to prevent the shellcode from finding an instruction sequence that it can use to read memory. However, there are a large number of ways in which the location of modules can be found and there are a <a href="http://en.wikipedia.org/wiki/X86_debug_register">limited number</a> of hardware breakpoints. There are not enough breakpoints available to protect all of locations that contain sensitive data.</p>
<p>I welcome your thoughts and ideas on this subject.</p>
]]></content:encoded>
			<wfw:commentRss>http://skypher.com/index.php/2010/11/17/bypassing-eaf/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
	</channel>
</rss>

