Created
May 6, 2026 14:21
-
-
Save mscalora/508587b514c87900d12adc15c9b67618 to your computer and use it in GitHub Desktop.
zsh function to disassemble pything3 .pyc files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pycdis() { | |
| if [[ -z "$1" ]]; then | |
| echo "Usage: pycdis <path_to_file.pyc>" | |
| return 1 | |
| fi | |
| # Check if the file exists | |
| if [[ ! -f "$1" ]]; then | |
| echo "Error: File '$1' not found." | |
| return 1 | |
| fi | |
| python3 -c " | |
| import dis | |
| import marshal | |
| import sys | |
| # Color formatting for the terminal | |
| HEADER = '\033[95m' | |
| BLUE = '\033[94m' | |
| CYAN = '\033[96m' | |
| ENDC = '\033[0m' | |
| path = '$1' | |
| with open(path, 'rb') as f: | |
| # Skip the 16-byte PEP 552 header in modern Python | |
| f.seek(16) | |
| try: | |
| code_obj = marshal.load(f) | |
| except Exception as e: | |
| print(f'Error loading .pyc: {e}') | |
| sys.exit(1) | |
| print(f'{HEADER}--- Disassembling: {path} ---{ENDC}') | |
| print(f'{BLUE}Python Version: {sys.version}{ENDC}\n') | |
| # 3.14 Specific / Advanced Flags: | |
| # show_caches: Shows the inline cache entries used for specialization | |
| # adaptive: Shows the specialized versions of instructions | |
| # show_offsets: Displays the byte offsets for every instruction | |
| dis.dis(code_obj, show_caches=True, adaptive=True) | |
| " | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment