2022-12-06 02:29:01 +00:00
|
|
|
package cli
|
|
|
|
|
|
|
|
import "fmt"
|
|
|
|
|
|
|
|
// FIXME make this write to a bytes.Buffer with fprintf
|
2022-12-06 13:43:07 +00:00
|
|
|
func DumpByteSlice(b []byte) {
|
2022-12-06 02:29:01 +00:00
|
|
|
var a [16]byte
|
|
|
|
n := (len(b) + 15) &^ 15
|
|
|
|
for i := 0; i < n; i++ {
|
|
|
|
if i%16 == 0 {
|
|
|
|
fmt.Printf("%4d", i)
|
|
|
|
}
|
|
|
|
if i%8 == 0 {
|
|
|
|
fmt.Print(" ")
|
|
|
|
}
|
|
|
|
if i < len(b) {
|
|
|
|
fmt.Printf(" %02X", b[i])
|
|
|
|
} else {
|
|
|
|
fmt.Print(" ")
|
|
|
|
}
|
|
|
|
if i >= len(b) {
|
|
|
|
a[i%16] = ' '
|
|
|
|
} else if b[i] < 32 || b[i] > 126 {
|
|
|
|
a[i%16] = '.'
|
|
|
|
} else {
|
|
|
|
a[i%16] = b[i]
|
|
|
|
}
|
|
|
|
if i%16 == 15 {
|
|
|
|
fmt.Printf(" %s\n", string(a[:]))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|