dissect.cstruct 4.7.dev1__tar.gz → 4.8.dev2__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.
Files changed (78) hide show
  1. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/PKG-INFO +1 -1
  2. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect.cstruct.egg-info/PKG-INFO +1 -1
  3. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect.cstruct.egg-info/SOURCES.txt +1 -0
  4. dissect_cstruct-4.8.dev2/tests/conftest.py +31 -0
  5. dissect_cstruct-4.8.dev2/tests/test_benchmark.py +176 -0
  6. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tox.ini +11 -1
  7. dissect_cstruct-4.7.dev1/tests/conftest.py +0 -13
  8. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/.git-blame-ignore-revs +0 -0
  9. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/.gitattributes +0 -0
  10. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/CHANGELOG.md +0 -0
  11. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/COPYRIGHT +0 -0
  12. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/LICENSE +0 -0
  13. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/MANIFEST.in +0 -0
  14. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/README.md +0 -0
  15. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/__init__.py +0 -0
  16. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/bitbuffer.py +0 -0
  17. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/compiler.py +0 -0
  18. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/cstruct.py +0 -0
  19. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/exceptions.py +0 -0
  20. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/expression.py +0 -0
  21. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/parser.py +0 -0
  22. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/tools/__init__.py +0 -0
  23. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/tools/stubgen.py +0 -0
  24. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/types/__init__.py +0 -0
  25. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/types/base.py +0 -0
  26. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/types/char.py +0 -0
  27. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/types/enum.py +0 -0
  28. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/types/flag.py +0 -0
  29. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/types/int.py +0 -0
  30. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/types/leb128.py +0 -0
  31. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/types/packed.py +0 -0
  32. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/types/pointer.py +0 -0
  33. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/types/structure.py +0 -0
  34. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/types/void.py +0 -0
  35. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/types/wchar.py +0 -0
  36. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect/cstruct/utils.py +0 -0
  37. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect.cstruct.egg-info/dependency_links.txt +0 -0
  38. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect.cstruct.egg-info/entry_points.txt +0 -0
  39. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect.cstruct.egg-info/requires.txt +0 -0
  40. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/dissect.cstruct.egg-info/top_level.txt +0 -0
  41. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/examples/disk.py +0 -0
  42. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/examples/mirai.py +0 -0
  43. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/examples/pe.py +0 -0
  44. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/examples/protobuf.py +0 -0
  45. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/examples/secdesc.py +0 -0
  46. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/pyproject.toml +0 -0
  47. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/setup.cfg +0 -0
  48. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/__init__.py +0 -0
  49. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/_data/testdef.txt +0 -0
  50. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/_docs/Makefile +0 -0
  51. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/_docs/__init__.py +0 -0
  52. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/_docs/conf.py +0 -0
  53. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/_docs/index.rst +0 -0
  54. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_align.py +0 -0
  55. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_annotations.py +0 -0
  56. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_basic.py +0 -0
  57. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_bitbuffer.py +0 -0
  58. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_bitfield.py +0 -0
  59. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_compiler.py +0 -0
  60. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_ctypes.py +0 -0
  61. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_expression.py +0 -0
  62. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_parser.py +0 -0
  63. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_tools_stubgen.py +0 -0
  64. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_types_base.py +0 -0
  65. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_types_char.py +0 -0
  66. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_types_custom.py +0 -0
  67. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_types_enum.py +0 -0
  68. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_types_flag.py +0 -0
  69. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_types_int.py +0 -0
  70. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_types_leb128.py +0 -0
  71. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_types_packed.py +0 -0
  72. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_types_pointer.py +0 -0
  73. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_types_structure.py +0 -0
  74. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_types_union.py +0 -0
  75. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_types_void.py +0 -0
  76. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_types_wchar.py +0 -0
  77. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/test_utils.py +0 -0
  78. {dissect_cstruct-4.7.dev1 → dissect_cstruct-4.8.dev2}/tests/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dissect.cstruct
3
- Version: 4.7.dev1
3
+ Version: 4.8.dev2
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-Expression: Apache-2.0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dissect.cstruct
3
- Version: 4.7.dev1
3
+ Version: 4.8.dev2
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-Expression: Apache-2.0
@@ -45,6 +45,7 @@ tests/conftest.py
45
45
  tests/test_align.py
46
46
  tests/test_annotations.py
47
47
  tests/test_basic.py
48
+ tests/test_benchmark.py
48
49
  tests/test_bitbuffer.py
49
50
  tests/test_bitfield.py
50
51
  tests/test_compiler.py
@@ -0,0 +1,31 @@
1
+ from __future__ import annotations
2
+
3
+ import importlib.util
4
+
5
+ import pytest
6
+
7
+ from dissect.cstruct.cstruct import cstruct
8
+
9
+ HAS_BENCHMARK = importlib.util.find_spec("pytest_benchmark") is not None
10
+
11
+
12
+ def pytest_configure(config: pytest.Config) -> None:
13
+ if not HAS_BENCHMARK:
14
+ # If we don't have pytest-benchmark (or pytest-codspeed) installed, register the benchmark marker ourselves
15
+ # to avoid pytest warnings
16
+ config.addinivalue_line("markers", "benchmark: mark test for benchmarking (requires pytest-benchmark)")
17
+
18
+
19
+ def pytest_runtest_setup(item: pytest.Item) -> None:
20
+ if not HAS_BENCHMARK and item.get_closest_marker("benchmark") is not None:
21
+ pytest.skip("pytest-benchmark is not installed")
22
+
23
+
24
+ @pytest.fixture
25
+ def cs() -> cstruct:
26
+ return cstruct()
27
+
28
+
29
+ @pytest.fixture(params=[True, False], ids=["compiled", "interpreted"])
30
+ def compiled(request: pytest.FixtureRequest) -> bool:
31
+ return request.param
@@ -0,0 +1,176 @@
1
+ from __future__ import annotations
2
+
3
+ from functools import partial
4
+ from typing import TYPE_CHECKING
5
+
6
+ import pytest
7
+
8
+ from dissect.cstruct.expression import Expression
9
+
10
+ if TYPE_CHECKING:
11
+ from pytest_benchmark.fixture import BenchmarkFixture
12
+
13
+ from dissect.cstruct.cstruct import cstruct
14
+
15
+
16
+ @pytest.mark.benchmark
17
+ def test_benchmark_basic(cs: cstruct, compiled: bool, benchmark: BenchmarkFixture) -> None:
18
+ """Benchmark the parsing of a simple struct with both the compiled and interpreted backends."""
19
+ cdef = """
20
+ struct test {
21
+ uint32 a;
22
+ uint64 b;
23
+ uint16 c;
24
+ uint8 d;
25
+ };
26
+ """
27
+ cs.load(cdef, compiled=compiled)
28
+
29
+ benchmark(lambda: cs.test(b"\x01\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x04"))
30
+
31
+
32
+ @pytest.mark.benchmark
33
+ def test_benchmark_union(cs: cstruct, compiled: bool, benchmark: BenchmarkFixture) -> None:
34
+ """Benchmark the parsing of a simple union with both the compiled and interpreted backends."""
35
+ cdef = """
36
+ union test {
37
+ uint32 a;
38
+ uint64 b;
39
+ uint16 c;
40
+ uint8 d;
41
+ };
42
+ """
43
+ cs.load(cdef, compiled=compiled)
44
+
45
+ benchmark(lambda: cs.test(b"\x01\x02\x03\x04\x05\x06\x07\x08"))
46
+
47
+
48
+ @pytest.mark.benchmark
49
+ def test_benchmark_attribute_access(cs: cstruct, benchmark: BenchmarkFixture) -> None:
50
+ """Benchmark the attribute access of a parsed struct."""
51
+ cdef = """
52
+ struct test {
53
+ uint32 a;
54
+ uint64 b;
55
+ uint16 c;
56
+ uint8 d;
57
+ };
58
+ """
59
+ cs.load(cdef)
60
+ obj = cs.test(b"\x01\x00\x00\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x04")
61
+
62
+ benchmark(lambda: (obj.a, obj.b, obj.c, obj.d))
63
+
64
+
65
+ @pytest.mark.benchmark
66
+ def test_benchmark_getattr_constants(cs: cstruct, benchmark: BenchmarkFixture) -> None:
67
+ """Benchmark the resolving of constants on the cstruct instance."""
68
+ cdef = """
69
+ #define CONST1 1
70
+ """
71
+ cs.load(cdef)
72
+
73
+ benchmark(lambda: cs.CONST1)
74
+
75
+
76
+ @pytest.mark.benchmark
77
+ def test_benchmark_getattr_types(cs: cstruct, benchmark: BenchmarkFixture) -> None:
78
+ """Benchmark the resolving of types on the cstruct instance."""
79
+ benchmark(lambda: cs.uint8)
80
+
81
+
82
+ @pytest.mark.benchmark
83
+ def test_benchmark_getattr_typedefs(cs: cstruct, benchmark: BenchmarkFixture) -> None:
84
+ """Benchmark the resolving of typedefs on the cstruct instance."""
85
+ cdef = """
86
+ typedef uint8 my_uint8;
87
+ """
88
+ cs.load(cdef)
89
+
90
+ benchmark(lambda: cs.my_uint8)
91
+
92
+
93
+ @pytest.mark.benchmark
94
+ def test_benchmark_expression_parse(cs: cstruct, benchmark: BenchmarkFixture) -> None:
95
+ """Benchmark the parsing of expressions."""
96
+ cs.load("#define a 5\n#define b 10")
97
+
98
+ benchmark(lambda: Expression("a * 2 + b * (3 + 4) >> 1"))
99
+
100
+
101
+ @pytest.mark.benchmark
102
+ def test_benchmark_expression_evaluate(cs: cstruct, benchmark: BenchmarkFixture) -> None:
103
+ """Benchmark the evaluation of expressions."""
104
+ cs.load("#define a 5\n#define b 10")
105
+
106
+ expression = Expression("a * 2 + b * (3 + 4) >> 1")
107
+ benchmark(lambda: expression.evaluate(cs))
108
+
109
+
110
+ @pytest.mark.benchmark
111
+ def test_benchmark_expression_parse_and_evaluate(cs: cstruct, benchmark: BenchmarkFixture) -> None:
112
+ """Benchmark the parsing and evaluation of expressions."""
113
+ cs.load("#define a 5\n#define b 10")
114
+
115
+ benchmark(lambda: Expression("a * 2 + b * (3 + 4) >> 1").evaluate(cs))
116
+
117
+
118
+ _BENCHMARK_CDEF = """
119
+ struct SECURITY_DESCRIPTOR {
120
+ uint8 Revision;
121
+ uint8 Sbz1;
122
+ uint16 Control;
123
+ uint32 OffsetOwner;
124
+ uint32 OffsetGroup;
125
+ uint32 OffsetSacl;
126
+ uint32 OffsetDacl;
127
+ };
128
+
129
+ struct LDAP_SID_IDENTIFIER_AUTHORITY {
130
+ char Value[6];
131
+ };
132
+
133
+ struct LDAP_SID {
134
+ uint8 Revision;
135
+ uint8 SubAuthorityCount;
136
+ LDAP_SID_IDENTIFIER_AUTHORITY IdentifierAuthority;
137
+ uint32 SubAuthority[SubAuthorityCount];
138
+ };
139
+
140
+ struct ACL {
141
+ uint8 AclRevision;
142
+ uint8 Sbz1;
143
+ uint16 AclSize;
144
+ uint16 AceCount;
145
+ uint16 Sbz2;
146
+ char Data[AclSize - 8];
147
+ };
148
+
149
+ struct ACE {
150
+ uint8 AceType;
151
+ uint8 AceFlags;
152
+ uint16 AceSize;
153
+ char Data[AceSize - 4];
154
+ };
155
+
156
+ struct ACCESS_ALLOWED_ACE {
157
+ uint16 Mask;
158
+ LDAP_SID Sid;
159
+ };
160
+
161
+ struct ACCESS_ALLOWED_OBJECT_ACE {
162
+ uint32 Mask;
163
+ uint32 Flags;
164
+ char ObjectType[(Flags & 1) * 16];
165
+ char InheritedObjectType[(Flags & 2) * 8];
166
+ LDAP_SID Sid;
167
+ };
168
+ """
169
+
170
+
171
+ @pytest.mark.benchmark
172
+ def test_benchmark_lexer_and_parser(cs: cstruct, benchmark: BenchmarkFixture) -> None:
173
+ """Benchmark tokenizing and parsing a realistic set of struct definitions."""
174
+ cs.add_type = partial(cs.add_type, replace=True)
175
+
176
+ benchmark(lambda: cs.load(_BENCHMARK_CDEF))
@@ -18,10 +18,20 @@ deps =
18
18
  coverage
19
19
  dependency_groups = test
20
20
  commands =
21
- pytest --basetemp="{envtmpdir}" {posargs:--color=yes --cov=dissect --cov-report=term-missing -v tests}
21
+ pytest --basetemp="{envtmpdir}" --import-mode="append" {posargs:--color=yes --cov=dissect --cov-report=term-missing -v tests}
22
22
  coverage report
23
23
  coverage xml
24
24
 
25
+ [testenv:benchmark]
26
+ deps =
27
+ pytest-benchmark
28
+ pytest-codspeed
29
+ dependency_groups = test
30
+ passenv =
31
+ CODSPEED_ENV
32
+ commands =
33
+ pytest --basetemp="{envtmpdir}" --import-mode="append" -m benchmark {posargs:--color=yes -v tests}
34
+
25
35
  [testenv:build]
26
36
  package = skip
27
37
  dependency_groups = build
@@ -1,13 +0,0 @@
1
- import pytest
2
-
3
- from dissect.cstruct.cstruct import cstruct
4
-
5
-
6
- @pytest.fixture
7
- def cs() -> cstruct:
8
- return cstruct()
9
-
10
-
11
- @pytest.fixture(params=[True, False])
12
- def compiled(request: pytest.FixtureRequest) -> bool:
13
- return request.param