Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/tc-hib/winres

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/tc-hib/winres

  • v0.3.1
  • Source
  • Go
  • Socket score

Version published
Created
Source

winres

Go Reference codecov Go Report

Package winres provides functions for embedding resources in a Windows executable built with Go.

Most often, you'll want to embed an application icon, a manifest, and "version information", which is what you can see in the Details tab of file properties.

Command line tool

If you are looking for a command line tool, please head to go-winres.

Alternatives

This project is similar to akavel/rsrc and josephspurrier/goversioninfo.

Limitations

This is not a real resource compiler, which means it won't help you embed these UI definitions:

  • ACCELERATORS
  • DIALOGEX
  • MENUEX
  • POPUP

If you ever need them, which is unlikely, use one of those tools instead:

  • rc.exe and cvtres.exe from Visual Studio
  • windres from GNU Binary Utilities
  • llvm-rc and llvm-cvtres from LLVM tools

See Resource Compiler for more information.

Usage

To embed resources, you need an .rsrc section in your executable. Winres provides functions to compile this .rsrc section into a COFF object file.

Put this file in your project directory, name it "something.syso" or, preferably, "something_windows_amd64.syso", and you're done : the go build command will detect it and automatically use it.

You should have a look at the command line tool to try it. Using the library gives you more control, though.

Here is a quick example:

package main

import (
	"io/ioutil"
	"os"

	"github.com/tc-hib/winres"
)

func main() {
	// Start by creating an empty resource set
	rs := winres.ResourceSet{}

	// Add resources
	// This is a cursor named ID(1)
	cursorData, _ := ioutil.ReadFile("cursor.cur")
	rs.Set(winres.RT_CURSOR, winres.ID(1), 0, cursorData)

	// This is a custom data type, translated in english (0x409) and french (0x40C)
	// You can find more language IDs by searching for LCID
	rs.Set(winres.Name("CUSTOM"), winres.Name("COOLDATA"), 0x409, []byte("Hello World"))
	rs.Set(winres.Name("CUSTOM"), winres.Name("COOLDATA"), 0x40C, []byte("Bonjour Monde"))

	// Compile to a COFF object file
	// It is recommended to use the target suffix "_window_amd64"
	// so that `go build` knows when not to include it.
	out, _ := os.Create("rsrc_windows_amd64.syso")
	rs.WriteObject(out, winres.ArchAMD64)
}

Thanks

Many thanks to akavel for his help.

This project uses these very helpful libs:

FAQs

Package last updated on 18 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc