-
Notifications
You must be signed in to change notification settings - Fork 6
/
gohack_windows_test.go
67 lines (47 loc) · 1.04 KB
/
gohack_windows_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
package gohack
import (
"os/exec"
"strings"
"testing"
"time"
)
func withProcess(path string, f func()) {
s := []string{"cmd.exe", "/C", "start", path}
cmd := exec.Command(s[0], s[1:]...)
if err := cmd.Run(); err != nil {
panic(err)
}
ss := strings.Split(path, "\\")
exe := ss[len(ss)-1]
defer exec.Command("TASKKILL", "/F", "/IM", exe).Run()
time.Sleep(1 * time.Second)
f()
}
func TestNoProcess(t *testing.T) {
_, err := Instrument()
got := err.Error()
want := "Failed to get pid csgo.exe"
if got != want {
t.Errorf("%q; want %q", got, want)
}
}
func TestStubProcessNoDLL(t *testing.T) {
withProcess("test\\nodll\\csgo.exe", func() {
_, err := Instrument()
got := err.Error()
want := "Failed to get module offset"
if got != want {
t.Errorf("%q; want %q", got, want)
}
})
}
func TestStubProcess(t *testing.T) {
withProcess("test\\dll\\csgo.exe", func() {
_, err := Instrument()
got := err.Error()
want := "Failed to get player offset"
if got != want {
t.Errorf("%q; want %q", got, want)
}
})
}