<?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>Unknown Kadath</title>
	<atom:link href="http://html5.litten.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://html5.litten.com</link>
	<description></description>
	<lastBuildDate>Mon, 14 May 2012 22:50:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Windows ‘File Recovery’ series : Part 6 Reading/Editing The Windows Registry From Outside of Windows</title>
		<link>http://html5.litten.com/windows-file-recovery-series-part-6-readingediting-the-windows-registry-from-outside-of-windows/</link>
		<comments>http://html5.litten.com/windows-file-recovery-series-part-6-readingediting-the-windows-registry-from-outside-of-windows/#comments</comments>
		<pubDate>Mon, 14 May 2012 22:13:01 +0000</pubDate>
		<dc:creator>James Litten</dc:creator>
				<category><![CDATA[Data Recovery]]></category>
		<category><![CDATA[Windows File Recovery]]></category>
		<category><![CDATA[data recovery]]></category>
		<category><![CDATA[registry]]></category>
		<category><![CDATA[registry editing]]></category>
		<category><![CDATA[windows file recovery]]></category>

		<guid isPermaLink="false">http://html5.litten.com/?p=838</guid>
		<description><![CDATA[Windows ‘File Recovery’ series Part 6 Reading/Editing The Windows Registry From Outside of Windows DISCLAIMER: These examples use techniques that I actually employ in the real world to deal with real problems. They might be wrong or dangerous. They might be inefficient. If you try them yourself, it might cause damage or irreparable loss. I [...]]]></description>
			<content:encoded><![CDATA[<h2>Windows ‘File Recovery’ series<br />
Part 6 Reading/Editing The Windows Registry From Outside of Windows</h2>
<strong>DISCLAIMER:</strong><em> These examples use techniques that I actually employ in the real world to deal with real problems. They might be wrong or dangerous. They might be inefficient. If you try them yourself, it might cause damage or irreparable loss. I take no responsibility for anything you do based on my examples or the information that I provide here.</em><br />
<br />
In this series we&#8217;ll look at some real world examples of disastrous situations salvaged and made better again.<br />
<br />
<span style="color: #ff0000;"><strong>Caution</strong></span><br />
<span style="color: #ff0000;">Incorrectly editing the registry may severely damage your system. Before making changes to the registry, you should back up any valued data on the computer.</span><br />
<br />
<span style="color: #ff0000;"> <strong>Caution</strong></span><br />
<span style="color: #ff0000;">Do not edit the registry directly unless you have no alternative. These techniques bypasses standard safeguards, allowing settings that can degrade performance, damage your system, or even require you to reinstall Windows. If you must edit the registry directly, back it up first.</span><br />
<br />
<p>
Most of the time you can use standard registry editing tools on a Windows computer that cannot boot into Windows. <br /><br />
<div style=" 
background-color: #F8F8F8;
padding: 10px;
width: 90%;
border-radius: 25px;
-moz-border-radius: 25px;
-webkit-border-radius: 25px;
    -webkit-box-shadow: 10px 10px 25px #D5D5D5;
    -moz-box-shadow: 10px 10px 25px #D5D5D5;
    box-shadow: 10px 10px 25px #D5D5D5;
"><br />
<strong>If you are able to boot the machine into Safe Mode with Command Prompt</strong> then you can use the reg command<br />
Reg Command <br />
<a href="http://technet.microsoft.com/en-us/library/bb490984.aspx">http://technet.microsoft.com/en-us/library/bb490984.aspx</a><br />
<br />
<strong>Recovery Console Command prompt on Windows Vista /  7</strong><br />
You can run regedit.exe.<br />
You can also use the reg.exe command.<br />
<br />
<strong>Windows 8 Startup Repair Command Prompt</strong><br />
You can run regedit.exe.<br />
You can also use the reg.exe command.<br />
<br />
</div><br /><br />
I&#8217;m sure that there are other ways. Computers are always full of new surprises when it comes to breaking them.   
</p>
Then there is Windows XP<br />
<strong>Recovery Console Command prompt in Windows XP has no reg or regedit command.</strong><br />
<br />
<h2>Using <em>chntpw</em> as a Windows registry editor</h2>
Anyone who repairs consumer computers on a regular basis comes across this scenario sooner or later.<br />
<br />
Client has a Windows XP computer with a problem that can be easily repaired from the XP Recovery Console. You proceed to boot into XP Recovery Console and ask the client &#8220;Is there an administrator password to this machine?&#8221; and they respond with something like &#8220;I don&#8217;t think so&#8230;&#8221;.<br />
<br /><span id="more-838"></span>
You proceed to choose the Windows install listed in the Recovery Console and it asks you for an administrator password so you press enter as if there is no password and up pops &#8220;The password is not valid&#8221;<br />
<br />
This is how I first came to know the program <em>chntpw</em> (which I presume stands for Change NT Password). It allows you to modify the Windows registry from a Live Linux CD and change the password.<br />
<br />
It doesn&#8217;t just give you the ability to change that part of the registry. It can view and edit other parts that can help you get a damaged machine to boot such as from a partial removal of malware that can cause an orphaned or erroneous registry value that crashes the Windows boot process.<br />
<br />
Before we look at some examples, I just want to be sure that you saw the disclaimers.<br />
<br />
<span style="color: #ff0000;"> <strong>Caution</strong></span><br />
<span style="color: #ff0000;">Do not edit the registry directly unless you have no alternative. These techniques bypasses standard safeguards, allowing settings that can degrade performance, damage your system, or even require you to reinstall Windows. If you must edit the registry directly, back it up first.</span><br />
<br />
For our examples, we will use a PartitionMagic Live CD to boot the Windows machine into Linux and use the tools that are available on it to view/edit the Windows registry on the machine.<br />
You can find the iso file for creating a PartedMagic boot CD here<br />
<a href="http://partedmagic.com/doku.php?id=downloads">http://partedmagic.com/doku.php?id=downloads</a><br />
<br />
In real life situations, I only reach this point when it is the last thing to try before a repair-reinstall which can take a considerable amount of time and is fraught with potential pitfalls.<br />
As I open the terminal in Linux and start typing chntpw commands I feel a little like Commisioner Gordon picking up the BatPhone and calling Gotham City&#8217;s last hope for salvation.<br />
<br />

<div style=" 
background-color: #F8F8F8;
padding: 10px;
width: 90%;
border-radius: 25px;
-moz-border-radius: 25px;
-webkit-border-radius: 25px;
    -webkit-box-shadow: 10px 10px 25px #D5D5D5;
    -moz-box-shadow: 10px 10px 25px #D5D5D5;
    box-shadow: 10px 10px 25px #D5D5D5;
"><br />
<strong>This means that&#8230;</strong><br />
<ul>
<li>The machine won&#8217;t boot into Windows XP safe mode or normal mode. </li>
<li>A System Restore is not an option or does not work.</li>
<li>The Last Known Good Configuration option does not work.</li>
</ul><br />
</div><br /><br />
<br />
<em>chntpw</em> is a console based tool that is included with the PartitionMagic Live CD that has a built-in registry editor which can be used to manipulate the Windows registry. To invoke the registry editor you have to specify the <code>-e</code> option with the name of registry hive file.<br />
<br />
Boot the Windows machine with the <a href="http://partedmagic.com/doku.php?id=downloads">PartitionMagic boot CD</a>.<br />
The button on the PartedMagic desktop in the lower left corner behaves like the START button on an XP desktop so we&#8217;ll call it START when we refer to it.<br />
<br />
Mount the disk that contains the registry hives.<br />
<strong>START&gt;SYSTEM TOOLS&gt;MOUNT-GTK</strong><br />
Click the mount button next to the drive that contains the Windows install that we will be working on. In our example it is <code>sda1</code> so this will mount it as <code>/media/sda1</code><br />
<br />
open a terminal window<br />
<strong>START&gt;ACCESSORIES&gt;LXTERMINAL</strong><br />
Go to the directory containing the registry hives (remember it is case sensitive)<br />
<code>cd /media/sda1/WINDOWS/system32/config</code><br />
<br />
<img src="http://html5.litten.com/images/reg/configlist.jpg" width="450"/><br />
<br />
Make a backup of the hive file that you will be editing<br />
<div style=" 
background-color: #F8F8F8;
padding: 10px;
width: 90%;
border-radius: 25px;
-moz-border-radius: 25px;
-webkit-border-radius: 25px;
    -webkit-box-shadow: 10px 10px 25px #D5D5D5;
    -moz-box-shadow: 10px 10px 25px #D5D5D5;
    box-shadow: 10px 10px 25px #D5D5D5;
"><br />
<table align="center" width="85%">
<tr><td><strong>Registry Key Name</strong></td><td><strong>Hive Filename</strong></td></tr>
<tr><td>HKEY_CURRENT_USER</td><td>NTuser.dat</td></tr>
<tr><td>HKEY_LOCAL_MACHINE\SAM</td><td>SAM</td></tr>
<tr><td>HKEY_LOCAL_MACHINE\SECURITY</td><td>SECURITY</td></tr>
<tr><td>HKEY_LOCAL_MACHINE\SOFTWARE</td><td>SOFTWARE</td></tr>
<tr><td>HKEY_LOCAL_MACHINE\SYSTEM</td><td>SYSTEM</td></tr>
<tr><td>HKEY_USERS\DEFAULT</td><td>DEFAULT</td></tr>
</table>
<br />
</div>
<br />
We&#8217;re going to play with the software hive so lets make a backup copy of it before we do anything.<br /><br />
<code>cp software software.mybak</code><br />
<br />
Now we can edit it with <em>chntpw</em><br />
<br />
<code>chntpw -e software</code><br />
<br />
We are now in the simple registry editor. Typing ? shows the options available to us.<br />
<br />
<img src="http://html5.litten.com/images/reg/options.jpg" width="450"/><br />
<br />
To navigate to the key<br />
<strong>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows<br />\CurrentVersion\Run</strong><br />
type (Case sensitive and use forward slashes)<br />
<br />
<code>cd Microsoft\Windows\CurrentVersion\Run</code><br />
<br />
and type <code>ls</code> to list the values in the key<br />
<br />
Lets add a value that will cause Windows Calculator (calc.exe) to run when a user logs in.<br />
Type<br />
<code>nv ?</code><br />
<br />
to see a list of the values for the different types.<br />
<br />
<img src="http://html5.litten.com/images/reg/values.jpg" width="400"/><br />
<br />
For our value we can type<br />
<br />
<code>nv 1 test</code><br />
<br />
now if we type <br />
<br />
<code>ls</code><br />
<br />
we see our new value listed<br />
<br />
Now to edit the contents of the value we type<br />
<br />
<code>ed test</code><br />
<br />
and we are asked to enter our string which in our case is <br />
<br />
<code>c:\windows\system32\calc.exe</code><br />
<br />
Then you can see the new value by typing<br />
<br />
<code>cat test</code><br />
<br />
<img src="http://html5.litten.com/images/reg/cattest.jpg" width="350"/><br />
<br />
Press <strong>q</strong> to exit the program and it gives you the option to save the changes that you made.<br />
<br />
Now when you reboot into Windows, the calculator program will open when a user logs in.<br />
<br />
<img src="http://html5.litten.com/images/reg/calc.jpg" width="400"/><br />
<br />
This is a very sensitive technique and you should do one change at a time and reboot to make sure everything is working. If not, restore your backup by copying it (so you have it still if there is another mishap) and try again. I have had to do this before.<br />
<br />
I have never used <em>chntpw</em> with Windows XP 64-bit but I have successfully used it with Windows XP 32-bit, Windows 7 64-bit and Windows 8 Consumer Preview 64-bit.<br /><br />]]></content:encoded>
			<wfw:commentRss>http://html5.litten.com/windows-file-recovery-series-part-6-readingediting-the-windows-registry-from-outside-of-windows/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows &#8216;File Recovery&#8217; series : Part 5 Manually Recover a Deleted File From an NTFS File System</title>
		<link>http://html5.litten.com/windows-file-recovery-series-part-5-manually-recover-a-deleted-file-from-an-ntfs-file-system/</link>
		<comments>http://html5.litten.com/windows-file-recovery-series-part-5-manually-recover-a-deleted-file-from-an-ntfs-file-system/#comments</comments>
		<pubDate>Mon, 12 Mar 2012 22:52:17 +0000</pubDate>
		<dc:creator>James Litten</dc:creator>
				<category><![CDATA[Data Recovery]]></category>
		<category><![CDATA[Windows File Recovery]]></category>
		<category><![CDATA[data recovery]]></category>
		<category><![CDATA[undelete files]]></category>
		<category><![CDATA[undelete.recover lost files]]></category>
		<category><![CDATA[windows file recovery]]></category>

		<guid isPermaLink="false">http://html5.litten.com/?p=817</guid>
		<description><![CDATA[Windows &#8216;File Recovery&#8217; series Part 5 Manually Recover a Deleted File From an NTFS File System DISCLAIMER: These examples use techniques that I actually employ in the real world to deal with real problems. They might be wrong or dangerous. They might be inefficient. If you try them yourself, it might cause damage or irreparable [...]]]></description>
			<content:encoded><![CDATA[<h2>Windows &#8216;File Recovery&#8217; series <br />
Part 5 Manually Recover a Deleted File From an NTFS File System</h2>
<p>
<b>DISCLAIMER:</b><i> These examples use techniques that I actually employ in the real world to deal with real problems. They might be wrong or dangerous. They might be inefficient. If you try them yourself, it might cause damage or irreparable loss. I take no responsibility for anything you do based on my examples or the information that I provide here.</i>
</p>
<p>
In this series we&#8217;ll look at some real world examples of disastrous situations salvaged and made better again.
</p>
<p>
For this post we will be looking at Windows NTFS filesystems.
</p>
<h2>How files are deleted</h2>   
<p>
Deleted files are not removed from the hard drive until the space that they occupy is needed by a new file.
</p>
<p>
When a file is deleted, the list of disk clusters occupied by the file is erased, marking those sectors available for use by other files created or modified thereafter. If the file wasn&#8217;t fragmented and the clusters haven&#8217;t been reused, you should have a great chance of getting it back.
</p>
<p>
Recovery is often done by looking at the raw data on the disk for data in areas that are marked as being available for use, then determine the file type and directory structure, copy them and save them elsewhere.
</p>

<h2>NTFS and the MFT</h2>
<span id="more-817"></span>
<p>
In an NTFS file system deleted data is found by looking at the hidden $BitMap file for areas of the disk marked as available for use. The $BitMap file is a special file within the NTFS file system. This file keeps track of all of the used and unused clusters on an NTFS volume. If data is found in an area of the disk that is marked as &#8216;unused&#8217; in the $BitMap file then it is probably deleted data.
</p>

<p>
Next the location of the data can be used to check for an existing entry in the MFT. Each file and folder on an NTFS volume is represented by a record in a special file called the master file table (MFT). That record contains the location of the clusters on the disk that hold the file&#8217;s data. The MFT record for the deleted file will stay there until something else is written to that location of the disk and overwrites the deleted files data (making it unrecoverable).
</p>

<p>
Enough talk, lets look at a real example. 
</p>  

<h2>Delete and recover a file</h2>
<p> Our OS is Windows XP Pro SP3
We have a hard drive with two NTFS partitions that Windows sees as a C: drive and an E: drive.
</p>

On our E: drive we have a image stored in a file named globe.jpg<br />
<p align="center"><a href="http://html5.litten.com/images/manund/1.jpg" rel="lightbox[manund]"><img src="http://html5.litten.com/images/manund/1.jpg" width="450"/></a></p>

Let&#8217;s look at the MFT record for this file. To do that, we&#8217;ll download and run the free program NTFSWalker&#8230; <br />
<a href="http://dmitrybrant.com/ntfswalker">http://dmitrybrant.com/ntfswalker</a><br />
Here is the MFT record for globe.jpg<br />
<p align="center"><a href="http://html5.litten.com/images/manund/3.jpg" rel="lightbox[manund]"><img src="http://html5.litten.com/images/manund/3.jpg" width="450"/></a></p>

Some of the important things for us to note about the MFT record for globe.jpg<br /><br />

It is MFT record #132<br /><br />

&#8216;Data runs&#8217; 300130:31 tells us that it starts in disk cluster 300130 and occupies 31 clusters.<br /><br />

Lets take a look at that first cluster. We&#8217;ll use another free program called Disk Investigator&#8230;<br />
<a href="http://www.diskcleaners.com/#dskinv">http://www.diskcleaners.com/#dskinv</a><br />
Here is the data for our file&#8230;<br />
<p align="center"><a href="http://html5.litten.com/images/manund/6.jpg" rel="lightbox[manund]"><img src="http://html5.litten.com/images/manund/6.jpg" width="450"/></a></p>
Note that our starting sector is 1200520. That means there are 4 sectors per cluster (1200520 sectors / 300130 clusters) .<br /><br />
 
We&#8217;ll shift-delete it<br />
<p align="center"><a href="http://html5.litten.com/images/manund/4.jpg" rel="lightbox[manund]"><img src="http://html5.litten.com/images/manund/4.jpg" width="450"/></a></p>

Now when we look at it&#8217;s MFT record we see a red &#8216;X&#8217; next to it. That is because the area it occupies on the disk is now marked as available for use by the $BitMap file.<br /><br />
<p align="center"><a href="http://html5.litten.com/images/manund/5.jpg" rel="lightbox[manund]"><img src="http://html5.litten.com/images/manund/5.jpg" width="450"/></a></p>
If we look at the raw disk data, it is still there&#8230;<br />
<p align="center"><a href="http://html5.litten.com/images/manund/6.jpg" rel="lightbox[manund]"><img src="http://html5.litten.com/images/manund/6.jpg" width="450"/></a></p>

The NTFSWalker program allows us to recover it but lets do this by grabbing the raw data and see what happens. First lets look at the end of the file. Notice that it does not use all of the last cluster and ends in sector 1200640.<br />
<p align="center"><a href="http://html5.litten.com/images/manund/7.jpg" rel="lightbox[manund]"><img src="http://html5.litten.com/images/manund/7.jpg" width="450"/></a></p>

Now lets boot into Linux using a PartedMagic boot CD so we can grab the raw data using a Disk Dump command (dd). <br />
<a href="http://partedmagic.com/doku.php?id=downloads">http://partedmagic.com/doku.php?id=downloads</a><br /><br />

<p align="center"><a href="http://html5.litten.com/images/manund/8.jpg" rel="lightbox[manund]"><img src="http://html5.litten.com/images/manund/8.jpg" width="450"/></a></p>

We open a terminal window and type this command&#8230;<br /><br />
dd if=/dev/sda2 of=/media/sda1/recoverglobe bs=512 skip=1200520 count=120 <br /><br />

dd (our disk dump command)<br />
if=/dev/sda2 (read from the partition that Windows calls the E: drive)<br />
of=/media/sda1/recoverglobe (save what we read to the file C:\recoverglobe)<br />
bs=512 (read in blocks of 512 bytes which is the size of one sector)<br /> 
skip=1200520 (skip the first 1200520 sectors)<br />
count=120 (read 120 sectors)<br />
<p align="center"><a href="http://html5.litten.com/images/manund/9.jpg" rel="lightbox[manund]"><img src="http://html5.litten.com/images/manund/9.jpg" width="450"/></a></p>

When we look at our new recoverglobe file it is indeed our picture.<br />
<p align="center"><a href="http://html5.litten.com/images/manund/10.jpg" rel="lightbox[manund]"><img src="http://html5.litten.com/images/manund/10.jpg" width="450"/></a></p>

And when we boot back into Windows our recoverglobe picture is there in the root of our C: drive.<br />
<p align="center"><a href="http://html5.litten.com/images/manund/12.jpg" rel="lightbox[manund]"><img src="http://html5.litten.com/images/manund/12.jpg" width="450"/></a></p>

<h2>A deleted file&#8217;s data is overwritten</h2>
<p>
 Now lets copy a bunch of random files to our E: drive and see what happens. Note that our record #132 in the MFT is now replaced with a new file that is occupying some of the space that our deleted file was in. The deleted file is now unrecoverable.
</p>
<p align="center"><a href="http://html5.litten.com/images/manund/13.jpg" rel="lightbox[manund]"><img src="http://html5.litten.com/images/manund/13.jpg" width="450"/></a></p>

]]></content:encoded>
			<wfw:commentRss>http://html5.litten.com/windows-file-recovery-series-part-5-manually-recover-a-deleted-file-from-an-ntfs-file-system/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows &#8216;File Recovery&#8217; series : Part 4 Recover Files From a Bad Hard Drive</title>
		<link>http://html5.litten.com/windows-file-recovery-series-part-4-recover-files-from-a-bad-hard-drive/</link>
		<comments>http://html5.litten.com/windows-file-recovery-series-part-4-recover-files-from-a-bad-hard-drive/#comments</comments>
		<pubDate>Sat, 10 Mar 2012 17:31:53 +0000</pubDate>
		<dc:creator>James Litten</dc:creator>
				<category><![CDATA[Data Recovery]]></category>
		<category><![CDATA[Windows File Recovery]]></category>
		<category><![CDATA[data recovery]]></category>
		<category><![CDATA[undelete files]]></category>
		<category><![CDATA[undelete.recover lost files]]></category>
		<category><![CDATA[windows file recovery]]></category>

		<guid isPermaLink="false">http://html5.litten.com/?p=799</guid>
		<description><![CDATA[Windows &#8216;File Recovery&#8217; series Part 4 Recover Files From a Bad Hard Drive DISCLAIMER: These examples use techniques that I actually employ in the real world to deal with real problems. They might be wrong or dangerous. They might be inefficient. If you try them yourself, it might cause damage or irreparable loss. I take [...]]]></description>
			<content:encoded><![CDATA[<h2>Windows &#8216;File Recovery&#8217; series <br />
Part 4 Recover Files From a Bad Hard Drive</h2>
<p>
<b>DISCLAIMER:</b><i> These examples use techniques that I actually employ in the real world to deal with real problems. They might be wrong or dangerous. They might be inefficient. If you try them yourself, it might cause damage or irreparable loss. I take no responsibility for anything you do based on my examples or the information that I provide here.</i>
</p>
<p>
In this series we&#8217;ll look at some real world examples of disastrous situations salvaged and made better again.
</p>
<p>
We will be looking at Windows (FAT and NTFS) filesystems.
</p>
<h2>How it usually starts</h2>
<p>
Often as a hard drive begins to go &#8216;bad&#8217; you start to get strange errors in programs and your computer occassionally shuts down with a blue screen error. You may also start to notice sounds from the hard drive that you have not heard before. In many cases, the computer will not boot to Windows at all and none of the repair options will seem to work. Disk diagnostics programs either crash, show errors on the disk or don&#8217;t run at all.
</p>
<p>
At this point the user realizes that they need to completely re-install Windows (and hopefully, but not always, understand that they need to replace the hard drive). How do they get their data from a crashing or unbootable drive? 
</p>
<h2>How to Recover the Data</h2>
<p>
<b>A broken hard drive isn&#8217;t just &#8216;broken&#8217; it is almost always still in the process of &#8216;breaking&#8217; and everything we do to it is going to make it worse. That means we have to be as efficient as possible in our recovery efforts.</b>
</p>
<span id="more-799"></span>
<p>
 In this example we are going to show a recovery &#8216;in the field&#8217; by connecting a good USB external drive and externally connecting the &#8216;bad&#8217; drive via a USB adapter to a Compaq Presario 2200 laptop named Buster.
</p>
<p>
 Preferably, this kind of job should be done on a dedicated recovery machine where the &#8216;good&#8217; and &#8216;bad&#8217; drives are connected directly to the motherboard and every thing about the machine is perfect except the &#8216;bad&#8217; hard drive that we are trying to recover. (This particular &#8216;bad&#8217; drive was already successfully recovered once using just such a computer.) Most people don&#8217;t have access to a machine like that but have a laptop in addition to their desktop so this example shows how to use the resources commonly on hand. The external drive used is a 1.5TB Western Digital external drive that costs about $100 and the USB to IDE drive connector used on the bad drive is a JMicron USB to ATA/ATAPI Bridge that can be found for about $20. If the laptop has enough free space on its internal drive (this one does not), you don&#8217;t need the external drive.
</p>
<p align="center"><img src="http://html5.litten.com/images/badhdresc/18.jpg" width="450"/></a></p>
<p align="center"><img src="http://html5.litten.com/images/badhdresc/19.jpg" width="450"/></a></p>
<p align="center"><img src="http://html5.litten.com/images/badhdresc/21.jpg" width="450"/></a></p>
Now we boot buster from a Parted Magic boot CD<br />
<a href="http://partedmagic.com/doku.php?id=downloads">http://partedmagic.com/doku.php?id=downloads</a><br /><br />
<p align="center"><img src="http://html5.litten.com/images/badhdresc/20.jpg" width="450"/></a></p>
First we run gparted by double clicking the Partition Editor icon.<br />
Looks like gparted sees no partitions on the bad drive.<br />
<p align="center"><a href="http://html5.litten.com/images/badhdresc/3.jpg" rel="lightbox[badhdresc]"><img src="http://html5.litten.com/images/badhdresc/3.jpg" width="450"/></a></p>
Now we open up the terminal and type<br />
<br />
fdisk -lu<br />
<p align="center"><a href="http://html5.litten.com/images/badhdresc/2.jpg" rel="lightbox[badhdresc]"><img src="http://html5.litten.com/images/badhdresc/2.jpg" width="450"/></a></p>
to identify the disks and we see<br />
/dev/sdc is our &#8216;bad&#8217; drive.<br />
/dev/sdb1 is where we wish to copy the data to as a disk image file.<br />

<p>
We&#8217;ll try to use the program ddrescue to recover the data.<br />
It is included on the Parted Magic boot CD, here&#8217;s the manual&#8230;<br />
<a href="http://www.gnu.org/software/ddrescue/manual/ddrescue_manual.html">http://www.gnu.org/software/ddrescue/manual/ddrescue_manual.html</a><br />
ddrescue helps you make a copy of a disk with errors while minimizing further damage to the disk. It does this by skipping every bad sector it comes across, noting where it exists and then coming back to it only after all of the good sectors have been copied. As long as you allow it to make a log file, you can repeatedly come back to the bad disk and try to recover the bad sectors. It also allows you to resume a copy from where it left off if there is a crash or a power failure.
</p>
<p>
ddrescue tries to make an exact copy of the disk. That way, you can recover deleted files and partitions from the copy just like you can recover them from the original.
</p>

In our example we use this command in the terminal of Parted Magic&#8230;<br />
<br />
ddrescue -r 3 /dev/sdc /media/sdb1/image.dd /media/sda1/rescuelog.log <br />
<p>
This runs ddrescue<br /> 
-r 3 tells ddrescue to retry rescuing each bad sector 3 times before giving up on it.<br />
/dev/sdc is the &#8216;bad&#8217; drive that we are copying.<br />
/media/sdb1/image.dd is the image file that we want to copy the &#8216;bad&#8217; drive to.<br />
/media/sda1/rescuelog.log is where we want to save our logfile which is in the root of Buster&#8217;s C: drive.<br />
</p>
<p>
After over 15 hours it completed and recovered the whole drive.<br />
As a comparison, a healthy 40GB IDE drive containing over 30GB of data on the same setup finished in under two hours (maybe sooner as I left it and returned two hours later to find it completed). 
</p>
<p align="center"><a href="http://html5.litten.com/images/badhdresc/7.jpg" rel="lightbox[badhdresc]"><img src="http://html5.litten.com/images/badhdresc/7.jpg" width="450"/></a></p>

Now we run TestDisk on the image file to search for partition(s)<br />
C:\testdisk-6.13.win\testdisk-6.13>testdisk_win.exe k:\image.dd<br /><br />

<b>NOTE:</b> We could also run PhotoRec (<b><a href="http://html5.litten.com/windows-file-recovery-series-part-2-recover-deleted-files-with-testdisk-and-photorec/">See Part 2 of this series</a></b>) against this image if we only wanted to recover specific filetypes.<br /><br />

In TestDisk we choose quicksearch and find a small DOS recovery partition with all files intact.<br />
Now we go further and choose the deepersearch option and find our main NTFS partition from a backup sector.<br />
<p align="center"><a href="http://html5.litten.com/images/badhdresc/15.jpg" rel="lightbox[badhdresc]"><img src="http://html5.litten.com/images/badhdresc/15.jpg" width="450"/></a></p>
Next we choose to restore the backup boot sector and the image is fixed.<br />
<p align="center"><a href="http://html5.litten.com/images/badhdresc/16.jpg" rel="lightbox[badhdresc]"><img src="http://html5.litten.com/images/badhdresc/16.jpg" width="450"/></a></p>
<p>
For our example, we&#8217;ll recover just the main partition&#8217;s files straight from TestDisk to illustrate that we could recover this to a disk from our repaired image. In a real life recovery, we would get a new disk large enough to hold the image and then use dd or ddrescue with the image file as our input and the new drive as our output.
</p>

<p>
In TestDisk from the partition list of our image file we select our partition then we press &#8216;p&#8217; to view files and folders on the partition then we press &#8216;a&#8217; to select all of them then we press &#8216;C&#8217; to copy selected files then we choose the location to send them to.
</p> 

<p>
Here we sent them to an empty partition that we made that Windows calls the H: drive. Here are all the files. There were about a dozen corrupted files in this recovery but they were not in any system files.
</p>
<p align="center"><a href="http://html5.litten.com/images/badhdresc/17.jpg" rel="lightbox[badhdresc]"><img src="http://html5.litten.com/images/badhdresc/17.jpg" width="450"/></a></p>
<p>
This drive was dead and inaccessible from Windows. When I originally rescued it I did the ddrescue, recovered the partitions to a new internal drive and after we put the new drive into the computer that the bad drive was in, it booted up fine and everything was there. That was over a year ago and it is still running with that drive and OS.
</p>
 
<p>
Even though the user had repeatedly run various disk repair tools which all crashed after several hours, we were able to recover this drive&#8217;s data and they were very happy.
</p>
]]></content:encoded>
			<wfw:commentRss>http://html5.litten.com/windows-file-recovery-series-part-4-recover-files-from-a-bad-hard-drive/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows ‘File Recovery’ series : Part 3 Recover A Deleted Partition with Testdisk</title>
		<link>http://html5.litten.com/windows-file-recovery-series-part-3-recover-a-deleted-partition-with-testdisk/</link>
		<comments>http://html5.litten.com/windows-file-recovery-series-part-3-recover-a-deleted-partition-with-testdisk/#comments</comments>
		<pubDate>Thu, 08 Mar 2012 22:54:02 +0000</pubDate>
		<dc:creator>James Litten</dc:creator>
				<category><![CDATA[Data Recovery]]></category>
		<category><![CDATA[Windows File Recovery]]></category>
		<category><![CDATA[data recovery]]></category>
		<category><![CDATA[undelete files]]></category>
		<category><![CDATA[undelete.recover lost files]]></category>
		<category><![CDATA[windows file recovery]]></category>

		<guid isPermaLink="false">http://html5.litten.com/?p=783</guid>
		<description><![CDATA[Windows &#8216;File Recovery&#8217; series Part 3 Recover A Deleted Partition with Testdisk DISCLAIMER: These examples use techniques that I actually employ in the real world to deal with real problems. They might be wrong or dangerous. They might be inefficient. If you try them yourself, it might cause damage or irreparable loss. I take no [...]]]></description>
			<content:encoded><![CDATA[<h2>Windows &#8216;File Recovery&#8217; series <br />
Part 3 Recover A Deleted Partition with Testdisk</h2>
<p>
<b>DISCLAIMER:</b><i> These examples use techniques that I actually employ in the real world to deal with real problems. They might be wrong or dangerous. They might be inefficient. If you try them yourself, it might cause damage or irreparable loss. I take no responsibility for anything you do based on my examples or the information that I provide here.</i>
</p>
<p>
In this series we&#8217;ll look at some real world examples of disastrous situations salvaged and made better again.
</p>
<p>
We will be looking at Windows (FAT and NTFS) filesystems.
</p>
<h2>How partitions are deleted</h2>   
This post is not about partitions disappearing due to damage or corruption of the file system. That kind of recovery will be covered later in this series. Here we will discuss solutions for recovering from accidental removal of a partition.
<p>
From personal experience, there are three ways that I have seen partitions accidentally deleted. <br /><br />
<div style=" 
background-color: #F8F8F8;
padding: 10px;
width: 90%;
border-radius: 25px;
-moz-border-radius: 25px;
-webkit-border-radius: 25px;
    -webkit-box-shadow: 10px 10px 25px #D5D5D5;
    -moz-box-shadow: 10px 10px 25px #D5D5D5;
    box-shadow: 10px 10px 25px #D5D5D5;
"><br />
<b>1.</b> While trying to use partition changing software. Usually while changing the size of an existing partition or adding a new one.<br /><br />

<b>2.</b> When adding an operating system to make a multiboot computer.<br /><br />

<b>3.</b> When re-installing an operating system on a drive with multiple partitions.<br /><br />
</div><br /><br />
I&#8217;m sure that there are other ways that it happens too. Computers are always full of new surprises when it comes to breaking them.   
</p>
<h2>Deleted Partition Recovery with TestDisk</h2>
<span id="more-783"></span>
<p>
We&#8217;ll do this in Windows XP Professional Service Pack 3
</p>
Let&#8217;s delete the E: drive partition. It has some files and folders on it.<br />
<p align="center"><a href="http://html5.litten.com/images/td_part/1.jpg" rel="lightbox[td_part]"><img src="http://html5.litten.com/images/td_part/1.jpg" width="450"/></a></p>
Goodbye E:<br />
<p align="center"><a href="http://html5.litten.com/images/td_part/3.jpg" rel="lightbox[td_part]"><img src="http://html5.litten.com/images/td_part/3.jpg" width="450"/></a></p>
<p align="center"><img src="http://html5.litten.com/images/td_part/4.jpg"/></a></p>
<p>
TestDisk does an excellent job of recovering deleted partitions.
</p>
Always create a log unless you are running from a read only location like a Live Boot CD.<br />
<p align="center"><a href="http://html5.litten.com/images/td_part/5.jpg" rel="lightbox[td_part]"><img src="http://html5.litten.com/images/td_part/5.jpg" width="450"/></a></p>
Choose the Drive that the partition was deleted from.<br />
Select Intel/PC partition<br />
Select Analyze<br />
Select Quick Search<br />
<p align="center"><a href="http://html5.litten.com/images/td_part/6.jpg" rel="lightbox[td_part]"><img src="http://html5.litten.com/images/td_part/6.jpg" width="450"/></a></p>
Even on XP I always answer &#8216;yes&#8217; to this question<br />
<p align="center"><a href="http://html5.litten.com/images/td_part/7.jpg" rel="lightbox[td_part]"><img src="http://html5.litten.com/images/td_part/7.jpg" width="450"/></a></p>
Found it!<br />
<p align="center"><a href="http://html5.litten.com/images/td_part/8.jpg" rel="lightbox[td_part]"><img src="http://html5.litten.com/images/td_part/8.jpg" width="450"/></a></p>
Let&#8217;s select P to see if our files are there.<br />
<p align="center"><a href="http://html5.litten.com/images/td_part/9.jpg" rel="lightbox[td_part]"><img src="http://html5.litten.com/images/td_part/9.jpg" width="450"/></a></p>
Looks great, let&#8217;s recover it press &#8216;q&#8217; then press enter and select &#8216;write&#8217; to write the partition&#8217;s location to the partition table of our MBR.<br />
<p align="center"><a href="http://html5.litten.com/images/td_part/10.jpg" rel="lightbox[td_part]"><img src="http://html5.litten.com/images/td_part/10.jpg" width="450"/></a></p>
It will write the new partition table and tell you to reboot so quit out of TestDisk and reboot.<br />
It worked!<br />
<p align="center"><a href="http://html5.litten.com/images/td_part/11.jpg" rel="lightbox[td_part]"><img src="http://html5.litten.com/images/td_part/11.jpg" width="450"/></a></p>

<h2>Deleted Boot Partition Recovery with TestDisk</h2>
Oops, I accidentally deleted the C: drive partition using a third party partition manager.<br /><br />
Now when I boot up the machine it says&#8230;<br />
&#8220;Operating system not found&#8221;<br />
<p align="center"><img src="http://html5.litten.com/images/td_part/not_found.jpg"/></a></p>
Lets get Parted Magic and make a boot CD<br />
<a href="http://partedmagic.com/doku.php?id=downloads">http://partedmagic.com/doku.php?id=downloads</a><br /><br />
Boot to the Parted Magic CD on your broken computer. Choose &#8216;Default Settings&#8217; to Run from RAM.<br /><br />
Run TestDisk <br />
<p align="center"><a href="http://html5.litten.com/images/td_part/12a.jpg" rel="lightbox[td_part]"><img src="http://html5.litten.com/images/td_part/12a.jpg" width="450"/></a></p>
Proceed as in the previous example and find the missing partition. There it is!<br />
<p align="center"><a href="http://html5.litten.com/images/td_part/13.jpg" rel="lightbox[td_part]"><img src="http://html5.litten.com/images/td_part/13.jpg" width="450"/></a></p>
Recover C: partition like we did for E: above.<br />
Reboot<br />
SUCCESS!<br />
<p align="center"><a href="http://html5.litten.com/images/td_part/14.jpg" rel="lightbox[td_part]"><img src="http://html5.litten.com/images/td_part/14.jpg" width="450"/></a></p>

]]></content:encoded>
			<wfw:commentRss>http://html5.litten.com/windows-file-recovery-series-part-3-recover-a-deleted-partition-with-testdisk/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows &#8216;File Recovery&#8217; series : Part 2 Recover Deleted files with Testdisk and PhotoRec</title>
		<link>http://html5.litten.com/windows-file-recovery-series-part-2-recover-deleted-files-with-testdisk-and-photorec/</link>
		<comments>http://html5.litten.com/windows-file-recovery-series-part-2-recover-deleted-files-with-testdisk-and-photorec/#comments</comments>
		<pubDate>Thu, 08 Mar 2012 01:34:09 +0000</pubDate>
		<dc:creator>James Litten</dc:creator>
				<category><![CDATA[Data Recovery]]></category>
		<category><![CDATA[Windows File Recovery]]></category>
		<category><![CDATA[data recovery]]></category>
		<category><![CDATA[undelete files]]></category>
		<category><![CDATA[undelete.recover lost files]]></category>
		<category><![CDATA[windows file recovery]]></category>

		<guid isPermaLink="false">http://html5.litten.com/?p=774</guid>
		<description><![CDATA[Windows &#8216;File Recovery&#8217; series Part 2 Recover Deleted files with Testdisk and PhotoRec DISCLAIMER: These examples use techniques that I actually employ in the real world to deal with real problems. They might be wrong or dangerous. They might be inefficient. If you try them yourself, it might cause damage or irreparable loss. I take [...]]]></description>
			<content:encoded><![CDATA[<h2>Windows &#8216;File Recovery&#8217; series <br />
Part 2 Recover Deleted files with Testdisk and PhotoRec</h2>

<p>
 <b>DISCLAIMER:</b><i> These examples use techniques that I actually employ in the real world to deal with real problems. They might be wrong or dangerous. They might be inefficient. If you try them yourself, it might cause damage or irreparable loss. I take no responsibility for anything you do based on my examples or the information that I provide here.</i>
</p>
<p>
<strong>Data recovery from hard drives</strong> has not changed much in decades. However, the effectiveness and ease of use of free tools has increased greatly. Also, the fact that CD&#8217;s, DVD&#8217;s, flash drives, SD cards and USB keys are made to behave like hard drives makes them candidates for recovery using the same tools. SSD&#8217;s provide some new challenges due to techniques they use to extend their life expectancy but for the most part are recoverable in the same manner as platter based drives.
</p>
<p>
 In this series we&#8217;ll look at some real world examples of disastrous situations salvaged and made better again.
</p>
<p>
 We will be looking at Windows (FAT and NTFS) filesystems.
</p>
<h2>How files are deleted</h2>   
<p>
 Deleted files are not removed from the hard drive until the space that they occupy is needed by a new file.
</p>
<p>
 When a file is deleted, the <b><i>list</i></b> of disk clusters occupied by the file is erased, marking those sectors available for use by other files created or modified thereafter. If the file wasn&#8217;t fragmented and the clusters haven&#8217;t been reused, you should have a great chance of getting it back.
</p>
<p>
 Recovery is often done by looking at the raw data on the disk for unreferenced data, then determine the file type and directory structure, rebuild them and save them elsewhere.
</p>

<h2>Simple Recovery with Testdisk and PhotoRec</h2>
<p>
 We&#8217;ll do this in Windows XP Professional Service Pack 3
</p>
<p>
 TestDisk is a program that does lots of things that we will talk about later in this series but for this post we are looking at its file undelete capabilities. It also comes with the program PhotoRec which has some advantages for recovering specific file types like pictures or Outlook mailboxes (currently over 200 file types).
</p>
<h2>When to use TestDisk or PhotoRec for Deleted File Recovery</h2>
<span id="more-774"></span>
<p>
 Recuva is great for recovering files when you are working in a Windows environment (<b><a href="http://html5.litten.com/windows-file-recovery-series-part-1-recover-deleted-files-with-recuva/">See Part 1 of this series</a></b>). It also has better directory structure recovery than TestDisk and is very easy to use. However, when you are trying to recover files from a broken Windows machine using a Linux bootdisk TestDisk and PhotoRec are your best choice. For this example we will be running it from within a Windows environment but it looks exactly the same as when you run it from a Linux Live environment like Puppy Linux. Use TestDisk to recover everything deleted on a partition and use PhotoRec to recover specific filetypes from a partition (all the .jpg picture files for example).
</p>
Since TestDisk looks at a whole partition for deleted files we will create a little 1GB test partition on our disk drive and call it the E: drive. <br />
<p align="center"><a href="http://html5.litten.com/images/testdisknorm/1.jpg" rel="lightbox[testdisknorm]"><img src="http://html5.litten.com/images/testdisknorm/1.jpg" width="450"/></a></p>
We then put a folder full of important files and some pictures on the E: drive.<br />
<p align="center"><a href="http://html5.litten.com/images/testdisknorm/2.jpg" rel="lightbox[testdisknorm]"><img src="http://html5.litten.com/images/testdisknorm/2.jpg" width="450"/></a></p>
Then we Shift-Delete everything on the E: drive<br />
<p align="center"><a href="http://html5.litten.com/images/testdisknorm/3.jpg" rel="lightbox[testdisknorm]"><img src="http://html5.litten.com/images/testdisknorm/3.jpg" width="450"/></a></p>
Download and run TestDisk<br />
<a href="http://www.cgsecurity.org/wiki/TestDisk">http://www.cgsecurity.org/wiki/TestDisk</a><br />
<p align="center"><a href="http://html5.litten.com/images/testdisknorm/4.jpg" rel="lightbox[testdisknorm]"><img src="http://html5.litten.com/images/testdisknorm/4.jpg" width="450"/></a></p>
Choose our hard drive<br />
<p align="center"><a href="http://html5.litten.com/images/testdisknorm/5.jpg" rel="lightbox[testdisknorm]"><img src="http://html5.litten.com/images/testdisknorm/5.jpg" width="450"/></a></p>
Select Intel/PC partition<br />
<p align="center"><a href="http://html5.litten.com/images/testdisknorm/6.jpg" rel="lightbox[testdisknorm]"><img src="http://html5.litten.com/images/testdisknorm/6.jpg" width="450"/></a></p>
Select the ADVANCED Filesystem Utils<br />
<p align="center"><a href="http://html5.litten.com/images/testdisknorm/7.jpg" rel="lightbox[testdisknorm]"><img src="http://html5.litten.com/images/testdisknorm/7.jpg" width="450"/></a></p>
Select our E: drive partition and select UNDELETE<br />
<p align="center"><a href="http://html5.litten.com/images/testdisknorm/8.jpg" rel="lightbox[testdisknorm]"><img src="http://html5.litten.com/images/testdisknorm/8.jpg" width="450"/></a></p>
Now you see all of the deleted files on the E: drive that you can recover<br />
<p align="center"><a href="http://html5.litten.com/images/testdisknorm/9.jpg" rel="lightbox[testdisknorm]"><img src="http://html5.litten.com/images/testdisknorm/9.jpg" width="450"/></a></p>
After telling it where to copy the undeleted data to, we can open it and it all works.
<p align="center"><a href="http://html5.litten.com/images/testdisknorm/11.jpg" rel="lightbox[testdisknorm]"><img src="http://html5.litten.com/images/testdisknorm/11.jpg" width="450"/></a></p>

<h2>What Happens When You Overwrite Some of the Deleted Data ?</h2>
Now before attempting to recover the files that we deleted, we put a bunch of audio files onto the E: drive<br />
<p align="center"><a href="http://html5.litten.com/images/testdiskover/1.jpg" rel="lightbox[testdiskover]"><img src="http://html5.litten.com/images/testdiskover/1.jpg" width="450"/></a></p>
When we attempt our recovery we see that we can no longer recover all of the files that were in the ImportantFiles folder and all we can get are the images.<br />
<p align="center"><a href="http://html5.litten.com/images/testdiskover/2.jpg" rel="lightbox[testdiskover]"><img src="http://html5.litten.com/images/testdiskover/2.jpg" width="450"/></a></p>
<p>
 This illustrates why it is important to attempt recovery before anything else is written on the disk and potentially overwrites the data that you need to recover.
</p>

<h2>Using PhotoRec for file recovery</h2>
<p>
 Since PhotoRec focuses on specific filetypes, it is incredibly powerful. It uses techniques such as <a href="http://en.wikipedia.org/wiki/File_carving">file carving</a> to try to get as complete a recovery as possible without a human actually analyzing the data stored on the drive.
</p>
When you run it, it looks like TestDisk and you select your partition the same way. Then it asks you which filetypes you want to recover. For our example we will choose only .jpg image files.<br />
<p align="center"><a href="http://html5.litten.com/images/photorec/3.jpg" rel="lightbox[photorec]"><img src="http://html5.litten.com/images/photorec/3.jpg" width="450"/></a></p>
Then you choose a destination for the recovered files and it works its magic.<br />
<p align="center"><a href="http://html5.litten.com/images/photorec/8.jpg" rel="lightbox[photorec]"><img src="http://html5.litten.com/images/photorec/8.jpg" width="450"/></a></p>
It recovered them all!<br />
<p align="center"><a href="http://html5.litten.com/images/photorec/10.jpg" rel="lightbox[photorec]"><img src="http://html5.litten.com/images/photorec/10.jpg" width="450"/></a></p>
And you also get a nice log file<br />
<p align="center"><a href="http://html5.litten.com/images/photorec/9.jpg" rel="lightbox[photorec]"><img src="http://html5.litten.com/images/photorec/9.jpg" width="450"/></a></p> 
]]></content:encoded>
			<wfw:commentRss>http://html5.litten.com/windows-file-recovery-series-part-2-recover-deleted-files-with-testdisk-and-photorec/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows &#8216;File Recovery&#8217; series : Part 1 Recover Deleted files with Recuva</title>
		<link>http://html5.litten.com/windows-file-recovery-series-part-1-recover-deleted-files-with-recuva/</link>
		<comments>http://html5.litten.com/windows-file-recovery-series-part-1-recover-deleted-files-with-recuva/#comments</comments>
		<pubDate>Wed, 07 Mar 2012 21:34:12 +0000</pubDate>
		<dc:creator>James Litten</dc:creator>
				<category><![CDATA[Data Recovery]]></category>
		<category><![CDATA[Windows File Recovery]]></category>
		<category><![CDATA[data recovery]]></category>
		<category><![CDATA[undelete files]]></category>
		<category><![CDATA[undelete.recover lost files]]></category>
		<category><![CDATA[windows file recovery]]></category>

		<guid isPermaLink="false">http://html5.litten.com/?p=744</guid>
		<description><![CDATA[Windows &#8216;File Recovery&#8217; series Part 1 Recover Deleted files with Recuva DISCLAIMER: These examples use techniques that I actually employ in the real world to deal with real problems. They might be wrong or dangerous. They might be inefficient. If you try them yourself, it might cause damage or irreparable loss. I take no responsibility [...]]]></description>
			<content:encoded><![CDATA[<h2>Windows &#8216;File Recovery&#8217; series <br />
Part 1 Recover Deleted files with Recuva</h2>

<p>
 <b>DISCLAIMER:</b><i> These examples use techniques that I actually employ in the real world to deal with real problems. They might be wrong or dangerous. They might be inefficient. If you try them yourself, it might cause damage or irreparable loss. I take no responsibility for anything you do based on my examples or the information that I provide here.</i>
</p>
<p>
<strong>Data recovery from hard drives</strong> has not changed much in decades. However, the effectiveness and ease of use of free tools has increased greatly. Also, the fact that CD&#8217;s, DVD&#8217;s, flash drives, SD cards and USB keys are made to behave like hard drives makes them candidates for recovery using the same tools. SSD&#8217;s provide some new challenges due to techniques they use to extend their life expectancy but for the most part are recoverable in the same manner as platter based drives.
</p>
<p>
 In this series we&#8217;ll look at some real world examples of disastrous situations salvaged and made better again.
</p>
<p>
 We will be looking at Windows (FAT and NTFS) filesystems.
</p>
<h2>How files are deleted</h2>   
<p>
 Deleted files are not removed from the hard drive until the space that they occupy is needed by a new file.
</p>
<p>
 When a file is deleted, the <b><i>list</i></b> of disk clusters occupied by the file is erased, marking those sectors available for use by other files created or modified thereafter. If the file wasn&#8217;t fragmented and the clusters haven&#8217;t been reused, you should have a great chance of getting it back.
</p>
<p>
 Recovery is often done by looking at the raw data on the disk for unreferenced data, then determine the file type and directory structure, rebuild them and save them elsewhere.
</p>
<span id="more-744"></span>
<h2>Simple Recovery with Recuva</h2>
We&#8217;ll do this in Windows XP Professional Service Pack 3<br />
<p align="center"><a href="http://html5.litten.com/images/recuvanorm/1.jpg" rel="lightbox[recuvanorm]"><img src="http://html5.litten.com/images/recuvanorm/1.jpg" width="450"/></a></p>
Here are the files in the <b><i>Important Files</i></b> folder<br />
<p align="center"><a href="http://html5.litten.com/images/recuvanorm/2.jpg" rel="lightbox[recuvanorm]"><img src="http://html5.litten.com/images/recuvanorm/2.jpg" width="450"/></a></p>
Delete the files in the <b><i>Important Files</i></b> folder<br />
<p align="center"><a href="http://html5.litten.com/images/recuvanorm/3.jpg" rel="lightbox[recuvanorm]"><img src="http://html5.litten.com/images/recuvanorm/3.jpg" width="450"/></a></p>
Empty the Recycle Bin<br />
<p align="center"><a href="http://html5.litten.com/images/recuvanorm/4.jpg" rel="lightbox[recuvanorm]"><img src="http://html5.litten.com/images/recuvanorm/4.jpg" width="450"/></a></p>
Download and install Recuva<br />
<a href="http://www.piriform.com/recuva" title="http://www.piriform.com/recuva">http://www.piriform.com/recuva</a><br />
and run it<br />
<p align="center"><a href="http://html5.litten.com/images/recuvanorm/7.jpg" rel="lightbox[recuvanorm]"><img src="http://html5.litten.com/images/recuvanorm/7.jpg" width="450"/></a></p>
Choose <b><i>Other</i></b> to recover all types of problems.<br />
<p align="center"><a href="http://html5.litten.com/images/recuvanorm/8.jpg" rel="lightbox[recuvanorm]"><img src="http://html5.litten.com/images/recuvanorm/8.jpg" width="450"/></a></p>
Choose a location to scan for deleted files (the <b><i>Important Files</i></b> folder in our example)<br />
<p align="center"><a href="http://html5.litten.com/images/recuvanorm/9.jpg" rel="lightbox[recuvanorm]"><img src="http://html5.litten.com/images/recuvanorm/9.jpg" width="450"/></a></p>
Enable Deep Scan<br />
<p align="center"><a href="http://html5.litten.com/images/recuvanorm/10.jpg" rel="lightbox[recuvanorm]"><img src="http://html5.litten.com/images/recuvanorm/10.jpg" width="450"/></a></p>
Wait for it to work its magic<br />
<p align="center"><a href="http://html5.litten.com/images/recuvanorm/11.jpg" rel="lightbox[recuvanorm]"><img src="http://html5.litten.com/images/recuvanorm/11.jpg" width="450"/></a></p>
Now you see a list of the files that it found and whether or not they are recoverable. Click the button to <b><i>Switch to Advanced Mode</i></b> and click <b><i>Options</i></b>, go to the <b><i>Actions</i></b> tab and make sure that <b><i>Restore Folder Structure</i></b> is checked so you recover the files in their folders instead of all in one place.<br />
<p align="center"><a href="http://html5.litten.com/images/recuvanorm/12.jpg" rel="lightbox[recuvanorm]"><img src="http://html5.litten.com/images/recuvanorm/12.jpg" width="450"/></a></p>
Click <b><i>Recover</i></b> to recover files to Recovery folder.<br />
<p align="center"><a href="http://html5.litten.com/images/recuvanorm/13.jpg" rel="lightbox[recuvanorm]"><img src="http://html5.litten.com/images/recuvanorm/13.jpg" width="450"/></a></p>
And now the files have all been recovered.<br />
<p align="center"><a href="http://html5.litten.com/images/recuvanorm/14.jpg" rel="lightbox[recuvanorm]"><img src="http://html5.litten.com/images/recuvanorm/14.jpg" width="450"/></a></p>
<h2>What Happens When You Overwrite Some of the Deleted Data ?</h2>

This time we have our files in the <b><i>Important Files2</i></b> folder<br />
<p align="center"><a href="http://html5.litten.com/images/recuvaover/1.jpg" rel="lightbox[recuvaover]"><img src="http://html5.litten.com/images/recuvaover/1.jpg" width="450"/></a></p>
We Shift-Delete the files in the <b><i>Important Files2</i></b> folder<br />
<p align="center"><a href="http://html5.litten.com/images/recuvaover/2.jpg" rel="lightbox[recuvaover]"><img src="http://html5.litten.com/images/recuvaover/2.jpg" width="450"/></a></p>
Now before attempting to recover the files that we deleted, we put a bunch of images into the <b><i>Important Files2</i></b> folder<br />
<p align="center"><a href="http://html5.litten.com/images/recuvaover/3.jpg" rel="lightbox[recuvaover]"><img src="http://html5.litten.com/images/recuvaover/3.jpg" width="450"/></a></p>
Now the Globe image is unrecoverable because some of its data was overwritten by one of the pictures that we added after deleting.<br />
<p align="center"><a href="http://html5.litten.com/images/recuvaover/4.jpg" rel="lightbox[recuvaover]"><img src="http://html5.litten.com/images/recuvaover/4.jpg" width="450"/></a></p>

<p>
 This illustrates why it is important to attempt recovery before anything else is written on the disk and potentially overwrite the data that you need to recover.
</p>
]]></content:encoded>
			<wfw:commentRss>http://html5.litten.com/windows-file-recovery-series-part-1-recover-deleted-files-with-recuva/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Monitoring the impact of Google/Webkit Prerendering of Pages with Piwik Analytics</title>
		<link>http://html5.litten.com/monitoring-the-impact-of-googlewebkit-prerendering-of-pages-with-piwik-analytics/</link>
		<comments>http://html5.litten.com/monitoring-the-impact-of-googlewebkit-prerendering-of-pages-with-piwik-analytics/#comments</comments>
		<pubDate>Tue, 21 Jun 2011 00:38:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[HTML5]]></category>

		<guid isPermaLink="false">http://html5.litten.com/?p=728</guid>
		<description><![CDATA[Google has announced that their search engine will begin prerendering pages. http://googlewebmastercentral.blogspot.com/2011/06/announcing-instant-pages.html The potential problem with Google&#8217;s prerendering&#8230; It&#8217;s done with Javascript. That means that it happens on the client and not on Google&#8217;s server. There is no way to tell if my page was actually viewed by the user or if the page was [...]]]></description>
			<content:encoded><![CDATA[Google has announced that their search engine will begin prerendering pages. <a href="http://googlewebmastercentral.blogspot.com/2011/06/announcing-instant-pages.html">http://googlewebmastercentral.blogspot.com/2011/06/announcing-instant-pages.html</a><br />
<br />
<strong><em>The potential problem with Google&#8217;s prerendering&#8230;</em></strong><br />

It&#8217;s done with Javascript.<br />
<br />
That means that it happens on the client and not on Google&#8217;s server. There is no way to tell if my page was actually viewed by the user or if the page was prefetched and cached by the user&#8217;s browser because the search page they were viewing told it to prerender the page. Well, no way to tell by just looking at my normal stats. There is a way to detect whether or not the user actually views the page using some javascript.<br />
<br />
I use Piwik on many websites in parallel with Google Analytics. Piwik gives me the ability to monitor performance and trends in real time.<br />
<br />
I use Google Analytics for monitoring trends over greater periods of time like weeks, months or years.<br />
<br />
Google Analytics will likely give me the ability to filter out and monitor prerendered pages in the near future. Piwik will probably add an option for this eventually also but right now, I want to begin monitoring it to see how often it happens and how important it is to my infrastructure.<br />
<br />
<div style=" 
background-color: #F8F8F8;
padding: 10px;
width: 90%;
border-radius: 25px;
-moz-border-radius: 25px;
-webkit-border-radius: 25px;
    -webkit-box-shadow: 10px 10px 25px #D5D5D5;
    -moz-box-shadow: 10px 10px 25px #D5D5D5;
    box-shadow: 10px 10px 25px #D5D5D5;
"><br />
1. How much bandwidth is used by pages that are prerendered but never viewed?<br /><br />

2. What pages does Google rank highly enough that they feel the need to prerender them and what keywords are they resulting from?<br /><br />

3. Who else is causing my pages to prerender besides Google.com?<br /><br />
</div>
<br />
Using some javascript we can check on the webkitVisibilityState of the page as it is viewed or cached by the client based on the W3C Page Visibility spec <a href="http://www.w3.org/TR/2011/WD-page-visibility-20110602/">http://www.w3.org/TR/2011/WD-page-visibility-20110602/</a><br /><br />

Google Chrome Labs has a page on this <a href="http://code.google.com/chrome/whitepapers/pagevisibility.html">http://code.google.com/chrome/whitepapers/pagevisibility.html</a><br /><br />

We&#8217;ll use their technique to log our Piwik stats differently if the page is prerendered and then properly log the visit if the prerendered page is subsequently viewed.<br /><br />

A simple Piwik tracking image will be sufficient for our tests. We can add full javascript based tracking once we know that it works. If it is prerendered then we will track it to a different website account on Piwik using the querystring variable <code>idsite</code> and then monitor it with an event listener so that if it is subsequently viewed then it will track it as normal.<br /><br />

<pre><code>var isPrerendering = false;

function handleVisibilityChange(evt) {
if (!isPrerendering) return;
countView();
isPrerendering = false;
}

function countView(){
document.write('&lt;img src="http://PIWIK WEBHOST/piwik/
   piwik.php?idsite=[ID OF NORMAL SITE]&amp;rec=1" /&gt;');
}

/*
* We can count the view right now if the document isn't being prerendered.
* Browsers that don't support the API will return undefined for
* webkitVisibilityState.
*/
if (document.webkitVisibilityState != "prerender") {
countView();
} else {
//We'll need to count the pageview later
isPrerendering = true;
document.write('&lt;img src="http://PIWIK WEBHOST/piwik/
   piwik.php?idsite=[ID OF PRERENDER TRACKING SITE]&amp;rec=1" /&gt;');
document.addEventListener("webkitvisibilitychange", 
   handleVisibilityChange, false);
}</code></pre>
<br /><br />
Trying it out<br />

Using Chrome 13 <a href="http://tools.google.com/dlpage/chromesxs">http://tools.google.com/dlpage/chromesxs</a> enable prerendering by starting Chrome like this&#8230;<br />

<code>chrome.exe –prerender=enabled</code><br /><br />

To test this I go to <a href="http://prerender-test.appspot.com/">http://prerender-test.appspot.com/</a> and enter the address of a page that I am tracking like this one and it will show a prerendered hit in the Piwik website I set up for tracking them.<br /><br />

I like it.<br />
It&#8217;s fast and enhances the users experience. Using javascript puts all of the cost (processing and bandwidth) on my webserver and user&#8217;s browser so we&#8217;ll see if this causes problems for its adoption. I&#8217;ll keep playing with it and when it does become mainstream, I hope to be ready to embrace it and not allow it to adversely affect my servers, visitors or analytics.<br /><br />]]></content:encoded>
			<wfw:commentRss>http://html5.litten.com/monitoring-the-impact-of-googlewebkit-prerendering-of-pages-with-piwik-analytics/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>X10 Lamp Control Over The Internet With Live Streaming Video Example</title>
		<link>http://html5.litten.com/x10-lamp-control-over-the-internet-with-live-streaming-video-example/</link>
		<comments>http://html5.litten.com/x10-lamp-control-over-the-internet-with-live-streaming-video-example/#comments</comments>
		<pubDate>Fri, 13 May 2011 19:28:14 +0000</pubDate>
		<dc:creator>James Litten</dc:creator>
				<category><![CDATA[Home Automation]]></category>
		<category><![CDATA[X10]]></category>
		<category><![CDATA[home automation]]></category>
		<category><![CDATA[internet controlled]]></category>
		<category><![CDATA[x10]]></category>

		<guid isPermaLink="false">http://html5.litten.com/?p=688</guid>
		<description><![CDATA[In this project, we are trying to find the simplest way to allow public access to X10 home automation devices while maintaining a secure environment that does not allow anything damaging to happen. The video and button below are live and in my home. This post will describe how this is done. &#160; Currently using [...]]]></description>
			<content:encoded><![CDATA[In this project, we are trying to find the simplest way to allow public access to X10 home automation devices while maintaining a secure environment that does not allow anything damaging to happen. The video and button below are live and in my home. This post will describe how this is done.
<span id="more-688"></span>
&nbsp;
<br /><br /><em>Currently using webcam snapshots instead of stream (delay of up to 5 seconds but much less bandwidth and no ads).</em><br />
<div><iframe id="frame1" src="http://litten.com/switch.php"  height="310" width="420" frameborder="0" scrolling="no"></iframe></div><div><em>Click this button to turn the lamp on/off</em></div>
<h2>Summary of Operation</h2>
This blog post is being served to your browser from a server on the internet provided by GoDaddy hosting. On this server I have created a database using MySQL which has a row in it representing the lamp in the streaming video you see above. In that row is a field representing the state of the lamp (on / off). The button that controls the state of the lamp, simply toggles that field in the database.

In my house there is an XAMPP server running on a Windows 7 PC which has a page open on it that does two things &#8230;
<ol>
	<li>It checks the field on the MySQL server at litten.com that represents the state of the lamp once per second.</li>
	<li>It sends an X10 command through the X10 PC interface to the lamp, setting it to that state.</li>
</ol>
This keeps all of the command and control of the lamp inside my secure home network. All that exists in the wild are three state values of the lamp. On, off or something else (things break or have unexpected results in the wild).

figure I shows the whole setup.
<br /><br />
<div class="wp-caption aligncenter" style="width: 460px"><img class=" " style="border: 0pt none;" title="x10 project diagram" src="http://litten.com/images/x10.jpg" alt="" width="450" height="330" /><p class="wp-caption-text">fig. I</p></div>

&nbsp;
<h2>MySQL Database</h2>
On my hosted server, I have the ability to make MySQL databases. Almost all hosting services have this these days.
<h3>Create new mySQL db</h3>
Most hosts have an option for creating new MySQL databases in their control panel. I used to make these from the command line but nowadays I just use the control panel for generic databases like this one. I created a new database called x10.

&nbsp;
<h3>Add a table</h3>
I rarely use the command line to make tables anymore. I find using the phpmyadmin interface sufficient for most of my needs. You should be able to access phpmyadmin from the control panel at your hosting account. Here are the settings for the table that I created for this project. The table is named <em>x10state</em>. There is a field named <em>device</em> that is a varchar(20) with a default value of the word <em>default</em> and another field named <em>state</em> that is a tinyint(1) with a default value of <em>0.</em>

<em>
</em>
<br /><br />
CREATE TABLE IF NOT EXISTS `x10state` (<br />
`device` varchar(20) NOT NULL default &#8216;default&#8217;,<br />
`state` tinyint(1) NOT NULL default &#8217;0&#8242;<br />
) ENGINE=MyISAM DEFAULT CHARSET=latin1;<br />
<br />
&nbsp;
<h3>Add new restricted users</h3>
We create a user that can only access the database from this server (replace  <span style="color: #008000;"><em>mypassword</em></span> with your own password)

&nbsp;
<br /><br />
CREATE USER &#8216;x10user&#8217;@'localhost&#8217; IDENTIFIED BY &#8216;<span style="color: #008000;"><em>mypassword</em></span>&#8216;;<br />
GRANT SELECT,INSERT,UPDATE,DELETE<br />
ON x10.*<br />
TO &#8216;x10user&#8217;@'localhost&#8217;;<br />
<br />
&nbsp;

We create another user (with the same username as above) that can only access the database from this server (replace  <span style="color: #008000;"><em>mypassword</em> </span>with your own password and replace <span style="color: #008000;"><em>MY FIOS ADDRESS</em></span> with the address that your home server has. You can find it by going to <a href="http://www.displaymyhostname.com/" target="_blank">http://www.displaymyhostname.com/</a> while on the PC that your home webserver will be on.
<br /><br />

CREATE USER &#8216;x10user&#8217;@&#8217;<span style="color: #008000;"><em>MY FIOS ADDRESS</em></span>&#8216; IDENTIFIED BY &#8216;<span style="color: #008000;"><em>mypassword</em></span>&#8216;;<br />
GRANT SELECT,INSERT,UPDATE,DELETE<br />
ON x10.*<br />
TO &#8216;x10user&#8217;@&#8217;<span style="color: #008000;"><em>MY FIOS ADDRESS</em></span>&#8216;;<br />
<br />
&nbsp;
<h2>ON/ OFF Button</h2>
The On / Off button is placed into this post using an IFRAME and consists of two PHP pages with access to the MySQL database and a form to submit the action of clicking it so that it can change the <em>state </em>value of the lamp in the database.
<br />
The IFRAME element looks like this&#8230;
<pre><code>
&lt;iframe id="frame1" src="http://litten.com/switch.php"  height="50"
width="100" frameborder="0" scrolling="no"&gt;&lt;/iframe&gt;
</code></pre>


switch.php gets the state of the lamp from the database and applies it as the label for the submit button. The action for the submit button is changestate.php.

<br />
<br />
The code for switch.php
<pre><code>
&lt;?php
$db_host = 'localhost';
$db_user = 'x10user';
$db_pwd = '<span style="color: #008000;"><em>mypassword</em></span>';
$database = 'x10';
$table = 'x10state';

if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");

if (!mysql_select_db($database))
die("Can't select database");

$result = mysql_query("SELECT * FROM {$table}
 WHERE device = 'lamp'");
if (!$result) {
die("failed");
}

$row = mysql_fetch_row($result);
$state = $row[1];

$lampstate = "OFF";
if ($state == 1) {
$lampstate = "ON";
}
?&gt;

&lt;form method=POST action="http://litten.com/changestate.php"&gt;
&lt;input type="submit" name="switch"
 value= "&lt;?php echo $lampstate ?&gt;"&gt;
&lt;/form&gt;
 </code></pre>
The form in switch.php has the action changestate.php which simply changes the value of the state of the lamp. If it is off, then clicking the button sets it to 1 (on) and if it is on then clicking the button sets it to 0 (off).

<br />
<br />
The code for changestate.php
<pre><code>
&lt;?php
$db_host = 'localhost';
$db_user = 'x10user';
$db_pwd = '<em><span style="color: #008000;">mypassword</span></em>';
$database = 'x10';
$table = 'x10state';

if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");

if (!mysql_select_db($database))
die("Can't select database");

$result1 = mysql_query("SELECT * FROM {$table}
 WHERE device = 'lamp'");
if (!$result1) {
die("failed");
}

$row = mysql_fetch_row($result1);
$state = $row[1];

$onoff = 1;
if ($state == 1) {
$onoff = 0;
}

$result2 = mysql_query("UPDATE {$table}
 SET state = {$onoff} WHERE device = 'lamp'");
if (!$result2) {
die("failed2");
}

$lampstate = "ON";
if ($state == 1) {
$lampstate = "OFF";
}
?&gt;

&lt;form method=POST action="http://litten.com/changestate.php"&gt;
&lt;input type="submit" name="switch"
 value= "&lt;?php echo $lampstate ?&gt;"&gt;
&lt;/form&gt;
 </code></pre>
<h2>Video Streaming</h2>
<strong>UPDATE:</strong> I am currently testing a solution that uses my webcams ability to detect when the light turns on or off. When a change is detected, it takes a snapshot and uploads it using Dorgem (<a href="http://dorgem.sourceforge.net/" target="_blank">dorgem.sourceforge.net</a>). That snapshot is shown in an IFRAME above the button. It&#8217;s not as pretty as a live stream but it is far more economical and has no ads.<br /><br />
The video stream is <del datetime="2011-05-14T14:28:30+00:00">currently</del> accomplished using a free account at Ustream (<a href="http://www.ustream.tv/" target="_blank">www.ustream.tv</a>) which is supported by ads. It is easy to setup and works very well. Another option would be to use something like Dorgem (<a href="http://dorgem.sourceforge.net/" target="_blank">dorgem.sourceforge.net</a>). I am using an inexpensive webcam with the generic Windows USB Webcam Drivers.
<h2>Web Server on Home PC</h2>
Now we need to set up a webserver on our home network that is capable of displaying a PHP web page that will periodically check the MySQL database at litten.com to get the value of the lamp&#8217;s state and then send that value to our X10 module controlling the lamp. The easiest way to set up a server that can serve PHP pages on a Windows 7 PC like I am using for this is to use XAMPP (<a href="http://www.apachefriends.org/en/xampp-windows.html" target="_blank">XAMPP </a>) (<a href="http://en.wikipedia.org/wiki/XAMPP" target="_blank">Wikipedia entry for XAMPP</a>)
<h2>X10 PC Interface via a PHP page</h2>
Now that we have a webserver on our home network. We need a few things to make this work.
<ul>
	<li>A lamp. I am using a nice Himalayan Salt lamp from Amazon.com.</li>
	<li>An <a href="http://affiliates.x10.com/?property=affiliates&amp;aposition=text29&amp;lineid=xtenafftxt27&amp;affid=x10_13050400551&amp;type=href" target="_blank">X10 3-pin Appliance Module (AM466)</a>. To plug the lamp into. Then it is plugged into an outlet.</li>
	<li>An <a href="http://affiliates.x10.com/?property=affiliates&amp;aposition=text29&amp;lineid=xtenafftxt27&amp;affid=x10_13050400551&amp;type=href" target="_blank">ActiveHome Professional Computer Interface (CM15A)</a>. That is plugged into an outlet and attached to your PC via USB cable.</li>
	<li>The <a href="http://www.activehomepro.com/sdk/index.html" target="_blank">ActiveHome Scripting SDK </a></li>
	<li>A copy of <a href="http://www.dll-files.com/dllindex/dll-files.shtml?msvcp71" target="_blank">msvcp71.dll</a> and <a href="http://www.dll-files.com/dllindex/dll-files.shtml?msvcr71" target="_blank">msvcr71.dll</a> (be careful, this site tries to trick you to click on ads)</li>
</ul>
On our XAMPP webserver, inside the htdocs directory, create a new folder called X10. Inside of that folder create a file called refresher.php. You will be able to access this file in your browser on that server/PC by going to

http://localhost/x10/refresher.php

Inside the X10 folder you also need to put a copy of ahcmd.exe which can be found in AHSDK\samples\php after installing The <a href="http://www.activehomepro.com/sdk/index.html" target="_blank">ActiveHome Scripting SDK</a>.

Inside the X10 folder you also need to put copies of <a href="http://www.dll-files.com/dllindex/dll-files.shtml?msvcp71" target="_blank">msvcp71.dll</a> and <a href="http://www.dll-files.com/dllindex/dll-files.shtml?msvcr71" target="_blank">msvcr71.dll</a> which are needed to support ahcmd.exe

This file will check the MySQL database on the public webserver (in my case at litten.com) and retrieve the state value for the lamp. Then it will use an exec command in PHP to send the state to the actual lamp. Here is the code for refresher.php

&nbsp;
<pre><code>
&lt;META HTTP-EQUIV=Refresh CONTENT='1; URL=refresher.php'&gt;
&lt;?php
$db_host = '<span style="color: #008000;"><em>litten.com</em></span>';
$db_user = 'x10user';
$db_pwd = '<span style="color: #008000;"><em>mypassword</em></span>';
$database = 'x10';
$table = 'x10state';

if (!mysql_connect($db_host, $db_user, $db_pwd))
die("Can't connect to database");

if (!mysql_select_db($database))
die("Can't select database");

$result = mysql_query("SELECT * FROM {$table} WHERE device = 'lamp'");
if (!$result) {
die("failed");
}
$row = mysql_fetch_row($result);
$state = $row[1];
echo $state;

$cmd = 'on';
if ($state == 0){
$cmd = 'off';
}

$cmdstring = "<span style="color: #008000;">A1</span> ".$cmd;
echo $cmdstring;
exec("ahcmd.exe sendplc $cmdstring");
?&gt;
</code></pre>
This page must be open in a browser on your server/PC in order for the lamp to work. To keep this as simple as possible I am using a META tag to refresh the page once per second. There are other options for this. 
<br />
The command string in this case uses A1 which is the house code/unit code of the X10 module that I have the lamp plugged into. Yours may be different. It is sent in this line.
<pre><code>
exec("ahcmd.exe sendplc $cmdstring");
</code></pre>
When $cmdstring is <em>A1on</em> it sends the X10 command to turn the device with house code A and unit code 1 (which is my lamp in this example) on.
&nbsp;
<br /><br />
Please leave comments if you have questions or use my contact page if you&#8217;d prefer to ask me privately.
<br /><br />]]></content:encoded>
			<wfw:commentRss>http://html5.litten.com/x10-lamp-control-over-the-internet-with-live-streaming-video-example/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Learning to Use Android NDK With a Neat Augmented Reality Example</title>
		<link>http://html5.litten.com/learning-to-use-android-ndk-with-a-neat-augmented-reality-example/</link>
		<comments>http://html5.litten.com/learning-to-use-android-ndk-with-a-neat-augmented-reality-example/#comments</comments>
		<pubDate>Mon, 07 Mar 2011 19:04:07 +0000</pubDate>
		<dc:creator>James Litten</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Native Code]]></category>
		<category><![CDATA[NDK]]></category>
		<category><![CDATA[Augmented Reality]]></category>

		<guid isPermaLink="false">http://html5.litten.com/?p=672</guid>
		<description><![CDATA[I&#8217;ve been moving some Flash SWF files over to AIR for Android and while looking into how best to optimize ActionScript code for AIR for Android, I got sidetracked. After reading about the obvious optimizations for memory and CPU resources, I decided to take a look at the AIR .apk file that is installed on [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been moving some Flash SWF files over to AIR for Android and while looking into how best to optimize ActionScript code for AIR for Android, I got sidetracked. After reading about the obvious optimizations for memory and CPU resources, I decided to take a look at the AIR .apk file that is installed on my Android phone. I found that the magic was happening in</p>
<p>\lib\armeabi\libCore.so</p>
<p>Ahh, the Adobe AIR runtime kind of runs beside the Dalvik virtual machine rather than completely inside of it.</p>
<p>The libCore.so file is a shared object file using JNI. Java Native Interface(JNI) <a href="http://en.wikipedia.org/wiki/JNI">http://en.wikipedia.org/wiki/JNI</a> code written in C or C++ allows you to access platform specific features and &#8216;touch the metal&#8217; with your code.</p>
<p>Android provides the Android NDK so you can use native code.<br />
<a href="http://developer.android.com/sdk/ndk/index.html">http://developer.android.com/sdk/ndk/index.html</a></p>
<p>Some words of wisdom from the Android developer page <img src='http://html5.litten.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<pre>The NDK will not benefit most applications. As a developer, you need 
to balance its benefits against its drawbacks; notably, using native 
code does not result in an automatic performance increase, but 
always increases application complexity. In general, you should 
only use native code if it is essential to your application, not just 
because you prefer to program in C/C++.<br /></pre>
<a href="http://developer.android.com/sdk/ndk/overview.html">http://developer.android.com/sdk/ndk/overview.html</a>
<p>I wanted to try compiling and running some native code on my phone (Android 2.2) so that I have that tool in my toolbox when I need it. I found a great example at Qualcomm.<br />
<a href="https://ar.qualcomm.com/qdevnet/sdk">https://ar.qualcomm.com/qdevnet/sdk</a></p>
<p>The sample application that comes with the SDK allows you to detect and track image targets in 3D using your phone&#8217;s camera and then it puts a floating teapot (<a href="http://www.sjbaker.org/wiki/index.php?title=The_History_of_The_Teapot">http://www.sjbaker.org/wiki/index.php?title=The_History_of_The_Teapot</a>) over your target. The NDK is required to compile the native C++ code which uses OpenGL ES <a href="http://en.wikipedia.org/wiki/OpenGL_ES">http://en.wikipedia.org/wiki/OpenGL_ES</a>. It has step by step instructions that will show you how to build the native C++ source files with the NDK package of the Android SDK and then use Eclipse to build the Java sources and create the APK package that can be deployed to the phone.</p>
<p>This is very much like the augmented reality on the new Nintendo 3DS<br />
<a href="http://www.siliconera.com/2011/03/04/lose-your-nintendo-3ds-ar-cards-just-print-out-new-ones/">http://www.siliconera.com/2011/03/04/lose-your-nintendo-3ds-ar-cards-just-print-out-new-ones/</a></p>
<p>If you are having a hard time with the NDK, try the sample that comes with it in \samples\hello-jni along with the tutorial at <a href="http://www.pocketmagic.net/?p=1332">http://www.pocketmagic.net/?p=1332</a> for a very basic example that will help you understand the proper procedure.</p>
<p>I have some broken antique clocks around the house so I made image targets out of their faces and now have a teapot floating in front of them. Next time I get a little break in the action, I&#8217;ll change that teapot to a semi-transparent digital clock so my clocks will no longer be broken provided, I run the program on my phone and point the camera at the clocks <img src='http://html5.litten.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><img src="http://litten.com/images/clock.jpg" alt="Clock Face" /></p>
<p>The NDK combined with current hardware capabilities certainly seem to be enough to make sophisticated and engaging toolkits and engines for game developers and artists. </p>
<p>Anyway, enjoy playing with the code as that is how you learn.</p>
]]></content:encoded>
			<wfw:commentRss>http://html5.litten.com/learning-to-use-android-ndk-with-a-neat-augmented-reality-example/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Developing With Flash CS5 for Adobe AIR on Android</title>
		<link>http://html5.litten.com/developing-with-flash-cs5-for-adobe-air-on-android/</link>
		<comments>http://html5.litten.com/developing-with-flash-cs5-for-adobe-air-on-android/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 20:47:57 +0000</pubDate>
		<dc:creator>James Litten</dc:creator>
				<category><![CDATA[android]]></category>
		<category><![CDATA[AIR]]></category>
		<category><![CDATA[flash]]></category>

		<guid isPermaLink="false">http://html5.litten.com/?p=656</guid>
		<description><![CDATA[Now that Adobe AIR is available for Android 2.2, it is easy to move your Flash games to Android's app store and also to add functionality that takes advantage of things like the camera and GPS.]]></description>
			<content:encoded><![CDATA[<p>Now that Adobe AIR is available for Android 2.2, it is easy to move your Flash games to Android&#8217;s app store and also to add functionality that takes advantage of things like the camera and GPS.</p>

<p>AIR stands for Adobe Integrated Runtime and was originally for</p> 

<pre>
...building rich Internet applications using Adobe Flash, Adobe Flex,
Adobe Dreamweaver (HTML or Ajax), AIR SDK, that can be run as 
desktop applications.
</pre>

<p>But now seems to be headed toward becoming an easy way to quickly develop powerful applications for smartphones, TV&#8217;s, car dashboards, tablets, big computers, tiny computers and everything in between.<br />
<a href="http://www.adobe.com/products/air/">http://www.adobe.com/products/air/</a> </p>
<br />
<h2>Setting up your development environment</h2>

<p>1. Get Flash CS5 (you can get a 30 day free trial at <a href="http://www.adobe.com/downloads">http://www.adobe.com/downloads</a>)</p>
<br />
<p>2. Install Flash extension for AIR  <a href="http://labs.adobe.com/technologies/flashpro_extensionforair/">http://labs.adobe.com/technologies/flashpro_extensionforair/</a></p>
<br />
<p>3. Install AIR SDK  <a href="http://www.adobe.com/products/air/">http://www.adobe.com/products/air/</a></p>
<br />
<p>4. Install Android SDK  <a href="http://developer.android.com/sdk/index.html">http://developer.android.com/sdk/index.html</a></p>
<br />
<h2>Step by step video instructions</h2>
<p>Setting up your development environment with Flash CS5 and AIR for Android<br />
<a href="http://www.gotoandlearn.com/play.php?id=123">http://www.gotoandlearn.com/play.php?id=123</a></p>
<br />
<h2>More instructions for setting up.</h2>
<p>Getting started with Adobe AIR for Android<br />
<a href="http://www.adobe.com/newsletters/edge/august2010/articles/article1/index.html">http://www.adobe.com/newsletters/edge/august2010/articles/article1/index.html</a></p>
<br />
<h2>Some AIR for Android examples</h2>
<p>Build a GPS Speedometer<br />
<a href="http://mobile.tutsplus.com/tutorials/android/build-a-gps-speedometer-getting-into-air-for-android/">http://mobile.tutsplus.com/tutorials/android/build-a-gps-speedometer-getting-into-air-for-android/</a></p>
<br />
<p>AIR for Android MazeFM Application<br />
<a href="http://www.flashandmath.com/mobile/mazefm/index.html">http://www.flashandmath.com/mobile/mazefm/index.html</a></p> 
<br />
<p>Air for Android: Geolocation<br />
<a href="http://www.unitedmindset.com/jonbcampos/2010/08/30/air-for-android-geolocation/">http://www.unitedmindset.com/jonbcampos/2010/08/30/air-for-android-geolocation/</a></p>
<br />
<p>Simple camera application with Flash CS5 and AIR for Android<br />
<a href="http://www.gotoandlearn.com/play.php?id=124">http://www.gotoandlearn.com/play.php?id=124</a></p>
<br />
<p>Publishing AIR for Android Applications to the App Store<br />
<a href="http://www.gotoandlearn.com/play.php?id=131">http://www.gotoandlearn.com/play.php?id=131</a></p>
<br />
<p>The .apk file that is created for AIR for Android has the .swf file in the assets folder and an application.xml file in the assets/META-INF/AIR folder which works with the main AndroidManifest.xml file to set the programs application properties and how it should start (run the swf file).</p> 
<br />
<p>Now it&#8217;s easy to move your  Flash apps and games to the mobile market. Enjoy.</p>]]></content:encoded>
			<wfw:commentRss>http://html5.litten.com/developing-with-flash-cs5-for-adobe-air-on-android/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

