-
Notifications
You must be signed in to change notification settings - Fork 6
/
debug.go
64 lines (62 loc) · 916 Bytes
/
debug.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
package main
import (
"fmt"
"unicode"
)
func _dump(i int, b []byte) string {
r := fmt.Sprintf("%06d:", i)
var j int
for j = 0; j < len(b); j++ {
if j%2 == 0 {
r = r + " "
}
r = r + fmt.Sprintf("%02x", b[j])
}
for ; j < 16; j++ {
if j%2 == 0 {
r = r + " "
}
r = r + " "
}
r = r + " "
for _, v := range b {
if unicode.IsPrint(rune(v)) {
r = r + string(v)
} else {
r = r + "."
}
}
return r
}
func Dump(what string, b []byte) {
fmt.Println("-->", what)
for i := 0; ; i = i + 16 {
if i >= len(b) {
break
}
m := i + 16
if m > len(b) {
m = len(b)
}
fmt.Println(_dump(i, b[i:m]))
}
}
func SDump(b []byte) string {
r := ""
for i := 0; ; i = i + 16 {
if i >= len(b) {
break
}
m := i + 16
if m > len(b) {
m = len(b)
}
r = r + _dump(i, b[i:m]) + "\n"
}
return r
}
func DDump(what string, b []byte) {
if *debugMode {
Dump(what, b)
}
}