Added logging

This commit is contained in:
Kass Rode 2024-08-18 11:14:10 -04:00
parent dd895e8478
commit 19c36a3463
3 changed files with 48 additions and 2 deletions

View File

@ -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}')

21
helpers/logger.py Normal file
View File

@ -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()

26
main.py
View File

@ -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()