From 4efc020538f959722f8b60b7adf96132f5118d6e Mon Sep 17 00:00:00 2001 From: Frederico Moreira <58743520+hypervanse@users.noreply.github.com> Date: Tue, 3 Jun 2025 23:51:43 -0300 Subject: [PATCH] Update symbolify to Python 3 --- tools/DoctorMyPass.py | 80 ++++++++++++++++++++++++++++++++ tools/symbolify.py | 29 ++++++------ tools/vm_sanitize_enforcement.py | 3 +- 3 files changed, 95 insertions(+), 17 deletions(-) create mode 100644 tools/DoctorMyPass.py diff --git a/tools/DoctorMyPass.py b/tools/DoctorMyPass.py new file mode 100644 index 000000000..1653dba58 --- /dev/null +++ b/tools/DoctorMyPass.py @@ -0,0 +1,80 @@ +import os +import sys +import platform +import pkgutil + + +def gather_info(): + info = { + "python_executable": sys.executable, + "python_version": sys.version, + "platform": f"{platform.system()} {platform.release()} ({platform.version()})", + "machine": platform.machine(), + "processor": platform.processor(), + "architecture": platform.architecture(), + "cwd": os.getcwd(), + "sys_path": list(sys.path), + "modules": sorted(m.name for m in pkgutil.iter_modules()), + } + return info + + +def print_info(info): + print("=" * 40) + print("\U0001FA7A DoctorMyPass - Local Python Diagnostic") + print("=" * 40) + print(f"Python Executable: {info['python_executable']}") + print(f"Python Version: {info['python_version']}") + print(f"Platform: {info['platform']}") + print(f"Machine: {info['machine']}") + print(f"Processor: {info['processor']}") + print(f"Architecture: {info['architecture']}") + print(f"Current Working Directory: {info['cwd']}") + print("\n\U0001F4C2 sys.path (where Python looks for modules):") + for p in info['sys_path']: + print(f" - {p}") + print("\n\U0001F4DA Importable Modules (minimal check):") + for mod in info['modules']: + print(f" - {mod}") + + +def save_report(info, filename): + try: + with open(filename, "w") as f: + f.write("DoctorMyPass - Local Python Diagnostic\n") + f.write("=" * 40 + "\n") + f.write(f"Python Executable: {info['python_executable']}\n") + f.write(f"Python Version: {info['python_version']}\n") + f.write(f"Platform: {info['platform']}\n") + f.write(f"Machine: {info['machine']}\n") + f.write(f"Processor: {info['processor']}\n") + f.write(f"Architecture: {info['architecture']}\n") + f.write(f"Current Working Directory: {info['cwd']}\n") + f.write("\nsys.path:\n") + for p in info['sys_path']: + f.write(f" - {p}\n") + f.write("\nImportable Modules:\n") + for mod in info['modules']: + f.write(f" - {mod}\n") + print(f"\U0001F4DD Diagnostic saved to {filename}") + except Exception as e: + print(f"\u26A0\uFE0F Could not write to {filename}: {e}") + + +def main(): + info = gather_info() + print_info(info) + paths = [ + os.path.join(os.getcwd(), "DoctorMyPass.txt"), + "/sdcard/DoctorMyPass.txt", + "/storage/emulated/0/DoctorMyPass.txt", + ] + for path in paths: + save_report(info, path) + print("=" * 40) + print("\U0001FA7A DoctorMyPass - Done") + print("=" * 40) + + +if __name__ == "__main__": + main() diff --git a/tools/symbolify.py b/tools/symbolify.py index 6ef18146b..2c73aac9c 100755 --- a/tools/symbolify.py +++ b/tools/symbolify.py @@ -1,5 +1,5 @@ -#!/usr/bin/env python -from subprocess import Popen, PIPE, call +#!/usr/bin/env python3 +from subprocess import Popen, PIPE import re import sys import os @@ -10,9 +10,9 @@ nm_re = re.compile(NM_FORMAT) -def parse_nm_output(str): - "returns (start, type, name)" - m = nm_re.match(str) +def parse_nm_output(line): + """Return tuple ``(start, type, name)`` parsed from an ``nm`` output line.""" + m = nm_re.match(line) if m: start = int(m.group(1), 16) return (start, m.group(2), m.group(3)) @@ -30,8 +30,8 @@ def __init__(self, file, min_width=16): self.symbols = [parse_nm_output(l) for l in nm(file)] self.symbols.sort(key=lambda x: x[0]) - def padded(self, str): - return ("%%%ds" % self.min_width) % str + def padded(self, text): + return ("%%%ds" % self.min_width) % text def __call__(self, saddr): addr = int(saddr.group(0), 16) @@ -52,18 +52,15 @@ def __call__(self, saddr): return saddr.group(0) return self.padded("<%s>+%x" % (last[2], addr - last[0])) -def symbolify(objfile, input, *args, **kargs): +def symbolify(objfile, stream, *args, **kargs): replacer = SymbolLookup(objfile, *args, **kargs) - for l in input: - print re.sub("(0x)?[0-9a-f]{6,16}", replacer, l), + for l in stream: + print(re.sub("(0x)?[0-9a-f]{6,16}", replacer, l), end="") def usage(): - - print "usage: %s [filename] [slide]" % sys.argv[0] - print "\tor speficy a filename in your SYMBOLIFY_KERNEL environment variable" - - # die now + print("usage: %s [filename] [slide]" % sys.argv[0]) + print("\tor speficy a filename in your SYMBOLIFY_KERNEL environment variable") sys.exit(1) KERNEL_FILE = None @@ -83,7 +80,7 @@ def usage(): if( KERNEL_FILE is None ): usage() -print "using kernel file '%s', slide 0x%x" % (KERNEL_FILE, SLIDE) +print("using kernel file '%s', slide 0x%x" % (KERNEL_FILE, SLIDE)) symbolify(KERNEL_FILE, sys.stdin, min_width=40) diff --git a/tools/vm_sanitize_enforcement.py b/tools/vm_sanitize_enforcement.py index b9fd3abc8..50d210c9d 100755 --- a/tools/vm_sanitize_enforcement.py +++ b/tools/vm_sanitize_enforcement.py @@ -112,7 +112,8 @@ def main(): return ERROR header = filename[:-1] + "h" - are_safe_types_used = are_safe_types_used_in_file(header) + if are_safe_types_used_in_file(header): + are_safe_types_used = True if are_safe_types_used: print_error("{}: {}".format(sys.argv[0], error_help_message))