dotnet

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 17 Imported by: 1 module, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go-dotnet

Go


A reader for compiled .NET assemblies: ECMA-335 metadata, IL method bodies, portable PDB sequence points and the Harmony, BepInEx and MelonLoader attributes, with no runtime and no reflection. Package dotnet, module github.com/Rethunk-Tech/go-dotnet.

Every query takes a path and returns an error, never a panic, for a truncated or crafted image. Reads are capped and never truncated. Nothing runs and nothing is loaded.

Quick start

go get github.com/Rethunk-Tech/go-dotnet

A worked example and the contracts: HUMANS.md.

Features

  • BepInEx 5 plugin identity and dependencies (Scan), Harmony patches (Patches), MelonLoader info and order.
  • Which game members a mod assigns (Writes), its members (Members) and who calls one (Usages).
  • Module id and source line for a stack frame (Identity, SourceLine), from embedded or sibling portable PDBs.
  • Crafted-input safe: panics become ErrMalformed, type-chain cycles are bounded, size caps are errors.
  • Standard library only.

Documentation

Doc Audience
HUMANS.md Running and using the package
AGENTS.md Internals, invariants, and why
CONTRIBUTING.md Process — commits, tests, docs
SECURITY.md Vulnerability disclosure
CHANGELOG.md Release notes

License

MIT — see LICENSE. © 2026 Rethunk.Tech, LLC.

Documentation

Overview

Package dotnet reads compiled .NET assemblies without running them: ECMA-335 metadata tables, IL method bodies, portable PDB sequence points, and the custom attributes that Harmony, BepInEx 5 and MelonLoader define. It parses PE files with debug/pe, does no reflection and loads no code.

Every query takes a path. A crafted or truncated image yields an error wrapping ErrMalformed, never a panic, and a file over MaxAssemblyBytes yields ErrTooLarge without being read.

Index

Constants

View Source
const (
	// MaxAssemblyBytes is the largest assembly a query reads; a larger file is refused unread with ErrTooLarge.
	MaxAssemblyBytes = 256 << 20
	// MaxPDBBytes bounds a PDB, read from a file or inflated from an embedded one.
	MaxPDBBytes = 64 << 20
)
View Source
const (
	HardDependency = "hard"
	SoftDependency = "soft"
	Incompatible   = "incompatible"
)

Kinds of Relation.

View Source
const (
	// PatchSkip is a prefix that returns bool, so it can skip the original method.
	PatchSkip       = "prefix-skip"
	PatchPrefix     = "prefix"
	PatchPostfix    = "postfix"
	PatchTranspiler = "transpiler"
	PatchFinalizer  = "finalizer"
	// PatchHook is a MonoMod HookGen On hook, which wraps the original and can skip it like a skipping prefix.
	PatchHook = "hook"
)

Kinds of Patch.

View Source
const (
	// SymbolsPortable is a portable PDB, embedded in the DLL or beside it, which Mono reads for source lines.
	SymbolsPortable = "portable"
	// SymbolsWindows is a Windows (MSF) PDB beside the DLL, which Mono cannot read.
	SymbolsWindows = "windows"
)

What Identity finds of an assembly's debug symbols.

Variables

View Source
var (
	// ErrNotAssembly marks a file that is not a PE image with a CLI header.
	ErrNotAssembly = errors.New("not a .NET assembly")
	// ErrMalformed marks an assembly whose metadata is truncated, inconsistent or crafted to exhaust the reader.
	ErrMalformed = errors.New("malformed assembly")
	// ErrTooLarge marks a file over MaxAssemblyBytes or MaxPDBBytes.
	ErrTooLarge = errors.New("file exceeds the size cap")
)

Functions

func Identity

func Identity(path string) (mvid, symbols string)

Identity reads the module version id of the assembly at path, as the runtime prints it in a stack frame it has no symbols for ("<mvid>:IL_002E", Guid.ToString("N")), and which symbols it ships: SymbolsPortable, SymbolsWindows or "". A file that is no assembly has neither.

func PatchKindByName

func PatchKindByName(method string) string

PatchKindByName is the kind Harmony gives a patch method by its name alone (Prefix, Postfix, Transpiler, Finalizer), or "".

func SourceLine

func SourceLine(path, method string, params, il int) string

SourceLine is the source file's base name and line ("Patch.cs:17") of IL offset il in method ("Namespace.Type::Method", taking params arguments, or -1 when unknown) of the assembly at path, read from its portable PDB, embedded or beside it. It is "" when the assembly has none, when the PDB is not the one built with this DLL (a weaver rewrote the DLL and left the PDB), when the name matches no method or several overloads, and when the method has no sequence point at or before il.

func Usages

func Usages(path, target string) ([]string, error)

Usages lists the methods of the assembly at path whose code calls, constructs, loads or stores target, named "Namespace.Type::Member" as Members names it; each caller is "Type::Method", once, in table order.

func Writes

func Writes(path, game, wrapper string) ([]string, error)

Writes lists the members of types in namespace game (or beneath it) that the assembly's method bodies assign, as "Namespace.Type::Member" with any set_ prefix removed: property setter calls and field stores through member references. A set_Value call on a type in namespace wrapper (a field wrapper such as Netcode's NetInt) counts as assigning the game member that loaded the wrapper. Instance writes to an object the same method built (an object initializer, or a local only ever assigned a new object) configure the mod's own object and are left out.

Types

type Declared

type Declared struct {
	Plugins   []Plugin
	Relations []Relation
}

Declared is what an assembly says about its BepInEx plugins.

func Scan

func Scan(path string) (Declared, error)

Scan reads the plugins the assembly at path declares and the dependencies and incompatibilities they carry.

type Melon

type Melon struct {
	// Assembly is the assembly's simple name, which other melons name as a dependency.
	Assembly              string
	Name, Version, Author string
	// Priority is MelonPriority; lower loads first.
	Priority                   int
	Refs, Additional, Optional []string
	HasInfo                    bool
	// Cycle is a melon MelonLoader leaves out because its dependencies depend on it.
	Cycle bool
}

Melon is what a MelonLoader mod or plugin assembly says about itself: its [assembly: MelonInfo], [MelonPriority], [MelonAdditionalDependencies] and [MelonOptionalDependencies] attributes (MelonLoader/Attributes), and the assemblies it references, which MelonLoader treats as dependencies too.

func MelonOrder

func MelonOrder(melons []Melon) []Melon

MelonOrder is the order MelonLoader registers melons of one kind (plugins, or mods) in (MelonBase.SortMelons): a topological sort in which a melon follows the melons whose assemblies it references or names in MelonAdditionalDependencies, the loadable melon with the smallest name going first, then a stable sort by priority. A melon in a dependency cycle is not loaded; the ones MelonLoader reports are returned last with Cycle set.

ponytail: names compare lower-cased ordinal where MelonLoader's SortedList uses the current culture.

func ScanMelon

func ScanMelon(path string) (Melon, error)

ScanMelon reads the MelonLoader attributes of the assembly at path; HasInfo is false for a library that is no melon.

type Member

type Member struct {
	Type string `json:"type"`
	// Kind is "method" or "field".
	Kind   string `json:"kind"`
	Method string `json:"method"`
	Static bool   `json:"static"`
	// Void is set when the method returns nothing.
	Void   bool     `json:"void"`
	Params []string `json:"params"`
}

Member is one method or field an assembly defines: its type as a stack frame names it ("Namespace.Outer+Inner"), and a method's parameters' names in order.

func Members

func Members(path string) ([]Member, error)

Members lists the fields and methods of every type the assembly at path defines, skipping compiler-generated types and members (names holding '<'), in table order.

type Patch

type Patch struct{ Target, Kind, Method string }

Patch is one Harmony patch an assembly declares with attributes: the method it targets as "Namespace.Type::Method", its kind, and the patch method itself as a stack frame names it ("Namespace.Outer+Inner::Method"; empty for a HookGen hook, whose handler is usually a lambda).

func Patches

func Patches(path string) ([]Patch, error)

Patches lists the Harmony patches the assembly at path declares with [HarmonyPatch] on a class, its methods or both, each method a [HarmonyPrefix]-style attribute or its name (Prefix, Postfix, Transpiler, Finalizer) marks, and the HookGen hooks it subscribes: On.Type.add_Method as a hook, IL.Type.add_Method as a transpiler. Patches a plugin applies by calling Harmony.Patch or new Hook(...) at run time name their target only through reflection and are not seen.

type Plugin

type Plugin struct{ GUID, Name, Version, Namespace string }

Plugin is one [BepInPlugin(GUID, Name, Version)] an assembly declares. Namespace is that of the class carrying it, which is how an exception's stack names the plugin.

type Relation

type Relation struct{ Plugin, GUID, MinVersion, Kind string }

Relation is a [BepInDependency] or [BepInIncompatibility] on a plugin class: Plugin is the GUID of the plugin whose class carries it, GUID the one it names. MinVersion is the dependency's minimum, empty for no minimum.

Jump to

Keyboard shortcuts

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