reflektor

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2026 License: GPL-3.0 Imports: 5 Imported by: 0

README

Reflektor

Reflektor is a Go library and CLI for loading shared libraries from bytes and invoking exported functions.

It exposes a stable root package (reflektor) so other projects can import it directly, while platform-specific loading is handled behind memmod.

Platform Support

OS Architectures Shared Library Format Status Loader Notes
Windows 386, amd64, arm, arm64 PE (.dll) Supported In-memory PE loader
Darwin amd64, arm64 Mach-O (.dylib, bundle) Supported Pure Go dyld4-based in-memory loader, no cgo, no temp-file legacy NS APIs.
Linux 386, amd64, arm64 ELF (.so) Supported Pure Go in-memory ELF loader (maps PT_LOAD segments, applies relocations, resolves externals from runtime modules/dlsym); no memfd, no /dev/shm, no temp-file disk writes.
Other - - Unsupported Returns an explicit unsupported-platform error.

Public API

Import path:

import "github.com/sliverarmory/reflektor"

Example:

payload := []byte{}

lib, err := reflektor.LoadLibrary(payload)
if err != nil {
    return err
}
defer lib.Close()

if err := lib.CallExport("StartW"); err != nil {
    return err
}

You can also load from a path:

lib, err := reflektor.LoadLibraryFile("./payload.dylib")

CLI

The CLI is in /Users/moloch/git/reflektor/cli and uses Cobra.

Build:

go build -o reflektor ./cli

Usage:

./reflektor <shared-library-path> [--call-export StartW]

--call-export defaults to StartW.

Behavior Notes

  • CallExport is designed for zero-argument exports.
  • Reflektor normalizes common symbol naming differences where possible (for example underscore-prefixed forms).
  • The root reflektor.Library interface is intentionally small: CallExport() and Close().

Test Data And Validation

C test shared libraries are generated from:

  • /Users/moloch/git/reflektor/testdata/c/basic.c

Build test shared libraries for the full matrix:

./testdata/build_c_shared_libs.sh

Run tests:

go test ./...

Linux cross-arch Docker harness:

  • /Users/moloch/git/reflektor/testdata/docker/linux-memmod.Dockerfile
  • /Users/moloch/git/reflektor/testdata/docker/run-linux-memmod-matrix.sh

Repository Layout

  • /Users/moloch/git/reflektor/reflektor.go: root importable package (reflektor).
  • /Users/moloch/git/reflektor/memmod: OS-specific loader backends.
  • /Users/moloch/git/reflektor/cli: CLI entrypoint.
  • /Users/moloch/git/reflektor/testdata: portable shared-library fixtures and build/test harnesses.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrLibraryClosed = errors.New("reflektor: library is closed")

Functions

This section is empty.

Types

type Library

type Library struct {
	// contains filtered or unexported fields
}

func LoadLibrary

func LoadLibrary(data []byte) (*Library, error)

LoadLibrary loads a shared library image from memory.

func LoadLibraryFile

func LoadLibraryFile(path string) (*Library, error)

LoadLibraryFile loads a shared library image from disk into memory.

func (*Library) CallExport

func (library *Library) CallExport(name string) error

CallExport resolves and calls a zero-argument exported function.

func (*Library) Close

func (library *Library) Close() error

Close releases library resources.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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