Skip to content

Commit 775f1f0

Browse files
committed
Support loading from a file and not just hex
1 parent 4b4eb7d commit 775f1f0

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

cmd/sc/main.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"encoding/hex"
55
"fmt"
6+
"io/ioutil"
67
"os"
78

89
shellcode "github.com/brimstone/go-shellcode"
@@ -16,13 +17,19 @@ import (
1617
func main() {
1718

1819
if len(os.Args) != 2 {
19-
fmt.Printf("Must have shellcode\n")
20+
fmt.Printf("Must have shellcode of file\n")
2021
os.Exit(1)
2122
}
22-
sc, err := hex.DecodeString(os.Args[1])
23-
if err != nil {
24-
fmt.Printf("Error decoding arg 1: %s\n", err)
25-
os.Exit(1)
23+
24+
// First, try to read the arg as a file
25+
sc, err := ioutil.ReadFile(os.Args[1])
26+
if os.IsNotExist(err) {
27+
// If that fails, try to interpret the arg as hex encoded
28+
sc, err = hex.DecodeString(os.Args[1])
29+
if err != nil {
30+
fmt.Printf("Error decoding arg 1: %s\n", err)
31+
os.Exit(1)
32+
}
2633
}
2734

2835
shellcode.Run(sc)

0 commit comments

Comments
 (0)