memorydll

package
v0.0.0-...-48d22b3 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2022 License: MIT Imports: 8 Imported by: 0

README

go-memorydll

a go wrapper for memory dll

it's the same as system's loadlibrary but it load dll content from memory usage : dll,err:=NewDLL(testdll,"example.dll"); proc,err:=dll.FindProc("gcd") result,,:=proc.Call(uintptr(4),uintptr(8))

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DLL

type DLL struct {
	Name   string
	Handle Handle
}

A DLL implements access to a single DLL.

func NewDLL

func NewDLL(dlldata []byte, dllname string) (*DLL, error)

remembe to release when this dll is useless

func (*DLL) FindProc

func (d *DLL) FindProc(name string) (proc *Proc, err error)

FindProc searches DLL d for procedure named name and returns *Proc if found. It returns an error if search fails.

func (*DLL) MustFindProc

func (d *DLL) MustFindProc(name string) *Proc

MustFindProc is like FindProc but panics if search fails.

func (*DLL) Release

func (d *DLL) Release()

Release unloads DLL d from memory.

type DLLError

type DLLError struct {
	Err     error
	ObjName string
	Msg     string
}

DLLError describes reasons for DLL load failures.

func (*DLLError) Error

func (e *DLLError) Error() string

type Handle

type Handle uintptr

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.

LazyDLL is subject to the same DLL preloading attacks as documented on LoadDLL.

Use LazyDLL in golang.org/x/sys/windows for a secure way to load system DLLs.

func NewLazyDLL

func NewLazyDLL(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.

type Proc

type Proc struct {
	Dll  *DLL
	Name string
	// contains filtered or unexported fields
}

A Proc implements access to a procedure inside a DLL.

func (*Proc) Addr

func (p *Proc) 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 (*Proc) Call

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

Call executes procedure p with arguments a. It will panic, if more then 15 arguments are supplied.

The returned error is always non-nil, constructed from the result of GetLastError. Callers must inspect the primary return value to decide whether an error occurred (according to the semantics of the specific function being called) before consulting the error. The error will be guaranteed to contain syscall.Errno.

Jump to

Keyboard shortcuts

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