dissect.cstruct 3.14.dev1__tar.gz → 3.14.dev3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dissect.cstruct-3.14.dev1/dissect.cstruct.egg-info → dissect.cstruct-3.14.dev3}/PKG-INFO +1 -1
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/parser.py +25 -6
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3/dissect.cstruct.egg-info}/PKG-INFO +1 -1
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/test_basic.py +29 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tox.ini +1 -1
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/COPYRIGHT +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/LICENSE +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/MANIFEST.in +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/README.md +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/__init__.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/bitbuffer.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/compiler.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/cstruct.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/exceptions.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/expression.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/types/__init__.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/types/base.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/types/bytesinteger.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/types/chartype.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/types/enum.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/types/flag.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/types/instance.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/types/packedtype.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/types/pointer.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/types/structure.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/types/voidtype.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/types/wchartype.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/utils.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect.cstruct.egg-info/SOURCES.txt +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect.cstruct.egg-info/dependency_links.txt +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect.cstruct.egg-info/top_level.txt +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/examples/disk.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/examples/mirai.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/examples/pe.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/examples/secdesc.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/pyproject.toml +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/setup.cfg +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/__init__.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/conftest.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/data/testdef.txt +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/docs/Makefile +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/docs/conf.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/docs/index.rst +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/test_align.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/test_bitbuffer.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/test_bitfield.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/test_bytesinteger.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/test_ctypes_type.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/test_enum.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/test_expression.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/test_flag.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/test_packedtype.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/test_parser.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/test_pointer.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/test_struct.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/test_union.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/test_util.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/test_utils.py +0 -0
- {dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/tests/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dissect.cstruct
|
|
3
|
-
Version: 3.14.
|
|
3
|
+
Version: 3.14.dev3
|
|
4
4
|
Summary: A Dissect module implementing a parser for C-like structures: structure parsing in Python made easy
|
|
5
5
|
Author-email: Dissect Team <dissect@fox-it.com>
|
|
6
6
|
License: Apache License 2.0
|
|
@@ -2,12 +2,21 @@ from __future__ import annotations
|
|
|
2
2
|
|
|
3
3
|
import ast
|
|
4
4
|
import re
|
|
5
|
-
from typing import TYPE_CHECKING, Dict, List
|
|
5
|
+
from typing import TYPE_CHECKING, Dict, List, Optional
|
|
6
6
|
|
|
7
7
|
from dissect.cstruct.compiler import Compiler
|
|
8
8
|
from dissect.cstruct.exceptions import ParserError
|
|
9
9
|
from dissect.cstruct.expression import Expression
|
|
10
|
-
from dissect.cstruct.types import
|
|
10
|
+
from dissect.cstruct.types import (
|
|
11
|
+
Array,
|
|
12
|
+
BaseType,
|
|
13
|
+
Enum,
|
|
14
|
+
Field,
|
|
15
|
+
Flag,
|
|
16
|
+
Pointer,
|
|
17
|
+
Structure,
|
|
18
|
+
Union,
|
|
19
|
+
)
|
|
11
20
|
|
|
12
21
|
if TYPE_CHECKING:
|
|
13
22
|
from dissect.cstruct import cstruct
|
|
@@ -158,6 +167,9 @@ class TokenParser(Parser):
|
|
|
158
167
|
|
|
159
168
|
names = self._names(tokens)
|
|
160
169
|
for name in names:
|
|
170
|
+
type_, name, bits = self._parse_field_type(type_, name)
|
|
171
|
+
if bits is not None:
|
|
172
|
+
raise ParserError(f"line {self._lineno(tokens.previous)}: typedefs cannot have bitfields")
|
|
161
173
|
self.cstruct.addtype(name, type_)
|
|
162
174
|
|
|
163
175
|
def _struct(self, tokens: TokenConsumer, register: bool = False) -> None:
|
|
@@ -236,9 +248,15 @@ class TokenParser(Parser):
|
|
|
236
248
|
raise ParserError(f"line {self._lineno(tokens.next)}: expected name")
|
|
237
249
|
nametok = tokens.consume()
|
|
238
250
|
|
|
251
|
+
type_, name, bits = self._parse_field_type(type_, nametok.value)
|
|
252
|
+
|
|
253
|
+
tokens.eol()
|
|
254
|
+
return Field(name.strip(), type_, bits)
|
|
255
|
+
|
|
256
|
+
def _parse_field_type(self, type_: BaseType, name: str) -> tuple[BaseType, str, Optional[int]]:
|
|
239
257
|
pattern = self.TOK.patterns[self.TOK.NAME]
|
|
240
258
|
# Dirty trick because the regex expects a ; but we don't want it to be part of the value
|
|
241
|
-
d = pattern.match(
|
|
259
|
+
d = pattern.match(name + ";").groupdict()
|
|
242
260
|
|
|
243
261
|
name = d["name"]
|
|
244
262
|
count_expression = d["count"]
|
|
@@ -269,8 +287,7 @@ class TokenParser(Parser):
|
|
|
269
287
|
|
|
270
288
|
type_ = Array(self.cstruct, type_, count)
|
|
271
289
|
|
|
272
|
-
|
|
273
|
-
return Field(name, type_, int(d["bits"]) if d["bits"] else None)
|
|
290
|
+
return type_, name, int(d["bits"]) if d["bits"] else None
|
|
274
291
|
|
|
275
292
|
def _names(self, tokens: TokenConsumer) -> List[str]:
|
|
276
293
|
names = []
|
|
@@ -564,6 +581,7 @@ class TokenConsumer:
|
|
|
564
581
|
def __init__(self, tokens: List[Token]):
|
|
565
582
|
self.tokens = tokens
|
|
566
583
|
self.flags = []
|
|
584
|
+
self.previous = None
|
|
567
585
|
|
|
568
586
|
def __contains__(self, token) -> bool:
|
|
569
587
|
return token in self.tokens
|
|
@@ -582,7 +600,8 @@ class TokenConsumer:
|
|
|
582
600
|
return None
|
|
583
601
|
|
|
584
602
|
def consume(self) -> Token:
|
|
585
|
-
|
|
603
|
+
self.previous = self.tokens.pop(0)
|
|
604
|
+
return self.previous
|
|
586
605
|
|
|
587
606
|
def reset_flags(self) -> None:
|
|
588
607
|
self.flags = []
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: dissect.cstruct
|
|
3
|
-
Version: 3.14.
|
|
3
|
+
Version: 3.14.dev3
|
|
4
4
|
Summary: A Dissect module implementing a parser for C-like structures: structure parsing in Python made easy
|
|
5
5
|
Author-email: Dissect Team <dissect@fox-it.com>
|
|
6
6
|
License: Apache License 2.0
|
|
@@ -4,6 +4,7 @@ import pytest
|
|
|
4
4
|
from dissect import cstruct
|
|
5
5
|
|
|
6
6
|
from dissect.cstruct.exceptions import ArraySizeError, ParserError, ResolveError
|
|
7
|
+
from dissect.cstruct.types import Array, Pointer
|
|
7
8
|
|
|
8
9
|
from .utils import verify_compiled
|
|
9
10
|
|
|
@@ -571,3 +572,31 @@ def test_reserved_keyword(compiled: bool):
|
|
|
571
572
|
assert verify_compiled(cs.resolve(name), compiled)
|
|
572
573
|
|
|
573
574
|
assert cs.resolve(name)(b"\x01").a == 1
|
|
575
|
+
|
|
576
|
+
|
|
577
|
+
def test_typedef_types():
|
|
578
|
+
cdef = """
|
|
579
|
+
typedef char uuid_t[16];
|
|
580
|
+
typedef uint32 *ptr;
|
|
581
|
+
|
|
582
|
+
struct test {
|
|
583
|
+
uuid_t uuid;
|
|
584
|
+
ptr ptr;
|
|
585
|
+
};
|
|
586
|
+
"""
|
|
587
|
+
cs = cstruct.cstruct(pointer="uint8")
|
|
588
|
+
cs.load(cdef)
|
|
589
|
+
|
|
590
|
+
assert isinstance(cs.uuid_t, Array)
|
|
591
|
+
assert cs.uuid_t(b"\x01" * 16) == b"\x01" * 16
|
|
592
|
+
|
|
593
|
+
assert isinstance(cs.ptr, Pointer)
|
|
594
|
+
assert cs.ptr(b"\x01AAAA") == 1
|
|
595
|
+
assert cs.ptr(b"\x01AAAA").dereference() == 0x41414141
|
|
596
|
+
|
|
597
|
+
obj = cs.test(b"\x01" * 16 + b"\x11AAAA")
|
|
598
|
+
assert obj.uuid == b"\x01" * 16
|
|
599
|
+
assert obj.ptr.dereference() == 0x41414141
|
|
600
|
+
|
|
601
|
+
with pytest.raises(ParserError, match="line 1: typedefs cannot have bitfields"):
|
|
602
|
+
cs.load("""typedef uint8 with_bits : 4;""")
|
|
@@ -4,7 +4,7 @@ envlist = lint, py3, pypy3
|
|
|
4
4
|
# requires if they are not available on the host system. This requires the
|
|
5
5
|
# locally installed tox to have a minimum version 3.3.0. This means the names
|
|
6
6
|
# of the configuration options are still according to the tox 3.x syntax.
|
|
7
|
-
minversion = 4.
|
|
7
|
+
minversion = 4.4.3
|
|
8
8
|
# This version of virtualenv will install setuptools version 65.5.0 and pip
|
|
9
9
|
# 22.3. These versions fully support python projects defined only through a
|
|
10
10
|
# pyproject.toml file (PEP-517/PEP-518/PEP-621)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect/cstruct/types/bytesinteger.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect.cstruct.egg-info/SOURCES.txt
RENAMED
|
File without changes
|
|
File without changes
|
{dissect.cstruct-3.14.dev1 → dissect.cstruct-3.14.dev3}/dissect.cstruct.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|