Files
set_exe_icon/main.go
T
2026-04-30 16:02:59 +02:00

48 lines
984 B
Go

package main
import (
"fmt"
"os"
"fn-registry/functions/infra"
)
const usage = `set_exe_icon - embed a .ico into a Windows .exe (post-build, no deps)
Usage:
set_exe_icon <exe> <ico>
Notes:
Modifies the .exe in place (creates a backup at <exe>.bak first).
Only supports PE binaries without an existing .rsrc section.
`
func main() {
if len(os.Args) != 3 {
fmt.Fprint(os.Stderr, usage)
os.Exit(2)
}
exePath, icoPath := os.Args[1], os.Args[2]
bak := exePath + ".bak"
src, err := os.ReadFile(exePath)
if err != nil {
die("read exe: %v", err)
}
if err := os.WriteFile(bak, src, 0o755); err != nil {
die("write backup: %v", err)
}
if err := infra.SetExeIcon(exePath, icoPath); err != nil {
_ = os.WriteFile(exePath, src, 0o755)
_ = os.Remove(bak)
die("set icon: %v", err)
}
fmt.Printf("OK: icon embedded in %s (backup: %s)\n", exePath, bak)
}
func die(format string, a ...any) {
fmt.Fprintf(os.Stderr, "error: "+format+"\n", a...)
os.Exit(1)
}