forked from F8LEFT/FAInHook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HookInfo.h
executable file
·97 lines (76 loc) · 3.3 KB
/
HookInfo.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//===------------------------------------------------------------*- C++ -*-===//
//
// Created by F8LEFT on 2017/6/9.
// Copyright (c) 2017. All rights reserved.
//===--------------------------------------------------------------------------
// Save hook func information
//===----------------------------------------------------------------------===//
#ifndef FAINHOOK_HOOKINFO_H
#define FAINHOOK_HOOKINFO_H
#include <cstdint>
namespace FAHook {
enum HookStatus {
ERRSTATUS = 0,
REGISTERED,
HOOKED,
};
enum FunctionType {
ERRTYPE = 0,
ARM,
THUMB,
ARM64,
X86,
X64,
MIPS,
MIPS64,
};
class HookInfo {
public:
HookInfo(void* originalAddr, void* hookAddr)
: original_addr_(originalAddr), hook_addr_(hookAddr),
original_stub_back_(nullptr), back_len_(0), call_original_ins_(nullptr),
hook_status_(ERRSTATUS),
original_function_type_(ERRTYPE), hook_function_type_(ERRTYPE){}
~HookInfo() {
if(jump_stub_back_ != nullptr) {
delete[] (uint8_t*)jump_stub_back_;
}
if(original_stub_back_ != nullptr) {
delete [] (uint8_t*)original_stub_back_;
}
}
private:
void* original_addr_;
void* hook_addr_;
// used for hook, to store jump stub
uint8_t * jump_stub_back_ = nullptr; // record jump opcode
uint32_t stub_len_;
// used for unhook, to restore opcodes.
uint8_t * original_stub_back_ = nullptr; // record original opcode
uint32_t back_len_; // orginal opcode size
uint8_t* call_original_ins_; // new opcode, to jump into hookAddr
HookStatus hook_status_;
FunctionType original_function_type_;
FunctionType hook_function_type_;
public:
void* getOriginalAddr() { return original_addr_; }
void* getHookAddr() { return hook_addr_; }
void setJumpStubBack(uint8_t* addr) { jump_stub_back_ = addr; }
uint8_t *getJumpStubBack() { return jump_stub_back_; }
void setJumpStubLen(uint32_t len) { stub_len_ = len; }
uint32_t getJumpStubLen() { return stub_len_; }
void setOriginalStubBack(uint8_t* addr) { original_stub_back_ = addr; }
uint8_t *getOriginalStubBack() { return original_stub_back_; }
void setBackLen(uint32_t len) { back_len_ = len; }
uint32_t getBackLen() { return back_len_; }
void setCallOriginalIns(uint8_t* addr) { call_original_ins_ = addr; }
uint8_t *getCallOriginalIns() { return call_original_ins_; }
void setHookStatus(HookStatus status) { hook_status_ = status; }
HookStatus getHookStatus() { return hook_status_; }
void setOriginalFunctionType(FunctionType type) { original_function_type_ = type; }
FunctionType getOriginalFunctionType() { return original_function_type_; }
void setHookFunctionType(FunctionType type) { hook_function_type_ = type; }
FunctionType getHookFunctionType() { return hook_function_type_; }
};
}
#endif //FAINHOOK_HOOKINFO_H