From 80da61e0bb316580196089837660c0381beda5b1 Mon Sep 17 00:00:00 2001 From: hyugogirubato <65763543+hyugogirubato@users.noreply.github.com> Date: Fri, 19 Apr 2024 21:52:59 +0200 Subject: [PATCH] fix subprocess codec --- extractor/cdm.py | 6 ++++-- keydive.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/extractor/cdm.py b/extractor/cdm.py index c9c88ce..fe2a60b 100644 --- a/extractor/cdm.py +++ b/extractor/cdm.py @@ -63,7 +63,8 @@ class Cdm: """ # https://source.android.com/docs/core/architecture/configuration/add-system-properties?#shell-commands properties = {} - for line in subprocess.getoutput(f'adb -s "{self.device.id}" shell getprop').splitlines(): + sp = subprocess.run(f'adb -s "{self.device.id}" shell getprop', capture_output=True) + for line in sp.stdout.decode('utf-8').splitlines(): match = re.match(r'\[(.*?)\]: \[(.*?)\]', line) if match: key, value = match.groups() @@ -135,7 +136,8 @@ class Cdm: # https://github.com/frida/frida/issues/1225#issuecomment-604181822 # Iterate through lines starting from the second line (skipping header) processes = {} - for line in subprocess.getoutput(f'adb -s "{self.device.id}" shell ps').splitlines()[1:]: + sp = subprocess.run(f'adb -s "{self.device.id}" shell ps', capture_output=True) + for line in sp.stdout.decode('utf-8').splitlines()[1:]: try: line = line.split() # USER,PID,PPID,VSZ,RSS,WCHAN,ADDR,S,NAME name = ' '.join(line[8:]).strip() diff --git a/keydive.py b/keydive.py index 24dce86..92f38a9 100644 --- a/keydive.py +++ b/keydive.py @@ -29,8 +29,8 @@ if __name__ == '__main__': logger.info('Version: %s', extractor.__version__) # Ensure the ADB server is running - exitcode, _ = subprocess.getstatusoutput('adb start-server') - if exitcode != 0: + sp = subprocess.run('adb start-server', capture_output=True) + if sp.returncode != 0: raise EnvironmentError('ADB is not recognized as an environment variable, see https://github.com/hyugogirubato/KeyDive/blob/main/docs/PACKAGE.md#adb-android-debug-bridge') # Initialize the CDM handler with the specified or default device