fishnet installed

This commit is contained in:
2023-05-31 11:32:21 -04:00
parent 47b25269f1
commit a001fe1b04
1291 changed files with 126631 additions and 1 deletions

View File

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 15700071751bd1349a26170e9f6a1f14
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,15 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
//[assembly: AssemblyTitle ("MonoFN.Cecil.Rocks")]
[assembly: CLSCompliant (false)]

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: f9ceb0221cb78b247b676d0ea5d57fc8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,261 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
using System.Collections.Generic;
using System.Text;
namespace MonoFN.Cecil.Rocks {
public class DocCommentId {
StringBuilder id;
DocCommentId ()
{
id = new StringBuilder ();
}
void WriteField (FieldDefinition field)
{
WriteDefinition ('F', field);
}
void WriteEvent (EventDefinition @event)
{
WriteDefinition ('E', @event);
}
void WriteType (TypeDefinition type)
{
id.Append ('T').Append (':');
WriteTypeFullName (type);
}
void WriteMethod (MethodDefinition method)
{
WriteDefinition ('M', method);
if (method.HasGenericParameters) {
id.Append ('`').Append ('`');
id.Append (method.GenericParameters.Count);
}
if (method.HasParameters)
WriteParameters (method.Parameters);
if (IsConversionOperator (method))
WriteReturnType (method);
}
static bool IsConversionOperator (MethodDefinition self)
{
if (self == null)
throw new ArgumentNullException ("self");
return self.IsSpecialName
&& (self.Name == "op_Explicit" || self.Name == "op_Implicit");
}
void WriteReturnType (MethodDefinition method)
{
id.Append ('~');
WriteTypeSignature (method.ReturnType);
}
void WriteProperty (PropertyDefinition property)
{
WriteDefinition ('P', property);
if (property.HasParameters)
WriteParameters (property.Parameters);
}
void WriteParameters (IList<ParameterDefinition> parameters)
{
id.Append ('(');
WriteList (parameters, p => WriteTypeSignature (p.ParameterType));
id.Append (')');
}
void WriteTypeSignature (TypeReference type)
{
switch (type.MetadataType) {
case MetadataType.Array:
WriteArrayTypeSignature ((ArrayType)type);
break;
case MetadataType.ByReference:
WriteTypeSignature (((ByReferenceType)type).ElementType);
id.Append ('@');
break;
case MetadataType.FunctionPointer:
WriteFunctionPointerTypeSignature ((FunctionPointerType)type);
break;
case MetadataType.GenericInstance:
WriteGenericInstanceTypeSignature ((GenericInstanceType)type);
break;
case MetadataType.Var:
id.Append ('`');
id.Append (((GenericParameter)type).Position);
break;
case MetadataType.MVar:
id.Append ('`').Append ('`');
id.Append (((GenericParameter)type).Position);
break;
case MetadataType.OptionalModifier:
WriteModiferTypeSignature ((OptionalModifierType)type, '!');
break;
case MetadataType.RequiredModifier:
WriteModiferTypeSignature ((RequiredModifierType)type, '|');
break;
case MetadataType.Pointer:
WriteTypeSignature (((PointerType)type).ElementType);
id.Append ('*');
break;
default:
WriteTypeFullName (type);
break;
}
}
void WriteGenericInstanceTypeSignature (GenericInstanceType type)
{
if (type.ElementType.IsTypeSpecification ())
throw new NotSupportedException ();
WriteTypeFullName (type.ElementType, stripGenericArity: true);
id.Append ('{');
WriteList (type.GenericArguments, WriteTypeSignature);
id.Append ('}');
}
void WriteList<T> (IList<T> list, Action<T> action)
{
for (int i = 0; i < list.Count; i++) {
if (i > 0)
id.Append (',');
action (list [i]);
}
}
void WriteModiferTypeSignature (IModifierType type, char id)
{
WriteTypeSignature (type.ElementType);
this.id.Append (id);
WriteTypeSignature (type.ModifierType);
}
void WriteFunctionPointerTypeSignature (FunctionPointerType type)
{
id.Append ("=FUNC:");
WriteTypeSignature (type.ReturnType);
if (type.HasParameters)
WriteParameters (type.Parameters);
}
void WriteArrayTypeSignature (ArrayType type)
{
WriteTypeSignature (type.ElementType);
if (type.IsVector) {
id.Append ("[]");
return;
}
id.Append ("[");
WriteList (type.Dimensions, dimension => {
if (dimension.LowerBound.HasValue)
id.Append (dimension.LowerBound.Value);
id.Append (':');
if (dimension.UpperBound.HasValue)
id.Append (dimension.UpperBound.Value - (dimension.LowerBound.GetValueOrDefault () + 1));
});
id.Append ("]");
}
void WriteDefinition (char id, IMemberDefinition member)
{
this.id.Append (id)
.Append (':');
WriteTypeFullName (member.DeclaringType);
this.id.Append ('.');
WriteItemName (member.Name);
}
void WriteTypeFullName (TypeReference type, bool stripGenericArity = false)
{
if (type.DeclaringType != null) {
WriteTypeFullName (type.DeclaringType);
id.Append ('.');
}
if (!string.IsNullOrEmpty (type.Namespace)) {
id.Append (type.Namespace);
id.Append ('.');
}
var name = type.Name;
if (stripGenericArity) {
var index = name.LastIndexOf ('`');
if (index > 0)
name = name.Substring (0, index);
}
id.Append (name);
}
void WriteItemName (string name)
{
id.Append (name.Replace ('.', '#').Replace ('<', '{').Replace ('>', '}'));
}
public override string ToString ()
{
return id.ToString ();
}
public static string GetDocCommentId (IMemberDefinition member)
{
if (member == null)
throw new ArgumentNullException ("member");
var documentId = new DocCommentId ();
switch (member.MetadataToken.TokenType) {
case TokenType.Field:
documentId.WriteField ((FieldDefinition)member);
break;
case TokenType.Method:
documentId.WriteMethod ((MethodDefinition)member);
break;
case TokenType.TypeDef:
documentId.WriteType ((TypeDefinition)member);
break;
case TokenType.Event:
documentId.WriteEvent ((EventDefinition)member);
break;
case TokenType.Property:
documentId.WriteProperty ((PropertyDefinition)member);
break;
default:
throw new NotSupportedException (member.FullName);
}
return documentId.ToString ();
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 370e40931a1b9cf478e08e66fd2a9eac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,41 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
using System.Collections.Generic;
namespace MonoFN.Cecil.Rocks {
static class Functional {
public static System.Func<A, R> Y<A, R> (System.Func<System.Func<A, R>, System.Func<A, R>> f)
{
System.Func<A, R> g = null;
g = f (a => g (a));
return g;
}
public static IEnumerable<TSource> Prepend<TSource> (this IEnumerable<TSource> source, TSource element)
{
if (source == null)
throw new ArgumentNullException ("source");
return PrependIterator (source, element);
}
static IEnumerable<TSource> PrependIterator<TSource> (IEnumerable<TSource> source, TSource element)
{
yield return element;
foreach (var item in source)
yield return item;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b481a942e0bdf8649b6b5b20db207190
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,228 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Cecil.Cil;
using MonoFN.Collections.Generic;
using System;
namespace MonoFN.Cecil.Rocks {
#if UNITY_EDITOR
public
#endif
interface IILVisitor {
void OnInlineNone (OpCode opcode);
void OnInlineSByte (OpCode opcode, sbyte value);
void OnInlineByte (OpCode opcode, byte value);
void OnInlineInt32 (OpCode opcode, int value);
void OnInlineInt64 (OpCode opcode, long value);
void OnInlineSingle (OpCode opcode, float value);
void OnInlineDouble (OpCode opcode, double value);
void OnInlineString (OpCode opcode, string value);
void OnInlineBranch (OpCode opcode, int offset);
void OnInlineSwitch (OpCode opcode, int [] offsets);
void OnInlineVariable (OpCode opcode, VariableDefinition variable);
void OnInlineArgument (OpCode opcode, ParameterDefinition parameter);
void OnInlineSignature (OpCode opcode, CallSite callSite);
void OnInlineType (OpCode opcode, TypeReference type);
void OnInlineField (OpCode opcode, FieldReference field);
void OnInlineMethod (OpCode opcode, MethodReference method);
}
#if UNITY_EDITOR
public
#endif
static class ILParser {
class ParseContext {
public CodeReader Code { get; set; }
public int Position { get; set; }
public MetadataReader Metadata { get; set; }
public Collection<VariableDefinition> Variables { get; set; }
public IILVisitor Visitor { get; set; }
}
public static void Parse (MethodDefinition method, IILVisitor visitor)
{
if (method == null)
throw new ArgumentNullException ("method");
if (visitor == null)
throw new ArgumentNullException ("visitor");
if (!method.HasBody || !method.HasImage)
throw new ArgumentException ();
method.Module.Read (method, (m, _) => {
ParseMethod (m, visitor);
return true;
});
}
static void ParseMethod (MethodDefinition method, IILVisitor visitor)
{
var context = CreateContext (method, visitor);
var code = context.Code;
var flags = code.ReadByte ();
switch (flags & 0x3) {
case 0x2: // tiny
int code_size = flags >> 2;
ParseCode (code_size, context);
break;
case 0x3: // fat
code.Advance (-1);
ParseFatMethod (context);
break;
default:
throw new NotSupportedException ();
}
code.MoveBackTo (context.Position);
}
static ParseContext CreateContext (MethodDefinition method, IILVisitor visitor)
{
var code = method.Module.Read (method, (_, reader) => reader.code);
var position = code.MoveTo (method);
return new ParseContext {
Code = code,
Position = position,
Metadata = code.reader,
Visitor = visitor,
};
}
static void ParseFatMethod (ParseContext context)
{
var code = context.Code;
code.Advance (4);
var code_size = code.ReadInt32 ();
var local_var_token = code.ReadToken ();
if (local_var_token != MetadataToken.Zero)
context.Variables = code.ReadVariables (local_var_token);
ParseCode (code_size, context);
}
static void ParseCode (int code_size, ParseContext context)
{
var code = context.Code;
var metadata = context.Metadata;
var visitor = context.Visitor;
var start = code.Position;
var end = start + code_size;
while (code.Position < end) {
var il_opcode = code.ReadByte ();
var opcode = il_opcode != 0xfe
? OpCodes.OneByteOpCode [il_opcode]
: OpCodes.TwoBytesOpCode [code.ReadByte ()];
switch (opcode.OperandType) {
case OperandType.InlineNone:
visitor.OnInlineNone (opcode);
break;
case OperandType.InlineSwitch:
var length = code.ReadInt32 ();
var branches = new int [length];
for (int i = 0; i < length; i++)
branches [i] = code.ReadInt32 ();
visitor.OnInlineSwitch (opcode, branches);
break;
case OperandType.ShortInlineBrTarget:
visitor.OnInlineBranch (opcode, code.ReadSByte ());
break;
case OperandType.InlineBrTarget:
visitor.OnInlineBranch (opcode, code.ReadInt32 ());
break;
case OperandType.ShortInlineI:
if (opcode == OpCodes.Ldc_I4_S)
visitor.OnInlineSByte (opcode, code.ReadSByte ());
else
visitor.OnInlineByte (opcode, code.ReadByte ());
break;
case OperandType.InlineI:
visitor.OnInlineInt32 (opcode, code.ReadInt32 ());
break;
case OperandType.InlineI8:
visitor.OnInlineInt64 (opcode, code.ReadInt64 ());
break;
case OperandType.ShortInlineR:
visitor.OnInlineSingle (opcode, code.ReadSingle ());
break;
case OperandType.InlineR:
visitor.OnInlineDouble (opcode, code.ReadDouble ());
break;
case OperandType.InlineSig:
visitor.OnInlineSignature (opcode, code.GetCallSite (code.ReadToken ()));
break;
case OperandType.InlineString:
visitor.OnInlineString (opcode, code.GetString (code.ReadToken ()));
break;
case OperandType.ShortInlineArg:
visitor.OnInlineArgument (opcode, code.GetParameter (code.ReadByte ()));
break;
case OperandType.InlineArg:
visitor.OnInlineArgument (opcode, code.GetParameter (code.ReadInt16 ()));
break;
case OperandType.ShortInlineVar:
visitor.OnInlineVariable (opcode, GetVariable (context, code.ReadByte ()));
break;
case OperandType.InlineVar:
visitor.OnInlineVariable (opcode, GetVariable (context, code.ReadInt16 ()));
break;
case OperandType.InlineTok:
case OperandType.InlineField:
case OperandType.InlineMethod:
case OperandType.InlineType:
var member = metadata.LookupToken (code.ReadToken ());
switch (member.MetadataToken.TokenType) {
case TokenType.TypeDef:
case TokenType.TypeRef:
case TokenType.TypeSpec:
visitor.OnInlineType (opcode, (TypeReference)member);
break;
case TokenType.Method:
case TokenType.MethodSpec:
visitor.OnInlineMethod (opcode, (MethodReference)member);
break;
case TokenType.Field:
visitor.OnInlineField (opcode, (FieldReference)member);
break;
case TokenType.MemberRef:
var field_ref = member as FieldReference;
if (field_ref != null) {
visitor.OnInlineField (opcode, field_ref);
break;
}
var method_ref = member as MethodReference;
if (method_ref != null) {
visitor.OnInlineMethod (opcode, method_ref);
break;
}
throw new InvalidOperationException ();
}
break;
}
}
}
static VariableDefinition GetVariable (ParseContext context, int index)
{
return context.Variables [index];
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2916628c81c279046adb746612d6067b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,411 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using MonoFN.Cecil.Cil;
using System;
namespace MonoFN.Cecil.Rocks {
#if UNITY_EDITOR
public
#endif
static class MethodBodyRocks {
public static void SimplifyMacros (this MethodBody self)
{
if (self == null)
throw new ArgumentNullException ("self");
foreach (var instruction in self.Instructions) {
if (instruction.OpCode.OpCodeType != OpCodeType.Macro)
continue;
switch (instruction.OpCode.Code) {
case Code.Ldarg_0:
ExpandMacro (instruction, OpCodes.Ldarg, self.GetParameter (0));
break;
case Code.Ldarg_1:
ExpandMacro (instruction, OpCodes.Ldarg, self.GetParameter (1));
break;
case Code.Ldarg_2:
ExpandMacro (instruction, OpCodes.Ldarg, self.GetParameter (2));
break;
case Code.Ldarg_3:
ExpandMacro (instruction, OpCodes.Ldarg, self.GetParameter (3));
break;
case Code.Ldloc_0:
ExpandMacro (instruction, OpCodes.Ldloc, self.Variables [0]);
break;
case Code.Ldloc_1:
ExpandMacro (instruction, OpCodes.Ldloc, self.Variables [1]);
break;
case Code.Ldloc_2:
ExpandMacro (instruction, OpCodes.Ldloc, self.Variables [2]);
break;
case Code.Ldloc_3:
ExpandMacro (instruction, OpCodes.Ldloc, self.Variables [3]);
break;
case Code.Stloc_0:
ExpandMacro (instruction, OpCodes.Stloc, self.Variables [0]);
break;
case Code.Stloc_1:
ExpandMacro (instruction, OpCodes.Stloc, self.Variables [1]);
break;
case Code.Stloc_2:
ExpandMacro (instruction, OpCodes.Stloc, self.Variables [2]);
break;
case Code.Stloc_3:
ExpandMacro (instruction, OpCodes.Stloc, self.Variables [3]);
break;
case Code.Ldarg_S:
instruction.OpCode = OpCodes.Ldarg;
break;
case Code.Ldarga_S:
instruction.OpCode = OpCodes.Ldarga;
break;
case Code.Starg_S:
instruction.OpCode = OpCodes.Starg;
break;
case Code.Ldloc_S:
instruction.OpCode = OpCodes.Ldloc;
break;
case Code.Ldloca_S:
instruction.OpCode = OpCodes.Ldloca;
break;
case Code.Stloc_S:
instruction.OpCode = OpCodes.Stloc;
break;
case Code.Ldc_I4_M1:
ExpandMacro (instruction, OpCodes.Ldc_I4, -1);
break;
case Code.Ldc_I4_0:
ExpandMacro (instruction, OpCodes.Ldc_I4, 0);
break;
case Code.Ldc_I4_1:
ExpandMacro (instruction, OpCodes.Ldc_I4, 1);
break;
case Code.Ldc_I4_2:
ExpandMacro (instruction, OpCodes.Ldc_I4, 2);
break;
case Code.Ldc_I4_3:
ExpandMacro (instruction, OpCodes.Ldc_I4, 3);
break;
case Code.Ldc_I4_4:
ExpandMacro (instruction, OpCodes.Ldc_I4, 4);
break;
case Code.Ldc_I4_5:
ExpandMacro (instruction, OpCodes.Ldc_I4, 5);
break;
case Code.Ldc_I4_6:
ExpandMacro (instruction, OpCodes.Ldc_I4, 6);
break;
case Code.Ldc_I4_7:
ExpandMacro (instruction, OpCodes.Ldc_I4, 7);
break;
case Code.Ldc_I4_8:
ExpandMacro (instruction, OpCodes.Ldc_I4, 8);
break;
case Code.Ldc_I4_S:
ExpandMacro (instruction, OpCodes.Ldc_I4, (int)(sbyte)instruction.Operand);
break;
case Code.Br_S:
instruction.OpCode = OpCodes.Br;
break;
case Code.Brfalse_S:
instruction.OpCode = OpCodes.Brfalse;
break;
case Code.Brtrue_S:
instruction.OpCode = OpCodes.Brtrue;
break;
case Code.Beq_S:
instruction.OpCode = OpCodes.Beq;
break;
case Code.Bge_S:
instruction.OpCode = OpCodes.Bge;
break;
case Code.Bgt_S:
instruction.OpCode = OpCodes.Bgt;
break;
case Code.Ble_S:
instruction.OpCode = OpCodes.Ble;
break;
case Code.Blt_S:
instruction.OpCode = OpCodes.Blt;
break;
case Code.Bne_Un_S:
instruction.OpCode = OpCodes.Bne_Un;
break;
case Code.Bge_Un_S:
instruction.OpCode = OpCodes.Bge_Un;
break;
case Code.Bgt_Un_S:
instruction.OpCode = OpCodes.Bgt_Un;
break;
case Code.Ble_Un_S:
instruction.OpCode = OpCodes.Ble_Un;
break;
case Code.Blt_Un_S:
instruction.OpCode = OpCodes.Blt_Un;
break;
case Code.Leave_S:
instruction.OpCode = OpCodes.Leave;
break;
}
}
}
static void ExpandMacro (Instruction instruction, OpCode opcode, object operand)
{
instruction.OpCode = opcode;
instruction.Operand = operand;
}
static void MakeMacro (Instruction instruction, OpCode opcode)
{
instruction.OpCode = opcode;
instruction.Operand = null;
}
public static void Optimize (this MethodBody self)
{
if (self == null)
throw new ArgumentNullException ("self");
OptimizeLongs (self);
OptimizeMacros (self);
}
static void OptimizeLongs (this MethodBody self)
{
for (var i = 0; i < self.Instructions.Count; i++) {
var instruction = self.Instructions [i];
if (instruction.OpCode.Code != Code.Ldc_I8)
continue;
var l = (long)instruction.Operand;
if (l >= int.MaxValue || l <= int.MinValue)
continue;
ExpandMacro (instruction, OpCodes.Ldc_I4, (int)l);
self.Instructions.Insert (++i, Instruction.Create (OpCodes.Conv_I8));
}
}
public static void OptimizeMacros (this MethodBody self)
{
if (self == null)
throw new ArgumentNullException ("self");
var method = self.Method;
foreach (var instruction in self.Instructions) {
int index;
switch (instruction.OpCode.Code) {
case Code.Ldarg:
index = ((ParameterDefinition)instruction.Operand).Index;
if (index == -1 && instruction.Operand == self.ThisParameter)
index = 0;
else if (method.HasThis)
index++;
switch (index) {
case 0:
MakeMacro (instruction, OpCodes.Ldarg_0);
break;
case 1:
MakeMacro (instruction, OpCodes.Ldarg_1);
break;
case 2:
MakeMacro (instruction, OpCodes.Ldarg_2);
break;
case 3:
MakeMacro (instruction, OpCodes.Ldarg_3);
break;
default:
if (index < 256)
ExpandMacro (instruction, OpCodes.Ldarg_S, instruction.Operand);
break;
}
break;
case Code.Ldloc:
index = ((VariableDefinition)instruction.Operand).Index;
switch (index) {
case 0:
MakeMacro (instruction, OpCodes.Ldloc_0);
break;
case 1:
MakeMacro (instruction, OpCodes.Ldloc_1);
break;
case 2:
MakeMacro (instruction, OpCodes.Ldloc_2);
break;
case 3:
MakeMacro (instruction, OpCodes.Ldloc_3);
break;
default:
if (index < 256)
ExpandMacro (instruction, OpCodes.Ldloc_S, instruction.Operand);
break;
}
break;
case Code.Stloc:
index = ((VariableDefinition)instruction.Operand).Index;
switch (index) {
case 0:
MakeMacro (instruction, OpCodes.Stloc_0);
break;
case 1:
MakeMacro (instruction, OpCodes.Stloc_1);
break;
case 2:
MakeMacro (instruction, OpCodes.Stloc_2);
break;
case 3:
MakeMacro (instruction, OpCodes.Stloc_3);
break;
default:
if (index < 256)
ExpandMacro (instruction, OpCodes.Stloc_S, instruction.Operand);
break;
}
break;
case Code.Ldarga:
index = ((ParameterDefinition)instruction.Operand).Index;
if (index == -1 && instruction.Operand == self.ThisParameter)
index = 0;
else if (method.HasThis)
index++;
if (index < 256)
ExpandMacro (instruction, OpCodes.Ldarga_S, instruction.Operand);
break;
case Code.Ldloca:
if (((VariableDefinition)instruction.Operand).Index < 256)
ExpandMacro (instruction, OpCodes.Ldloca_S, instruction.Operand);
break;
case Code.Ldc_I4:
int i = (int)instruction.Operand;
switch (i) {
case -1:
MakeMacro (instruction, OpCodes.Ldc_I4_M1);
break;
case 0:
MakeMacro (instruction, OpCodes.Ldc_I4_0);
break;
case 1:
MakeMacro (instruction, OpCodes.Ldc_I4_1);
break;
case 2:
MakeMacro (instruction, OpCodes.Ldc_I4_2);
break;
case 3:
MakeMacro (instruction, OpCodes.Ldc_I4_3);
break;
case 4:
MakeMacro (instruction, OpCodes.Ldc_I4_4);
break;
case 5:
MakeMacro (instruction, OpCodes.Ldc_I4_5);
break;
case 6:
MakeMacro (instruction, OpCodes.Ldc_I4_6);
break;
case 7:
MakeMacro (instruction, OpCodes.Ldc_I4_7);
break;
case 8:
MakeMacro (instruction, OpCodes.Ldc_I4_8);
break;
default:
if (i >= -128 && i < 128)
ExpandMacro (instruction, OpCodes.Ldc_I4_S, (sbyte)i);
break;
}
break;
}
}
OptimizeBranches (self);
}
static void OptimizeBranches (MethodBody body)
{
ComputeOffsets (body);
foreach (var instruction in body.Instructions) {
if (instruction.OpCode.OperandType != OperandType.InlineBrTarget)
continue;
if (OptimizeBranch (instruction))
ComputeOffsets (body);
}
}
static bool OptimizeBranch (Instruction instruction)
{
var offset = ((Instruction)instruction.Operand).Offset - (instruction.Offset + instruction.OpCode.Size + 4);
if (!(offset >= -128 && offset <= 127))
return false;
switch (instruction.OpCode.Code) {
case Code.Br:
instruction.OpCode = OpCodes.Br_S;
break;
case Code.Brfalse:
instruction.OpCode = OpCodes.Brfalse_S;
break;
case Code.Brtrue:
instruction.OpCode = OpCodes.Brtrue_S;
break;
case Code.Beq:
instruction.OpCode = OpCodes.Beq_S;
break;
case Code.Bge:
instruction.OpCode = OpCodes.Bge_S;
break;
case Code.Bgt:
instruction.OpCode = OpCodes.Bgt_S;
break;
case Code.Ble:
instruction.OpCode = OpCodes.Ble_S;
break;
case Code.Blt:
instruction.OpCode = OpCodes.Blt_S;
break;
case Code.Bne_Un:
instruction.OpCode = OpCodes.Bne_Un_S;
break;
case Code.Bge_Un:
instruction.OpCode = OpCodes.Bge_Un_S;
break;
case Code.Bgt_Un:
instruction.OpCode = OpCodes.Bgt_Un_S;
break;
case Code.Ble_Un:
instruction.OpCode = OpCodes.Ble_Un_S;
break;
case Code.Blt_Un:
instruction.OpCode = OpCodes.Blt_Un_S;
break;
case Code.Leave:
instruction.OpCode = OpCodes.Leave_S;
break;
}
return true;
}
static void ComputeOffsets (MethodBody body)
{
var offset = 0;
foreach (var instruction in body.Instructions) {
instruction.Offset = offset;
offset += instruction.GetSize ();
}
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0c47d4756ed8120429bad0887cff0366
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,72 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
namespace MonoFN.Cecil.Rocks {
#if UNITY_EDITOR
public
#endif
static class MethodDefinitionRocks {
public static MethodDefinition GetBaseMethod (this MethodDefinition self)
{
if (self == null)
throw new ArgumentNullException ("self");
if (!self.IsVirtual)
return self;
if (self.IsNewSlot)
return self;
var base_type = ResolveBaseType (self.DeclaringType);
while (base_type != null) {
var @base = GetMatchingMethod (base_type, self);
if (@base != null)
return @base;
base_type = ResolveBaseType (base_type);
}
return self;
}
public static MethodDefinition GetOriginalBaseMethod (this MethodDefinition self)
{
if (self == null)
throw new ArgumentNullException ("self");
while (true) {
var @base = self.GetBaseMethod ();
if (@base == self)
return self;
self = @base;
}
}
static TypeDefinition ResolveBaseType (TypeDefinition type)
{
if (type == null)
return null;
var base_type = type.BaseType;
if (base_type == null)
return null;
return base_type.Resolve ();
}
static MethodDefinition GetMatchingMethod (TypeDefinition type, MethodDefinition method)
{
return MetadataResolver.GetMethod (type.Methods, method);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7a5d7596633ddb043b9785a7fa7bfa6f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,32 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
using System.Collections.Generic;
using System.Linq;
namespace MonoFN.Cecil.Rocks {
#if UNITY_EDITOR
public
#endif
static class ModuleDefinitionRocks {
public static IEnumerable<TypeDefinition> GetAllTypes (this ModuleDefinition self)
{
if (self == null)
throw new ArgumentNullException ("self");
// it was fun to write, but we need a somewhat less convoluted implementation
return self.Types.SelectMany (
Functional.Y<TypeDefinition, IEnumerable<TypeDefinition>> (f => type => type.NestedTypes.SelectMany (f).Prepend (type)));
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d90334a1cd085c047b9b8eddaa65cf09
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,11 @@
namespace MonoFN.Cecil.Rocks {
public static class ParameterReferenceRocks {
public static int GetSequence (this ParameterReference self)
{
return self.Index + 1;
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d276fe9256961b847b51a9bfc735384b
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,157 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
#if !NET_CORE
using System;
using System.Security;
using SSP = System.Security.Permissions;
namespace MonoFN.Cecil.Rocks {
#if UNITY_EDITOR
public
#endif
static class SecurityDeclarationRocks {
public static PermissionSet ToPermissionSet (this SecurityDeclaration self)
{
if (self == null)
throw new ArgumentNullException ("self");
PermissionSet set;
if (TryProcessPermissionSetAttribute (self, out set))
return set;
return CreatePermissionSet (self);
}
static bool TryProcessPermissionSetAttribute (SecurityDeclaration declaration, out PermissionSet set)
{
set = null;
if (!declaration.HasSecurityAttributes && declaration.SecurityAttributes.Count != 1)
return false;
var security_attribute = declaration.SecurityAttributes [0];
if (!security_attribute.AttributeType.IsTypeOf ("System.Security.Permissions", "PermissionSetAttribute"))
return false;
var attribute = new SSP.PermissionSetAttribute ((SSP.SecurityAction)declaration.Action);
var named_argument = security_attribute.Properties [0];
string value = (string)named_argument.Argument.Value;
switch (named_argument.Name) {
case "XML":
attribute.XML = value;
break;
case "Name":
attribute.Name = value;
break;
default:
throw new NotImplementedException (named_argument.Name);
}
set = attribute.CreatePermissionSet ();
return true;
}
static PermissionSet CreatePermissionSet (SecurityDeclaration declaration)
{
var set = new PermissionSet (SSP.PermissionState.None);
foreach (var attribute in declaration.SecurityAttributes) {
var permission = CreatePermission (declaration, attribute);
set.AddPermission (permission);
}
return set;
}
static IPermission CreatePermission (SecurityDeclaration declaration, SecurityAttribute attribute)
{
var attribute_type = Type.GetType (attribute.AttributeType.FullName);
if (attribute_type == null)
throw new ArgumentException ("attribute");
var security_attribute = CreateSecurityAttribute (attribute_type, declaration);
if (security_attribute == null)
throw new InvalidOperationException ();
CompleteSecurityAttribute (security_attribute, attribute);
return security_attribute.CreatePermission ();
}
static void CompleteSecurityAttribute (SSP.SecurityAttribute security_attribute, SecurityAttribute attribute)
{
if (attribute.HasFields)
CompleteSecurityAttributeFields (security_attribute, attribute);
if (attribute.HasProperties)
CompleteSecurityAttributeProperties (security_attribute, attribute);
}
static void CompleteSecurityAttributeFields (SSP.SecurityAttribute security_attribute, SecurityAttribute attribute)
{
var type = security_attribute.GetType ();
foreach (var named_argument in attribute.Fields)
type.GetField (named_argument.Name).SetValue (security_attribute, named_argument.Argument.Value);
}
static void CompleteSecurityAttributeProperties (SSP.SecurityAttribute security_attribute, SecurityAttribute attribute)
{
var type = security_attribute.GetType ();
foreach (var named_argument in attribute.Properties)
type.GetProperty (named_argument.Name).SetValue (security_attribute, named_argument.Argument.Value, null);
}
static SSP.SecurityAttribute CreateSecurityAttribute (Type attribute_type, SecurityDeclaration declaration)
{
SSP.SecurityAttribute security_attribute;
try {
security_attribute = (SSP.SecurityAttribute)Activator.CreateInstance (
attribute_type, new object [] { (SSP.SecurityAction)declaration.Action });
}
catch (MissingMethodException) {
security_attribute = (SSP.SecurityAttribute)Activator.CreateInstance (attribute_type, new object [0]);
}
return security_attribute;
}
public static SecurityDeclaration ToSecurityDeclaration (this PermissionSet self, SecurityAction action, ModuleDefinition module)
{
if (self == null)
throw new ArgumentNullException ("self");
if (module == null)
throw new ArgumentNullException ("module");
var declaration = new SecurityDeclaration (action);
var attribute = new SecurityAttribute (
module.TypeSystem.LookupType ("System.Security.Permissions", "PermissionSetAttribute"));
attribute.Properties.Add (
new CustomAttributeNamedArgument (
"XML",
new CustomAttributeArgument (
module.TypeSystem.String, self.ToXml ().ToString ())));
declaration.SecurityAttributes.Add (attribute);
return declaration;
}
}
}
#endif

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e9d89d937b712004089aafb3a1391907
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,65 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
using System.Collections.Generic;
using System.Linq;
namespace MonoFN.Cecil.Rocks {
#if UNITY_EDITOR
public
#endif
static class TypeDefinitionRocks {
public static IEnumerable<MethodDefinition> GetConstructors (this TypeDefinition self)
{
if (self == null)
throw new ArgumentNullException ("self");
if (!self.HasMethods)
return Empty<MethodDefinition>.Array;
return self.Methods.Where (method => method.IsConstructor);
}
public static MethodDefinition GetStaticConstructor (this TypeDefinition self)
{
if (self == null)
throw new ArgumentNullException ("self");
if (!self.HasMethods)
return null;
return self.GetConstructors ().FirstOrDefault (ctor => ctor.IsStatic);
}
public static IEnumerable<MethodDefinition> GetMethods (this TypeDefinition self)
{
if (self == null)
throw new ArgumentNullException ("self");
if (!self.HasMethods)
return Empty<MethodDefinition>.Array;
return self.Methods.Where (method => !method.IsConstructor);
}
public static TypeReference GetEnumUnderlyingType (this TypeDefinition self)
{
if (self == null)
throw new ArgumentNullException ("self");
if (!self.IsEnum)
throw new ArgumentException ();
return Mixin.GetEnumUnderlyingType (self);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b4d5393ac3307a84ca5babfbdcad9eea
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,87 @@
//
// Author:
// Jb Evain (jbevain@gmail.com)
//
// Copyright (c) 2008 - 2015 Jb Evain
// Copyright (c) 2008 - 2011 Novell, Inc.
//
// Licensed under the MIT/X11 license.
//
using System;
namespace MonoFN.Cecil.Rocks {
#if UNITY_EDITOR
public
#endif
static class TypeReferenceRocks {
public static ArrayType MakeArrayType (this TypeReference self)
{
return new ArrayType (self);
}
public static ArrayType MakeArrayType (this TypeReference self, int rank)
{
if (rank == 0)
throw new ArgumentOutOfRangeException ("rank");
var array = new ArrayType (self);
for (int i = 1; i < rank; i++)
array.Dimensions.Add (new ArrayDimension ());
return array;
}
public static PointerType MakePointerType (this TypeReference self)
{
return new PointerType (self);
}
public static ByReferenceType MakeByReferenceType (this TypeReference self)
{
return new ByReferenceType (self);
}
public static OptionalModifierType MakeOptionalModifierType (this TypeReference self, TypeReference modifierType)
{
return new OptionalModifierType (modifierType, self);
}
public static RequiredModifierType MakeRequiredModifierType (this TypeReference self, TypeReference modifierType)
{
return new RequiredModifierType (modifierType, self);
}
public static GenericInstanceType MakeGenericInstanceType (this TypeReference self, params TypeReference [] arguments)
{
if (self == null)
throw new ArgumentNullException ("self");
if (arguments == null)
throw new ArgumentNullException ("arguments");
if (arguments.Length == 0)
throw new ArgumentException ();
if (self.GenericParameters.Count != arguments.Length)
throw new ArgumentException ();
var instance = new GenericInstanceType (self, arguments.Length);
foreach (var argument in arguments)
instance.GenericArguments.Add (argument);
return instance;
}
public static PinnedType MakePinnedType (this TypeReference self)
{
return new PinnedType (self);
}
public static SentinelType MakeSentinelType (this TypeReference self)
{
return new SentinelType (self);
}
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 25d089a650c8e0f45a6f9086aaf0004a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: