-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnull.go
More file actions
81 lines (68 loc) · 1.76 KB
/
Copy pathnull.go
File metadata and controls
81 lines (68 loc) · 1.76 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
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
/* Distributed under the MIT license. See the LICENSE file.
* Copyright (c) 2014--2016 Thomas Fogal */
package main
import (
"./debug"
"github.com/tfogal/ptrace"
)
// Null is like MallocTrace, but does no prints.
type Null struct {
BaseEvent
maddr uintptr
faddr uintptr
}
func (n *Null) malloc(inferior *ptrace.Tracee,
bp debug.Breakpoint) error {
var stk x86_64
// figure out where the caller is and set a BP there.
retaddr := stk.RetAddr(inferior)
if err := n.AddBP(inferior, retaddr, n.mallocret); err != nil {
return err
}
return nil
}
func (n *Null) mallocret(inferior *ptrace.Tracee,
bp debug.Breakpoint) error {
// re-insert our BP for malloc.
if err := n.AddBP(inferior, n.maddr, n.malloc); err != nil {
return err
}
return nil
}
func (n *Null) free(inferior *ptrace.Tracee,
bp debug.Breakpoint) error {
var stk x86_64
// make sure this BP gets re-added when we come back.
// I do not understand why this needs the 'Top' variant, but it does...
raddr := uintptr(stk.RetAddrTop(inferior))
if err := n.AddBP(inferior, raddr, n.freeret); err != nil {
return err
}
return nil
}
func (n *Null) freeret(inferior *ptrace.Tracee,
bp debug.Breakpoint) error {
if err := n.AddBP(inferior, n.faddr, n.free); err != nil {
return err
}
return nil
}
func (n *Null) Setup(inferior *ptrace.Tracee) error {
if err := n.BaseEvent.Setup(inferior); err != nil {
return err
}
n.faddr = symbol("free", globals.symbols).Address()
n.maddr = symbol("malloc", globals.symbols).Address()
assert(n.faddr != 0x0)
assert(n.maddr != 0x0)
if err := n.AddBP(inferior, n.maddr, n.malloc); err != nil {
return err
}
if err := n.AddBP(inferior, n.faddr, n.free); err != nil {
return err
}
return nil
}
func (n *Null) Close(*ptrace.Tracee) error {
return nil
}