From 19c36a3463b9a87aa8bdedea7e8dc140c62bbec5 Mon Sep 17 00:00:00 2001 From: kass Date: Sun, 18 Aug 2024 11:14:10 -0400 Subject: [PATCH] Added logging --- helpers/adb/adb.py | 3 +++ helpers/logger.py | 21 +++++++++++++++++++++ main.py | 26 ++++++++++++++++++++++++-- 3 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 helpers/logger.py diff --git a/helpers/adb/adb.py b/helpers/adb/adb.py index b21acd3..88c1fcb 100644 --- a/helpers/adb/adb.py +++ b/helpers/adb/adb.py @@ -23,6 +23,9 @@ def connect_device(): def shell(device, command): return device.shell(command) +def serialno(): + return os.popen("adb get-serialno").read() + def pull(device, ipath, opath): print(f"Pulling {ipath} to {opath}...") os.system(f'adb pull {ipath} {opath}') diff --git a/helpers/logger.py b/helpers/logger.py new file mode 100644 index 0000000..96b44da --- /dev/null +++ b/helpers/logger.py @@ -0,0 +1,21 @@ +import datetime +def start_logger(): + date = datetime.datetime.now() + filename = str(date) + '-log.txt' + with open(filename, 'a+') as f: + f.write("------------------ASMR Log--------------\n") + f.write("Log started at: "+str(date)+"\n") + f.close() + return filename + +def add_log(filename, data): + with open(filename, 'a+') as f: + f.write(data+"\n") + f.close() + +def stop_logger(filename): + date = datetime.datetime.now() + with open(filename, "a+") as f: + f.write("Acquisition finished at: "+str(date)+"\n") + f.write("----------------------------------------") + f.close() diff --git a/main.py b/main.py index 53ee94e..fbd0bd1 100644 --- a/main.py +++ b/main.py @@ -1,6 +1,8 @@ -import helpers.adb.adb as adb, helpers.fastboot.fastboot as fastboot, install, time, os, requests, urllib.request, sys, helpers.unpackBackup as unpackBackup +import helpers.adb.adb as adb, helpers.fastboot.fastboot as fastboot, install, time, os, requests, urllib.request, sys, helpers.logger as logger from lxml import html +filename = '' + def download_twrp(): cpu = os.popen('adb shell getprop ro.product.board').read() cpu = cpu.rstrip('\n') @@ -28,6 +30,8 @@ def device_pull(): except: print("Unable to connect to device. Ensure that Debug Mode is enabled and USB Debugging is allowed") sys.exit() + serialno = adb.serialno() + logger.add_log(filename, "Serial Number: "+str(serialno)) print("getting twrp...") if os.path.isfile('./twrp.img'): pass @@ -52,11 +56,16 @@ def logicpull(): device = adb.connect_device() except: print("Unable to connect to device. Ensure that Debug Mode is enabled and USB Debugging is allowed") + logger.add_log(filename, "Unable to connect to device. Ensure that Debug Mode is enabled and USB Debugging is allowed") sys.exit() + serialno = adb.serialno() + logger.add_log(filename, "Serial Number: "+str(serialno)) print("pulling data...") adb.pull(device, "/sdcard", "./sdcard") os.system('zip -r logical.zip ./sdcard') os.system("rm -r ./sdcard") + hash = os.popen("md5sum logical.zip").read() + logger.add_log(filename, "MD5 Hash: "+str(hash)) def menu(): print('Acquisition Script for Mobile Resources') @@ -69,14 +78,27 @@ def menu(): def main(): menu() choice = int(input("Please select an option: ")) + global filename match choice: case 1: + filename = logger.start_logger() + logger.add_log(filename, "Type: Physical Image") device_pull() + logger.stop_logger(filename) case 2: + filename = logger.start_logger() + logger.add_log(filename, "Type: Logical Image") logicpull() - case 3: + logger.stop_logger(filename) + case 3: + filename = logger.start_logger() + logger.add_log(filename, "Type: ADB Backup") + serialno = adb.serialno() + logger.add_log(filename, "Serial Number: " + str(serialno)) adb.backup() + input("After confirming the backup operation, press enter to continue.") os.system("dd if=backup.ab bs=1 skip=24 | python3 -c 'import zlib,sys;sys.stdout.buffer.write(zlib.decompress(sys.stdin.buffer.read()))' > backup.tar") + logger.stop_logger(filename) case 99: sys.exit()