mirror of
https://github.com/rwinkhart/sys.git
synced 2026-09-01 22:57:29 -04:00
windows: add resource extraction functions
These functions make it possible to read executable resource information at runtime. Change-Id: I00f260199ecda8daeb3417eaa9c02198663063b7 Reviewed-on: https://go-review.googlesource.com/c/sys/+/298173 Trust: Jason A. Donenfeld <Jason@zx2c4.com> Trust: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Go Bot <gobot@golang.org>
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
package windows_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"debug/pe"
|
||||
"errors"
|
||||
"fmt"
|
||||
@@ -562,3 +563,26 @@ func TestPEBFilePath(t *testing.T) {
|
||||
t.Errorf("expected os.Executable() to return same value as peb.Ldr.{entry}.FullDllName - want %#q; got %#q", osPath, pebPath)
|
||||
}
|
||||
}
|
||||
|
||||
func TestResourceExtraction(t *testing.T) {
|
||||
system32, err := windows.GetSystemDirectory()
|
||||
if err != nil {
|
||||
t.Errorf("unable to find system32 directory: %v", err)
|
||||
}
|
||||
cmd, err := windows.LoadLibrary(filepath.Join(system32, "cmd.exe"))
|
||||
if err != nil {
|
||||
t.Errorf("unable to load cmd.exe: %v", err)
|
||||
}
|
||||
defer windows.FreeLibrary(cmd)
|
||||
rsrc, err := windows.FindResource(cmd, windows.CREATEPROCESS_MANIFEST_RESOURCE_ID, windows.RT_MANIFEST)
|
||||
if err != nil {
|
||||
t.Errorf("unable to find cmd.exe manifest resource: %v", err)
|
||||
}
|
||||
manifest, err := windows.LoadResourceData(cmd, rsrc)
|
||||
if err != nil {
|
||||
t.Errorf("unable to load cmd.exe manifest resource data: %v", err)
|
||||
}
|
||||
if !bytes.Contains(manifest, []byte("</assembly>")) {
|
||||
t.Errorf("did not find </assembly> in manifest")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user