-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhook.go
More file actions
49 lines (43 loc) · 1.03 KB
/
hook.go
File metadata and controls
49 lines (43 loc) · 1.03 KB
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
package hookingo
import (
"errors"
"sync"
)
type hook struct {
// the modified instructions
target []byte
// the moved and jump back instructions
jumper []byte
// use to call the origin function
origin interface{}
}
var (
// hooks applied with target addresses as keys
hooks map[uintptr]*hook
// protect the hooks map
lock sync.Mutex
)
var (
// ErrDoubleHook means already hooked
ErrDoubleHook = errors.New("double hook")
// ErrHookNotFound means the hook not found
ErrHookNotFound = errors.New("hook not found")
// ErrDifferentType means from and to are of different types
ErrDifferentType = errors.New("inputs are of different type")
// ErrInputType means inputs are not func type
ErrInputType = errors.New("inputs are not func type")
// ErrRelativeAddr means cannot call the origin function
ErrRelativeAddr = errors.New("relative address in instruction")
)
var (
gomajor = -1
gominor = -1
)
var pageSize uintptr
func init() {
hooks = make(map[uintptr]*hook)
}
type info struct {
length int
relocatable bool
}