OP
Sam Widges
Active Member
Anyone fancy some beta testing?
Here's the draft code for 'unencrypt.sh'
Because of the risks of losing recordings, I've tried to predict a lot of potential issues and to build in the appropriate checks and balances. Certainly, when tested on a given subdirectory, it has successfully decrypted the contents, so it seems safe enough to be let loose on a wider audience.
The script needs a directory to work on and each time it is run, it will decrypt a file. It will not run 2 copies simultaneously, so trying to run it once every 15 minutes should be fine, even if decrypting HD programmes can take up to half an hour (or more).
To set this up, first take a modded HDR-T2 and install the cron, auto-unprotect and hmt utilities (most recent versions please) and save the script somewhere safe, like /mod/test.
I suggest that, for initial tests, you run it from the command line against a test directory, e.g.
But once you are confident that gerbils won't explode and that it won't rain marsupials on your firstborn (and that your precious collection of QVC highlights is safe), you can move to running it from cron.
Here's my crontab entry
Add the above line to '/mod/var/spool/cron/crontabs/root', giving it the name of the directory where you want to run your tests in the obvious place. Then, run the command
As the code says, "This is version 0.0.1 - Danger Will Robinson!" Please don't dabble unless you want to undertake a little risk, but hopefully the rewards will more than outweigh the risks.
Here's the draft code for 'unencrypt.sh'
Code:
#!/bin/sh
#need to specify paths when running from cron
LSOF=/mod/bin/lsof
GREP=/mod/bin/busybox/grep
DIRNAME=/mod/bin/busybox/dirname
BASENAME=/mod/bin/busybox/basename
MV=/mod/bin/busybox/mv
WGET=/mod/bin/busybox/wget
HMT=/mod/bin/hmt
SQLITE3=/mod/bin/sqlite3
ECHO=/mod/bin/busybox/echo
RM=/mod/bin/busybox/rm
PS=/mod/bin/busybox/ps
WC=/mod/bin/busybox/wc
OPKG=/bin/opkg
EXPR=/mod/bin/busybox/expr
on_hangup ()
{
$ECHO 'Interrupted by user'
exit
}
trap on_hangup 2
# How do we deal with auto-unprotect - make it a prereq?
#Remove the trailing slash if there is one
targetpath=${1%/}
if [ ! -n "$targetpath" ]; then
$ECHO "Humax HDR-T2 decryption utility"
$ECHO "Version 0.0.1 - Danger Will Robinson!"
$ECHO "Needs hmt 1.1.0 to work"
$ECHO
$ECHO "Gradually works its way through your videos and decrypts them"
$ECHO
$ECHO "Target path needed"
exit
fi
#You need this or the for loop gets confused by spaces
IFS=$'\n'
# Stop the process running more than once at a time
# Warning - wc here returns one more line than it should so the count is 2 not 1
# Yes, I could have used pgrep, but it's one fewer dependancy
pscount=`$PS -w | $GREP "$0" | $GREP -v grep | grep -v '/bin/sh -c' | $WC -l`
$ECHO "pscount = $pscount"
if [ $pscount -gt 3 ]; then
$ECHO "Unencrypt process already running - exiting"
exit
fi
host='127.0.0.1'
#What about standby? Can this be tweaked on the fly?
# You really don't want to run this if you have HD content and you aren't running auto-unprotect
AP=`$OPKG list-installed | $GREP auto-unprotect`
if [ "$AP" = "" ]; then
$ECHO "Auto-unprotect isn't running"
exit
fi
#pwrdwn=`$SQLITE3 /var/lib/humaxtv/setup.db "Select itemvalue from tbl_menuconfig where itemName like 'AUTOMATIC_POWER_DOWN'"`
#$ECHO "Auto Power Off is set to: $pwrdwn"
#pwrstby=`$SQLITE3 /var/lib/humaxtv/setup.db "Select itemvalue from tbl_menuconfig where itemName like 'PWR_SAVING_ON_STANDBY'" `
#$ECHO "Power Saving In Standby is set to: $pwrstby"
#For each of the recorded programmes...
for line in `$SQLITE3 /mnt/hd2/dms_cds.db "select mediaID,folder from tblMedia"`
do
sep=`$EXPR index "$line" \|` #There is a '|' separator between the fields
mediaID="${line:0:$(($sep-1))}"
filename="${line:$sep}"
filename=${filename%.ts}
dir=`$DIRNAME $filename`
file=`$BASENAME $filename`
# Only process files, not directories
# and only directories that match the command line
if [ "$filename" != "(NULL)" ] && [ `$EXPR match "/media/$dir" "$targetpath"` -gt 0 ]; then
cd "/media/$dir"
$ECHO "Processing \"$filename\", Media ID is $mediaID"
url="http://$host:9000/web/media/$mediaID.TS"
encrypted=`$HMT $file.hmt | $GREP '^Flags.*ODEncrypted'`
if [ "$encrypted" ]; then
# Check that port 9000 is open and exit if not
# Needs to be implemented
#Get rid of any old files from a previous run that failed
if [ -f "$mediaID.TS" ]; then
$RM "$mediaID.TS"
fi
$ECHO "Getting $url"
$WGET $url
#The copy can fail - only copy and process if the file actually exists
if [ -f "$mediaID.TS" ]; then
# Need to check that the main file is not being modified
inuse=`$LSOF | $GREP "$file.ts"`
if [ "$inuse" == "" ]; then
$MV $mediaID.TS $file.ts
$HMT -encrypted $file.hmt
fi
# Exit after each successful decryption
exit
else
echo "$file is in use, skipping"
fi
fi
fi
done
Because of the risks of losing recordings, I've tried to predict a lot of potential issues and to build in the appropriate checks and balances. Certainly, when tested on a given subdirectory, it has successfully decrypted the contents, so it seems safe enough to be let loose on a wider audience.
The script needs a directory to work on and each time it is run, it will decrypt a file. It will not run 2 copies simultaneously, so trying to run it once every 15 minutes should be fine, even if decrypting HD programmes can take up to half an hour (or more).
To set this up, first take a modded HDR-T2 and install the cron, auto-unprotect and hmt utilities (most recent versions please) and save the script somewhere safe, like /mod/test.
I suggest that, for initial tests, you run it from the command line against a test directory, e.g.
Code:
sh /mod/test/unencrypt.sh /media/My\ Video/***your test directory here***/
But once you are confident that gerbils won't explode and that it won't rain marsupials on your firstborn (and that your precious collection of QVC highlights is safe), you can move to running it from cron.
Here's my crontab entry
Code:
0,15,30,45 * * * * /mod/test/unencrypt.sh /media/My\ Video/***your test directory here***/ > /mod/tmp/unencrypt.log 2>&1
Add the above line to '/mod/var/spool/cron/crontabs/root', giving it the name of the directory where you want to run your tests in the obvious place. Then, run the command
Code:
/mod/etc/init.d/S01crond restart
As the code says, "This is version 0.0.1 - Danger Will Robinson!" Please don't dabble unless you want to undertake a little risk, but hopefully the rewards will more than outweigh the risks.