Skip to main content

Module dir_listing

Module dir_listing 

Source
Expand description

Pure logic supporting hooks::query_dir’s directory-listing hook: buffer rewriting, plus the glob-style filename matching used to decide which mod-provided files belong in a given listing.

This used to live entirely as raw-pointer arithmetic directly inside hooks::query_dir’s detour closure, the riskiest unsafe code in the proxy crate (walking and mutating an OS-owned, variable-length-record buffer) and, until now, the least testable, since it only ever existed as a *mut u8 live during an actual NtQueryDirectoryFile call.

Everything here instead takes plain, owned/borrowed values, a &mut [u8] for the buffer functions, &str for the matcher, and uses ordinary slice indexing: an out-of-bounds access panics loudly instead of corrupting memory silently, and the whole thing can be exercised against a hand-built buffer in a plain #[test], with no OS, no Windows target, and no running game involved. hooks::query_dir’s detour is now a thin unsafe wrapper that builds a &mut [u8] view of the real syscall buffer via slice::from_raw_parts_mut(file_information as *mut u8, length as usize) and hands it to the functions below, the unsafe is now confined to that one slice construction instead of spread across every field access.

Structs§

EntryOffsets
Byte offsets of the three fields every supported FileXxxInformation variant has, relative to the start of one directory-listing entry. hooks::query_dir::get_dir_info_offsets derives these (via offset_of! on the real struct layouts) and passes them in here; this module doesn’t know about any specific info class, only these offsets.
FilterResult
Result of filter_redirected_entries.

Functions§

filter_redirected_entries
Compacts buf[..valid_len] in place: entries are FileXxxInformation- shaped records chained by NextEntryOffset, and any entry whose rel_key (rel_dir/name, or bare name when rel_dir is empty, lowercased) makes is_redirected return true is dropped. Retained entries are copied down to close the resulting gap and rechained.
wildcard_match
Glob-style filename matcher supporting * (any run of characters, including none) and ? (exactly one character), via a straightforward O(n·m) dynamic-programming table over the two strings’ characters.
write_directory_entry
Writes one synthetic directory entry (an injected mod-only filename) at buf[pos..], matching the layout the original inline code built: zeroed header, NextEntryOffset left at 0 (patched later, on the previous entry, once this one is known to exist, see prev_entry_offset below), FileAttributes set to FILE_ATTRIBUTE_NORMAL when this info class has that field (offsets.file_name >= 60 mirrors the original’s name_off >= 60 check, every supported class with a file_name offset that high also has file_attributes at byte 56), FileNameLength, and the name itself.