-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmem_editor_cmds.go
109 lines (99 loc) · 2.97 KB
/
mem_editor_cmds.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
package main
import(
"fmt"
mem "github.com/sdab/MemEditor/memlib"
)
type CmdHandler struct {
scanner *mem.Scanner
addresses []mem.ScanResult
}
func NewCmdHandler(pid int) *CmdHandler {
scanner := mem.NewScanner(pid)
return &CmdHandler{scanner, nil}
}
// Returns a help prompt describing the commands that CmdHandler
// can take as input.
func (c *CmdHandler) Usage() string {
help := "Prompt:\n" +
"%d>: prompt where %d is the number of tracking " +
"addresses.\n" +
"Commands:\n" +
"* scan val - scans the current values of all " +
"tracked addresses and filters the tracked " +
"addresses by value. Scans the whole of mapped " +
"memory if there are no tracked addresses (such " +
"as on startup or after a reset).\n" +
"* list - lists all tracked addresses and their " +
"last values.\n" +
"* update - scans the current values of all " +
"tracked addresses.\n" +
"* set addr val - Writes val to address addr.\n" +
"* setall val - Writes val to all tracked " +
"addresses.\n" +
"* reset - Removes all tracked addresses. The " +
"next scan will read all of mapped memory.\n" +
"* help - prints the commands\n"
return help
}
// %d>: shell where %d is the number of tracking addresses
// commands:
// scan val - scans the current values of all tracked addresses and
// filters the tracked addresses by value. Scans the whole of
// mapped memory if there are no tracked addresses (such as on
// startup or after a reset).
//
// list - lists all tracked addresses and their last values.
//
// update - scans the current values of all tracked addresses.
//
// set addr val - Writes val to address addr.
//
// setall val - Writes val to all tracked addresses.
//
// reset - Removes all tracked addresses. The next scan will read
// all of mapped memory.
//
// help - prints the commands
func (c *CmdHandler) HandleNextCmd() {
fmt.Printf("%d>:", len(c.addresses))
var cmd string
fmt.Scan(&cmd)
if cmd == "scan" {
var val uint64
fmt.Scan(&val)
if c.addresses == nil {
c.addresses = c.scanner.ScanAll(val)
} else {
c.addresses = c.scanner.ScanAndFilter(val, c.addresses)
}
} else if cmd == "list" {
fmt.Println("\nAddress: value")
for _, result := range c.addresses {
fmt.Printf("%x: %d\n", result.Address, result.Value)
}
} else if cmd == "update" {
c.addresses = c.scanner.Scan(c.addresses)
} else if cmd == "set" {
var addr uintptr
fmt.Scan(&addr)
var val uint64
fmt.Scan(&val)
c.scanner.WriteToAddress(addr, val)
// update scan so we can see updated value
c.addresses = c.scanner.Scan(c.addresses)
} else if cmd == "setall" {
var val uint64
fmt.Scan(&val)
for _, result := range c.addresses {
c.scanner.WriteToAddress(result.Address, val)
}
// update scan so we can see updated value
c.addresses = c.scanner.Scan(c.addresses)
} else if cmd == "reset" {
c.addresses = nil
} else if cmd == "help" {
fmt.Println(c.Usage())
} else {
fmt.Printf("Unknown command.\nHelp text:\n%s", c.Usage())
}
}