-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdllinquent_test.go
130 lines (121 loc) · 2.71 KB
/
dllinquent_test.go
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package dllinquent
import (
"os"
"testing"
"golang.org/x/sys/windows"
)
func TestFindInSelf(t *testing.T) {
type args struct {
dllName string
functionName string
}
tests := []struct {
name string
args args
wantDll Dll
wantErr bool
}{
{
name: "does not find dbghelp",
args: args{
dllName: "dbghelp.dll",
functionName: "MiniDumpWriteDump",
},
wantDll: Dll{},
wantErr: true,
},
{
name: "finds amsi",
args: args{
dllName: "amsi.dll",
functionName: "AmsiScanBuffer",
},
wantDll: Dll{},
wantErr: false,
},
}
windows.MustLoadDLL("amsi.dll").MustFindProc("AmsiScanBuffer")
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotDll, err := FindInSelf(tt.args.dllName, tt.args.functionName)
if (err != nil) != tt.wantErr {
t.Errorf("FindInSelf() error = %v, wantErr %v", err, tt.wantErr)
return
}
if !(gotDll.DllBaseAddr <= uint64(gotDll.FuncAddress)) {
t.Errorf("FindInSelf() = %v, want %v", gotDll, tt.wantDll)
}
})
}
}
func TestFindInProcess(t *testing.T) {
type args struct {
pid int
dllName string
functionName string
}
tests := []struct {
name string
args args
wantDll Dll
wantErr bool
}{
{
name: "finds dll but doesn't find non-exitent proc",
args: args{
pid: os.Getpid(),
dllName: "rpcrt4.dll",
functionName: "foo",
},
wantDll: Dll{},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotDll, err := FindInProcess(tt.args.pid, tt.args.dllName, tt.args.functionName)
if (err != nil) != tt.wantErr {
t.Errorf("FindInProcess() error = %v, wantErr %v", err, tt.wantErr)
return
}
if err != windows.ERROR_PROC_NOT_FOUND {
t.Errorf("FindInProcess() = %v, want %v", gotDll, tt.wantDll)
}
})
}
}
func TestFindInProcesses(t *testing.T) {
type args struct {
dllName string
funcionName string
}
tests := []struct {
name string
args args
wantFundAddrs []Dll
wantErr bool
}{
{
name: "finds many processes with dbghelp.MiniDumpWriteDump",
args: args{
dllName: "amsi.dll",
funcionName: "AmsiScanBuffer",
},
wantFundAddrs: []Dll{},
wantErr: false,
},
}
windows.MustLoadDLL("amsi.dll").MustFindProc("AmsiScanBuffer")
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotFundAddrs, err := FindInProcesses(tt.args.dllName, tt.args.funcionName)
if (err != nil) != tt.wantErr {
t.Errorf("FindInProcesses() error = %v, wantErr %v", err, tt.wantErr)
return
}
if len(gotFundAddrs) < 1 {
t.Errorf("FindInProcesses() = %v, want %v", gotFundAddrs, tt.wantFundAddrs)
}
})
}
}