-
Notifications
You must be signed in to change notification settings - Fork 19
/
ntopenfile.c
52 lines (46 loc) · 1.13 KB
/
ntopenfile.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <winsock2.h>
#include <windows.h>
#include <time.h>
#include "ntdll.h"
#include "ntopenfile.h"
// ntdll.ntopenfile
NTSTATUS WINAPI NewNtOpenFile(
PHANDLE FileHandle,
ACCESS_MASK DesiredAccess,
POBJECT_ATTRIBUTES ObjectAttributes,
PIO_STATUS_BLOCK IoStatusBlock,
ULONG ShareAccess,
ULONG OpenOptions
)
{
NTSTATUS rc;
ACCESS_MASK modDesiredAccess=DesiredAccess;
// give all "files" read access to helpout NtSaveKey hook :)
// dirty but it works ;)
if (!(DesiredAccess&GENERIC_READ||DesiredAccess&FILE_READ_DATA))
modDesiredAccess|=GENERIC_READ;
// call original function
rc=OldNtOpenFile(
FileHandle,
modDesiredAccess,
ObjectAttributes,
IoStatusBlock,
ShareAccess,
OpenOptions
);
// some objects don't like GENERIC_READ added,
// so we call the function again with original parameters
if (!NT_SUCCESS(rc))
{
// call original function
rc=OldNtOpenFile(
FileHandle,
DesiredAccess,
ObjectAttributes,
IoStatusBlock,
ShareAccess,
OpenOptions
);
}
return rc;
}