xboxscene.org forums

Author Topic: Development Of Chimp2618  (Read 213 times)

ldotsfan

  • Archived User
  • Hero Member
  • *
  • Posts: 2072
Development Of Chimp2618
« on: July 05, 2010, 10:57:00 PM »

The new locking script in chimp2618, lockhda:

CODE

#!/bin/sh

REALOP="$1"
TARGET=/dev/hda
PASSWORD_OPT=" -a "
PASSWORD_SRC="Motherboard"

if [ -z "$1" ]; then
echo "usage: $0 "
exit 1
fi

if [ "$2" != "" ]; then
pass=$(echo $2 | grep hdpass.txt)
eeprom=$(echo $2 | grep eeprom.bin)
hddkey=$(echo $2 | grep hddkey.txt)
if [ -e "$2" ]; then
if [ "$eeprom" != "" ]; then
PASSWORD_OPT="-e $2"
PASSWORD_SRC="$2"
elif [ "$pass" != "" ]; then
pass=$(cat $2)
if [ $pass -eq "TEAMASSEMBLY" ]; then
pass="5445414D414353454D424C59"
elif [ $pass -eq "XBOXSCENE" ]; then
pass="58424F585343454E4500"
fi
[ -z "$pass" ] && echo "$2 empty" && exit 1
PASSWORD_OPT="-p $pass"
else
hddkey=$(cat $2)
[ -z "$hddkey" ] && echo "$2 empty" && exit 1
PASSWORD_OPT="-k $hddkey"
fi
PASSWORD_SRC="$2"
fi
fi

if [ -e $TARGET ]; then
hdtool2  $PASSWORD_OPT -d $TARGET -o unlock | head -n 11 > /tmp/abc.$$
info=$(cat /tmp/abc.$$)
if [ "$1" != "unlock" ]; then
dialog --defaultno --title "Password from $PASSWORD_SRC, choose Yes to $1" --yesno "$info" 15 90
case $? in
  0 ) lock="yes";;
esac
rm /tmp/abc.$$
clear
if  [ "$lock" != "" ]; then
if  [ "$hddkey" != "" ]; then
hdtool2 -d $TARGET $PASSWORD_OPT -o disable-pw > /tmp/pass.$$
[ "$1" != "disable-pw" ] && echo "y" | hdtool2 -d $TARGET $PASSWORD_OPT -o $REALOP >> /tmp/pass.$$
else
hdtool -d $TARGET $PASSWORD_OPT -o disable-pw > /tmp/pass.$$
[ "$1" != "disable-pw" ] && echo "y" | hdtool -d $TARGET $PASSWORD_OPT -o $REALOP >> /tmp/pass.$$
fi
dialog  --title "Done, Password from $PASSWORD_SRC saved in /tmp/pass.$$" --textbox /tmp/pass.$$ 15 90
clear
fi
else
dialog --title "$1 result - password generated from $PASSWORD_SRC" --msgbox "$info" 15 90
clear
fi
fi


cloneab, which does the actual cloning.
CODE

#!/bin/sh

F_START=15633072
G_START=268435456
CACHE_SIZE=1500
C_SIZE=1000
let my_tmp=0
full_clone="$1"

scanide

is_fatx() {
sig=$(dd if=$1 bs=4 count=1 2>/dev/null)
if [ "$sig" = "FATX" ]; then
return 0
else
return 1
fi
}

has_parttable() {
sig=$(dd if=$1 bs=1 count=8 skip=4 2>/dev/null)
if [ "$sig" = "PARTINFO" ]; then
return 0
else
return 1
fi
}

prepare_hd () {
local t=$1
local h=$2
local s=$3
# just create the basic structre, 512k byte for Sys, X, Y, Z, C, E, F, G

dd if=$h of=$t bs=512k count=1 2> /dev/null
dd if=$s of=$t seek=1 bs=512k count=1 2> /dev/null
dd if=$s of=$t seek=1501 bs=512k count=1 2> /dev/null
dd if=$s of=$t seek=3001 bs=512k count=1 2> /dev/null
dd if=$s of=$t seek=4501 bs=512k count=1 2> /dev/null
dd if=$s of=$t seek=5501 bs=512k count=1 2> /dev/null
dd if=$s of=$t seek=15633072 bs=512 count=1k 2> /dev/null
dd if=$s of=$t seek=268435456 bs=512 count=1k 2> /dev/null
}

mini_clone_fg () {
#only clone the signature sector of the F: and G:
local s=$1
local t=$2
dd if=$s of=$t skip=15633072 seek=15633072 bs=512 count=1 2> /dev/null
dd if=$s of=$t skip=268435456 seek=268435456 bs=512 count=1 2> /dev/null
}

progress_dd () {
local s=$1
local t=$2
local option="$3"
local t_file=$$.$my_tmp

if [ "$no_progress" != "" ]; then
dd if=$s of=$t bs=512k $option
else
#let my_tmp=my_tmp+1
clear
echo -e "Cloning Status\n"
/usr/bin/pv $s | dd of=$t bs=512k $option
#pid=$!
#trap "kill $pid" 1 2 9 15
#dialog --title "Device cloning" --ok-label "Stop" --timeout 3 --msgbox "Preparing $t" 10 75  > /dev/null 2>&1
#case $? in
#  0 ) kill $pid; sleep 3; cancel="true";;
#esac
#while [ -e /proc/$pid ]; do
#kill -USR1 $pid
#sleep 3
#STATUS=$(tail -2 /tmp/$t_file)
#dialog --title "Cloning from $s to $t in 10M blocks" --ok-label "Stop" --timeout 10 --msgbox "$STATUS" 10 75  > /dev/null 2>
#case $? in
#  0 ) kill $pid; sleep 3; cancel="true";;
#esac
#done
#trap
clear
#rm /tmp/$t_file > /dev/null 2>&1
#if [ "$cancel" != "true" ]; then
return 0
#else
#return 1
fi
#fi
}

clone_parts() {
for i in $1; do
case $i in
  *C*) progress_dd ${SRC}51 ${TARGET} seek=4501 bs=512k || return 1;;
  *E*) progress_dd ${SRC}50 ${TARGET} seek=5501 bs=512k || return 1;;
  *F*) dd if=/dev/hda bs=512 count=1 2> /dev/null | hexdump | grep "0000 8000" | awk '{ if (NR == 6) print $5 $4" "$7 $6; }' | while read PSTART PEND; do clear; echo -e "Cloning Status\n"; /usr/bin/pv ${SRC}55 | dd of=${TARGET} bs=512 seek=$((0x$PSTART)) count=$((0x$PEND)); done || return 1;;
  *G*) dd if=/dev/hda bs=512 count=1 2> /dev/null | hexdump | grep "0000 8000" | awk '{ if (NR == 7) print $5 $4" "$7 $6; }' | while read PSTART PEND; do clear; echo -e "Cloning Status\n"; /usr/bin/pv ${SRC}56 | dd of=${TARGET} bs=512 seek=$((0x$PSTART)) count=$((0x$PEND)); done || return 1;;
  esac
done
}

choose_parts() {
if [ "$full_clone" != "full" ]; then
# ask what partitions to clone
clone_partitions='C C-drive on E E-drive on F F-drive off G G-drive off'
dialog --checklist "Partitions to clone" 20 50 10 $clone_partitions 2> /tmp/choice.$$
case $? in
 0 ) parts_to_clone=$(cat /tmp/choice.$$);;
esac
rm /tmp/choice.$$
clear
fi
}

choose_style() {
local choice=2
dialog --nocancel --title "HD cloning from $SRC to $TARGET"\
                 --radiolist "How to you like to clone it?" 25 75 5 \
                "1" "full disk(byte by byte)" off \
                "2" "selective(by partition/drives)" on \
                2> /tmp/choice.$$
case $? in
 0) choice=$(cat /tmp/choice.$$);;
esac

case $choice in
 *1*) full_clone="full";;
esac
clear
return
}

choose_progress() {
local choice=2
dialog --nocancel --title "HD cloning from $SRC to $TARGET"\
                 --radiolist "How do you like to monitor the cloning progress" 25 75 5 \
                "1" "blind(no progress till done, fastest)" off \
                "2" "periodically showing progress done, much slower" on \
                2> /tmp/choice.$$
case $? in
 0) choice=$(cat /tmp/choice.$$);;
esac

case $choice in
 *1*) no_progress="yes";;
esac
clear
return
}

#starts here
if [ -e /dev/hda ]; then
SRC=/dev/hda
else
SRC=/dev/zero
DD_OPTION="count=100000"
fi

if [ -e /dev/hdb ]; then
TARGET=/dev/hdb
else
TARGET=/dev/null
fi

# find out what partition the source has

if [ -e $TARGET ]; then
hdparm -i $TARGET > /tmp/hdinfo.$$
out=$(cat /tmp/hdinfo.$$)
unset doit
dialog --defaultno --title "Choose Yes will wipe out and reformat this disk($TARGET), BE WARNED" --yesno "$out" 25 75
case $? in
 0 ) doit="yes";;
esac
rm /tmp/hdinfo.$$
if [ "$doit" != "" ]; then
xboxdumper prepare $TARGET 1
clear
#prepare_hd $TARGET /head.raw /fatx.raw
#if [ -e ${SRC}55 ]; then
#[ "$TARGET" != "/dev/null" ] && mini_clone_fg $SRC $TARGET
#fi
#scan_parts disc1 $TARGET
if hasparttable ${SRC}; then
dd if=$SRC of=$TARGET bs=512 count=8 2> /dev/null
fi
hdparm -z $TARGET
choose_style
choose_progress

if [ "$full_clone" != "" ]; then
progress_dd $SRC $TARGET
else
choose_parts
clone_parts "$parts_to_clone"
fi
fi
fi
clear


menu script, chimp:
CODE

#!/bin/sh

network_settings_menu() {
        local IP=`ifconfig eth0 | grep 'inet addr' | cut -d ':' -f 2 | cut -d ' ' -f 1`
        if dialog --defaultno --yesno "Current IP Address: $IP\nDo you wish to reconfigure?" 0 0; then
                /usr/bin/netcardconfig
                network_settings_menu
        fi
}

choose_key() {
local choice=1
dialog --nocancel --title "Xbox HD locking tools "\
         --menu "Where is the key source " 25 75 5 \
        1 "From Motherboard" \
        2 "From /tmp/eeprom.bin" \
        3 "From Master password:XBOXSCENE" \
        4 "From Master password:TEAMASSEMBLY" \
        5 "From /tmp/hddkey.txt" \
        2> /tmp/choice.$$
choice=`cat /tmp/choice.$$`
case $choice in
 1) key_src="";;
 2) key_src=/tmp/eeprom.bin;;
 3) key_src=XBOXSCENE;;
 4) key_src=TEAMASSEMBLY;;
 5) key_src=/tmp/hddkey.txt;;
esac
rm /tmp/choice.$$
return
}

main_menu() {
TMP=/tmp/xbox-menu.tmp$$
dialog --nocancel --title "ldotsfan hdd tools" --menu "Choose option" 0 0 0 \
        1 "Scan physical IDE devices" \
        2 "Clone from master to slave" \
        3 "Lock slave drive" \
        4 "Unlock slave drive" \
        5 "Display slave drive security status" \
        6 "Unlock master drive" \
        7 "Display master drive security status" \
        8 "Format extended partitions on master drive" \
        9 "Network Settings" \
        10 "Backup eeprom" \
        11 "Reboot" \
        12 "Shutdown" \
        13 "Start a Linux shell" 2> /tmp/choice.$$
choice=`cat /tmp/choice.$$`
case $choice in
  1) /usr/bin/scanide;
    main_menu;;;
  2) /usr/bin/cloneab;
    main_menu;;;
  3)    choose_key;
    clear;
    /usr/bin/lockhdb lock "$key_src";
    main_menu;;;
  4)    choose_key;
    clear;
    /usr/bin/lockhdb unlock "$key_src";
    /usr/bin/lockhdb disable-pw "$key_src";
    main_menu;;;
  5)    dialog --msgbox "`/usr/bin/hdsecinfo /dev/hdb`" 0 0;
    main_menu;;
  6)    choose_key;
      clear;
      /usr/bin/lockhda unlock "$key_src";
    /usr/bin/lockhda disable-pw "$key_src";
    main_menu;;
  7)    dialog --msgbox "`/usr/bin/hdsecinfo /dev/hda`" 0 0;
        main_menu;;
  8)    /usr/bin/lpartitioner;
    main_menu;;
  9)    network_settings_menu
    main_menu;;
  10)     /usr/sbin/xbox-info -r /tmp/eeprom.bin
      dialog --msgbox "Eeprom backup saved to /tmp/eeprom.bin" 8 45;
      main_menu;;
  11)     clear
    /sbin/reboot;;;
  12)   clear
    /sbin/poweroff;;;     
  13)
                       dialog --inputbox "A USB keyboard is required to enter commands. Type \"ok\" to continue" 0 0 2> "$TMP"
                        if [ "$?" = 0 -a "`cat "$TMP"|tr '[A-Z]' '[a-z]'`" = ok ]; then
                                clear
                                echo "Type exit to return to the menu"
                                /bin/sh -i
                        fi
                        main_menu;;;
  *);;
esac
}
main_menu
rm -f /tmp/choice.$$

Logged