Skip to content

Commit 97f3ff6

Browse files
committed
ghash utility (work in progress)
1 parent 10239cb commit 97f3ff6

4 files changed

Lines changed: 89 additions & 6 deletions

File tree

README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
# File Format Tools
1+
# File Format Tools [<img alt="Logo for fftools" src="docs/favicon.svg" height="96" align="right"/>](https://www.fileformat.info/)
22

33
## Credits
44

5+
[![Git](https://www.vectorlogo.zone/logos/git-scm/git-scm-ar21.svg)](https://git-scm.com/ "Version control")
6+
[![Github](https://www.vectorlogo.zone/logos/github/github-ar21.svg)](https://github.com/ "Code hosting")
7+
[![golang](https://www.vectorlogo.zone/logos/golang/golang-ar21.svg)](https://golang.org/ "Programming language")
8+
[![svgrepo](https://www.vectorlogo.zone/logos/svgrepo/svgrepo-ar21.svg)](https://www.svgrepo.com/svg/276165/gardening-tools-rake "Icon")
59

610
## To Do
711

812
- [ ] `anyascii`: converts to ASCII using [anyascii](https://github.com/anyascii/anyascii)
913
- [ ] `asciitable`: prints out an table of ASCII characters
1014
- [ ] `bytecount`: counts the number of occurrences of each byte
1115
- [ ] `ghash`: calculate various hashes
12-
- [ ] `hexdumpc`: generate `hexdump -C` output in case you don't have `hexdump` installed
16+
- [x] `hexdumpc`: generate canonical hexdump (`hexdump -C`) output in case you don't have [`hexdump`](https://man7.org/linux/man-pages/man1/hexdump.1.html) installed
1317
- [ ] `trilobyte`: translates bytes according to a map
14-
- [ ] `ustrings`: like the standard [`strings`]() utility, but with Unicode support
15-
- [ ] `unhexdump`: convert the (edited) output of [`hexdump -C`]() back to binary
18+
- [ ] `ustrings`: like the standard [`strings`](https://man7.org/linux/man-pages/man1/strings.1.html) utility, but with Unicode support
19+
- [ ] `unhexdump`: convert the (edited) output of [`hexdump -C`](https://man7.org/linux/man-pages/man1/hexdump.1.html) back to binary

cmd/ghash/ghash.go

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"crypto"
6+
_ "crypto/md5"
7+
_ "crypto/sha1"
8+
_ "crypto/sha256"
9+
_ "crypto/sha3"
10+
_ "crypto/sha512"
11+
12+
"fmt"
13+
"os"
14+
15+
_ "golang.org/x/crypto/blake2b"
16+
_ "golang.org/x/crypto/blake2s"
17+
_ "golang.org/x/crypto/md4"
18+
_ "golang.org/x/crypto/ripemd160"
19+
20+
"github.com/spf13/pflag"
21+
)
22+
23+
func printHashes(fileName string, hashes []string) error {
24+
// Open the file
25+
file, err := os.Open(fileName)
26+
if err != nil {
27+
return err
28+
}
29+
defer file.Close()
30+
31+
reader := bufio.NewReader(file)
32+
33+
return nil
34+
}
35+
36+
func main() {
37+
var hashes []string
38+
var list bool
39+
pflag.StringArrayVar(&hashes, "hash", []string{}, "Hash algorithms to use (e.g., sha256, sha512)")
40+
pflag.BoolVar(&list, "list", false, "List available hash algorithms")
41+
//LATER: output format
42+
43+
pflag.Parse()
44+
45+
if list {
46+
for i := crypto.MD4; i <= crypto.BLAKE2b_512; i++ {
47+
if i.Available() {
48+
fmt.Fprintf(os.Stdout, "%s: %s\n", i, "true")
49+
} else {
50+
fmt.Fprintf(os.Stdout, "%s: %s\n", i, "false")
51+
}
52+
}
53+
return
54+
}
55+
56+
args := pflag.Args()
57+
if len(args) == 0 {
58+
args = []string{"-"}
59+
}
60+
for _, arg := range args {
61+
if arg == "-" {
62+
arg = "/dev/stdin"
63+
}
64+
65+
if err := printHashes(arg, hashes); err != nil {
66+
panic(err)
67+
}
68+
}
69+
70+
}

go.mod

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
module github.com/FileFormatInfo/fftools
22

3-
go 1.23.2
3+
go 1.24
44

5-
require github.com/spf13/pflag v1.0.6 // indirect
5+
require golang.org/x/crypto v0.38.0
6+
7+
require (
8+
github.com/spf13/pflag v1.0.6 // indirect
9+
golang.org/x/sys v0.33.0 // indirect
10+
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
22
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
3+
golang.org/x/crypto v0.38.0 h1:jt+WWG8IZlBnVbomuhg2Mdq0+BBQaHbtqHEFEigjUV8=
4+
golang.org/x/crypto v0.38.0/go.mod h1:MvrbAqul58NNYPKnOra203SB9vpuZW0e+RRZV+Ggqjw=
5+
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
6+
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=

0 commit comments

Comments
 (0)