From 7c2b953f61874a4ab06075445c43d875ef105fd5 Mon Sep 17 00:00:00 2001 From: Bjoern Kerler Date: Sat, 4 Jan 2014 14:15:09 +0100 Subject: [PATCH 1/2] Exception handling fixes and GetDEK vold fixes --- ErrorHandler.py | 12 ++++++++++ adb/adb.py | 7 +++++- config.cfg | 4 ++++ modules/sandgetdek/sandgetdek.py | 39 ++++++++++++++++++++++---------- sandutils.py | 30 ++++++++++++++++-------- 5 files changed, 69 insertions(+), 23 deletions(-) create mode 100644 ErrorHandler.py diff --git a/ErrorHandler.py b/ErrorHandler.py new file mode 100644 index 0000000..35e22ac --- /dev/null +++ b/ErrorHandler.py @@ -0,0 +1,12 @@ +''' +Created on 04.01.2014 + +@author: bkerler +#Added exception handling +''' + +class ADBError(Exception): + def __init__ (self,value): + self.value = value + def __str__(self): + return repr(self.value) \ No newline at end of file diff --git a/adb/adb.py b/adb/adb.py index a7e1d0c..7afd440 100644 --- a/adb/adb.py +++ b/adb/adb.py @@ -7,14 +7,17 @@ #The adb push writes the messages to the standard error, so we can check #wether the push was successfull or not. +#Modified by bkerler. Added exception handling for adb shell errors + try: import sys + from ErrorHandler import ADBError from os import popen3 as pipe except ImportError,e: # should never be reached print "[f] Required module missing. %s" % e.args[0] sys.exit(-1) - + class ADB(): PYADB_VERSION = "0.1.1" @@ -296,6 +299,8 @@ def shell_command(self,cmd): """ self.__clean__() self.run_cmd('shell %s' % cmd) + if self.__error!=None: + raise ADBError(self.__error) return self.__output def listen_usb(self): diff --git a/config.cfg b/config.cfg index 3f41788..391e4d0 100644 --- a/config.cfg +++ b/config.cfg @@ -22,3 +22,7 @@ sdcard_file=/data/system/edk_p_sd data=/dev/block/mmcblk0p12 footer=y sdcard_file=/data/system/edk_p_sd +[GT-I9300 4.3] +data=/dev/block/mmcblk0p12 +footer=y +sdcard_file=/data/system/edk_p_sd diff --git a/modules/sandgetdek/sandgetdek.py b/modules/sandgetdek/sandgetdek.py index 29f0559..8bec9c8 100644 --- a/modules/sandgetdek/sandgetdek.py +++ b/modules/sandgetdek/sandgetdek.py @@ -63,25 +63,40 @@ def get_vold_data_segment(self): self.dest_dir="/data/local/tmp" ps=self.adb.shell_command("su -c ps") + self.voldpid=None for process in ps.splitlines(): - if(process.rfind("vold") != -1 ): - process=re.sub("\s+", ' ' , process) - self.voldpid=process.split(' ')[1] - + if(process.rfind("vold") != -1 ): + process=re.sub("\s+", ' ' , process) + self.voldpid=process.split(' ')[1] + break + + if self.voldpid==None: + self.adb.shell_command("su -c start vold") + ps=self.adb.shell_command("su -c ps") + for process in ps.splitlines(): + if(process.rfind("vold") != -1 ): + process=re.sub("\s+", ' ' , process) + self.voldpid=process.split(' ')[1] + break + if self.voldpid==None: + print "Couldn't find vold process. Try to start manually using \"adb shell su -c 'start vold'\"" + return -1 + self.printer.print_debug("Found vold process id: %s!" % self.voldpid) memsegments=self.adb.shell_command("su -c cat /proc/%s/maps" % self.voldpid).splitlines() for segment in memsegments: - if(re.match(".*w-p.*vold.*", segment)!=None): - addresses=segment.split(" ")[0].split("-") - self.datastart=addresses[0] - self.dataend=addresses[1] - self.numberofbytes=int(addresses[1],16)-int(addresses[0],16) + if(re.match(".*w-p.*vold.*", segment)!=None): + addresses=segment.split(" ")[0].split("-") + self.datastart=addresses[0] + self.dataend=addresses[1] + self.numberofbytes=int(addresses[1],16)-int(addresses[0],16) + break self.printer.print_debug("The data segment addresses are: %s - %s" % (self.datastart, self.dataend)) self.printer.print_info("Copy the memory dumper to %s." % (self.dest_dir)) - push=self.adb.push_local_file("dump_android_memory/dump_android_memory","%s" % self.dest_dir) + push=self.adb.push_local_file("dump_android_memory/dump_android_memory","%s/dump_android_memory" % self.dest_dir) if(push.find("bytes")==-1): self.print_info_adb(push, False) return -1 @@ -95,7 +110,7 @@ def get_vold_data_segment(self): if(dump): self.printer.print_info_adb(dump,False) return -1 - self.printer.print_ok("Memory dumber - Done") + self.printer.print_ok("Memory dumper - Done") self.printer.print_info("Download the dump file") @@ -108,7 +123,7 @@ def get_vold_data_segment(self): self.print_info_adb(pull.rstrip("\n")) #Cleanup - self.printer.print_info("Cleaning up! Please check the %s folder. Unsuccessull cleanup weakens the security of the phone!!!!" % self.dest_dir) + self.printer.print_info("Cleaning up! Please check the %s folder. Unsuccessfull cleanup weakens the security of the phone!!!!" % self.dest_dir) out=self.adb.shell_command(su+"rm %s/dumpfile" % self.dest_dir) out=self.adb.shell_command(su+"rm %s/dump_android_memory" % self.dest_dir) self.printer.print_ok("Clean up - Done") diff --git a/sandutils.py b/sandutils.py index d5595d7..a206f51 100644 --- a/sandutils.py +++ b/sandutils.py @@ -5,6 +5,7 @@ import printer import ConfigParser from pbkdf2 import PBKDF2 +from ErrorHandler import ADBError import Crypto.Cipher.AES import Crypto.Hash.HMAC import Crypto.Hash.SHA256 @@ -20,10 +21,15 @@ IV_LEN_BYTES = 16 def getphonewithos(adb): - phone=adb.shell_command("getprop ro.product.model").rstrip() - os=adb.shell_command("getprop ro.build.version.release").rstrip() - phonewithos="%s %s" % (phone, os) - return phonewithos + try: + adb.start_server() + phone=adb.shell_command("getprop ro.product.model").rstrip() + os=adb.shell_command("getprop ro.build.version.release").rstrip() + phonewithos="%s %s" % (phone, os) + except ADBError,e: + print "ADB Error occurred : %s\n" % e.value + sys.exit(-1) + return phonewithos def checkcryptostate(adb): state=adb.shell_command("getprop ro.crypto.state").rstrip() @@ -37,12 +43,16 @@ def checkforsu(adb): return su def config2params(config,params,section): - items = config.items(section) - - for (key,value) in items: - if (key in params): - params[key]["value"] = value - return + try: + items = config.items(section) + for (key,value) in items: + if (key in params): + params[key]["value"] = value + break + except ConfigParser.NoSectionError: + print "Config error, couldn't find section : %s\n" % section + sys.exit(-1) + return def decrypt_key(encrypted_key, salt, password): From 447807a46d92745507b422f6c17c951091cf2ea3 Mon Sep 17 00:00:00 2001 From: Bjoern Kerler Date: Sat, 4 Jan 2014 16:27:18 +0100 Subject: [PATCH 2/2] Added modification reference --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 070f0db..b32b87e 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,7 @@ sandy ===== Copyright 2013 Sandy Written by: Laszlo Toth, Ferenc Spala +Modified by: Bjoern Kerler Description -----------