Created
December 20, 2014 20:13
-
-
Save hymkor/59da48b9f3578e159a3c to your computer and use it in GitHub Desktop.
16進数形式でバイナリファイルをダンプする
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io" | |
"os" | |
) | |
func main() { | |
for _, fname := range os.Args[1:] { | |
fd, fdErr := os.Open(fname) | |
if fdErr != nil { | |
fmt.Fprintln(os.Stderr, fdErr.Error()) | |
return | |
} | |
defer fd.Close() | |
var buffer [16]byte | |
for { | |
n, nErr := fd.Read(buffer[:]) | |
if nErr != nil { | |
if nErr != io.EOF { | |
fmt.Fprintln(os.Stderr, nErr.Error()) | |
} | |
break | |
} | |
for i := 0; i < n; i++ { | |
fmt.Printf("%02X ", buffer[i]) | |
} | |
fmt.Println() | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment