-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIATHooking.cpp
54 lines (44 loc) · 2.8 KB
/
IATHooking.cpp
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
53
54
#include "pch.h"
#include "hook.h"
#define LEN 20
#define FILENAME "file.txt"
int main() {
//create file data
HANDLE hFile;
CHAR buffer[LEN];
DWORD num;
LPDWORD numread = #
//hook data
PCSTR func_to_hook = "CreateFileA";
PCSTR DLL_to_hook = "KERNEL32.dll";
_IMAGE_THUNK_DATA64 new_entry_data;
new_entry_data.u1.Function = (ULONGLONG)&ShowMsgHook;
//hook CreateFileA function by its LOOKUP NAME with the ShowMsgHook function addr
hook(func_to_hook, DLL_to_hook, new_entry_data);
//open file Handler
hFile = CreateFileA(FILENAME, // file name
GENERIC_READ, // open for read
0, // do not share
NULL, // default security
OPEN_EXISTING, // open only if exists
FILE_ATTRIBUTE_NORMAL, // normal file
NULL); // no attr. template
//check if the file opened correctly
if (hFile == INVALID_HANDLE_VALUE) {
DWORD error = GetLastError();
printf("Error code: %d\n", error);
return 0;
}
//read file content (LEN bytes)
BOOL result = ReadFile(hFile, // handle to open file
buffer, // pointer to buffer to store data
LEN - 1, // bytes to read
numread, // return value - bytes actually read
NULL); // overlapped
buffer[*numread] = 0;
//print file content
cout << buffer << endl;
//close file Handler
CloseHandle(hFile);
return 0;
};