universal

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

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

Go to latest
Published: May 19, 2022 License: GPL-3.0 Imports: 6 Imported by: 1

README

The Universal Loader

This loader provides a unified Go interface for loading shared libraries from memory on Windows, OSX, and Linux.

Also included is a cross-platform Call() implementation that lets you call into exported symbols from those libraries without stress.

Basic Usage

libraryPath set to lib.so for Linux, lib.dyld for OSX, or lib.DLL for Windows, then:

	image, err = ioutil.ReadFile(libraryPath)
	...

	loader, err := universal.NewLoader()
	...

	library, err := loader.LoadLibrary("main", &image)
	...

	val, err := library.Call("Runme", 7)
	...

Complete working examples of usage can be found in the examples/ folder in this repo.

Features and Limitations
  • OSX backend uses the system loader, so multiple interdependent libraries can be loaded.
  • OSX backend automatically adds the underscore prefix for you, so you can refer to symbols the same way on Linux, Windows, and OSX.
  • Linux and Windows backends do not use the system loader, so interdependent libraries cannot be loaded.
  • Linux backend does not use memfd!
    I believe this is the first Golang Linux loader that does not use memfd!
Supported Architectures
  • OSX arm64 M1 Apple Chip (tested)
    This is the first loader I've seen, Golang or not, that works on the M1!
  • OSX amd64 (tested)
  • Windows amd64 (tested)
  • Windows 386 (untested, should work)
  • Linux amd64 (tested)
  • Linux 386 (untested, should work)
  • Other POSIX systems on 386, amd64, or arm64 (untested, should work)

If you try this on any untested platforms, whether it works or not, let me know!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Library

type Library struct {
	Name        string
	BaseAddress uintptr
	Exports     map[string]uint64
}

Library - describes a loaded library

func LoadLibraryImpl

func LoadLibraryImpl(name string, image *[]byte) (*Library, error)

LoadLibraryImpl - loads a single library to memory, without trying to check or load required imports

func (*Library) Call

func (l *Library) Call(functionName string, args ...uintptr) (uintptr, error)

Call - call a function in a loaded library

func (*Library) FindProc

func (l *Library) FindProc(funcname string) (uintptr, bool)

FindProc - returns the address of the given function in this library

type Loader

type Loader struct {
	Libraries []*Library
}

Loader - keeps track of

func NewLoader

func NewLoader() (*Loader, error)

NewLoader - returns a new instance of a Loader

func (*Loader) FindProc

func (l *Loader) FindProc(libname string, funcname string) (uintptr, bool)

FindProc - returns the address of the given function from the given library

func (*Loader) LoadLibrary

func (l *Loader) LoadLibrary(name string, image *[]byte) (*Library, error)

LoadLibrary - loads a library into this process from the given buffer

Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

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