Skip to content

Instantly share code, notes, and snippets.

@edermi
Forked from ropnop/go-sharp-loader.go
Created April 4, 2021 09:23
Show Gist options
  • Save edermi/7bcbc3ee5082c781fd4290fc2f31a0bb to your computer and use it in GitHub Desktop.
Save edermi/7bcbc3ee5082c781fd4290fc2f31a0bb 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:
$ 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