go-winloader
Note: This library is still experimental. There are no guarantees of API stability, or runtime stability. Proceed with caution.
go-winloader is a library that implements the Windows module loader algorithm in pure Go. The actual Windows module loader, accessible via LoadLibrary
, only supports loading modules from disk, which is sometimes undesirable. With go-winloader, you can load modules directly from memory without needing to write intermediate temporary files to disk.
This is a bit more versatile than linking directly to object files, since you do not need object files for this approach. As a downside, it is a purely Windows-only approach.
Note: Unlike native APIs, in place of processor register sized values go-winloader uses uint64
instead of uintptr
except when calling native host functions. This allows it to remain neutral to processor architecture at runtime, which in the future may allow for more esoteric use cases. (See TODO for more information on potential future features.)
Example
// Load a module off disk (for simplicity; you can pass in any byte slice.)
b, _ := ioutil.ReadFile("my.dll")
mod, err := winloader.LoadFromMemory(b)
if err != nil {
log.Fatalln("error loading module:", err)
}
// Get a procedure.
addProc := mod.Proc("Add")
if proc == nil {
log.Fatalln("module my.dll is missing required procedure Add")
}
// Call the procedure!
result, _, _ := addProc.Call(1, 2)
log.Printf("1 + 2 = %d", result)
TODO