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
- Variables
- func Identity(path string) (mvid, symbols string)
- func PatchKindByName(method string) string
- func SourceLine(path, method string, params, il int) string
- func Usages(path, target string) ([]string, error)
- func Writes(path, game, wrapper string) ([]string, error)
- type Declared
- type Melon
- type Member
- type Patch
- type Plugin
- type Relation
Constants ¶
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 )
const ( HardDependency = "hard" SoftDependency = "soft" Incompatible = "incompatible" )
Kinds of Relation.
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.
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 ¶
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 ¶
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 ¶
PatchKindByName is the kind Harmony gives a patch method by its name alone (Prefix, Postfix, Transpiler, Finalizer), or "".
func SourceLine ¶
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 ¶
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 ¶
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 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 ¶
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.
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.
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 ¶
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.