Skip to content

Commit

Permalink
Add test for Unknown block
Browse files Browse the repository at this point in the history
  • Loading branch information
Matmaus committed Mar 12, 2024
1 parent 6db6618 commit 1bf81c6
Show file tree
Hide file tree
Showing 4 changed files with 167 additions and 0 deletions.
88 changes: 88 additions & 0 deletions tests/json/unknown_block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"data": {
"command_line_arguments": "/c ren cfsdaacdfawd\\*.vbss *.vbs &start \\cfsdaacdfawd\\aiasfacoiaksf.vbs&start explorer .android_secure&exit",
"icon_location": "%SystemRoot%\\System32\\shell32.dll"
},
"extra": {
"SPECIAL_FOLDER_LOCATION_BLOCK": {
"offset": 213,
"size": 16,
"special_folder_id": 37
},
"UNKNOWN_BLOCK": [
{
"extra_data_sha256": "4f022b4bc7668d870e158010c9877224df1b9b07bd24ef32b731963232b15eb2",
"size": 28
},
{
"extra_data_sha256": "40ebe6ee6ad3303ae2db241742e857aee523b21553a51e2f6c2a2461f1010879",
"size": 153
}
]
},
"header": {
"accessed_time": null,
"creation_time": null,
"file_flags": [],
"file_size": 0,
"guid": "00021401-0000-0000-C000-000000000046",
"header_size": 76,
"hotkey": "UNSET - UNSET {0x0000}",
"icon_index": 3,
"link_flags": [
"HasTargetIDList",
"HasArguments",
"HasIconLocation",
"IsUnicode"
],
"modified_time": null,
"r_file_flags": 0,
"r_hotkey": 0,
"r_link_flags": 225,
"reserved0": 0,
"reserved1": 0,
"reserved2": 0,
"windowstyle": "SW_SHOWMINNOACTIVE"
},
"link_info": {},
"target": {
"index": 78,
"items": [
{
"class": "Root Folder",
"guid": "20D04FE0-3AEA-1069-A2D8-08002B30309D",
"sort_index": "My Computer"
},
{
"class": "Volume Item",
"data": null,
"flags": "0xf"
},
{
"class": "File entry",
"file_attribute_flags": 16,
"file_size": 0,
"flags": "Is directory",
"modification_time": null,
"primary_name": "Windows"
},
{
"class": "File entry",
"file_attribute_flags": 16,
"file_size": 0,
"flags": "Is directory",
"modification_time": null,
"primary_name": "system32"
},
{
"class": "File entry",
"file_attribute_flags": 0,
"file_size": 0,
"flags": "Is file",
"modification_time": null,
"primary_name": "cmd.exe"
}
],
"size": 297
}
}
63 changes: 63 additions & 0 deletions tests/json/unknown_block.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Windows Shortcut Information:
Header Size: 76
Link CLSID: 00021401-0000-0000-C000-000000000046
Link Flags: HasTargetIDList | HasArguments | HasIconLocation | IsUnicode - (225)
File Flags: - (0)

Creation Timestamp: None
Modified Timestamp: None
Accessed Timestamp: None

File Size: 0 (r: 860)
Icon Index: 3
Window Style: SW_SHOWMINNOACTIVE
HotKey: UNSET - UNSET {0x0000}
Reserved0: 0
Reserved1: 0
Reserved2: 0

TARGETS:
Size: 297
Index: 78
ITEMS:
Root Folder
Sort index: My Computer
Guid: 20D04FE0-3AEA-1069-A2D8-08002B30309D
Volume Item
Flags: 0xf
Data: None
File entry
Flags: Is directory
File size: 0
Modification time: None
File attribute flags: 16
Primary name: Windows
File entry
Flags: Is directory
File size: 0
Modification time: None
File attribute flags: 16
Primary name: system32
File entry
Flags: Is file
File size: 0
Modification time: None
File attribute flags: 0
Primary name: cmd.exe

DATA
Command line arguments: /c ren cfsdaacdfawd\*.vbss *.vbs &start \cfsdaacdfawd\aiasfacoiaksf.vbs&start explorer .android_secure&exit
Icon location: %SystemRoot%\System32\shell32.dll

EXTRA BLOCKS:
SPECIAL_FOLDER_LOCATION_BLOCK
Size: 16
Special folder id: 37
Offset: 213
UNKNOWN_BLOCK
Block:
Size: 28
Extra data sha256: 4f022b4bc7668d870e158010c9877224df1b9b07bd24ef32b731963232b15eb2
Block:
Size: 153
Extra data sha256: 40ebe6ee6ad3303ae2db241742e857aee523b21553a51e2f6c2a2461f1010879
Binary file added tests/samples/unknown_block
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/test_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,22 @@ def test_print_unknown_target(self):

self.assertEqual(our, their)

def test_print_unknown_block(self):
with open('tests/samples/unknown_block', 'rb') as indata:
lnk = LnkParse3.lnk_file(indata)

mock_stdout = StringIO()
with redirect_stdout(mock_stdout):
lnk.print_lnk_file(print_all=True)

our = mock_stdout.getvalue()

txt_path = os.path.join(JSON_DIR, "unknown_block.txt")
with open(txt_path, 'r') as fp:
their = fp.read()

self.assertEqual(our, their)


if __name__ == '__main__':
unittest.main()

0 comments on commit 1bf81c6

Please sign in to comment.