forked from pwaller/goupx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
67 lines (54 loc) · 1.14 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
package main
import (
"flag"
"log"
"os"
"os/exec"
"github.com/pwaller/goupx/hemfix"
)
const usageText = "usage: goupx [args...] path\n"
// usage prints some nice output instead of panic stacktrace when an user calls goupx without arguments
func usage() {
os.Stderr.WriteString(usageText)
flag.PrintDefaults()
}
func main() {
run_strip := flag.Bool("s", false, "run strip")
run_upx := flag.Bool("u", true, "run upx")
flag.Parse()
if flag.NArg() != 1 {
usage()
return
}
defer func() {
if err := recover(); err != nil {
log.Print("Panicked. Giving up.")
panic(err)
return
}
}()
input_file := flag.Arg(0)
err := hemfix.FixFile(input_file)
if err != nil {
log.Panicf("Failed to fix '%s': %v", input_file, err)
}
log.Print("File fixed!")
if *run_strip {
cmd := exec.Command("strip", "-s", input_file)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
log.Panic("strip failed: ", err)
}
}
if *run_upx {
cmd := exec.Command("upx", input_file)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err = cmd.Run()
if err != nil {
log.Panic("upx failed: ", err)
}
}
}