Skip to content

Commit

Permalink
Compatibility with cstruct v4
Browse files Browse the repository at this point in the history
  • Loading branch information
Schamper committed May 24, 2024
1 parent a7c0535 commit 3a18207
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
9 changes: 4 additions & 5 deletions dissect/shellitem/lnk/c_lnk.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from enum import IntEnum
from typing import Optional

from dissect import cstruct
from dissect.cstruct import cstruct

# structs are reconstructed as faithfull as possible from MS documentation
# reference: https://winprotocoldoc.blob.core.windows.net/productionwindowsarchives/MS-SHLLINK/%5bMS-SHLLINK%5d.pdf

c_lnk_def = """
lnk_def = """
flag FILE_ATTRIBUTE : uint32 {
READONLY = 0x00000001,
HIDDEN = 0x00000002,
Expand Down Expand Up @@ -297,7 +297,7 @@
typedef struct SPECIAL_FOLDER_PROPS {
uint32 special_folder_id; // A 32-bit, unsigned integer that specifies the folder integer ID.
uint32 offset; // A 32-bit, unsigned integer that specifies the location of the ItemID of the first child segment of the IDList specified by SpecialFolderID. This value is the offset, in bytes, into the link target IDList.
uint32 offset; // A 32-bit, unsigned integer that specifies the location of the ItemID of the first child segment of the IDList specified by SpecialFolderID. This value is the offset, in bytes, into the link target IDList.
};
typedef struct DARWIN_PROPS {
Expand Down Expand Up @@ -389,5 +389,4 @@ def _has_value(cls, value: int) -> bool:
JUMPLIST_HEADER_SIZE = 0x24
JUMPLIST_FOOTER = 0xBABFFBAB

c_lnk = cstruct.cstruct()
c_lnk.load(c_lnk_def)
c_lnk = cstruct().load(lnk_def)
10 changes: 5 additions & 5 deletions dissect/shellitem/lnk/lnk.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,17 @@ def _parse(self, fh: BinaryIO) -> None:
if block_name == "PROPERTY_STORE_PROPS":
# TODO implement actual serialized property parsing
guid = self._parse_guid(struct.format_id)
struct._values.update({"format_id": guid})
setattr(struct, "format_id", guid)

elif block_name == "TRACKER_PROPS":
for name, value in struct._values.items():
if "droid" in name:
guid = self._parse_guid(value)
struct._values.update({name: guid})
setattr(struct, name, guid)

elif block_name == "KNOWN_FOLDER_PROPS":
guid = self._parse_guid(struct.known_folder_id)
struct._values.update({"known_folder_id": guid})
setattr(struct, "known_folder_id", guid)

elif (
block_name == "ENVIRONMENT_PROPS"
Expand Down Expand Up @@ -247,14 +247,14 @@ def _parse(self, buff: BinaryIO) -> None:
header = c_lnk.COMMON_NETWORK_RELATIVE_LINK_HEADER(buff.read(20))
flags = header.common_network_relative_link_flags

if flags & flags.enum.valid_device:
if flags & c_lnk.COMMON_NETWORK_RELATIVE_LINK_FLAGS.valid_device:
offset = buff.seek(start_common_network_relative_link + header.device_name_offset)
device_name = c_lnk.DEVICE_NAME(buff.read())
read_size = len(device_name.dumps())
device_name = device_name.device_name
buff.seek(offset + read_size)

if flags & flags.enum.valid_net_type:
if flags & c_lnk.COMMON_NETWORK_RELATIVE_LINK_FLAGS.valid_net_type:
offset = buff.seek(start_common_network_relative_link + header.net_name_offset)
net_name = c_lnk.NET_NAME(buff.read())
read_size = len(net_name.dumps())
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ classifiers = [
"Topic :: Utilities",
]
dependencies = [
"dissect.cstruct>=3.0.dev,<4.0.dev",
"dissect.util>=3.0.dev,<4.0.dev",
"dissect.cstruct>3,<5",
"dissect.util>2,<4",
]
dynamic = ["version"]

Expand Down
7 changes: 7 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ deps =
pytest
pytest-cov
coverage
# Unfortunately, tox does not allow separate installation flags for the project
# dependencies and the test dependencies. When running tox, we want to install the
# project dependencies with the --pre flag, so that we get the latest version of all
# dependencies. We do the installation step ourselves for this reason.
skip_install = true
commands_pre =
pip install --pre -e .
commands =
pytest --basetemp="{envtmpdir}" {posargs:--color=yes --cov=dissect --cov-report=term-missing -v tests}
coverage report
Expand Down

0 comments on commit 3a18207

Please sign in to comment.