import struct,sys
va=int(sys.argv[1],16)
f=open('content/BTL4OPT.EXE','rb').read()
# PE header
pe=struct.unpack_from('<I',f,0x3c)[0]
assert f[pe:pe+4]==b'PE\0\0'
numsec=struct.unpack_from('<H',f,pe+6)[0]
optsz=struct.unpack_from('<H',f,pe+20)[0]
imgbase=struct.unpack_from('<I',f,pe+0x34)[0]
sectab=pe+24+optsz
for i in range(numsec):
    off=sectab+i*40
    name=f[off:off+8].rstrip(b'\0').decode(errors='replace')
    vsz,vaddr,rsz,raddr=struct.unpack_from('<IIII',f,off+8)
    if imgbase+vaddr <= va < imgbase+vaddr+max(vsz,rsz):
        fo=raddr+(va-imgbase-vaddr)
        raw=f[fo:fo+4]
        print(f"VA {va:#x} sec={name} bytes={raw.hex()} float={struct.unpack('<f',raw)[0]} int={struct.unpack('<i',raw)[0]}")
        break
else:
    print("not found; imgbase",hex(imgbase))
