Recover media files from HTC HSMBackup

Filed Under IT Tipz & Trix

Due to my M7 going in for repair, I have temporarily got a Samsung as a loan phone. With an upcoming weekend away I wanted to grab my music and stick it on the Samsung so I could listen to it in the car on the long drive.

However, as most things in bb_land, this is not just a case of using the HTC Sync Manager to Restore -> New Phone where it extracts the files into their native format and copies them over. In fact you can’t do it at all.

A quick bit of bumbling around and I find the files stores in AppData/Local/HTC MediaHub/HSM Backup/ in folders helpfully named things like BR_534833355459393033373038 and 35F67E512C69CF39ECF43E90A40F2BDE5A510F2C with useful filenames such as 0C52E903FFEC6CDFBB37A3113D99476A0BB46891. Awesome.

Some quick peeking with a Hex Editor reveals these to be the files I need, just with no extension and a garbled filename. Only wanting to grab the MP3s and not any videos etc I banged up this quick script to be run from the HSM Backup folder

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php

$di = new RecursiveDirectoryIterator('C:\Test Directory');
foreach (new RecursiveIteratorIterator($di) as $filename => $file) {
//read first 3 bytes of file
echo "Attempting File : $file \n"; //Show file we are attempting
if (substr($file,-1) <> ".") { //Eliminate whining when attempting . and .. in the dir structure
$newhandle = fopen($file, "r");
echo "Opened File : $file \n"; //Show we have a handle on the file
$contents = fread($newhandle, 3);
echo "Read File : $file \n"; //Show we have read from the file
//is it ID3
if ($contents == "ID3") {
//Yes -> copy to place and rename to MP3
$newfile=$file.".MP3";
copy ($file, $newfile);
}
fclose($newhandle);
}
}
?>

Running the script copies any files with ID3 as the first 3 bytes of the file to a new file with the same name but an MP3 extension (thus preserving the original for when the M7 comes back from repair to be resynced. After that a simple Windows Search for *.MP3 showed me all my files that I just cut and pasted into the Music folder on the Samsung.

Script is easy to change for different formats (i.e if you are looking for a video just change the number of bytes read and the compare constant)

Hope it helps someone recover their music if they’ve swapped phones and this is the only backup they have.