func createCoffSyso(boxFilename string, symname string, arch string, data []byte) { boxCoff := coff.NewRDATA() switch arch { case "386": case "amd64": boxCoff.FileHeader.Machine = 0x8664 default: panic("invalid arch") } boxCoff.AddData("_bricebox_"+symname, sizedReader{bytes.NewReader(data)}) boxCoff.AddData("_ericebox_"+symname, io.NewSectionReader(strings.NewReader("\000\000"), 0, 2)) // TODO: why? copied from rsrc, which copied it from as-generated boxCoff.Freeze() err := writeCoff(boxCoff, boxFilename+"_"+arch+".rice-box.syso") if err != nil { fmt.Printf("error writing %s coff/.syso: %v\n", arch, err) os.Exit(1) } }
func rundata(fnamedata, fnameout string) error { if !strings.HasSuffix(fnameout, ".syso") { return fmt.Errorf("Output file name '%s' must end with '.syso'", fnameout) } symname := strings.TrimSuffix(fnameout, ".syso") ok, err := regexp.MatchString(`^[a-z0-9_]+$`, symname) if err != nil { return fmt.Errorf("Internal error: %s", err) } if !ok { return fmt.Errorf("Output file name '%s' must be composed of only lowercase letters (a-z), digits (0-9) and underscore (_)", fnameout) } dat, err := binutil.SizedOpen(fnamedata) if err != nil { return fmt.Errorf("Error opening data file '%s': %s", fnamedata, err) } defer dat.Close() coff := coff.NewRDATA() coff.AddData("_brsrc_"+symname, dat) coff.AddData("_ersrc_"+symname, io.NewSectionReader(strings.NewReader("\000\000"), 0, 2)) // TODO: why? copied from as-generated coff.Freeze() err = write(coff, fnameout) if err != nil { return err } //FIXME: output a .c file fmt.Println(strings.Replace(`#include "runtime.h" extern byte _brsrc_NAME[], _ersrc_NAME; /* func get_NAME() []byte */ void ·get_NAME(Slice a) { a.array = _brsrc_NAME; a.len = a.cap = &_ersrc_NAME - _brsrc_NAME; FLUSH(&a); }`, "NAME", symname, -1)) return nil }