import struct, sys
PATH = r"C:\git\bt411\content\BTL4OPT.EXE"
data = open(PATH, "rb").read()
e_lfanew = struct.unpack_from("<I", data, 0x3C)[0]
coff = e_lfanew + 4
num_sec = struct.unpack_from("<H", data, coff+2)[0]
opt_size = struct.unpack_from("<H", data, coff+16)[0]
opt = coff + 20
image_base = struct.unpack_from("<I", data, opt+28)[0]
sec_tbl = opt + opt_size
secs = []
for i in range(num_sec):
    off = sec_tbl + i*40
    vsize, va, rawsize, rawptr = struct.unpack_from("<IIII", data, off+8)
    secs.append((va, vsize, rawptr, rawsize))
def va_to_off(va):
    rva = va - image_base
    for sva, vsize, rawptr, rawsize in secs:
        if sva <= rva < sva + max(vsize, rawsize):
            return rawptr + (rva - sva)
    return None
VT = int(sys.argv[1], 16)
N = int(sys.argv[2]) if len(sys.argv) > 2 else 32
o = va_to_off(VT)
print(f"vtable @0x{VT:x}:")
for i in range(N):
    fp = struct.unpack_from("<I", data, o + i*4)[0]
    tag = ""
    if 0x4c2f94 <= fp <= 0x4c6771: tag = "  <-- BT btl4gaug fn"
    print(f"  [+0x{i*4:02x}] slot{i:2d} = 0x{fp:x}{tag}")
