-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (41 loc) · 921 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
package main
import (
"flag"
"fmt"
"os"
"path/filepath"
)
var target string
var fullMagicByte bool
var magicByteLength int8
func init() {
flag.BoolVar(&fullMagicByte, "full", false, "Reads the full 16 byte length of the Magic Byte header")
flag.StringVar(&target, "target", "", "The file to extract the Magic Bytes")
}
// Nasty little function, but I'm in a hurry, don't blame me.
func check(err error) {
if err != nil {
fmt.Println(err.Error())
os.Exit(1)
}
}
func main() {
flag.Parse()
if target == "" {
fmt.Println("Usage: mbex -target file [-full]")
os.Exit(1)
}
physicalPath, err := filepath.Abs(target)
check(err)
fileData, err := os.Open(physicalPath)
check(err)
defer fileData.Close()
if fullMagicByte {
magicByteLength = 16
} else {
magicByteLength = 8
}
bytes := make([]byte, magicByteLength)
fileData.Read(bytes)
fmt.Printf("Magic Bytes found: %X\n", bytes)
}