-
-
Save edermi/7bcbc3ee5082c781fd4290fc2f31a0bb to your computer and use it in GitHub Desktop.
Example Go file embedding multiple .NET executables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
/* | |
Example Go program with multiple .NET Binaries embedded | |
This requires packr (https://github.com/gobuffalo/packr) and the utility. Install with: | |
$ go get -u github.com/gobuffalo/packr/packr | |
Place all your EXEs are in a "binaries" folder | |
Run "packr build". The resulting Go binary will contain all the binaries embedded | |
*/ | |
import ( | |
"fmt" | |
"log" | |
"os" | |
"github.com/gobuffalo/packr" | |
clr "github.com/ropnop/go-clr" | |
) | |
var TARGET_VERSION = "v2" | |
var binaries packr.Box | |
func init() { | |
binaries = packr.NewBox("./binaries") | |
} | |
func showUsage() { | |
fmt.Printf("Usage:\n%s <binary> <args>\n", os.Args[0]) | |
fmt.Println("\nPackaged Binaries:") | |
for _, binary := range binaries.List() { | |
fmt.Printf("\t%s\n", binary) | |
} | |
} | |
func main() { | |
if len(os.Args) == 1 { | |
showUsage() | |
os.Exit(1) | |
} | |
binName := os.Args[1] | |
binArgs := os.Args[1:] | |
binBytes, err := binaries.Find(binName) | |
if err != nil { | |
fmt.Printf("[!] Error finding binary: %s\n", binName) | |
log.Fatal(err) | |
} | |
retCode, err := clr.ExecuteByteArray(TARGET_VERSION, binBytes, binArgs) | |
if err != nil { | |
log.Fatal(err) | |
} | |
fmt.Printf("[+] %s returned exit code: %d\n", binName, retCode) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment