-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
60 lines (54 loc) · 987 Bytes
/
main.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
package main
import (
"bufio"
"fmt"
"io"
"os"
"github.com/codegangsta/cli"
)
func main() {
app := cli.NewApp()
app.Name = "zerochk"
app.Usage = "Checks given binary file is 0-filled or not"
app.Version = "0.0.1"
app.Author = "Shun Sugai"
app.Email = "[email protected]"
app.Action = func(c *cli.Context) {
if len(c.Args()) < 1 {
cli.ShowAppHelp(c)
os.Exit(1)
}
for _, path := range []string(c.Args()) {
if err := checkZero(path); err != nil {
fmt.Println(err)
}
}
os.Exit(0)
}
app.Run(os.Args)
}
func checkZero(path string) (err error) {
fmt.Println(path)
f, err := os.Open(path)
if err != nil {
return
}
var count uint64
r := bufio.NewReader(f)
for {
c, err := r.ReadByte()
if err == io.EOF {
break
}
if err != nil {
fmt.Println(err)
}
if int(c) != 0x00 {
fmt.Printf("NOT 0-filled: found 0x%X at 0x%08X\n", c, count)
return nil
}
count++
}
fmt.Printf("0-filled: read %d bytes", count)
return nil
}