Skip to content

Instantly share code, notes, and snippets.

@HopHouse
Forked from ropnop/go-sharp-loader.go
Last active August 5, 2020 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save HopHouse/3c92c84803a3023e2f0c4e9a64e77d44 to your computer and use it in GitHub Desktop.
Save HopHouse/3c92c84803a3023e2f0c4e9a64e77d44 to your computer and use it in GitHub Desktop.
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:
$ GOOS=windows go get -u github.com/gobuffalo/packr/packr
Place all your EXEs are in a "binaries" folder
Run "GOOS=windows 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