2023-03-06 00:32:03 +08:00
|
|
|
import ctypes
|
|
|
|
import os
|
|
|
|
import pathlib
|
2024-09-24 15:23:43 +08:00
|
|
|
import struct
|
2023-03-06 00:32:03 +08:00
|
|
|
from hexdump import hexdump
|
|
|
|
|
|
|
|
fxn = None
|
2023-12-17 15:10:50 +08:00
|
|
|
def disasm_raw(buf):
|
2023-03-06 00:32:03 +08:00
|
|
|
global fxn
|
|
|
|
if fxn is None:
|
|
|
|
shared = pathlib.Path(__file__).parent / "disasm.so"
|
2023-08-31 01:41:08 +08:00
|
|
|
if not shared.is_file():
|
2023-03-06 00:32:03 +08:00
|
|
|
os.system(f'cd {pathlib.Path(__file__).parent} && gcc -shared disasm-a3xx.c -o disasm.so')
|
2023-04-19 10:17:41 +08:00
|
|
|
fxn = ctypes.CDLL(shared.as_posix())['disasm']
|
2023-12-17 15:10:50 +08:00
|
|
|
fxn(buf, len(buf))
|
|
|
|
|
|
|
|
def disasm(buf):
|
2024-09-24 15:23:43 +08:00
|
|
|
def _read_lib(off): return struct.unpack("I", buf[off:off+4])[0]
|
|
|
|
|
|
|
|
image_offset = _read_lib(0xc0)
|
|
|
|
image_size = _read_lib(0x100)
|
|
|
|
disasm_raw(buf[image_offset:image_offset+image_size])
|