-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
69 lines (61 loc) · 1.95 KB
/
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
61
62
63
64
65
66
67
68
69
package main
import (
"flag"
"fmt"
"os"
)
func main() {
if len(os.Args) < 2 {
fmt.Println("expected subcommand. Exiting")
os.Exit(1)
}
dumpCmd := flag.NewFlagSet("dump", flag.ExitOnError)
dumpFlbFile := dumpCmd.String("file", "", "Flb file to be dumped.")
dumpOutFile := dumpCmd.String("out", "dump.out", "Output file.")
dumpVerbose := dumpCmd.Bool("v", false, "Activates verbose mode.")
checkCmd := flag.NewFlagSet("check", flag.ExitOnError)
fileName := checkCmd.String("file", "", "File to be processed. Mutually exclusive with -dir.")
verbose := checkCmd.Bool("v", false, "Activates verbose mode.")
directory := checkCmd.String("dir", ".", "Directory containing the file(s) to process. Mutually exclusive with -file.")
switch os.Args[1] {
case "dump":
err := dumpCmd.Parse(os.Args[2:])
check(err)
options := DumpOption{*dumpFlbFile, *dumpOutFile, *dumpVerbose}
err = Dump(options)
check(err)
os.Exit(0)
case "check":
err := checkCmd.Parse(os.Args[2:])
check(err)
options := CheckOption{*fileName, *directory, *verbose}
err = Check(options)
check(err)
os.Exit(0)
default:
fmt.Println("Command expected. Quitting")
os.Exit(1)
}
}
/**
+--------------+----------------+
| 0xC1 | 0x00 +--> Header 2 bytes
+--------------+----------------+
| 4 BYTES CRC32 + 16 BYTES +--> CRC32(Content) + Padding
+-------------------------------+
| Content |
| +-------------------------+ |
| | 2 BYTES +-----> Metadata Length
| +-------------------------+ |
| +-------------------------+ |
| | | |
| | Metadata +-----> Optional Metadata (up to 65535 bytes)
| | | |
| +-------------------------+ |
| +-------------------------+ |
| | | |
| | Content Data +-----> User Data
| | | |
| +-------------------------+ |
+-------------------------------+
*/