-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
95 lines (81 loc) · 2.09 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
//
// Copyright (C) 2017 Alan (Quey-Liang) Kao alankao@andestech.com
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
package main
// main.go: The unified entry point
import (
"errors"
"flag"
"fmt"
"os"
"strings"
"github.com/NonerKao/go-binutils/as"
"github.com/NonerKao/go-binutils/common"
"github.com/NonerKao/go-binutils/nm"
"github.com/NonerKao/go-binutils/objdump"
"github.com/NonerKao/go-binutils/readelf"
"github.com/NonerKao/go-binutils/size"
)
func main() {
util, err := route()
if err != nil {
fmt.Println(err.Error())
printUsage()
return
}
args := util.DefineFlags()
flag.Usage = printUsage
flag.Parse()
tail := flag.Args()
err1 := util.Init(tail[len(tail)-1])
if err1 != nil {
fmt.Println(err1.Error())
return
}
err2 := util.Run(args)
if err2 != nil {
fmt.Println(err2.Error())
return
}
err3 := util.Output(args)
if err3 != nil {
fmt.Println(err3.Error())
return
}
}
func route() (common.Util, error) {
var util common.Util
switch {
case strings.HasSuffix(os.Args[0], "as"):
util = as.New()
case strings.HasSuffix(os.Args[0], "nm"):
util = nm.New()
case strings.HasSuffix(os.Args[0], "objdump"):
util = objdump.New()
case strings.HasSuffix(os.Args[0], "readelf"):
util = readelf.New()
case strings.HasSuffix(os.Args[0], "size"):
util = size.New()
default:
return nil, errors.New("No such usage!")
}
return util, nil
}
func printUsage() {
fmt.Printf("Usage of go-binutils: %s\n", os.Args[0])
fmt.Printf(" example7 file1 file2 ...\n")
flag.PrintDefaults()
}