aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Waller <[email protected]>2015-07-02 15:53:30 +0100
committerPeter Waller <[email protected]>2015-07-02 15:53:30 +0100
commit50315c072183b03cb5eada2700922388b6902c0e (patch)
tree0b623dfce4b94f75ff522a61796dfa5c535858a2
parentUpdate README.md (diff)
parentSearch upx in PATH instead of hardcoded paths. (diff)
downloadgoupx-50315c072183b03cb5eada2700922388b6902c0e.tar.xz
goupx-50315c072183b03cb5eada2700922388b6902c0e.zip
Merge pull request #14 from toqueteos/master
Search upx in PATH instead of hardcoded paths.
-rw-r--r--main.go22
1 files changed, 17 insertions, 5 deletions
diff --git a/main.go b/main.go
index 40fb246..38fcfb0 100644
--- a/main.go
+++ b/main.go
@@ -1,22 +1,24 @@
package main
import (
- "github.com/pwaller/goupx/hemfix"
"log"
"os"
"os/exec"
+
+ "github.com/pwaller/goupx/hemfix"
)
const usageText = `usage: goupx [args...] files...
-
+
--no-upx: Disables UPX from running.
--strip-binary: Strips binaries before compressing them.
-
+
See UPX's documentation (man upx) for information on UPX's flags.
`
var run_strip = false
var run_upx = true
+var upxPath string
// usage prints some nice output instead of panic stacktrace when an user calls
// goupx without arguments
@@ -24,13 +26,22 @@ func usage() {
os.Stderr.WriteString(usageText)
}
+// findUpxBinary searches for the upx binary in PATH.
+func findUpxBinary() {
+ var err error
+ upxPath, err = exec.LookPath("upx")
+ if err != nil {
+ log.Fatal("Couldn't find upx binary in PATH")
+ }
+}
+
// parseArguments parses arguments from os.Args and separates the goupx flags
// from the UPX flags, as well as separating the files from the arguments.
func parseArguments() (args []string, files []string) {
if len(os.Args) == 1 {
usage()
}
- args = append(args, "/usr/bin/upx")
+ args = append(args, upxPath)
for _, arg := range os.Args[1:] {
switch {
case arg == "-h" || arg == "--help":
@@ -52,7 +63,7 @@ func parseArguments() (args []string, files []string) {
func compressBinary(input_file string, arguments []string) {
if run_upx {
cmd := &exec.Cmd{
- Path: "/usr/bin/upx",
+ Path: upxPath,
Args: append(arguments, input_file),
}
cmd.Stdout = os.Stdout
@@ -84,6 +95,7 @@ func runHemfix(input_file string) {
}
func main() {
+ findUpxBinary()
arguments, files := parseArguments()
for _, file := range files {
runHemfix(file)