-
Notifications
You must be signed in to change notification settings - Fork 54
/
adb.py
25 lines (22 loc) · 1011 Bytes
/
adb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import subprocess, os, re
from consts import *
def execute_privileged_command(command_str):
'''
Executes the given privileged command on the device
'''
proc = subprocess.Popen(["adb", "shell", "su", "-c", "\"%s\"" % command_str], stdout=subprocess.PIPE)
proc.wait()
return proc.stdout.read()
def pull_file(remote_path, local_path):
'''
Pulls the remote path from the device to the local path
'''
proc = subprocess.Popen(["adb", "pull", remote_path, local_path], stdout=subprocess.PIPE)
proc.wait()
def dev_mem_read_memory(address, length):
'''
Reads memory from the device using /dev/mem
'''
output = execute_privileged_command("dd if=/dev/mem of=%s bs=1 count=%d skip=%d && hd %s" %
(REMOTE_TEMP_DUMP_PATH, length, address, REMOTE_TEMP_DUMP_PATH))
return "".join(re.findall("^[0-9a-f]{8}: (.*?) s", output, re.MULTILINE)).replace(" ","").decode("hex")