Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example Go file embedding multiple .NET executables
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