Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions tools/DoctorMyPass.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import os
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Follow Python naming conventions for module names.

The module name should follow snake_case convention.

Rename the file to doctor_my_pass.py to follow Python naming conventions:

-tools/DoctorMyPass.py
+tools/doctor_my_pass.py
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import os
-tools/DoctorMyPass.py
+tools/doctor_my_pass.py
import os
🧰 Tools
🪛 Pylint (3.3.7)

[convention] 1-1: Missing module docstring

(C0114)


[convention] 1-1: Module name "DoctorMyPass" doesn't conform to snake_case naming style

(C0103)

🤖 Prompt for AI Agents
In tools/DoctorMyPass.py at line 1, the module filename does not follow Python's
snake_case naming convention. Rename the file from DoctorMyPass.py to
doctor_my_pass.py to comply with standard Python module naming practices.

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:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Specify encoding when opening files.

Opening files without explicit encoding can lead to issues across different systems.

Apply this diff to specify UTF-8 encoding:

-        with open(filename, "w") as f:
+        with open(filename, "w", encoding="utf-8") as f:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
with open(filename, "w") as f:
with open(filename, "w", encoding="utf-8") as f:
🧰 Tools
🪛 Pylint (3.3.7)

[warning] 43-43: Using open without explicitly specifying an encoding

(W1514)

🤖 Prompt for AI Agents
In tools/DoctorMyPass.py at line 43, the file is opened without specifying an
encoding, which can cause cross-platform issues. Modify the open call to include
encoding="utf-8" to ensure consistent file handling across different systems.

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}")
Comment on lines +60 to +61
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Handle specific exceptions instead of catching all exceptions.

Catching Exception is too broad and can mask unexpected errors.

Apply this diff to handle specific exceptions:

-    except Exception as e:
+    except (OSError, IOError, PermissionError) as e:
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
except Exception as e:
print(f"\u26A0\uFE0F Could not write to {filename}: {e}")
except (OSError, IOError, PermissionError) as e:
print(f"\u26A0\uFE0F Could not write to {filename}: {e}")
🧰 Tools
🪛 Pylint (3.3.7)

[warning] 60-60: Catching too general exception Exception

(W0718)

🤖 Prompt for AI Agents
In tools/DoctorMyPass.py around lines 60 to 61, replace the broad except
Exception clause with handling of specific exceptions related to file writing
errors, such as IOError or OSError. This will prevent masking unexpected errors
and improve error handling clarity. Identify the relevant exceptions for file
write operations and catch only those, updating the except block accordingly.



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()
29 changes: 13 additions & 16 deletions tools/symbolify.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)

3 changes: 2 additions & 1 deletion tools/vm_sanitize_enforcement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment on lines +115 to +116
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix indentation to match Python standards.

The logic change correctly prevents the flag from being reset once safe types are detected. However, the indentation is incorrect and will cause a syntax error.

Apply this diff to fix the indentation:

-	if are_safe_types_used_in_file(header):
-		are_safe_types_used = True
+		if are_safe_types_used_in_file(header):
+			are_safe_types_used = True

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 Pylint (3.3.7)

[warning] 115-115: Bad indentation. Found 2 spaces, expected 8

(W0311)


[warning] 116-116: Bad indentation. Found 3 spaces, expected 12

(W0311)

🤖 Prompt for AI Agents
In tools/vm_sanitize_enforcement.py around lines 115 to 116, the indentation of
the if statement block is incorrect and will cause a syntax error. Fix the
indentation by ensuring the line setting are_safe_types_used to True is indented
one level inside the if block, following Python standards.


if are_safe_types_used:
print_error("{}: {}".format(sys.argv[0], error_help_message))
Expand Down