MonoMod.Utils An IL manipulation "context" with various helpers and direct access to the MethodBody. The manipulator callback, accepted by the Invoke method. The manipulated method. The manipulated method's IL processor. The manipulated method body. The manipulated method's module. The manipulated method instructions. A readonly list of all defined labels. Has the context been made read-only? No further method access is possible, but the context has not yet been disposed. Events which run when the context will be disposed. The current reference bag. Used for methods such as EmitReference and EmitDelegate. Invoke a given manipulator callback. The manipulator to run in this context. Mark this ILContext as read-only and prevent this context from further accessing the originally passed method. If the method is altered prior to calling MakeReadOnly or afterwards by accessing the method directly, the results are undefined. See See See Define a new label to be marked with a cursor. A label without a target instruction. Define a new label pointing at a given instruction. The instruction the label will point at. A label pointing at the given instruction. Determine the index of a given instruction. The instruction to get the index of. The instruction index, or the end of the method body if it hasn't been found. Obtain all labels pointing at the given instruction. The instruction to get all labels for. All labels targeting the given instruction. Bind an arbitary object to an ILContext for static retrieval. The type of the object. The combination of typeparam and id provides the unique static reference. The object to store. The id to use in combination with the typeparam for object retrieval. Dispose this context, making it read-only and invoking all OnDispose event listeners. Obtain a string representation of this context (method ID and body). A string representation of this context. Specifies where a ILCursor should be positioned in relation to the target of a search function Move the cursor before the first instruction in the match Equivalent to Before with `cursor.MoveAfterLabels()` causing emitted instructions to become the target of incoming labels Move the cursor after the last instruction in the match Indicates whether the position of a ILCursor is the result of a search function and if the next search should ignore the instruction preceeding or following this cursor. SearchTarget.Next is the result of searching with MoveType.Before, and SearchTarget.Prev from MoveType.After A foward searching function cannot match the Next instruction and must move the cursor forward A reverse searching function cannot match the Next instruction and must move the cursor backward A cursor used to manipulate a method body in an ILContext. The context to which this cursor belongs to. The instruction immediately following the cursor position or null if the cursor is at the end of the instruction list. The instruction immediately preceding the cursor position or null if the cursor is at the start of the instruction list. The instruction immediately preceding the cursor position or null if the cursor is at the start of the instruction list. The index of the instruction immediately following the cursor position. Range: 0 to Instrs.Count Setter accepts negative indexing by adding Instrs.Count to the operand Indicates whether the position of a MMILCursor is the result of a search function and if the next search should ignore the instruction preceeding or following this cursor. See Enumerates all labels which point to the current instruction (label.Target == Next) See See See See See Create a clone of this cursor. The cloned cursor. Is this cursor before the given instruction? The instruction to check. True if this cursor is before the given instruction, false otherwise. Is this cursor after the given instruction? The instruction to check. True if this cursor is after the given instruction, false otherwise. Obtain a string representation of this cursor (method ID, index, search target, surrounding instructions). A string representation of this cursor. Move the cursor to a target instruction. All other movements go through this. The target instruction Where to move in relation to the target instruction and incoming labels (branches) Whether to set the `SearchTarget` and skip the target instruction with the next search function this Move the cursor after incoming labels (branches). If an instruction is emitted, all labels which currently point to Next, will point to the newly emitted instruction. this Move the cursor before incoming labels (branches). This is the default behaviour. Emitted instructions will not cause labels to change targets. this Move the cursor to a target index. Supports negative indexing. See this Overload for Goto(label.Target). defaults to MoveType.AfterLabel this Search forward and moves the cursor to the next sequence of instructions matching the corresponding predicates. See also this If no match is found Search forward and moves the cursor to the next sequence of instructions matching the corresponding predicates. True if a match was found Search backward and moves the cursor to the next sequence of instructions matching the corresponding predicates. See also this If no match is found Search backward and moves the cursor to the next sequence of instructions matching the corresponding predicates. True if a match was found Find the next occurences of a series of instructions matching the given set of predicates with gaps permitted. An array of cursors corresponding to each found instruction (MoveType.Before) If no match is found Find the next occurences of a series of instructions matching the given set of predicates with gaps permitted. An array of cursors corresponding to each found instruction (MoveType.Before) True if a match was found Search backwards for occurences of a series of instructions matching the given set of predicates with gaps permitted. An array of cursors corresponding to each found instruction (MoveType.Before) If no match is found Search backwards for occurences of a series of instructions matching the given set of predicates with gaps permitted. An array of cursors corresponding to each found instruction (MoveType.Before) True if a match was found Set the target of a label to the current position (label.Target = Next) and moves after it. The label to mark Create a new label targetting the current position (label.Target = Next) and moves after it. The newly created label Create a new label for use with A new label with no target Remove the Next instruction Remove several instructions Move the cursor and all labels the cursor is positioned after to a target instruction Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position. The instruction opcode. The instruction operand. this Emit a new instruction at this cursor's current position, accessing a given member. The type in which the member is defined. The instruction opcode. The accessed member name. this Bind an arbitary object to an ILContext for static retrieval. See Emit the IL to retrieve a stored reference of type with the given and place it on the stack. Store an object in the reference store, and emit the IL to retrieve it and place it on the stack. Emit the IL to invoke a delegate as if it were a method. Stack behaviour matches OpCodes.Call A label to be used in ILContexts. The target instruction this label points at. All instructions using this label. An IL inline reference bag used for ILContexts. Get the object for the given ID. The object type. The object ID. The stored object. Get a MethodInfo for the getter. The object type. The getter method. Store a new object. The object type. The object to be stored. An ID to be used for all further operations. Remove the object with the given ID from the bag, essentially clearing the ID's slot. The object type. The object ID. Get a MethodInfo invoking a delegate of the given type, with the delegate at the top of the stack. Used by . The delegate type. A MethodInfo invoking a delegate of the given type. The default IL reference bag. Throws NotSupportedException for every operation. An IL reference bag implementation to be used for runtime-generated methods. Collection of extensions used by MonoMod and other projects. Create a hexadecimal string for the given bytes. The input bytes. The output hexadecimal string. Invokes all delegates in the invocation list, passing on the result to the next. Type of the result. The multicast delegate. The initial value and first parameter. Any other arguments that may be passed. The result of all delegates. Invokes all delegates in the invocation list, as long as the previously invoked delegate returns true. Invokes all delegates in the invocation list, as long as the previously invoked delegate returns false. Invokes all delegates in the invocation list, as long as the previously invoked delegate returns null. Split PascalCase words to become Pascal Case instead. PascalCaseString Pascal Case String Read the string from the BinaryReader BinaryWriter in a C-friendly format. The input which the method reads from. The output string. Write the string to the BinaryWriter in a C-friendly format. The output which the method writes to. The input string. Cast a delegate from one type to another. Compatible with delegates holding an invocation list (combined delegates). The input delegate. The output delegate. Cast a delegate from one type to another. Compatible with delegates holding an invocation list (combined delegates). The input delegate. The wanted output delegate type. The output delegate. Print the exception to the console, including extended loading / reflection data useful for mods. Get the method of interest for a given state machine method. The method creating the state machine. The "main" method in the state machine. Gets the actual generic method definition of a method, as defined on the fully open type. The potentially instantiated method to find the definition of. The original method definition, with no generic arguments filled in. Safely resolve a reference, silently discarding any exceptions. The reference to resolve. The resolved definition or null. Safely resolve a reference, silently discarding any exceptions. The reference to resolve. The resolved definition or null. Safely resolve a reference, silently discarding any exceptions. The reference to resolve. The resolved definition or null. Safely resolve a reference, silently discarding any exceptions. The reference to resolve. The resolved definition or null. Get a certain custom attribute from an attribute provider. The attribute provider. The custom attribute name. The first matching custom attribute, or null if no matching attribute has been found. Determine if an attribute provider has got a specific custom attribute. The attribute provider. The custom attribute name. true if the attribute provider contains the given custom attribute, false otherwise. Get the integer value pushed onto the stack with this instruction. The instruction to get the pushed integer value for. The pushed integer value. Get the integer value pushed onto the stack with this instruction. The instruction to get the pushed integer value for. The pushed integer value or null. Determine if the method call is a base method call. The caller method body. The called method. True if the called method is a base method of the caller method, false otherwise. Determine if the given method can be preferably called using callvirt. The called method. True if the called method can be called using callvirt, false otherwise. Determine if the given type is a struct (also known as "value type") or struct-alike (f.e. primitive). The type to check. True if the type is a struct, primitive or similar, false otherwise. Get the long form opcode for any short form opcode. The short form opcode. The long form opcode. Get the short form opcode for any long form opcode. The long form opcode. The short form opcode. Calculate updated instruction offsets. Required for certain manual fixes. The method to recalculate the IL instruction offsets for. Fix (and optimize) any instructions which should use the long / short form opcodes instead. The method to apply the fixes to. Check if the signatures of a given System.Reflection and Mono.Cecil member reference match. The System.Reflection member reference. The Mono.Cecil member reference. True if both references share the same signature, false otherwise. Check if the signatures of a given System.Reflection and Mono.Cecil member reference match. The Mono.Cecil member reference. The System.Reflection member reference. True if both references share the same signature, false otherwise. See See See See See Determine if two types are compatible with each other (f.e. object with string, or enums with their underlying integer type). The first type. The second type. True if both types are compatible with each other, false otherwise. Creates a delegate of the specified type from this method. The method to create the delegate from. The type of the delegate to create. The delegate for this method. Creates a delegate of the specified type with the specified target from this method. The method to create the delegate from. The type of the delegate to create. The object targeted by the delegate. The delegate for this method. Creates a delegate of the specified type from this method. The method to create the delegate from. The type of the delegate to create. The delegate for this method. Creates a delegate of the specified type with the specified target from this method. The method to create the delegate from. The type of the delegate to create. The object targeted by the delegate. The delegate for this method. Find a method for a given ID. The type to search in. The method ID. Whether to perform a simple search pass as well or not. The first matching method or null. Find a method for a given ID recursively (including the passed type's base types). The type to search in. The method ID. Whether to perform a simple search pass as well or not. The first matching method or null. Find a method for a given ID. The type to search in. The method ID. Whether to perform a simple search pass as well or not. The first matching method or null. Find a method for a given ID recursively (including the passed type's base types). The type to search in. The method ID. Whether to perform a simple search pass as well or not. The first matching method or null. Find a property for a given name. The type to search in. The property name. The first matching property or null. Find a property for a given name recursively (including the passed type's base types). The type to search in. The property name. The first matching property or null. Find a field for a given name. The type to search in. The field name. The first matching field or null. Find a field for a given name recursively (including the passed type's base types). The type to search in. The field name. The first matching field or null. Find an event for a given name. The type to search in. The event name. The first matching event or null. Find an event for a given name recursively (including the passed type's base types). The type to search in. The event name. The first matching event or null. Get a reference ID that is similar to the full name, but consistent between System.Reflection and Mono.Cecil. The method to get the ID for. The name to use instead of the reference's own name. The ID to use instead of the reference's declaring type ID. Whether the type ID should be included or not. System.Reflection avoids it by default. Whether the ID should be "simple" (name only). The ID. Get a reference ID that is similar to the full name, but consistent between System.Reflection and Mono.Cecil. The call site to get the ID for. The ID. Get a reference ID that is similar to the full name, but consistent between System.Reflection and Mono.Cecil. The method to get the ID for. The name to use instead of the reference's own name. The ID to use instead of the reference's declaring type ID. Whether the type ID should be included or not. System.Reflection avoids it by default. Whether the method is regarded as a proxy method or not. Setting this paramater to true will skip the first parameter. Whether the ID should be "simple" (name only). The ID. Get the "patch name" - the name of the target to patch - for the given member. The member to get the patch name for. The patch name. Get the "patch name" - the name of the target to patch - for the given member. The member to get the patch name for. The patch name. Clone the given method definition. The original method. The method definition to apply the cloning process onto, or null to create a new method. A clone of the original method. Clone the given method body. The original method body. The method which will own the newly cloned method body. A clone of the original method body. Force-update a generic parameter's position and type. The generic parameter to update. The new position. The new type. The updated generic parameter. Resolve a given generic parameter in another context. The new context. The original generic parameter. A generic parameter provided by the given context which matches the original generic parameter. Relink the given member reference (metadata token provider). The reference to relink. The relinker to use during the relinking process. The generic context provided to relink generic references. A relinked reference. Relink the given type reference. The reference to relink. The relinker to use during the relinking process. The generic context provided to relink generic references. A relinked reference. Relink the given method reference. The reference to relink. The relinker to use during the relinking process. The generic context provided to relink generic references. A relinked reference. Relink the given callsite. The reference to relink. The relinker to use during the relinking process. The generic context provided to relink generic references. A relinked reference. Relink the given field reference. The reference to relink. The relinker to use during the relinking process. The generic context provided to relink generic references. A relinked reference. Relink the given parameter definition. The reference to relink. The relinker to use during the relinking process. The generic context provided to relink generic references. A relinked reference. Clone the given parameter definition. The original parameter definition. A clone of the original parameter definition. Relink the given custom attribute. The reference to relink. The relinker to use during the relinking process. The generic context provided to relink generic references. A relinked reference. Clone the given custom attribute. The original custom attribute. A clone of the original custom attribute. Relink the given generic parameter reference. The reference to relink. The relinker to use during the relinking process. The generic context provided to relink generic references. A relinked reference. Clone the given generic parameter. The original generic parameter. A clone of the original generic parameter. Get the managed size of a given type. This matches an IL-level sizeof(t), even if it cannot be determined normally in C#. Note that sizeof(t) != Marshal.SizeOf(t), f.e. when t is char. The type to get the size from. The managed type size. Get a type which matches what the method should receive via ldarg.0 The method to obtain the "this" parameter type from. The "this" parameter type. Get a native function pointer for a given method. This matches an IL-level ldftn. The result of ldftn doesn't always match that of MethodHandle.GetFunctionPointer(). For example, ldftn doesn't JIT-compile the method on mono, which thus keeps the class constructor untouched. And on .NET, struct overrides (f.e. ToString) have got multiple entry points pointing towards the same code. The method to get a native function pointer for. The native function pointer. A variant of ILGenerator which uses Mono.Cecil under the hood. The underlying Mono.Cecil.Cil.ILProcessor. Abstract version of System.Reflection.Emit.ILGenerator. See for proper documentation. Get a "real" ILGenerator for this ILGeneratorShim. A "real" ILGenerator. Get the proxy type for a given ILGeneratorShim type. The proxy type implements ILGenerator. The ILGeneratorShim type. The "real" ILGenerator type. Get the proxy type for a given ILGeneratorShim type. The proxy type implements ILGenerator. The ILGeneratorShim type. The "real" ILGenerator type. Get the non-generic proxy type implementing ILGenerator. The "real" ILGenerator type, non-generic. A DynamicMethodDefinition "generator", responsible for generating a runtime MethodInfo from a DMD MethodDefinition. A DMDGenerator implementation using Mono.Cecil to build an in-memory assembly. Fill the DynamicMethod with a stub. Fill the DynamicMethod with a stub. Emit a reference to an arbitrary object. Note that the references "leak." Emit a reference to an arbitrary object. Note that the references "leak." Emit a reference to an arbitrary object. Note that the references "leak." Emit a reference to an arbitrary object. Note that the references "leak." Allows you to remap library paths / names and specify loading flags. Useful for cross-platform compatibility. Applies only to DynDll. Open a given library and get its handle. The library name. Whether to skip using the mapping or not. Any optional platform-specific flags. The library handle. Try to open a given library and get its handle. The library name. The library handle, or null if it failed loading. Whether to skip using the mapping or not. Any optional platform-specific flags. True if the handle was obtained, false otherwise. Release a library handle obtained via OpenLibrary. Don't release the result of OpenLibrary(null)! The library handle. Get a function pointer for a function in the given library. The library handle. The function name. The function pointer. Get a function pointer for a function in the given library. The library handle. The function name. The function pointer, or null if it wasn't found. True if the function pointer was obtained, false otherwise. Extension method wrapping Marshal.GetDelegateForFunctionPointer Fill all static delegate fields with the DynDllImport attribute. Call this early on in the static constructor. The type containing the DynDllImport delegate fields. Any optional mappings similar to the static mappings. Fill all instance delegate fields with the DynDllImport attribute. Call this early on in the constructor. An instance of a type containing the DynDllImport delegate fields. Any optional mappings similar to the static mappings. Similar to DllImport, but requires you to run typeof(DeclaringType).ResolveDynDllImports(); The library or library alias to use. A list of possible entrypoints that the function can be resolved to. Implicitly includes the field name and delegate name. The library or library alias to use. A list of possible entrypoints that the function can be resolved to. Implicitly includes the field name and delegate name. A mapping entry, to be used by . The name as which the library will be resolved as. Useful to remap libraries or to provide full paths. Platform-dependent loading flags. The name as which the library will be resolved as. Useful to remap libraries or to provide full paths. Platform-dependent loading flags. The relinker callback delegate type. The reference (metadata token provider) to relink. The generic context provided to relink generic references. A relinked reference. Generic platform enum. Bit applied to all OSes (Unknown, Windows, MacOS, ...). On demand 64-bit platform bit. Applied to all NT and NT-oid platforms (Windows). Applied to all Unix and Unix-oid platforms (macOS, Linux, ...). On demand ARM platform bit. Unknown OS. Windows, using the NT kernel. macOS, using the Darwin kernel. Linux. Android, using the Linux kernel. iOS, sharing components with macOS.