-
Notifications
You must be signed in to change notification settings - Fork 11
/
util.go
28 lines (23 loc) · 767 Bytes
/
util.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
package hinako
import (
"fmt"
"golang.org/x/arch/x86/x86asm"
)
func printDisas(arch Arch, ptr uintptr, size int, title string) {
code := make([]byte, size)
unsafeReadMemory(ptr, code)
printCodes(arch, code, fmt.Sprintf("[0x%X] %s", ptr, title), ptr)
}
func printCodes(arch Arch, code []byte, title string, baseAddr uintptr) {
insts, _ := disassemble(code, arch.DisassembleMode())
printInsts(insts, title, baseAddr)
}
func printInsts(insts []*x86asm.Inst, title string, baseAddr uintptr) {
fmt.Printf("============ %s ==============\n", title)
addr := baseAddr
for _, inst := range insts {
fmt.Printf("[0x%X] %s\n", addr, x86asm.IntelSyntax(*inst, 0, nil))
addr += uintptr(inst.Len)
}
fmt.Printf("===========================================\n")
}