mirror of
https://github.com/elliotnunn/tbxi.git
synced 2024-09-27 06:54:42 +00:00
Account for missing length bytes in NDRV sources
This commit is contained in:
parent
de37ceec98
commit
9dd0317bdc
@ -174,6 +174,16 @@ def parse_version(num):
|
|||||||
return vers
|
return vers
|
||||||
|
|
||||||
|
|
||||||
|
def pstring_or_cstring(s):
|
||||||
|
plen = s[0]
|
||||||
|
pstr = s[1:][:plen]
|
||||||
|
cstr = s.rstrip(b'\0')
|
||||||
|
if b'\0' in pstr or plen + 1 > len(s):
|
||||||
|
return cstr
|
||||||
|
else:
|
||||||
|
return pstr
|
||||||
|
|
||||||
|
|
||||||
def suggest_name(pef):
|
def suggest_name(pef):
|
||||||
if not pef.startswith(b'Joy!peff'): return
|
if not pef.startswith(b'Joy!peff'): return
|
||||||
|
|
||||||
@ -186,7 +196,10 @@ def suggest_name(pef):
|
|||||||
if section and sectype in (1, 2):
|
if section and sectype in (1, 2):
|
||||||
hdr_ofs = section.find(b'mtej')
|
hdr_ofs = section.find(b'mtej')
|
||||||
if hdr_ofs != -1:
|
if hdr_ofs != -1:
|
||||||
sig, strvers, devnam, drvvers = struct.unpack_from('>4s L 32p L', section, hdr_ofs)
|
sig, strvers, devnam, drvvers = struct.unpack_from('>4s L 32s L', section, hdr_ofs)
|
||||||
|
|
||||||
|
# devnam *should* be a 32-byte pascal string, but not if someone forgot the "\p"...
|
||||||
|
devnam = pstring_or_cstring(devnam)
|
||||||
|
|
||||||
sugg = devnam.decode('mac_roman') + '-' + parse_version(drvvers)
|
sugg = devnam.decode('mac_roman') + '-' + parse_version(drvvers)
|
||||||
return sugg
|
return sugg
|
||||||
|
Loading…
Reference in New Issue
Block a user