-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
56 lines (46 loc) · 1.15 KB
/
main.go
File metadata and controls
56 lines (46 loc) · 1.15 KB
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
package main
import (
"flag"
"fmt"
"os"
)
func main() {
//validFormats := []string{"INTEL", "MOTO", "TEX"}
var outFile string
flag.StringVar(&outFile, "o", "dump.bin", "File to dump extracted data.")
var hexFormat string
flag.StringVar(&hexFormat, "f", "INTEL", "Format of data. Must be INTEL/MOTO/TEX.")
fmt.Println(os.Args)
flag.Parse()
inputFile := flag.Args()[0]
fmt.Printf("Reading from %s in %s format. Dumping to %s\n", inputFile, hexFormat, outFile)
if hexFormat != "INTEL" {
fmt.Println("Unsupported format " + hexFormat)
flag.Usage()
os.Exit(1)
}
ifile, err := os.Open(inputFile)
if err != nil {
fmt.Println("Failed to open input file. Err:", err)
flag.Usage()
os.Exit(2)
}
ofile, err := os.Create(outFile)
if err != nil {
fmt.Println("Failed to open output file. Err:", err)
flag.Usage()
os.Exit(3)
}
iHexParser := IntelHex{
input: ifile,
output: ofile,
records: make([]*HexRecord, 0)}
iHexParser.Parse()
for record := range iHexParser.records {
fmt.Printf("%+v\n", *(iHexParser.records[record]))
}
iHexParser.Dump()
for addr, data := range iHexParser.buffers {
fmt.Printf("%8x : %v\n", addr, data)
}
}