forked from F8LEFT/FAInHook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FAInHook.h
71 lines (55 loc) · 2.06 KB
/
FAInHook.h
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//===------------------------------------------------------------*- C++ -*-===//
//
// Created by F8LEFT on 2017/6/19.
// Copyright (c) 2017. All rights reserved.
//===----------------------------------------------------------------------===//
// Inline hook engine. Base on GodInHook.
//===----------------------------------------------------------------------===//
#ifndef FAINHOOK_FAINHOOK_H
#define FAINHOOK_FAINHOOK_H
#include "elfex.h"
#include "HookInfo.h"
#include <map>
class FAInHook {
public:
enum HOOK_STATUS {
FERROR_UNKNOWN = -1,
FERROR_SUCCESS = 0,
FERROR_NOT_REGISTERED,
FERROR_NOT_EXECUTABLE,
FERROR_ALREADY_HOOKED,
FERROR_MEMORY,
};
static FAInHook* instance();
/* you must register a func before hook.
* callOrigin pointer to call origin funcation, not support yet!!!*/
HOOK_STATUS registerHook(Elf_Addr orginalFunAddr, Elf_Addr newFunAddr,
Elf_Addr* callOrigin);
/* do make hook*/
bool hook(Elf_Addr originalFunAddr);
/* do unhook func*/
bool unhook(Elf_Addr originalFuncAddr);
void hookAll();
void unhookAll();
/* check whether func is hooked.*/
bool isAlreadyHooked(Elf_Addr originalFunAddr);
/* if func is hooked, return call original address.*/
Elf_Addr getCallOriginFuncAddr(Elf_Addr originalFunAddr);
/* if func is hooked, return hook func address*/
Elf_Addr getNewFunAddr(Elf_Addr originalFunAddr);
int getHookedCount();
private:
FAInHook();
~FAInHook();
FAHook::HookStatus getFunctionStatus(Elf_Addr functionAddr);
FAHook::HookInfo* getHookInfo(Elf_Addr origFunAddr);
void addHookInfo(FAHook::HookInfo *info);
bool delHookInfo(FAHook::HookInfo *info);
/* hook function and flash memory*/
bool Hook(FAHook::HookInfo* info);
/* unhook funciton and flash memory*/
bool UnHook(FAHook::HookInfo* info);
// map to record originalFun and HookInfo.
std::map<Elf_Addr , FAHook::HookInfo*> hook_map;
};
#endif //FAINHOOK_FAINHOOK_H