<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Prekageo's Blog</title>
	<atom:link href="http://shiftlock.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://shiftlock.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Sun, 29 Jan 2012 12:52:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='shiftlock.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Prekageo's Blog</title>
		<link>http://shiftlock.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://shiftlock.wordpress.com/osd.xml" title="Prekageo&#039;s Blog" />
	<atom:link rel='hub' href='http://shiftlock.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Adobe Flash (SWF) to SVG and PDF</title>
		<link>http://shiftlock.wordpress.com/2011/12/26/adobe-flash-swf-to-svg-and-pdf/</link>
		<comments>http://shiftlock.wordpress.com/2011/12/26/adobe-flash-swf-to-svg-and-pdf/#comments</comments>
		<pubDate>Mon, 26 Dec 2011 11:01:26 +0000</pubDate>
		<dc:creator>prekageo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://shiftlock.wordpress.com/?p=373</guid>
		<description><![CDATA[Recently, I found some documents exported as SWF. It would be certainly more convenient for me if I could read these documents in my PDF reader. So I needed a utility to convert content from Adobe Flash to PDF. For this reason, I&#8217;ve written a small Python program that utilizes the SWFTools in order to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=373&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently, I found some documents exported as <a href="http://en.wikipedia.org/wiki/SWF">SWF</a>. It would be certainly more convenient for me if I could read these documents in my PDF reader. So I needed a utility to convert content from <a href="http://en.wikipedia.org/wiki/Adobe_Flash">Adobe Flash</a> to <a href="http://en.wikipedia.org/wiki/Portable_Document_Format">PDF</a>. For this reason, I&#8217;ve written a small Python program that utilizes the <a href="http://www.swftools.org/">SWFTools</a> in order to parse the SWF and exports output in <a href="http://en.wikipedia.org/wiki/Scalable_Vector_Graphics">SVG</a> and PDF file formats.</p>
<p><span id="more-373"></span></p>
<p>You can download the utility from here: <a href="http://labpower.teipir.gr/prekageo/swf_to_svg_pdf/swf_to_svg_pdf.zip">SWF to SVG/PDF</a>. It is still very experimental and will certainly need some tuning in order to produce perfect output. In order to use it, you need, of course, Python and, also, the SWFTools. You need to add a few lines in lib/Makefile of SWFTools in order to create a dynamic library for Python:</p>
<p><pre class="brush: plain;">
librfxswf.$(SLEXT): $(rfxswf_objects) rfxswf.$(O) drawer.$(O) $(lame_in_source) $(h263_objects) $(as12compiler_in_source) $(as3compiler_objects) libbase$(A)
$(L) -g -shared $@ -o $^ -lz
</pre></p>
<p>The utility is split into two parts. The swf_lib.py uses <a href="http://docs.python.org/library/ctypes">Python ctype</a> in order to communicate with the dynamic library and the swf_to_pdf.py is the main engine that performs the transformation. Currently shapes and text are supported. Eventually, more stuff could be implemented. It should be possible to transform a Flash application completely into an equivalent HTML5 application. I&#8217;ll leave that as an exercise for the reader!</p>
<p>You can see here an example of the utility:</p>
<ul>
<li>The <a href="http://labpower.teipir.gr/prekageo/swf_to_svg_pdf/original.pdf">original PDF</a>.</li>
<li>The <a href="http://labpower.teipir.gr/prekageo/swf_to_svg_pdf/input.swf">SWF</a> produced by SWFTools&#8217; pdf2swf tool.</li>
<li>The <a href="http://labpower.teipir.gr/prekageo/swf_to_svg_pdf/output.svg">output SVG</a> produced by the SWF to SVG/PDF utility presented here.</li>
<li>The <a href="http://labpower.teipir.gr/prekageo/swf_to_svg_pdf/output.pdf">output PDF</a> produced by the SWF to SVG/PDF utility presented here.</li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiftlock.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiftlock.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiftlock.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiftlock.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shiftlock.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shiftlock.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shiftlock.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shiftlock.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiftlock.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiftlock.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiftlock.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiftlock.wordpress.com/373/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiftlock.wordpress.com/373/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiftlock.wordpress.com/373/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=373&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shiftlock.wordpress.com/2011/12/26/adobe-flash-swf-to-svg-and-pdf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/92f1bdf5f7f139a3512da8b655abc80e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">prekageo</media:title>
		</media:content>
	</item>
		<item>
		<title>MySQL and character sets</title>
		<link>http://shiftlock.wordpress.com/2011/09/05/mysql-and-character-sets/</link>
		<comments>http://shiftlock.wordpress.com/2011/09/05/mysql-and-character-sets/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 10:38:15 +0000</pubDate>
		<dc:creator>prekageo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://shiftlock.wordpress.com/?p=369</guid>
		<description><![CDATA[Nowadays, it is common place to use UTF-8 when working with text data. Unfortunately, this is not the case when you deal with legacy software or old configuration. MySQL supports a lot of character sets. There are two places where a developer has to choose the character set. Every column of type VARCHAR has an [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=369&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Nowadays, it is common place to use <a href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> when working with text data. Unfortunately, this is not the case when you deal with legacy software or old configuration. <a href="http://en.wikipedia.org/wiki/MySQL">MySQL</a> supports a lot of <a href="http://dev.mysql.com/doc/refman/5.6/en/charset-charsets.html">character sets</a>. There are two places where a developer has to choose the character set.</p>
<ul>
<li>Every column of type VARCHAR has an associated character set, which means that data in this column are stored in the specified character set.</li>
<li>For every connection, the client can negotiate the character set that wants to send and receive. It can do that by issuing a <a href="http://dev.mysql.com/doc/refman/5.6/en/set-option.html#id856078">SET NAMES SQL statement</a>.</li>
</ul>
<p>MySQL handles conversion between character sets when necessary. It can actually get really messy if you do not use the same character set everywhere. To demonstrate this fact, I have written a <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29">Python</a> utility that tries combinations of character sets and operations and produces a nice summary in HTML. You can find the summary here: <a href="http://labpower.teipir.gr/prekageo/mysql-charset-tables.html">MySQL &#8211; character sets comparison tables</a>.</p>
<p><span id="more-369"></span></p>
<p>The script uses the following MySQL character sets:</p>
<ul>
<li>latin1</li>
<li>utf8</li>
<li>greek</li>
<li>binary</li>
</ul>
<p>It performs this sequence of operations:</p>
<ul>
<li>Flush the table.</li>
<li>Insert a row of data.</li>
<li>Select all rows.</li>
<li>Select the inserted row using a WHERE clause.</li>
<li>Select the inserted row using a fulltext index.</li>
</ul>
<p>This sequence is repeated for every combination of the following:</p>
<ul>
<li>Column character set.</li>
<li>Character set during INSERT.</li>
<li>Character set during SELECT.</li>
</ul>
<p>The test data used are the first 4 (in order for the fulltext index to work) capital letters of the Greek alphabet. When working with the latin1 and binary character sets, these letters are encoded as UTF-8 (which is plain wrong, but it happens in bad configurations).<br />
The output of the script consists of tables that describe the behavior for each case. The observed behavior fits in 5 categories:</p>
<ul>
<li>INSERT triggers error.</li>
<li>SELECT &#8230; WHERE &#8230; triggers error.</li>
<li>SELECT &#8230; WHERE &#8230; returns empty set.</li>
<li>Almost correct behavior. Fulltext search does not work.</li>
<li>Correct behavior.</li>
</ul>
<p>Notice, also, that by looking at the main diagonal of the tables you can understand how the system behaves when the client uses a specific character set on a column of the specified character set. By looking at other elements of the tables you can understand what will happen if you decide to switch your client from a character set A to character set B. You can see, that most of the time, this switch will cause you trouble.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiftlock.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiftlock.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiftlock.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiftlock.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shiftlock.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shiftlock.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shiftlock.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shiftlock.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiftlock.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiftlock.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiftlock.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiftlock.wordpress.com/369/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiftlock.wordpress.com/369/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiftlock.wordpress.com/369/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=369&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shiftlock.wordpress.com/2011/09/05/mysql-and-character-sets/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/92f1bdf5f7f139a3512da8b655abc80e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">prekageo</media:title>
		</media:content>
	</item>
		<item>
		<title>HTTP Request Logger add-on for Mozilla Firefox</title>
		<link>http://shiftlock.wordpress.com/2011/07/30/http-request-logger-add-on-for-mozilla-firefox/</link>
		<comments>http://shiftlock.wordpress.com/2011/07/30/http-request-logger-add-on-for-mozilla-firefox/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 09:20:55 +0000</pubDate>
		<dc:creator>prekageo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://shiftlock.wordpress.com/?p=358</guid>
		<description><![CDATA[Sometimes it might be useful to log each and every URL that is accessed through your Mozilla Firefox web browser. It might be for security, auditing or other reasons that you want to log accessed URLs. I developed the HTTP Request Logger add-on in order to track and discover a malicious web page that triggered [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=358&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sometimes it might be useful to log each and every URL that is accessed through your <a href="http://www.mozilla.com/en-US/firefox/fx/">Mozilla Firefox</a> web browser. It might be for security, auditing or other reasons that you want to log accessed URLs. I developed the HTTP Request Logger add-on in order to track and discover a malicious web page that triggered the <a href="http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2010-4452">CVE-2010-4452</a> vulnerability in <a href="http://www.oracle.com/us/java/index.html">Oracle Java</a> through a specially crafted <a href="http://www.w3.org/TR/html40/struct/objects.html#h-13.4">applet tag</a> and a respective Java applet class. You can download and install the add-on from here: <a href="https://addons.mozilla.org/en-US/firefox/addon/http-request-logger/">HTTP Request Logger</a>.</p>
<p><span id="more-358"></span></p>
<p>The add-on implements a <a href="https://developer.mozilla.org/en/how_to_build_an_xpcom_component_in_javascript">JavaScript XPCOM component</a>. This component is registered in <a href="https://developer.mozilla.org/en/chrome_registration">chrome.manifest</a>. The component registers an observer for <a href="https://developer.mozilla.org/en/Observer_Notifications">http-on-modify-request topics</a>. The observer&#8217;s callback function is called when a new HTTP request is ready to be sent. The function appends into a simple text file located on the user&#8217;s desktop a line consisting of the referrer, HTTP method and URL of the HTTP request.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiftlock.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiftlock.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiftlock.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiftlock.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shiftlock.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shiftlock.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shiftlock.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shiftlock.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiftlock.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiftlock.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiftlock.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiftlock.wordpress.com/358/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiftlock.wordpress.com/358/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiftlock.wordpress.com/358/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=358&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shiftlock.wordpress.com/2011/07/30/http-request-logger-add-on-for-mozilla-firefox/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/92f1bdf5f7f139a3512da8b655abc80e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">prekageo</media:title>
		</media:content>
	</item>
		<item>
		<title>SQL table view extension for Yii PHP Framework</title>
		<link>http://shiftlock.wordpress.com/2011/07/21/sql-table-view-extension-for-yii-php-framework/</link>
		<comments>http://shiftlock.wordpress.com/2011/07/21/sql-table-view-extension-for-yii-php-framework/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 12:00:41 +0000</pubDate>
		<dc:creator>prekageo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://shiftlock.wordpress.com/?p=354</guid>
		<description><![CDATA[While developing a web application, sometimes it is useful to provide an interface for displaying and browsing SQL tables. I have created an extension for the Yii PHP Framework which accomplishes that. One more interesting fact about this extension is that it avoids counting all the table&#8217;s rows in order to increase performance. You can [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=354&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>While developing a web application, sometimes it is useful to provide an interface for displaying and browsing SQL tables. I have created an extension for the <a href="http://www.yiiframework.com/">Yii PHP Framework</a> which accomplishes that. One more interesting fact about this extension is that it avoids counting all the table&#8217;s rows in order to increase performance.</p>
<p><a href="http://shiftlock.files.wordpress.com/2011/07/sql-table-view-screenshot.png"><img src="http://shiftlock.files.wordpress.com/2011/07/sql-table-view-screenshot.png?w=450&#038;h=173" alt="" title="sql-table-view-screenshot" width="450" height="173" class="aligncenter size-full wp-image-355" /></a></p>
<p>You can download the extension and some other required extensions from here:</p>
<ul>
<li><a href="http://www.yiiframework.com/extension/auto-count-sql-data-provider/">auto count sql data provider extension</a></li>
<li><a href="http://www.yiiframework.com/extension/auto-count-grid-view/">auto count grid view extension</a></li>
<li><a href="http://www.yiiframework.com/extension/sql-table-view/">sql table view extension</a></li>
</ul>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiftlock.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiftlock.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiftlock.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiftlock.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shiftlock.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shiftlock.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shiftlock.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shiftlock.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiftlock.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiftlock.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiftlock.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiftlock.wordpress.com/354/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiftlock.wordpress.com/354/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiftlock.wordpress.com/354/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=354&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shiftlock.wordpress.com/2011/07/21/sql-table-view-extension-for-yii-php-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/92f1bdf5f7f139a3512da8b655abc80e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">prekageo</media:title>
		</media:content>

		<media:content url="http://shiftlock.files.wordpress.com/2011/07/sql-table-view-screenshot.png" medium="image">
			<media:title type="html">sql-table-view-screenshot</media:title>
		</media:content>
	</item>
		<item>
		<title>Enhanced Windows service manager</title>
		<link>http://shiftlock.wordpress.com/2011/07/16/enhanced-windows-service-manager/</link>
		<comments>http://shiftlock.wordpress.com/2011/07/16/enhanced-windows-service-manager/#comments</comments>
		<pubDate>Sat, 16 Jul 2011 17:09:42 +0000</pubDate>
		<dc:creator>prekageo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://shiftlock.wordpress.com/?p=349</guid>
		<description><![CDATA[Are you tired of manually starting and stopping several Windows services at once? Do you want to disable a bunch of Windows service without going through each one of them? Here, I present an enhanced Windows services manager that provides features missing from the builtin services snap-in of Microsoft Management Console. The application is written [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=349&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Are you tired of manually starting and stopping several Windows services at once? Do you want to disable a bunch of Windows service without going through each one of them? Here, I present an enhanced Windows services manager that provides features missing from the builtin services snap-in of Microsoft Management Console. The application is written in Python and you can download the source code from here: <a href="http://labpower.teipir.gr/prekageo/windows_service_manager.zip">Enhanced Windows services manager</a>.</p>
<p><a href="http://shiftlock.files.wordpress.com/2011/07/windows_service_manager.png"><img src="http://shiftlock.files.wordpress.com/2011/07/windows_service_manager.png?w=450&#038;h=262" alt="" title="windows_service_manager" width="450" height="262" class="aligncenter size-full wp-image-350" /></a></p>
<p><span id="more-349"></span></p>
<p>The application uses <a href="http://www.wxpython.org/">wxPython</a> in order to provide a GUI. Also, it uses <a href="http://pywin32.sourceforge.net/">pywin32</a> in order to communicate with the Windows API. Both of these are requirements for executing the application. Also, it features the notion of protected services, which are not allowed to be manipulated. Starting, stopping or changing the start-up type of these services can result to operating system instability and/or boot failure.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiftlock.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiftlock.wordpress.com/349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiftlock.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiftlock.wordpress.com/349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shiftlock.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shiftlock.wordpress.com/349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shiftlock.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shiftlock.wordpress.com/349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiftlock.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiftlock.wordpress.com/349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiftlock.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiftlock.wordpress.com/349/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiftlock.wordpress.com/349/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiftlock.wordpress.com/349/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=349&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shiftlock.wordpress.com/2011/07/16/enhanced-windows-service-manager/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/92f1bdf5f7f139a3512da8b655abc80e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">prekageo</media:title>
		</media:content>

		<media:content url="http://shiftlock.files.wordpress.com/2011/07/windows_service_manager.png" medium="image">
			<media:title type="html">windows_service_manager</media:title>
		</media:content>
	</item>
		<item>
		<title>Windows XP: My monitor does not turn off for power saving</title>
		<link>http://shiftlock.wordpress.com/2011/06/26/windows-xp-my-monitor-does-not-turn-off-for-power-saving/</link>
		<comments>http://shiftlock.wordpress.com/2011/06/26/windows-xp-my-monitor-does-not-turn-off-for-power-saving/#comments</comments>
		<pubDate>Sun, 26 Jun 2011 14:25:20 +0000</pubDate>
		<dc:creator>prekageo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://shiftlock.wordpress.com/?p=342</guid>
		<description><![CDATA[I had this problem for a long time in my Windows XP machine. I had set up my monitor to turn off after 3 minutes of inactivity for power saving reasons. I, also, had disabled the screensaver although the last time it was enabled it was set to appear after 1 minute of inactivity. This [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=342&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I had this problem for a long time in my Windows XP machine. I had set up my monitor to turn off after 3 minutes of inactivity for power saving reasons. I, also, had disabled the screensaver although the last time it was enabled it was set to appear after 1 minute of inactivity. This piece of information will become significant latter on.</p>
<p>The problem was that sometimes my monitor could not go into power saving mode. I had absolutely no idea why such a thing happened and I couldn&#8217;t correlate this problem with any user action I was performing each time the problem arose. I knew that I could fix this problem by just clicking Apply in the Power Options control panel applet and I, also, had figured out that the problem disappeared if I adjusted the inactivity period down to 1 minute.</p>
<p>If you don&#8217;t want to go into all the technical details that will follow, you may want to know that the cause for this problem is the Adobe Flash player. The problem happens after viewing a Flash video (e.g. YouTube) and there is a bug report for this issue: <a href="http://bugs.adobe.com/jira/browse/FP-5216">FP-5216</a>. If you want to learn more please continue reading and/or watch the screen-cast: <a href="http://youtu.be/dM5Idqb83wU">Part 1</a> and <a href="http://youtu.be/WMelymrFtgM">Part 2</a>.</p>
<p><span id="more-342"></span></p>
<p>So, in the last few days, I decided to finally find the cause (and a possible solution) for this problem. The tools and references I used include:</p>
<ul>
<li><a href="http://technet.microsoft.com/en-us/sysinternals/bb896645">Process Monitor</a></li>
<li><a href="http://en.wikipedia.org/wiki/Interactive_Disassembler">IDA Pro</a></li>
<li><a href="http://en.wikipedia.org/wiki/SoftICE">SoftICE</a></li>
<li>leaked Windows 2000 source code</li>
</ul>
<p>The process will be described in discrete steps:</p>
<ol>
<li>The first thing I had to do was to discover where the monitor power off timeout was stored, who stored it and who accessed it. I started the Power Options control panel applet, then I started Process Monitor, made a change in the applet, clicked Apply and observed the output of Process Monitor. By inspecting the stack traces I was able to discover that ntoskrnl!NtPowerInformation was the function that stored the power policy into the registry (HKLM\System\CurrentControlSet\Control\Session Manager\Power\AcPolicy). This registry key is binary, so I couldn&#8217;t extract any more information from it.</li>
<li>The next step was to find about the NtPowerInformation function. So, I looked the Windows 2000 source code for references and I found some. The most interesting was the reference from the Power Options control panel applet itself (win2k/private/windows/shell/cpls/powrprof/powrprof.c). The most interesting function call looked like:<br />
<blockquote>
<pre>NtPowerInformation(SystemPowerPolicyAc, InputBufferAc, sizeof(SYSTEM_POWER_POLICY), OutputBufferAc, sizeof(SYSTEM_POWER_POLICY));</pre>
</blockquote>
<p>So, I had to find more information about the SYSTEM_POWER_POLICY structure. Fortunately, it is defined inside winnt.h and also has a DWORD member named VideoTimeout (offset 0xC0).</li>
<li>My next step was to open ntoskrnl.exe into IDA Pro and try to understand what NtPowerInformation did. Turns out that it calls PopApplyPolicy, which in turn does a memcpy of the given SYSTEM_POWER_POLICY structure to PopAcPolicy (which resides in kernel memory).</li>
<li>So, I used SoftICE to set a memory breakpoint at PopAcPolicy+0xC0 in order to determine who accessed the VideoTimeout field. The field was accessed from PopDispatchPolicyCallout.</li>
<li>Back to IDA Pro where I could see that PopDispatchPolicyCallout was sending the VideoTimeout field as a parameter to a function pointed by PopEventCallout. Now, I just had to learn where this pointer goes.</li>
<li>Back to SoftICE, it was easy to see that PopEventCallout contained the address of win32k!UserPowerEventCallout.</li>
<li>Now, I started reading the Windows 2000 source code. UserPowerEventCallout was in file win2k/private/ntos/w32/ntuser/kernel/power.c, it calls QueuePowerRequest, which calls xxxUserPowerCalloutWorker, which calls xxxUserPowerEventCalloutWorker, which does something like that:<br />
<blockquote>
<pre>xxxSystemParametersInfo(SPI_SETLOWPOWERTIMEOUT, VideoTimeout, 0, 0);
xxxSystemParametersInfo(SPI_SETPOWEROFFTIMEOUT, VideoTimeout, 0, 0);</pre>
</blockquote>
<p>I looked for xxxSystemParametersInfo and found it inside win2k/private/ntos/w32/ntuser/kernel/rare.c. This function contains a huge switch statement. The SPI_SETLOWPOWERTIMEOUT and SPI_SETPOWEROFFTIMEOUT cases set two global variables: giLowPowerTimeOutMs and giPowerOffTimeOutMs respectively.</li>
<li>Now, the question is: Who reads these variables? Again, it&#8217;s time for SoftICE. I installed a memory breakpoint at these variables and within 1 second it was hit! The variables were accessed by win32k!IdleTimerProc.</li>
<li>Back to reading source code. IdleTimerProc is defined in win2k/private/ntos/w32/ntuser/kernel/input.c. First it check if it is time to display the screen saver and then it checks if it is time to turn off the monitor.
<ul>
<li>How does it check if it is time to take action? It calls IsTimeFromLastInput (defined in win2k/private/ntos/w32/ntuser/kernel/userk.h), which uses a global structure named glinp of type LASTINPUT. LASTINPUT is defined in win2k/private/ntos/w32/ntuser/kernel/userk.h and contains a field named timeLastInputMessage. This field, probably, holds the timestamp of the last user activity.</li>
<li>How does it turns off the monitor? Well, it is simple:<br />
<blockquote>
<pre>PostMessage(gpqForeground-&gt;spwndActive, WM_SYSCOMMAND, SC_MONITORPOWER, LOWPOWER_PHASE);
PostMessage(gpqForeground-&gt;spwndActive, WM_SYSCOMMAND, SC_MONITORPOWER, POWEROFF_PHASE);</pre>
</blockquote>
<p>It sends a message to the foreground window. And what happens next? Well, probably the foreground window calls DefWindowProc and the message is handled internally. I looked the source code for references to SC_MONITORPOWER and found that this message is handled by the function xxxSysCommand which resides in win2k/private/ntos/w32/ntuser/kernel/syscmd.c. xxxSysCommand does a DrvSetMonitorPowerState call which probably goes directly to video card driver and that&#8217;s it!</li>
</ul>
</li>
<li>By now, I had all the information that I needed. The question, though, remains: Where is the problem?
<ol>
<li>First I thought that it might be a video card driver problem. So, I just wrote a simple Windows application, that posted the above mentioned message into its message loop and&#8230; tada&#8230; the monitor turned off!</li>
<li>Then, I thought that it might be a rogue foreground window that does not call DefWindowProc. I didn&#8217;t check that. Besides the problem usually happened when I had only my desktop appear and no other active foreground windows.</li>
<li>A wild guess now&#8230; let&#8217;s monitor the glinp structure. I&#8217;ve written a small driver that reads kernel memory and a small user-mode application that displays it every few seconds. Let it run and&#8230; boom&#8230; after exactly 1 minute of inactivity the glinp gets reset. How does that happen?</li>
</ol>
</li>
<li>I went to SoftICE and set a memory breakpoint there. A little bit tricky because glinp was changed when I exited SoftICE resulting in an endless loop. Fortunatelly, SoftICE supports conditional breakpoints. After 1 minute, I found that glinp was reset from winlogon!RunScreenSaver.</li>
<li>I went to IDA Pro and found out that RunScreenSaver calls SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT) which in turn resets glinp as seen from the source file win2k/private/ntos/w32/ntuser/kernel/rare.c. Actually RunScreenSaver does that only when it was unable to start the screen saver.</li>
<li>Why is the screen saver trying to activate itself? It shouldn&#8217;t do that. I check the global variable giScreenSaveTimeOutMs with SoftICE. Weird&#8230; it&#8217;s positive. When I booted the machine it was negative. Negative means that the screen saver is disabled. Somebody changed this value. But the code that changes this value inside win2k/private/ntos/w32/ntuser/kernel/rare.c takes care to maintain the sign of it. Now, somebody is doing something nasty. Let&#8217;s reset the value to negative and set a memory breakpoint through SoftICE to it. Now, let&#8217;s do our normal job on the computer. Hmm&#8230; nothing happens&#8230; Now what? Never mind, let&#8217;s watch a YouTube video! Bingo&#8230; the value is changed. npswf32.dll did it! Adobe Flash player plugin did it! How does it do it? Well&#8230;<br />
<blockquote>
<pre>int x;
SystemParametersInfo(SPI_GETSCREENSAVETIMEOUT, 0, &amp;x, 0);
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, 0, 0, 0);
SystemParametersInfo(SPI_SETSCREENSAVETIMEOUT, x, 0, 0);</pre>
</blockquote>
<p>The above code snippet, changes the negative value into a positive one!</li>
</ol>
<p>So the mystery is solved! How do I fix it? I set the screen saver wait time to 20 minutes and then disable it. Also, another way is just to open the Screen Saver control panel applet and click OK every time this problem happens and everything resets back to normal.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiftlock.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiftlock.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiftlock.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiftlock.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shiftlock.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shiftlock.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shiftlock.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shiftlock.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiftlock.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiftlock.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiftlock.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiftlock.wordpress.com/342/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiftlock.wordpress.com/342/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiftlock.wordpress.com/342/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=342&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shiftlock.wordpress.com/2011/06/26/windows-xp-my-monitor-does-not-turn-off-for-power-saving/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/92f1bdf5f7f139a3512da8b655abc80e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">prekageo</media:title>
		</media:content>
	</item>
		<item>
		<title>Windows hooks detector</title>
		<link>http://shiftlock.wordpress.com/2011/06/22/windows-hooks-detector/</link>
		<comments>http://shiftlock.wordpress.com/2011/06/22/windows-hooks-detector/#comments</comments>
		<pubDate>Wed, 22 Jun 2011 15:07:15 +0000</pubDate>
		<dc:creator>prekageo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://shiftlock.wordpress.com/?p=336</guid>
		<description><![CDATA[Recently, I had to fix a problem with Microsoft Office Word. The problem was that the normal key combination Alt-Shift for changing the input language was not working. After some time I discovered that the culprit was a rather old piece of software that had installed some Windows hooks targeted at the Microsoft Office Word, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=336&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently, I had to fix a problem with Microsoft Office Word. The problem was that the normal key combination Alt-Shift for changing the input language was not working. After some time I discovered that the culprit was a rather old piece of software that had installed some Windows hooks targeted at the Microsoft Office Word, which (probably) stopped the propagation of the Alt-Shift key combination before it could actually change the language.</p>
<p>While I was investigating this issue, I noticed that there was no available utility that could detect and report installed Windows hooks. So here I present a Windows hooks detector. It is a command line application accompanied by a system driver, that scans, detects and reports installed Windows hooks. The source code and the binary compiled for Windows XP is available here: <a href="http://labpower.teipir.gr/prekageo/hook_detect.zip">Windows hooks detector</a>.</p>
<p>Also you can download a demo hook application, that installs local and global hooks for testing purposes. The source code and the binary is available here: <a href="http://labpower.teipir.gr/prekageo/hook_demo.zip">Demo Windows hook application</a></p>
<p><span id="more-336"></span></p>
<p>According to the <a href="http://msdn.microsoft.com/en-us/library/ms632589">MSDN documentation for Windows hooks</a>:</p>
<blockquote><p>
a hook is a point in the system message-handling mechanism where an application can install a subroutine to monitor the message traffic in the system and process certain types of messages before they reach the target window procedure.
</p></blockquote>
<p>A Windows hook is installed by calling <a href="http://msdn.microsoft.com/en-us/library/ms644990">SetWindowsHookEx</a> (<a href="http://blog.csdn.net/uvbs/archive/2008/08/06/2778911.aspx">source code</a>) and removed by calling <a href="http://msdn.microsoft.com/en-us/library/ms644993">UnhookWindowsHookEx</a>. It can either be installed globally or locally. When it is installed globally it intercepts messages for all threads belonging to the same desktop. When it is installed locally it intercepts messages directed to a specific thread.</p>
<p>The Windows API does not offer any way for an application to list the installed hooks. After a hook is installed, it is stored and managed inside kernel structures which cannot be accessed from the user mode. Thus a kernel driver is necessary to access these structures. Furthermore, the whole mechanism of installing, handling and removing hooks is undocumented, which means that there is need to reverse engineer the relevant code. So after spending some time with the <a href="http://www.hex-rays.com/idapro/">IDA Pro Disassembler</a>, <a href="http://en.wikipedia.org/wiki/SoftICE">SoftICE</a> and a Windows XP image running on <a href="http://www.vmware.com/">VMware</a> the job was done.</p>
<p>An overview for detecting installed global hooks follows:</p>
<ol>
<li>Call <a href="http://msdn.microsoft.com/en-us/library/ff559936%28v=vs.85%29.aspx">PsGetCurrentThread</a> and get the <a href="http://msdn.microsoft.com/en-us/library/ff544319%28v=vs.85%29.aspx">ETHREAD</a> structure of the current thread. ETHREAD is an opaque data structure according to the MSDN documentation.</li>
<li>Extract the <a href="http://blog.csdn.net/coffeemay/archive/2006/09/18/1238777.aspx">THREADINFO</a> structure by calling PsGetThreadWin32Thread. Both of them are undocumented.</li>
<li>Extract the DESKTOPINFO.</li>
<li>There you can a find all the globally installed hooks. They are organized in a array. Each element is a linked list and corresponds to a specific hook (WH_*).</li>
</ol>
<p>An overview for detecting installed local hooks follows:</p>
<ol>
<li>Given a thread ID.</li>
<li>Call <a href="http://msdn.microsoft.com/en-us/library/ff551925%28v=VS.85%29.aspx">PsLookupThreadByThreadId</a> and get the ETHREAD structure of the specified thread.</li>
<li>Extract the THREADINFO structure by calling PsGetThreadWin32Thread.</li>
<li>There you can a find all the locally installed hooks for the specified thread. They are organized in a array. Each element is a linked list and corresponds to a specific hook (WH_*).</li>
</ol>
<p>Each hook is represented by a HOOK structure, which is undocumented. The HOOK structure stores the virtual address of the handler function. If the handler resides inside a DLL, then the relative virtual address is stored and the DLL path is stored in an atom table. That&#8217;s because a DLL&#8217;s base address may be different across processes. Also, by storing the DLL path in the atom table, the system knows which DLL to load if the hook is triggered inside a new process. We could say that the hook DLL is lazily loaded into processes.</p>
<p>Unfortunately, this atom table is internal. Also, there is no exported function of the kernel that accesses it. So the only way to read its contents is to call directly non-exported and undocumented kernel function calls. In order to get the necessary addresses, the utility uses the <a href="http://msdn.microsoft.com/en-us/library/ms679309%28v=VS.85%29.aspx">Debug Help Library</a> to load the <a href="http://en.wikipedia.org/wiki/Program_database">PDB</a> of win32k.sys. Two symbols are needed:</p>
<ul>
<li>UserGetAtomName: A function that reads the above mentioned internal atom table.</li>
<li>aatomSysLoaded: An array containing the atoms of hook DLLs. The necessary offset in this array is stored in the HOOK structure.</li>
</ul>
<p>The utility has been tested with the following versions of win32k.sys: 5.1.2600.2180, 5.1.2600.2770, 5.1.2600.5512. These versions correspond to Windows XP SP2 and SP3. If you don&#8217;t have one of those versions and the utility crashes your system, please send me your win32k.sys for analysis. Otherwise, please inform me in order to update the supported versions.</p>
<p>There is one more way to get the DLL path for a hook, although it is less reliable, so I haven&#8217;t implemented it. Though, I am going to describe it. After loading a hook DLL the system stores in the PROCESSINFO structure the base address of the loaded DLL. So if the hook DLL is loaded in the inspected process, you can retrieve its base address and from the base address after traversing the module list of the process you can find the DLL path. If the hook DLL has not been loaded yet, then you are out of luck.</p>
<p>If you would like to compile the utility you need the <a href="http://msdn.microsoft.com/en-us/windows/hardware/gg487428">Windows Driver Kit (WDK)</a> and <a href="http://www.hollistech.com/Resources/ddkbuild/ddkbuild.htm">ddkbuild</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiftlock.wordpress.com/336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiftlock.wordpress.com/336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiftlock.wordpress.com/336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiftlock.wordpress.com/336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shiftlock.wordpress.com/336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shiftlock.wordpress.com/336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shiftlock.wordpress.com/336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shiftlock.wordpress.com/336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiftlock.wordpress.com/336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiftlock.wordpress.com/336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiftlock.wordpress.com/336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiftlock.wordpress.com/336/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiftlock.wordpress.com/336/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiftlock.wordpress.com/336/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=336&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shiftlock.wordpress.com/2011/06/22/windows-hooks-detector/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/92f1bdf5f7f139a3512da8b655abc80e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">prekageo</media:title>
		</media:content>
	</item>
		<item>
		<title>Moore state machine solver and optimizer</title>
		<link>http://shiftlock.wordpress.com/2011/05/17/moore-state-machine-solver-and-optimizer/</link>
		<comments>http://shiftlock.wordpress.com/2011/05/17/moore-state-machine-solver-and-optimizer/#comments</comments>
		<pubDate>Tue, 17 May 2011 17:49:55 +0000</pubDate>
		<dc:creator>prekageo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://shiftlock.wordpress.com/?p=328</guid>
		<description><![CDATA[A Moore machine is a finite-state machine whose output values are determined solely by its current state, in contrast to a Mealy machine. A state machine has a number of states, which are usually conveniently labeled 0, 1, 2, etc.. Below you can find a utility that can help you design and implement a state [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=328&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A <a href="http://en.wikipedia.org/wiki/Moore_machine">Moore machine</a> is a finite-state machine whose output values are determined solely by its current state, in contrast to a <a href="http://en.wikipedia.org/wiki/Mealy_machine">Mealy machine</a>. A state machine has a number of states, which are usually conveniently labeled 0, 1, 2, etc.. Below you can find a utility that can help you design and implement a state machine in hardware.</p>
<p><span id="more-328"></span></p>
<p>When you have to implement the state machine in hardware you have to find a way to map these abstract states into logical signals. There are a lot of possibilities. Two of the most common are:</p>
<ul>
<li>Use one signal for each state, e.g. if there are 3 states you must use 3 signals (S0, S1, S2). Each signal requires its own electrical path so this method becomes quickly inefficient as the number of states increases. On the other hand, it is quite easy to derive the transition (next state) functions and the output functions because you don&#8217;t have to deal with any special encoding of states, e.g. OUTPUT_A = STATE_1 OR STATE_2 can be easily implemented in hardware with a 2-input OR gate, because every state has its one signal.</li>
<li>Encode states in binary, e.g. state 0 is encoded as 00, state 1 as 01, state 2 as 10. Each binary digit requires its own electrical path. That way we minimize the number of signals required but we increase the complexity of the transition and output functions.</li>
</ul>
<p>The utility presented here has two features that can help designers implement their state machines in hardware:</p>
<ul>
<li>For a given mapping of abstract states to state encodings, it uses the <a href="http://en.wikipedia.org/wiki/Quine%E2%80%93McCluskey_algorithm">Quine-McCluskey algorithm</a> in order to find the minimum two-level logic functions that implement the state machine.</li>
<li>It can try all permutations of state encodings for a given state word length in order to find the one that minimizes the total complexity of all the required functions for the implementation of the state machine. Be aware, that this mode of operation has exponential complexity so it can only be used for relatively small state machines.</li>
</ul>
<p>You can find the Moore state machine solver and optimizer here: <a href="http://labpower.teipir.gr/prekageo/optistate.py">optistate.py</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiftlock.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiftlock.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiftlock.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiftlock.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shiftlock.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shiftlock.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shiftlock.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shiftlock.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiftlock.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiftlock.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiftlock.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiftlock.wordpress.com/328/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiftlock.wordpress.com/328/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiftlock.wordpress.com/328/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=328&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shiftlock.wordpress.com/2011/05/17/moore-state-machine-solver-and-optimizer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/92f1bdf5f7f139a3512da8b655abc80e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">prekageo</media:title>
		</media:content>
	</item>
		<item>
		<title>Quine-McCluskey algorithm implementation in Python</title>
		<link>http://shiftlock.wordpress.com/2011/05/17/quine-mccluskey-algorithm-implementation-in-python/</link>
		<comments>http://shiftlock.wordpress.com/2011/05/17/quine-mccluskey-algorithm-implementation-in-python/#comments</comments>
		<pubDate>Tue, 17 May 2011 16:44:20 +0000</pubDate>
		<dc:creator>prekageo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://shiftlock.wordpress.com/?p=317</guid>
		<description><![CDATA[Recently, I had to minimize some boolean functions using Karnaugh maps. The functions were part of a state machine, which I would like to optimize, so I had to repeat the process using Karnaugh maps over and over until, finally, I decided it would be much more productive, if I could write a program that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=317&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently, I had to minimize some boolean functions using <a href="http://en.wikipedia.org/wiki/Karnaugh_map">Karnaugh maps</a>. The functions were part of a state machine, which I would like to optimize, so I had to repeat the process using Karnaugh maps over and over until, finally, I decided it would be much more productive, if I could write a program that could do the trick. So, here it is; an implementation of the <a href="http://en.wikipedia.org/wiki/Quine%E2%80%93McCluskey_algorithm">Quine-McCluskey algorithm</a> written in Python. Before writing the code, I had studied the implementation of <a href="http://robertdick.org/">Robert Dick</a>, which can be found here: <a href="http://pypi.python.org/pypi/qm/0.2">http://pypi.python.org/pypi/qm/0.2</a>.</p>
<p><span id="more-317"></span></p>
<p>I improved the performance of the above mentioned implementations by:</p>
<ul>
<li>using bitwise operations,</li>
<li>eliminating uses of strings and</li>
<li>using <a href="http://en.wikipedia.org/wiki/Petrick%27s_method">Petrick&#8217;s method</a> for determining all minimum sum-of-products solutions from a prime implicant chart.</li>
</ul>
<p>I have also run <a href="http://packages.python.org/line_profiler/">line_profiler</a> in order to pinpoint the lines of code that might need optimization if necessary.</p>
<p>You can find the Python module here: <a href="http://labpower.teipir.gr/prekageo/qm.py">qm.py</a> and the line_profiler output here: <a href="http://labpower.teipir.gr/prekageo/qm_line_profiler_output.txt">qm_line_profiler_output.txt</a>.</p>
<p><b>Update 2011/05/19:</b> I have improved the complexity calculation method. Before this change the complexity of a NOT gate was the same as the complexity of a 2-input OR gate, so instead of the minimal function NOT B, the function A OR C was produced. I have also written a function that provides an interface in case you would like to use this implementation instead of Robert Dick&#8217;s. The interface translates the output to match that of Robert Dick&#8217;s implementation.</p>
<p><pre class="brush: python;">
def t(x,n):
  x = x[1]
  if x == '1':
    return ['X'*n]
  if x == '0':
    return ['X'*n]

  result = []
  for a,b in x:
    tmp = []
    for i in xrange(n):
      if a &amp; 1:
        tmp.append('1')
      elif b &amp; 1:
        tmp.append('X')
      else:
        tmp.append('0')
      a &gt;&gt;= 1
      b &gt;&gt;= 1
    tmp.reverse()
    result.append(''.join(tmp))
  return result
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiftlock.wordpress.com/317/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiftlock.wordpress.com/317/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiftlock.wordpress.com/317/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiftlock.wordpress.com/317/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shiftlock.wordpress.com/317/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shiftlock.wordpress.com/317/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shiftlock.wordpress.com/317/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shiftlock.wordpress.com/317/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiftlock.wordpress.com/317/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiftlock.wordpress.com/317/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiftlock.wordpress.com/317/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiftlock.wordpress.com/317/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiftlock.wordpress.com/317/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiftlock.wordpress.com/317/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=317&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shiftlock.wordpress.com/2011/05/17/quine-mccluskey-algorithm-implementation-in-python/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/92f1bdf5f7f139a3512da8b655abc80e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">prekageo</media:title>
		</media:content>
	</item>
		<item>
		<title>Web site monitor</title>
		<link>http://shiftlock.wordpress.com/2011/03/16/web-site-monitor/</link>
		<comments>http://shiftlock.wordpress.com/2011/03/16/web-site-monitor/#comments</comments>
		<pubDate>Wed, 16 Mar 2011 14:39:37 +0000</pubDate>
		<dc:creator>prekageo</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://shiftlock.wordpress.com/?p=289</guid>
		<description><![CDATA[I wanted to monitor a number of web sites that did not provide RSS feeds or their RSS feeds were misbehaving. So, I ended up writing a Python utility that does exactly that: Given a list of URLs and some rules, it retrieves them, stores them and compares them. The utility is composed of several [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=289&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I wanted to monitor a number of web sites that did not provide <a href="http://en.wikipedia.org/wiki/RSS">RSS</a> feeds or their RSS feeds were misbehaving. So, I ended up writing a <a href="http://www.python.org/">Python</a> utility that does exactly that: Given a list of <a href="http://en.wikipedia.org/wiki/Uniform_Resource_Locator">URLs</a> and some rules, it retrieves them, stores them and compares them.</p>
<p><span id="more-289"></span></p>
<p>The utility is composed of several components:</p>
<ul>
<li>The <b>WebBrowser</b> component is responsible for transferring data from the configured URLs. It supports <a href="http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol">HTTP</a> cookies, it can submit <a href="http://en.wikipedia.org/wiki/HTML">HTML</a> forms in order to login into web sites and, also, uses the user agent string of <a href="http://www.mozilla.com/en-US/firefox/">Mozilla Firefox</a> in order not to trigger weird behaviour in some web sites.</li>
<li>The <b>Storage</b> component is responsible for storing the retrieved web pages into an <a href="http://www.sqlite.org/">SQLite</a> database. Each web page is compressed using <a href="http://en.wikipedia.org/wiki/Zlib">zlib</a> and stored along with its URL and its retrieval timestamp. This component can, also, read from the database the two most recent versions of a web page for comparison.</li>
<li>The <b>HTMLReport</b> component handles the generation of the HTML report that summarises the changes found in the configured URLs. It uses <a href="http://www.makotemplates.org/">Mako Templates for Python</a> in order to easily generate the desired HTML output.</li>
<li>The <b>ConfParser</b> component handles reading the configuration file, which is written in <a href="http://en.wikipedia.org/wiki/YAML">YAML</a>, through <a href="http://pyyaml.org/">PyYAML</a>.</li>
<li>The <b>BaseDiffEngine</b> component is an abstract component which is the basis for creating components that compare specific web sites. Comparing HTML documents is accomplished through the <a href="http://lxml.de/">lxml library</a>. Each URL can be set in the configuration file to use a specific difference engine for comparison.</li>
</ul>
<p>Along with the sitemon utility come some sample difference engines:</p>
<ul>
<li>The <b>Comparison</b> engine compares web sites line-by-line as if someone used the diff command line utility on them.</li>
<li>The <b>DiffInvision</b>, <b>DiffVBulletin</b> and <b>DiffPHPBB</b> compare the respective forums (<a href="http://www.invisionpower.com/products/board/">Invision&#8217;s IP.Board</a>, <a href="http://www.vbulletin.com/">vBulletin</a> and <a href="http://www.phpbb.com/">phpBB</a>). Actually these engines can compare the topic summary pages that these forums provide (so that you can see if a new post has been made).</li>
</ul>
<p>You can download the sitemon utility along with the above described difference engines from here: <a href="http://labpower.teipir.gr/prekageo/sitemon.zip">sitemon</a>.</p>
<p>Below you can see a sample configuration file for comparing the <a href="http://www.dropbox.com/">Dropbox home page</a> after logging into it.<br />
<pre class="brush: plain; auto-links: false;">
authentication:
  https://www.dropbox.com :
    method: post
    url: https://www.dropbox.com/login
    params:
      login_email: HIDDEN
      login_password: HIDDEN
      remember_me: on
      t: ''
sites:
  - url: https://www.dropbox.com/home
    diff_engine: Comparison
    validations:
      - xpath: //a[contains(@href,&quot;/logout&quot;)]
        should_exist: Yes
</pre></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/shiftlock.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/shiftlock.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/shiftlock.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/shiftlock.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/shiftlock.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/shiftlock.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/shiftlock.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/shiftlock.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/shiftlock.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/shiftlock.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/shiftlock.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/shiftlock.wordpress.com/289/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/shiftlock.wordpress.com/289/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/shiftlock.wordpress.com/289/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=shiftlock.wordpress.com&amp;blog=6787110&amp;post=289&amp;subd=shiftlock&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://shiftlock.wordpress.com/2011/03/16/web-site-monitor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/92f1bdf5f7f139a3512da8b655abc80e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">prekageo</media:title>
		</media:content>
	</item>
	</channel>
</rss>
