fix subprocess codec

This commit is contained in:
hyugogirubato 2024-04-19 21:52:59 +02:00
parent da3b1f95d9
commit 80da61e0bb
2 changed files with 6 additions and 4 deletions

View File

@ -63,7 +63,8 @@ class Cdm:
""" """
# https://source.android.com/docs/core/architecture/configuration/add-system-properties?#shell-commands # https://source.android.com/docs/core/architecture/configuration/add-system-properties?#shell-commands
properties = {} 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) match = re.match(r'\[(.*?)\]: \[(.*?)\]', line)
if match: if match:
key, value = match.groups() key, value = match.groups()
@ -135,7 +136,8 @@ class Cdm:
# https://github.com/frida/frida/issues/1225#issuecomment-604181822 # https://github.com/frida/frida/issues/1225#issuecomment-604181822
# Iterate through lines starting from the second line (skipping header) # Iterate through lines starting from the second line (skipping header)
processes = {} 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: try:
line = line.split() # USER,PID,PPID,VSZ,RSS,WCHAN,ADDR,S,NAME line = line.split() # USER,PID,PPID,VSZ,RSS,WCHAN,ADDR,S,NAME
name = ' '.join(line[8:]).strip() name = ' '.join(line[8:]).strip()

View File

@ -29,8 +29,8 @@ if __name__ == '__main__':
logger.info('Version: %s', extractor.__version__) logger.info('Version: %s', extractor.__version__)
# Ensure the ADB server is running # Ensure the ADB server is running
exitcode, _ = subprocess.getstatusoutput('adb start-server') sp = subprocess.run('adb start-server', capture_output=True)
if exitcode != 0: 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') 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 # Initialize the CDM handler with the specified or default device