| 181 | |
| 182 | |
| 183 | NTSTATUS WINAPI FakeNtCreateFile( |
| 184 | PHANDLE FileHandle, |
| 185 | ACCESS_MASK DesiredAccess, |
| 186 | POBJECT_ATTRIBUTES ObjectAttributes, |
| 187 | PIO_STATUS_BLOCK IoStatusBlock, |
| 188 | PLARGE_INTEGER AllocationSize, |
| 189 | ULONG FileAttributes, |
| 190 | ULONG ShareAccess, |
| 191 | ULONG CreateDisposition, |
| 192 | ULONG CreateOptions, |
| 193 | PVOID EaBuffer, |
| 194 | ULONG EaLength |
| 195 | ) { |
| 196 | |
| 197 | |
| 198 | KMUTEX Mutex; |
| 199 | KeInitializeMutex(&Mutex, 0); |
| 200 | KeWaitForSingleObject(&Mutex, Executive, ExGetPreviousMode(), FALSE, NULL); |
| 201 | |
| 202 | int requestorPid = 0x0; |
| 203 | |
| 204 | try |
| 205 | { |
| 206 | __try { |
| 207 | |
| 208 | |
| 209 | write_to_read_only_memory(xHooklist.NtCreateFileAddress, &xHooklist.NtCreateFileOrigin, sizeof(xHooklist.NtCreateFileOrigin)); |
| 210 | |
| 211 | if (ObjectAttributes && |
| 212 | ObjectAttributes->ObjectName && |
| 213 | ObjectAttributes->ObjectName->Buffer) |
| 214 | { |
| 215 | |
| 216 | if (wcsstr(ObjectAttributes->ObjectName->Buffer, xHooklist.filename)) |
| 217 | { |
| 218 | |
| 219 | DbgPrint("Blocked : %wZ.\n", ObjectAttributes->ObjectName); |
| 220 | |
| 221 | FLT_CALLBACK_DATA flt; |
| 222 | |
| 223 | DbgPrint("requestor pid %d\n", requestorPid = FltGetRequestorProcessId(&flt)); |
| 224 | |
| 225 | if ((ULONG)requestorPid == (ULONG)xHooklist.pID) |
| 226 | { |
| 227 | |
| 228 | DbgPrint("process allowed\n"); |
| 229 | |
| 230 | NTSTATUS FakeStatus = NtCreateFile(FileHandle, DesiredAccess, ObjectAttributes, IoStatusBlock, AllocationSize, FileAttributes, ShareAccess, CreateDisposition, CreateOptions, EaBuffer, EaLength); |
| 231 | |
| 232 | write_to_read_only_memory(xHooklist.NtCreateFileAddress, &xHooklist.NtCreateFilePatch, sizeof(xHooklist.NtCreateFilePatch)); |
| 233 | |
| 234 | return (FakeStatus); |
| 235 | } |
| 236 | |
| 237 | write_to_read_only_memory(xHooklist.NtCreateFileAddress, &xHooklist.NtCreateFilePatch, sizeof(xHooklist.NtCreateFilePatch)); |
| 238 | |
| 239 | return (STATUS_ACCESS_DENIED); |
| 240 | } |
nothing calls this directly
no test coverage detected