Skip to content

Commit 408cd73

Browse files
committed
Added VPK matching by directories
1 parent 179058d commit 408cd73

3 files changed

Lines changed: 38 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ cmd_whitelist.txt
55
sar_whitelist.txt
66
cvar_whitelist.txt
77
filesum_whitelist.txt
8+
vpk_directories_whitelist.txt
89
expected_maps.txt
910
config.txt
1011
errors.txt

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,15 @@ This is a whitelist of file checksums - SAR adds checksums for certain important
5959
placing its name in this file, or a specific checksum can be allowed for it by writing its name, then a space, then the expected checksum. Allowed values are
6060
omitted from output.
6161

62+
For VPK checksum data, this whitelist is checked against the outer VPK path/checksum. If it matches, the VPK is omitted from output.
63+
64+
### `vpk_directories_whitelist.txt`
65+
66+
This is a whitelist for files inside VPK checksum data. Each line is `path checksum`, where `path` is matched as a suffix and `checksum` is an 8-digit hex
67+
value. You can use `*` as the checksum to allow any checksum for that path.
68+
69+
If a VPK is not matched by `filesum_whitelist.txt`, then all inner VPK entries are checked against this file. Only non-matching entries are shown in output.
70+
6271
### `config.txt`
6372

6473
This file contains a few configuration settings, configured using lines of the format `key value`. Possible options:

src/main.c

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define SAR_WHITELIST_FILE "sar_whitelist.txt"
1717
#define CVAR_WHITELIST_FILE "cvar_whitelist.txt"
1818
#define FILESUM_WHITELIST_FILE "filesum_whitelist.txt"
19+
#define VPK_DIRECTORIES_WHITELIST_FILE "vpk_directories_whitelist.txt"
1920
#define GENERAL_CONF_FILE "config.txt"
2021

2122
FILE *g_errfile;
@@ -24,6 +25,7 @@ FILE *g_outfile;
2425
static char **g_cmd_whitelist;
2526
static char **g_sar_sum_whitelist;
2627
static struct var_whitelist *g_filesum_whitelist;
28+
static struct var_whitelist *g_vpk_directories_whitelist;
2729
static struct var_whitelist *g_cvar_whitelist;
2830

2931
// general config options
@@ -78,6 +80,23 @@ static bool _ignore_filesum(const char *path) {
7880
return false;
7981
}
8082

83+
static int _check_vpk_directory_whitelist(const char *path, const char *sum) {
84+
if (!g_vpk_directories_whitelist) return 0;
85+
86+
bool found = false;
87+
for (struct var_whitelist *entry = g_vpk_directories_whitelist; entry->var_name; ++entry) {
88+
size_t path_len = strlen(path);
89+
size_t entry_len = strlen(entry->var_name);
90+
if (path_len < entry_len) continue;
91+
if (strcmp(entry->var_name, "*") && strcmp(path + path_len - entry_len, entry->var_name)) continue;
92+
93+
found = true;
94+
if (!entry->val || !strcmp(entry->val, "*") || !strcmp(entry->val, sum)) return 2;
95+
}
96+
97+
return found ? 1 : 0;
98+
}
99+
81100
// janky hack lol
82101
static const char *const _g_map_found = "_MAP_FOUND";
83102
static const char **_g_expected_maps;
@@ -188,11 +207,16 @@ static void _output_sar_data(struct demo *demo, uint32_t tick, struct sar_data d
188207
break;
189208
case SAR_DATA_VPK_CHECKSUM:
190209
if (g_config.file_sum_mode != 0) {
210+
char strbuf[9];
211+
snprintf(strbuf, sizeof strbuf, "%08X", data.vpk_checksum.sum);
212+
if (config_check_var_whitelist(g_filesum_whitelist, data.vpk_checksum.path, strbuf) == 2) {
213+
break;
214+
}
215+
191216
bool printed = false;
192217
for (size_t i = 0; i < data.vpk_checksum.nentries; ++i) {
193-
char strbuf[9];
194218
snprintf(strbuf, sizeof strbuf, "%08X", data.vpk_checksum.entries[i].sum);
195-
int whitelist_status = config_check_var_whitelist(g_filesum_whitelist, data.vpk_checksum.entries[i].path, strbuf);
219+
int whitelist_status = _check_vpk_directory_whitelist(data.vpk_checksum.entries[i].path, strbuf);
196220
if (whitelist_status == 1 || (whitelist_status == 0 && g_config.file_sum_mode == 2)) {
197221
if (!printed) {
198222
fprintf(g_outfile, "\t\t[%5u] [SAR] VPK \"%s\" has checksum %08X\n", tick, data.vpk_checksum.path, data.vpk_checksum.sum);
@@ -488,6 +512,7 @@ int main(int argc, char **argv) {
488512
g_cmd_whitelist = config_read_newline_sep(CMD_WHITELIST_FILE);
489513
g_sar_sum_whitelist = config_read_newline_sep(SAR_WHITELIST_FILE);
490514
g_filesum_whitelist = config_read_var_whitelist(FILESUM_WHITELIST_FILE);
515+
g_vpk_directories_whitelist = config_read_var_whitelist(VPK_DIRECTORIES_WHITELIST_FILE);
491516
g_cvar_whitelist = config_read_var_whitelist(CVAR_WHITELIST_FILE);
492517

493518
g_config.file_sum_mode = 2;
@@ -615,6 +640,7 @@ int main(int argc, char **argv) {
615640
config_free_newline_sep(g_cmd_whitelist);
616641
config_free_newline_sep(g_sar_sum_whitelist);
617642
config_free_var_whitelist(g_filesum_whitelist);
643+
config_free_var_whitelist(g_vpk_directories_whitelist);
618644
config_free_var_whitelist(g_cvar_whitelist);
619645

620646
fclose(g_errfile);

0 commit comments

Comments
 (0)