Skip to content

Commit 0d0ed30

Browse files
committed
Initial commit
0 parents  commit 0d0ed30

File tree

9 files changed

+1606
-0
lines changed

9 files changed

+1606
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 Maldev Academy
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

PrefetchFileParser.sln

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 17
4+
VisualStudioVersion = 17.14.36705.20 d17.14
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PrefetchFileParser", "PrefetchFileParser\PrefetchFileParser.vcxproj", "{E1551717-8095-4FBF-B08A-0DD022FF5F3F}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{E1551717-8095-4FBF-B08A-0DD022FF5F3F}.Debug|x64.ActiveCfg = Debug|x64
17+
{E1551717-8095-4FBF-B08A-0DD022FF5F3F}.Debug|x64.Build.0 = Debug|x64
18+
{E1551717-8095-4FBF-B08A-0DD022FF5F3F}.Debug|x86.ActiveCfg = Debug|Win32
19+
{E1551717-8095-4FBF-B08A-0DD022FF5F3F}.Debug|x86.Build.0 = Debug|Win32
20+
{E1551717-8095-4FBF-B08A-0DD022FF5F3F}.Release|x64.ActiveCfg = Release|x64
21+
{E1551717-8095-4FBF-B08A-0DD022FF5F3F}.Release|x64.Build.0 = Release|x64
22+
{E1551717-8095-4FBF-B08A-0DD022FF5F3F}.Release|x86.ActiveCfg = Release|Win32
23+
{E1551717-8095-4FBF-B08A-0DD022FF5F3F}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
GlobalSection(ExtensibilityGlobals) = postSolution
29+
SolutionGuid = {E9227144-6948-4812-ABAC-60B9F6D0FEB9}
30+
EndGlobalSection
31+
EndGlobal

PrefetchFileParser/Headers.h

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
#pragma once
2+
#ifndef HEADERS_H
3+
#define HEADERS_H
4+
5+
#include <Windows.h>
6+
#include <shlwapi.h>
7+
#include <strsafe.h>
8+
#include <stdio.h>
9+
10+
#pragma comment(lib, "Shlwapi.lib")
11+
#pragma comment(lib, "Advapi32.lib")
12+
#pragma comment(lib, "ntdll.lib")
13+
14+
15+
// ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
16+
// Constants
17+
18+
#define BUFFER_SIZE_16 16
19+
#define BUFFER_SIZE_32 32
20+
#define BUFFER_SIZE_64 64
21+
#define BUFFER_SIZE_128 128
22+
#define BUFFER_SIZE_256 256
23+
#define BUFFER_SIZE_512 512
24+
#define BUFFER_SIZE_1024 1024
25+
#define BUFFER_SIZE_2048 2048
26+
#define BUFFER_SIZE_4096 4096
27+
#define BUFFER_SIZE_8192 8192
28+
29+
#define DRIVE_LETTER_COUNT 26
30+
#define ARRAY_INITIAL_CAPACITY 64
31+
32+
// ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
33+
34+
#define PREFETCH_SIGNATURE 0x41434353 // "SCCA"
35+
#define PREFETCH_COMPRESSED_SIGNATURE 0x044D414D // "MAM\x04"
36+
37+
38+
// https://github.com/libyal/libscca/blob/main/documentation/Windows%20Prefetch%20File%20(PF)%20format.asciidoc#411-format-version
39+
/*
40+
17 - Used in: Windows XP, Windows 2003 [NOT SUPPORTED]
41+
23 - Used in: Windows Vista, Windows 7 [NOT SUPPORTED]
42+
26 - Used in: Windows 8.1 [NOT SUPPORTED]
43+
30 - Used in: Windows 10 [SUPPORTED]
44+
31 - Used in: Windows 11 [SUPPORTED]
45+
*/
46+
47+
#define PREFETCH_VERSION_WIN10 30
48+
#define PREFETCH_VERSION_WIN11 31
49+
50+
// https://github.com/libyal/libscca/blob/main/documentation/Windows%20Prefetch%20File%20(PF)%20format.asciidoc?plain=1#L387
51+
// https://github.com/libyal/libscca/blob/main/documentation/Windows%20Prefetch%20File%20(PF)%20format.asciidoc?plain=1#L423
52+
#define PREFETCH_MAX_LAST_RUN_TIMES 8
53+
54+
// ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
55+
56+
#define PREFETCH_PATH L"C:\\Windows\\Prefetch"
57+
58+
#define DEFAULT_OUTPUT_FILENAME L"PrefetchData.json"
59+
60+
#define MAX_BINARY_FILTERS 64
61+
62+
// ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
63+
// Windows Defintions
64+
65+
#ifndef NT_SUCCESS
66+
#define NT_SUCCESS(Status) (((NTSTATUS)(Status)) >= 0)
67+
#endif
68+
69+
// https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-rtldecompressbufferex
70+
EXTERN_C NTSTATUS NTAPI RtlDecompressBufferEx(
71+
IN USHORT CompressionFormat,
72+
OUT PUCHAR UncompressedBuffer,
73+
IN ULONG UncompressedBufferSize,
74+
IN PUCHAR CompressedBuffer,
75+
IN ULONG CompressedBufferSize,
76+
OUT PULONG FinalUncompressedSize,
77+
IN PVOID WorkSpace
78+
);
79+
80+
// https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-rtlgetcompressionworkspacesize
81+
EXTERN_C NTSTATUS NTAPI RtlGetCompressionWorkSpaceSize(
82+
IN USHORT CompressionFormatAndEngine,
83+
OUT PULONG CompressBufferWorkSpaceSize,
84+
OUT PULONG CompressFragmentWorkSpaceSize
85+
);
86+
87+
#pragma pack(push, 1)
88+
89+
// https://github.com/libyal/libscca/blob/main/documentation/Windows%20Prefetch%20File%20(PF)%20format.asciidoc#31-file-header
90+
typedef struct _PREFETCH_MAM_HEADER
91+
{
92+
DWORD dwSignature; // 0x00 - Signature ("MAM\x04" - 0x04 indicates XPRESS Huffman compression)
93+
DWORD dwUncompressedSize; // 0x04 - Uncompressed data size
94+
} PREFETCH_MAM_HEADER, *PPREFETCH_MAM_HEADER;
95+
96+
// https://github.com/libyal/libscca/blob/main/documentation/Windows%20Prefetch%20File%20(PF)%20format.asciidoc#41-file-header
97+
typedef struct _PREFETCH_HEADER
98+
{
99+
DWORD dwVersion; // 0x00 - Format version (17=XP, 23=Vista/7, 26=8.1, 30=10, 31=11)
100+
DWORD dwSignature; // 0x04 - Signature ("SCCA" - 0x41434353)
101+
DWORD dwUnknown1; // 0x08 - Unknown (flags? 0x01 = boot prefetch)
102+
DWORD dwFileSize; // 0x0C - File size (uncompressed)
103+
WCHAR wszExecutableName[30]; // 0x10 - Executable filename (UTF-16, max 29 chars + null terminator)
104+
DWORD dwHash; // 0x4C - Prefetch hash (path hash)
105+
DWORD dwUnknown2; // 0x50 - Unknown (possibly padding)
106+
} PREFETCH_HEADER, *PPREFETCH_HEADER;
107+
108+
// https://github.com/libyal/libscca/blob/main/documentation/Windows%20Prefetch%20File%20(PF)%20format.asciidoc#442-file-metrics-array-entry---version-23
109+
// Versions 23/26/30/31 are all the same
110+
typedef struct _PREFETCH_FILE_METRICS_ENTRY {
111+
DWORD dwStartTime;
112+
DWORD dwDuration;
113+
DWORD dwAverageDuration;
114+
DWORD dwFilenameOffset; // Offset into filename strings section
115+
DWORD dwFilenameLength; // Length in characters
116+
DWORD dwFlags;
117+
ULONGLONG ullMftReference;
118+
} PREFETCH_FILE_METRICS_ENTRY, * PPREFETCH_FILE_METRICS_ENTRY;
119+
120+
121+
// https://github.com/libyal/libscca/blob/main/documentation/Windows%20Prefetch%20File%20(PF)%20format.asciidoc#volume-information-entry---version-30
122+
// Versions 30/31 are the same
123+
typedef struct _PREFETCH_VOLUME_INFO {
124+
DWORD dwDevicePathOffset; // 0x00 - Volume device path offset (relative to start of volume info)
125+
DWORD dwDevicePathLength; // 0x04 - Volume device path number of characters (without end-of-string)
126+
FILETIME ftCreationTime; // 0x08 - Volume creation time (FILETIME)
127+
DWORD dwSerialNumber; // 0x10 - Volume serial number
128+
DWORD dwFileReferencesOffset; // 0x14 - File references offset (relative to start of volume info)
129+
DWORD dwFileReferencesSize; // 0x18 - File references data size
130+
DWORD dwDirectoryStringsOffset; // 0x1C - Directory strings offset (relative to start of volume info)
131+
DWORD dwDirectoryStringsCount; // 0x20 - Number of directory strings
132+
BYTE padding[64]; // 0x24 - Unknown/padding (to reach 96 bytes)
133+
} PREFETCH_VOLUME_INFO, * PPREFETCH_VOLUME_INFO;
134+
135+
136+
// https://github.com/libyal/libscca/blob/main/documentation/Windows%20Prefetch%20File%20(PF)%20format.asciidoc#425-file-information---version-30---variant-1
137+
// File information - version 30 variant 1 - 220 bytes (Windows 10 pre-1903)
138+
typedef struct _PREFETCH_FILE_INFO_V30_1
139+
{
140+
DWORD dwMetricsArrayOffset; // 0x00 - File metrics array offset
141+
DWORD dwMetricsArrayCount; // 0x04 - Number of file metrics array entries
142+
DWORD dwTraceChainsOffset; // 0x08 - Trace chains array offset
143+
DWORD dwTraceChainsCount; // 0x0C - Number of trace chains array entries
144+
DWORD dwFilenameStringsOffset; // 0x10 - Filename strings offset
145+
DWORD dwFilenameStringsSize; // 0x14 - Filename strings data size
146+
DWORD dwVolumesInfoOffset; // 0x18 - Volumes information offset
147+
DWORD dwVolumesInfoCount; // 0x1C - Number of volumes
148+
DWORD dwVolumesInfoSize; // 0x20 - Volumes information data size
149+
DWORD dwTotalDirectoryCount; // 0x24 - Total number of directory strings (across all volumes)
150+
DWORD dwUnknown1; // 0x28 - Unknown
151+
FILETIME ftLastRunTime[8]; // 0x2C - Last run times (FILETIME array, 8 entries, 64 bytes)
152+
DWORD dwUnknown2; // 0x6C - Unknown (remnant data after 8 run times filled)
153+
DWORD dwUnknown3; // 0x70 - Unknown
154+
DWORD dwRunCount; // 0x74 - Run count
155+
BYTE padding[100]; // 0x78 - Unknown/padding (to reach 220 bytes)
156+
} PREFETCH_FILE_INFO_V30_1, *PPREFETCH_FILE_INFO_V30_1;
157+
158+
// https://github.com/libyal/libscca/blob/main/documentation/Windows%20Prefetch%20File%20(PF)%20format.asciidoc#426-file-information---version-30---variant-2
159+
// File information - version 30 variant 2 / version 31 - 212 bytes (Windows 10 1903+ / Windows 11)
160+
typedef struct _PREFETCH_FILE_INFO_V30_2
161+
{
162+
DWORD dwMetricsArrayOffset; // 0x00 - File metrics array offset
163+
DWORD dwMetricsArrayCount; // 0x04 - Number of file metrics array entries
164+
DWORD dwTraceChainsOffset; // 0x08 - Trace chains array offset
165+
DWORD dwTraceChainsCount; // 0x0C - Number of trace chains array entries
166+
DWORD dwFilenameStringsOffset; // 0x10 - Filename strings offset
167+
DWORD dwFilenameStringsSize; // 0x14 - Filename strings data size
168+
DWORD dwVolumesInfoOffset; // 0x18 - Volumes information offset
169+
DWORD dwVolumesInfoCount; // 0x1C - Number of volumes
170+
DWORD dwVolumesInfoSize; // 0x20 - Volumes information data size
171+
DWORD dwTotalDirectoryCount; // 0x24 - Total number of directory strings (across all volumes)
172+
DWORD dwUnknown1; // 0x28 - Unknown
173+
FILETIME ftLastRunTime[8]; // 0x2C - Last run times (FILETIME array, 8 entries, 64 bytes)
174+
DWORD dwUnknown2; // 0x6C - Unknown (remnant data after 8 run times filled)
175+
DWORD dwRunCount; // 0x70 - Run count
176+
BYTE padding[96]; // 0x74 - Unknown/padding (to reach 212 bytes)
177+
} PREFETCH_FILE_INFO_V30_2, *PPREFETCH_FILE_INFO_V30_2;
178+
179+
// Common file information structure (shared fields up to offset 0x6C)
180+
typedef struct _PREFETCH_FILE_INFO
181+
{
182+
DWORD dwMetricsArrayOffset; // 0x00 - File metrics array offset
183+
DWORD dwMetricsArrayCount; // 0x04 - Number of file metrics array entries
184+
DWORD dwTraceChainsOffset; // 0x08 - Trace chains array offset
185+
DWORD dwTraceChainsCount; // 0x0C - Number of trace chains array entries
186+
DWORD dwFilenameStringsOffset; // 0x10 - Filename strings offset
187+
DWORD dwFilenameStringsSize; // 0x14 - Filename strings data size
188+
DWORD dwVolumesInfoOffset; // 0x18 - Volumes information offset
189+
DWORD dwVolumesInfoCount; // 0x1C - Number of volumes
190+
DWORD dwVolumesInfoSize; // 0x20 - Volumes information data size
191+
DWORD dwTotalDirectoryCount; // 0x24 - Total number of directory strings (across all volumes)
192+
DWORD dwUnknown1; // 0x28 - Unknown
193+
FILETIME ftLastRunTime[8]; // 0x2C - Last run times (FILETIME array, 8 entries, 64 bytes)
194+
} PREFETCH_FILE_INFO, *PPREFETCH_FILE_INFO;
195+
#pragma pack(pop)
196+
197+
#define PREFETCH_FILE_INFO_V30_1_SIZE 220
198+
#define PREFETCH_FILE_INFO_V30_2_SIZE 212
199+
#define PREFETCH_RUN_COUNT_OFFSET_V30_1 0x74
200+
#define PREFETCH_RUN_COUNT_OFFSET_V30_2 0x70
201+
202+
// ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
203+
// Output Structures
204+
205+
// Parsed prefetch entry containing extracted information
206+
typedef struct _PREFETCH_ENTRY
207+
{
208+
WCHAR wszExecutableName[BUFFER_SIZE_64]; // Executable filename (from header)
209+
WCHAR wszPrefetchFile[MAX_PATH]; // Prefetch filename
210+
DWORD dwRunCount; // Number of times the executable has been run
211+
FILETIME ftLastRunTimes[PREFETCH_MAX_LAST_RUN_TIMES]; // Last 8 execution timestamps
212+
DWORD dwLastRunTimeCount; // Number of valid entries in ftLastRunTimes
213+
DWORD dwVersion; // Prefetch format version
214+
DWORD dwHash; // Prefetch path hash
215+
WCHAR wszExecutablePath[MAX_PATH]; // Full path of executable
216+
LPWSTR* ppszLoadedFiles; // Array of loaded file paths (DLLs, etc.)
217+
DWORD dwLoadedFileCount; // Number of entries in ppszLoadedFiles
218+
LPWSTR* ppszDirectories; // Array of accessed directories
219+
DWORD dwDirectoryCount; // Number of entries in ppszDirectories
220+
WCHAR wszVolumeDevicePath[MAX_PATH]; // Volume device path
221+
DWORD dwVolumeSerialNumber; // Volume serial number
222+
FILETIME ftVolumeCreationTime; // Volume creation time
223+
FILETIME ftPrefetchCreated; // Prefetch file creation time (from file system)
224+
FILETIME ftPrefetchModified; // Prefetch file last modified time (from file system)
225+
} PREFETCH_ENTRY, *PPREFETCH_ENTRY;
226+
227+
// Dynamic array of prefetch entries
228+
typedef struct _PREFETCH_LIST
229+
{
230+
DWORD dwCount;
231+
DWORD dwCapacity;
232+
PPREFETCH_ENTRY pEntries;
233+
} PREFETCH_LIST, *PPREFETCH_LIST;
234+
235+
236+
// ==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
237+
// Functions
238+
239+
BOOL WritePrefetchJson(IN PPREFETCH_LIST pList, IN PCWSTR pszOutputPath);
240+
241+
242+
#endif // !HEADERS_H

0 commit comments

Comments
 (0)