From a5e0a0a03682cd8ae37d4c88211ddb841925bdde Mon Sep 17 00:00:00 2001 From: Gabriele Vivinetto Date: Sat, 4 Apr 2020 19:27:11 +0200 Subject: [PATCH 1/2] * Adds first globbing code to pull --- adb-root.py | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/adb-root.py b/adb-root.py index bfe708d..bddd97f 100755 --- a/adb-root.py +++ b/adb-root.py @@ -1,5 +1,5 @@ -#!/bin/env python -import argparse, subprocess, logging +#!/usr/bin/env python3 +import argparse, subprocess, logging, os parser = argparse.ArgumentParser(description="read/write files as root on any Android device") parser.add_argument("action", choices=["push", "pull"], help="pull to copy from device, push to copy to device") @@ -52,13 +52,29 @@ def push(): if args.check: hash_check(args.source, args.target) - +def yes_or_no(question): + reply = str(input(question+' (y/n): ')).lower().strip() + if reply[0] == 'y': + return True + if reply[0] == 'n': + return False + else: + return yes_or_no("Please enter y or n:") def pull(): logging.info("Started pulling %s", args.source) - with open(args.target, "w+") as file: - result = subprocess.run(['adb', 'shell', "su -c", "dd if="+args.source], stdout=file) - log_exitcode("Transfer", result) + filelist = subprocess.run(['adb', 'shell', "su -c", "ls "+args.source], encoding='utf-8', stdout=subprocess.PIPE) + for source in filelist.stdout.split('\n'): + if source != '': + source_filename=os.path.basename(source) + destination=args.target + "/" + source_filename + print("Copying " + source + " to " + destination) + if os.path.isfile(destination): + if yes_or_no("Destination file exits. Ovewrite it ?"): + with open(destination, "w+") as file: + result = subprocess.run(['adb', 'shell', "su -c", "dd if="+source], stdout=file) + log_exitcode("Transfer", result) + return if args.check: hash_check(args.target, args.source) From 78e9f9711181db72ea2fc147ada897c2555b7799 Mon Sep 17 00:00:00 2001 From: Gabriele Vivinetto Date: Sat, 4 Apr 2020 22:24:32 +0200 Subject: [PATCH 2/2] * Fixes su command to work with older android versions (7.x) --- adb-root.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/adb-root.py b/adb-root.py index bddd97f..9e772ad 100755 --- a/adb-root.py +++ b/adb-root.py @@ -63,7 +63,7 @@ def yes_or_no(question): def pull(): logging.info("Started pulling %s", args.source) - filelist = subprocess.run(['adb', 'shell', "su -c", "ls "+args.source], encoding='utf-8', stdout=subprocess.PIPE) + filelist = subprocess.run(['adb', 'shell', "su -c \"", "ls "+args.source + "\""], encoding='utf-8', stdout=subprocess.PIPE) for source in filelist.stdout.split('\n'): if source != '': source_filename=os.path.basename(source) @@ -72,10 +72,13 @@ def pull(): if os.path.isfile(destination): if yes_or_no("Destination file exits. Ovewrite it ?"): with open(destination, "w+") as file: - result = subprocess.run(['adb', 'shell', "su -c", "dd if="+source], stdout=file) + result = subprocess.run(['adb', 'shell', "su -c \"", "dd if="+source + "\""], stdout=file) log_exitcode("Transfer", result) - return - + else: + with open(destination, "w+") as file: + result = subprocess.run(['adb', 'shell', "su -c \"", "dd if="+source + "\""], stdout=file) + log_exitcode("Transfer", result) + if args.check: hash_check(args.target, args.source)