From f972f09e18f246668b2248836691ede7abe2d451 Mon Sep 17 00:00:00 2001 From: Max Groot <19346100+MaxGroot@users.noreply.github.com> Date: Mon, 22 Apr 2024 20:44:30 +0200 Subject: [PATCH 1/2] Fix colored hexdumps for zero-length field values --- dissect/cstruct/utils.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/dissect/cstruct/utils.py b/dissect/cstruct/utils.py index 302c653..db40361 100644 --- a/dissect/cstruct/utils.py +++ b/dissect/cstruct/utils.py @@ -55,6 +55,8 @@ def _hexdump(data: bytes, palette: Palette = None, offset: int = 0, prefix: str for j in range(16): if not active and palette: remaining, active = palette.pop() + while remaining == 0: + remaining, active = palette.pop() values += active elif active and j == 0: values += active From 581aff036f5341d242b876fc415bf43f7ed5ef89 Mon Sep 17 00:00:00 2001 From: Max Groot <19346100+MaxGroot@users.noreply.github.com> Date: Mon, 22 Apr 2024 21:50:17 +0200 Subject: [PATCH 2/2] Account for empty value at end of structure --- dissect/cstruct/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/dissect/cstruct/utils.py b/dissect/cstruct/utils.py index db40361..05b2acc 100644 --- a/dissect/cstruct/utils.py +++ b/dissect/cstruct/utils.py @@ -56,7 +56,12 @@ def _hexdump(data: bytes, palette: Palette = None, offset: int = 0, prefix: str if not active and palette: remaining, active = palette.pop() while remaining == 0: - remaining, active = palette.pop() + if len(palette) == 0: + # Last palette tuple is empty: print remaining whitespaces + active = "" + break + else: + remaining, active = palette.pop() values += active elif active and j == 0: values += active