Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some fixes :) #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ErrorHandler.py
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ sandy
=====
Copyright 2013 Sandy
Written by: Laszlo Toth, Ferenc Spala
Modified by: Bjoern Kerler

Description
-----------
Expand Down
7 changes: 6 additions & 1 deletion adb/adb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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):
Expand Down
4 changes: 4 additions & 0 deletions config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
39 changes: 27 additions & 12 deletions modules/sandgetdek/sandgetdek.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")

Expand All @@ -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")
Expand Down
30 changes: 20 additions & 10 deletions sandutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand All @@ -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):
Expand Down