dissect.cstruct icon indicating copy to clipboard operation
dissect.cstruct copied to clipboard

add support for const pointer array ```const char* arr[]```

Open andkae opened this issue 5 months ago • 1 comments

Hello Together,

the dissect.cstruct is a real big deal to parse c files. For const *char i encounter the error, that const is unsupported. Following example:

from dissect.cstruct import cstruct
cdef = """
const char* pArrChr[] = {
    "myStr1",   /**< comment */
    "myStr2",   /**< comment */
    "myStr3"
};
"""
cs = cstruct()
cs.load(cdef)

Following output:

  File "/home/ubuntu/Desktop/dissect.cstruct/dissect/cstruct/cstruct.py", line 268, in load
    TokenParser(self, \*\*kwargs).parse(definition)
  File "/home/ubuntu/Desktop/dissect.cstruct/dissect/cstruct/parser.py", line 470, in parse
    raise ParserError(f"line {self._lineno(token)}: unexpected token {token!r}")
dissect.cstruct.exceptions.ParserError: line 2: unexpected token <Token.IDENTIFIER value='const'>

Thanks again for your support.

BR, Andreas

andkae avatar Aug 01 '25 07:08 andkae

Hey Andreas, while it would be really nice to support this, unfortunately the current parser is a little too inflexible to easily add support for this syntax. But I'll leave the ticket open for future reference!

Schamper avatar Aug 18 '25 14:08 Schamper