Skip to content

Commit 3370154

Browse files
committed
Add support for combined name and pointer typedef
1 parent c1cf4c3 commit 3370154

2 files changed

Lines changed: 17 additions & 3 deletions

File tree

dissect/cstruct/parser.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,11 +314,11 @@ def _names(self, tokens: TokenConsumer) -> list[str]:
314314
tokens.eol()
315315
break
316316

317-
if tokens.next not in (self.TOK.NAME, self.TOK.DEFS):
317+
if tokens.next not in (self.TOK.NAME, self.TOK.DEFS, self.TOK.IDENTIFIER):
318318
break
319319

320320
ntoken = tokens.consume()
321-
if ntoken == self.TOK.NAME:
321+
if ntoken in (self.TOK.NAME, self.TOK.IDENTIFIER):
322322
names.append(ntoken.value.strip())
323323
elif ntoken == self.TOK.DEFS:
324324
names.extend([name.strip() for name in ntoken.value.strip().split(",")])

tests/test_parser.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from dissect.cstruct.exceptions import ParserError
99
from dissect.cstruct.parser import TokenParser
10-
from dissect.cstruct.types import BaseArray, Pointer
10+
from dissect.cstruct.types import BaseArray, Pointer, Structure
1111
from tests.utils import verify_compiled
1212

1313
if TYPE_CHECKING:
@@ -150,3 +150,17 @@ def test_includes(cs: cstruct) -> None:
150150
assert len(cs.myStruct.fields) == 1
151151
assert cs.myStruct.fields.get("charVal")
152152

153+
154+
def test_typedef_pointer(cs: cstruct) -> None:
155+
cdef = """
156+
typedef struct _IMAGE_DATA_DIRECTORY {
157+
DWORD VirtualAddress;
158+
DWORD Size;
159+
} IMAGE_DATA_DIRECTORY, *PIMAGE_DATA_DIRECTORY;
160+
"""
161+
cs.load(cdef)
162+
163+
assert issubclass(cs._IMAGE_DATA_DIRECTORY, Structure)
164+
assert cs.IMAGE_DATA_DIRECTORY is cs._IMAGE_DATA_DIRECTORY
165+
assert issubclass(cs.PIMAGE_DATA_DIRECTORY, Pointer)
166+
assert cs.PIMAGE_DATA_DIRECTORY.type == cs._IMAGE_DATA_DIRECTORY

0 commit comments

Comments
 (0)