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§
- Entry
Offsets - Byte offsets of the three fields every supported
FileXxxInformationvariant has, relative to the start of one directory-listing entry.hooks::query_dir::get_dir_info_offsetsderives these (viaoffset_of!on the real struct layouts) and passes them in here; this module doesn’t know about any specific info class, only these offsets. - Filter
Result - Result of
filter_redirected_entries.
Functions§
- filter_
redirected_ entries - Compacts
buf[..valid_len]in place: entries areFileXxxInformation- shaped records chained byNextEntryOffset, and any entry whose rel_key (rel_dir/name, or barenamewhenrel_diris empty, lowercased) makesis_redirectedreturntrueis 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,NextEntryOffsetleft at 0 (patched later, on the previous entry, once this one is known to exist, seeprev_entry_offsetbelow),FileAttributesset toFILE_ATTRIBUTE_NORMALwhen this info class has that field (offsets.file_name >= 60mirrors the original’sname_off >= 60check, every supported class with afile_nameoffset that high also hasfile_attributesat byte 56),FileNameLength, and the name itself.