Skip to content

Commit ce6c4b8

Browse files
authored
Compatibility with cstruct v4 (#717)
1 parent 4962256 commit ce6c4b8

37 files changed

Lines changed: 171 additions & 169 deletions

.github/workflows/dissect-ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ on:
1111
jobs:
1212
ci:
1313
uses: fox-it/dissect-workflow-templates/.github/workflows/dissect-ci-template.yml@main
14+
with:
15+
deb-packages: 'liblzo2-dev'
1416
secrets: inherit
1517

1618
publish:

.github/workflows/on-demand-test.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
python-include: "pypy3.9"
1717
tox-env: "pypy39"
1818
steps:
19+
- run: sudo apt-get install -qq liblzo2-dev
1920
- uses: actions/checkout@v3
2021
with:
2122
fetch-depth: 0

dissect/target/helpers/protobuf.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,26 @@
33
from typing import Any, BinaryIO
44

55
from dissect.cstruct.types.base import BaseType
6-
from dissect.cstruct.types.bytesinteger import BytesInteger
76

87

9-
class ProtobufVarint(BytesInteger):
8+
class ProtobufVarint(BaseType):
109
"""Implements a protobuf integer type for dissect.cstruct that can span a variable amount of bytes.
1110
12-
Mainly follows the cstruct BytesInteger implementation with minor tweaks
13-
to support protobuf's msb varint implementation.
11+
Supports protobuf's msb varint implementation.
1412
1513
Resources:
1614
- https://protobuf.dev/programming-guides/encoding/
1715
- https://github.com/protocolbuffers/protobuf/blob/main/python/google/protobuf/internal/decoder.py
1816
"""
1917

20-
def _read(self, stream: BinaryIO, context: dict[str, Any] = None) -> int:
18+
@classmethod
19+
def _read(cls, stream: BinaryIO, context: dict[str, Any] = None) -> int:
2120
return decode_varint(stream)
2221

23-
def _write(self, stream: BinaryIO, data: int) -> int:
22+
@classmethod
23+
def _write(cls, stream: BinaryIO, data: int) -> int:
2424
return stream.write(encode_varint(data))
2525

26-
_read_array = BaseType._read_array
27-
28-
_write_array = BaseType._write_array
29-
3026

3127
def decode_varint(stream: BinaryIO) -> int:
3228
"""Reads a varint from the provided buffer stream.

dissect/target/helpers/ssh.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import base64
22
import binascii
33

4-
from dissect import cstruct
4+
from dissect.cstruct import cstruct
55

6-
c_rfc4716_def = """
6+
rfc4716_def = """
77
struct ssh_string {
88
uint32 length;
99
char value[length];
@@ -23,8 +23,7 @@
2323
}
2424
"""
2525

26-
c_rfc4716 = cstruct.cstruct(endian=">")
27-
c_rfc4716.load(c_rfc4716_def)
26+
c_rfc4716 = cstruct(endian=">").load(rfc4716_def)
2827

2928
RFC4716_MARKER_START = b"-----BEGIN OPENSSH PRIVATE KEY-----"
3029
RFC4716_MARKER_END = b"-----END OPENSSH PRIVATE KEY-----"

dissect/target/plugins/apps/av/trendmicro.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Iterator
22

3-
from dissect import cstruct
3+
from dissect.cstruct import cstruct
44
from dissect.util.ts import from_unix
55

66
from dissect.target import Target
@@ -47,8 +47,7 @@
4747
char _pad3[10];
4848
};
4949
"""
50-
c_pfwlog = cstruct.cstruct()
51-
c_pfwlog.load(pfwlog_def)
50+
c_pfwlog = cstruct().load(pfwlog_def)
5251

5352

5453
class TrendMicroPlugin(Plugin):

dissect/target/plugins/apps/container/docker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"""
8989

9090
c_local = cstruct(endian=">")
91-
c_local.addtype("varint", ProtobufVarint(c_local, "varint", size=None, signed=False, alignment=1))
91+
c_local.add_custom_type("varint", ProtobufVarint, size=None, alignment=1, signed=False)
9292
c_local.load(local_def, compiled=False)
9393

9494
RE_DOCKER_NS = re.compile(r"\.(?P<nanoseconds>\d{7,})(?P<postfix>Z|\+\d{2}:\d{2})")

dissect/target/plugins/os/unix/locate/gnulocate.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@
2626
],
2727
)
2828

29-
c_gnulocate = cstruct()
30-
c_gnulocate.load(gnulocate_def)
29+
c_gnulocate = cstruct().load(gnulocate_def)
3130

3231

3332
class GNULocateFile:

dissect/target/plugins/os/unix/locate/mlocate.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
int32 conf_size;
2121
int8 version; /* file format version */
2222
int8 require_visibility;
23-
int8 pad[2]; /* 32-bit total alignment */
23+
int8 pad0[2]; /* 32-bit total alignment */
2424
char root_database;
2525
char config_block[conf_size];
26-
int8 pad;
26+
int8 pad1;
2727
};
2828
2929
enum DBE_TYPE: uint8 { /* database entry type */
@@ -68,8 +68,7 @@ class MLocate:
6868
],
6969
)
7070

71-
c_mlocate = cstruct(endian=">")
72-
c_mlocate.load(mlocate_def)
71+
c_mlocate = cstruct(endian=">").load(mlocate_def)
7372

7473

7574
class MLocateFile:

dissect/target/plugins/os/unix/locate/plocate.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@
6565
],
6666
)
6767

68-
c_plocate = cstruct()
69-
c_plocate.load(plocate_def)
68+
c_plocate = cstruct().load(plocate_def)
7069

7170

7271
class PLocateFile:

dissect/target/plugins/os/unix/log/atop.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from io import BytesIO
33
from typing import BinaryIO, Iterator
44

5-
from dissect.cstruct import Instance, cstruct
5+
from dissect.cstruct import cstruct
66

77
from dissect.target.exceptions import UnsupportedPluginError
88
from dissect.target.helpers.record import TargetRecordDescriptor
@@ -178,8 +178,7 @@
178178
};
179179
""" # noqa: E501
180180

181-
c_atop = cstruct()
182-
c_atop.load(atop_def)
181+
c_atop = cstruct().load(atop_def)
183182
c_atop.load(atop_tstat_def, align=True)
184183

185184
AtopRecord = TargetRecordDescriptor(
@@ -226,7 +225,7 @@ def __init__(self, fh: BinaryIO):
226225
self.header = c_atop.rawheader(self.fh)
227226
self.version = self.version()
228227

229-
def __iter__(self) -> Iterator[Instance]:
228+
def __iter__(self) -> Iterator[c_atop.tstat]:
230229
while True:
231230
try:
232231
record = c_atop.rawrecord(self.fh)

0 commit comments

Comments
 (0)