From 38ae64ea20f3c42459eaa53ccb01514cbe8d69e8 Mon Sep 17 00:00:00 2001 From: Stefan de Reuver <9864602+Horofic@users.noreply.github.com> Date: Tue, 30 Jan 2024 09:44:10 +0100 Subject: [PATCH] Add test --- tests/conftest.py | 17 +++++++++++------ tests/data/vista.idlist.lnk | Bin 0 -> 1069 bytes tests/test_lnk.py | 24 ++++++++++++++++++------ 3 files changed, 29 insertions(+), 12 deletions(-) create mode 100755 tests/data/vista.idlist.lnk diff --git a/tests/conftest.py b/tests/conftest.py index a72b1b9..11ccc40 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,30 +4,35 @@ import pytest -def absolute_path(filename): +def absolute_path(filename: str) -> str: return os.path.join(os.path.dirname(__file__), filename) @pytest.fixture -def xp_modified_remote_lnk_file(): +def xp_modified_remote_lnk_file() -> Path: return Path(absolute_path("data/modified_remote.file.xp.lnk")) @pytest.fixture -def xp_remote_lnk_file(): +def xp_remote_lnk_file() -> Path: return Path(absolute_path("data/remote.file.xp.lnk")) @pytest.fixture -def xp_remote_lnk_dir(): +def xp_remote_lnk_dir() -> Path: return Path(absolute_path("data/remote.directory.xp.lnk")) @pytest.fixture -def win7_local_lnk_dir(): +def win7_local_lnk_dir() -> Path: return Path(absolute_path("data/local.directory.seven.lnk")) @pytest.fixture -def win81_downloads_lnk_dir(): +def win81_downloads_lnk_dir() -> Path: return Path(absolute_path("data/downloads.win81.lnk")) + + +@pytest.fixture +def vista_idlist_lnk_file() -> Path: + return Path(absolute_path("data/vista.idlist.lnk")) diff --git a/tests/data/vista.idlist.lnk b/tests/data/vista.idlist.lnk new file mode 100755 index 0000000000000000000000000000000000000000..974bacbc6d3c568740aa910209dee1602f4d027a GIT binary patch literal 1069 zcmeZaU|?VrVFHp23bKnF6nr&ND|10s0QkT zsE3pBK$Z*;!{k8{Aifh2s{t`cTm*ZE{Jgc|%x@VAy3M!59V? Xu None: # The first 16 bytes contain the LNK GUID a to simulate a Jumplist CustomDestination file fh = xp_modified_remote_lnk_file.open("rb") fh.seek(16) @@ -14,7 +16,7 @@ def test_xp_custom_destination_remote_lnk_file(xp_modified_remote_lnk_file): assert str(lnk_file.clsid) == "00021401-0000-0000-c000-000000000046" -def test_xp_remote_lnk_file(xp_remote_lnk_file): +def test_xp_remote_lnk_file(xp_remote_lnk_file: Path) -> None: fh = xp_remote_lnk_file.open("rb") lnk_file = Lnk(fh) @@ -68,7 +70,7 @@ def test_xp_remote_lnk_file(xp_remote_lnk_file): assert uuid1timestamp(tracker_props.file_droid.time).ctime() == "Wed Feb 8 07:52:55 2006" -def test_xp_remote_lnk_dir(xp_remote_lnk_dir): +def test_xp_remote_lnk_dir(xp_remote_lnk_dir: Path) -> None: fh = xp_remote_lnk_dir.open("rb") lnk_file = Lnk(fh) @@ -81,7 +83,7 @@ def test_xp_remote_lnk_dir(xp_remote_lnk_dir): idlist = lnk_file.target_idlist.idlist assert len(idlist.itemid_list) == 7 assert idlist.terminalid == b"\x00\x00" - assert all([entry.itemid_size == len(entry.dumps()) for entry in idlist.itemid_list]) + assert all(entry.itemid_size == len(entry.dumps()) for entry in idlist.itemid_list) assert flags & c_lnk.LINK_FLAGS.has_link_info link_info = lnk_file.linkinfo.link_info @@ -116,7 +118,7 @@ def test_xp_remote_lnk_dir(xp_remote_lnk_dir): assert uuid1timestamp(tracker_props.file_droid.time).ctime() == "Tue Jul 21 07:31:44 2009" -def test_win7_local_lnk_dir(win7_local_lnk_dir): +def test_win7_local_lnk_dir(win7_local_lnk_dir: Path) -> None: fh = win7_local_lnk_dir.open("rb") lnk_file = Lnk(fh) @@ -179,7 +181,7 @@ def test_win7_local_lnk_dir(win7_local_lnk_dir): assert str(property_store_props.format_id) == "b725f130-47ef-101a-a5f1-02608c9eebac" -def test_common_path_suffix(win81_downloads_lnk_dir): +def test_common_path_suffix(win81_downloads_lnk_dir: Path) -> None: fh = win81_downloads_lnk_dir.open("rb") downloads = Lnk(fh) @@ -190,3 +192,13 @@ def test_common_path_suffix(win81_downloads_lnk_dir): assert link_info_flags & c_lnk.LINK_INFO_FLAGS.common_network_relative_link_and_pathsuffix == 0 assert link_info.common_path_suffix == b"" assert link_info.common_path_suffix.decode() == "" + + +def test_vista_and_above_idlist_lnk_props(vista_idlist_lnk_file: Path) -> None: + fh = vista_idlist_lnk_file.open("rb") + lnk_file = Lnk(fh) + vista_props = lnk_file.extradata.extradata["VISTA_AND_ABOVE_IDLIST_PROPS"] + + assert vista_props.size == 0x62 # 98 + assert vista_props.idlist.itemid_list[0].itemid_size == 0x60 # 96 + assert len(vista_props.idlist.itemid_list[0].data) == 0x5E # 94