tempdll

package module
v0.0.0-...-b1f2fa7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 7, 2020 License: MIT Imports: 13 Imported by: 0

README

GOAL

Allow a golang library to be dependent on windows dlls and hide this from library consumers.

The reason I want to do this a lot of people prefer single file distributables. This code allows that. They embed the dll in the binary, and this will have some helper functions to load it. It accomplishes this by writing the binary to a temporary file. It remains for consideration in the future to use https://github.com/fancycode/MemoryModule.

Currently the code follows the pattern from https://www.drdobbs.com/packing-dlls-in-your-exe/184416443 (write file, open file with delete on close, load library). Cannot due this due to loadlibrary not allowing FILE_SHARE_DELETE

Currently this code copies the dll into windows temp directory. It does so with the following pattern.

    tempdirectory/(base32 ecoded sha256)-(originalfilename)

The copied dll stays there forever.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CopyFile

func CopyFile(dst string, data io.Reader) string

func OpenWithDelete

func OpenWithDelete(fileName string) *syscall.Handle

Types

type LazyDLL

type LazyDLL struct {
	Name string
	// contains filtered or unexported fields
}

A LazyDLL implements access to a single DLL. It will delay the load of the DLL until the first call to its Handle method or to one of its LazyProc's Addr method.

func NewLazyDLL

func NewLazyDLL(dll io.Reader, name string) *LazyDLL

NewLazyDLL creates new LazyDLL associated with DLL file.

func (*LazyDLL) Handle

func (d *LazyDLL) Handle() uintptr

Handle returns d's module handle.

func (*LazyDLL) Load

func (d *LazyDLL) Load() error

Load loads DLL file d.Name into memory. It returns an error if fails. Load will not try to load DLL, if it is already loaded into memory.

func (*LazyDLL) NewProc

func (d *LazyDLL) NewProc(name string) *LazyProc

NewProc returns a LazyProc for accessing the named procedure in the DLL d.

type LazyProc

type LazyProc struct {
	Name string
	// contains filtered or unexported fields
}

A LazyProc implements access to a procedure inside a LazyDLL. It delays the lookup until the Addr, Call, or Find method is called.

func (*LazyProc) Addr

func (p *LazyProc) Addr() uintptr

Addr returns the address of the procedure represented by p. The return value can be passed to Syscall to run the procedure.

func (*LazyProc) Call

func (p *LazyProc) Call(a ...uintptr) (r1, r2 uintptr, lastErr error)

Call executes procedure p with arguments a. See the documentation of Proc.Call for more information.

func (*LazyProc) Find

func (p *LazyProc) Find() error

Find searches DLL for procedure named p.Name. It returns an error if search fails. Find will not search procedure, if it is already found and loaded into memory.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL