File size: 875 Bytes
9bd4ce5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import os
import sys
from io import TextIOWrapper

# Add project root to path to allow imports from engine
if __name__ == "__main__":
    sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")))

from engine.models.bytecode_readable import decode_bytecode


if __name__ == "__main__":
    # Standardized UTF-8 Handling
    if sys.stdout.encoding.lower() != "utf-8":
        sys.stdout = TextIOWrapper(sys.stdout.buffer, encoding="utf-8", errors="replace")

    if len(sys.argv) < 2:
        print('Usage: python bytecode_decoder.py "[41, 3, 385876097, 0, 1, 0, 0, 0]"')
        sys.exit(1)

    raw = sys.argv[1]
    # Clean up input if it's bracketed
    raw = raw.strip("[] ")
    try:
        data = [int(x.strip()) for x in raw.split(",")]
        print(decode_bytecode(data))
    except Exception as e:
        print(f"Error decoding: {e}")