Skip to content

Commit 0b509da

Browse files
committed
m1n1.constructutils: Handle variable-length tail structs nicely
Signed-off-by: Hector Martin <[email protected]>
1 parent 60c523d commit 0b509da

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

proxyclient/m1n1/constructutils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,11 +158,13 @@ def __new__(cls, name, bases, attrs):
158158
try:
159159
sizeof = subcon.sizeof()
160160
except:
161-
break
161+
sizeof = None
162162
if isinstance(subcon, Renamed):
163163
name = subcon.name
164164
subcon = subcon.subcon
165165
cls._off[name] = off, sizeof
166+
if sizeof is None:
167+
break
166168
off += sizeof
167169
return cls
168170

@@ -380,7 +382,11 @@ def __str__(self, ignore=[]) -> str:
380382
meta = ""
381383
if key in self._off:
382384
offv, sizeof = self._off[key]
383-
off = f"\x1b[32m[{offv:3x}.{sizeof:3x}]\x1b[m "
385+
if sizeof is not None:
386+
sizeofs = f"{sizeof:3x}"
387+
else:
388+
sizeofs = " *"
389+
off = f"\x1b[32m[{offv:3x}.{sizeofs}]\x1b[m "
384390
if key in self._meta:
385391
meta = f" \x1b[34m{self._meta[key]}\x1b[m"
386392
if '\n' in val_repr:

0 commit comments

Comments
 (0)