a simple PNG decoder in Go

while working with image files, I needed a simple way to analyze content of a picture; so I wrote this tool that “walks” inside a PNG file and reports all the chunks seen; this is intended to be expanded with more features in a future. package main import ( "encoding/binary" "fmt" "io" "os" ) type chunk struct { Length uint32 ChunkType [4]byte } func main() { if len(os.Args) != 2 { fmt....

January 28, 2018 · Andrea Manzini

convert a binary file to ascii using hexdump

I have a binary file with data stored as two-byte big-endian 16-bit words. We need to extract the values in the file and print them in decimal ASCII format, so to obtain numbers in the 0-655535 range. let’s create the sample file: $ echo -en "\x01\x02\x03\x04\x05\x06\x07\x08" > file.bin and show its content in binary form: $ hexdump -C file.bin 00000000 01 02 03 04 05 06 07 08 |........| 00000008 to get the desired output we can use the powerful, but little documented format string option of hexdump:...

October 20, 2016 · Andrea Manzini