rudimentary implementation of translating IL bytecode into source code (should be laid out in XML though)

This commit is contained in:
Michael Becker 2020-01-23 02:25:37 -05:00
parent d97d2057fc
commit 7826deeed5
No known key found for this signature in database
GPG Key ID: 506F54899E2BFED7
7 changed files with 2377 additions and 3 deletions

View File

@ -0,0 +1,451 @@
using System;
using System.Collections.Generic;
using System.Reflection;
namespace UniversalEditor.Plugins.Executable.UserInterface.Editors.Executable
{
public abstract class CodeProvider
{
/// <summary>
/// Gets the <see cref="CodeProviders.CSharpCodeProvider" />
/// </summary>
/// <value>The CS harp.</value>
public static CodeProviders.CSharpCodeProvider CSharp { get; } = new CodeProviders.CSharpCodeProvider();
public abstract string Title { get; }
public abstract string CodeFileExtension { get; }
protected abstract string GetAccessModifiersInternal(bool isPublic, bool isFamily, bool isAssembly, bool isPrivate, bool isAbstract, bool isSealed);
public string GetAccessModifiers(EventInfo ei)
{
MethodInfo miAdd = ei.GetAddMethod();
MethodInfo miRemove = ei.GetRemoveMethod();
MethodInfo miRaise = ei.GetRaiseMethod();
bool IsPublic = false;
bool IsFamily = false;
bool IsAssembly = false;
bool IsPrivate = false;
if (miAdd != null)
{
IsPublic = miAdd.IsPublic;
IsFamily = miAdd.IsFamily;
IsAssembly = miAdd.IsAssembly;
IsPrivate = miAdd.IsPrivate;
}
else if (miRemove != null)
{
IsPublic = miRemove.IsPublic;
IsFamily = miRemove.IsFamily;
IsAssembly = miRemove.IsAssembly;
IsPrivate = miRemove.IsPrivate;
}
else if (miRaise != null)
{
IsPublic = miRaise.IsPublic;
IsFamily = miRaise.IsFamily;
IsAssembly = miRaise.IsAssembly;
IsPrivate = miRaise.IsPrivate;
}
else
{
}
return GetAccessModifiersInternal(IsPublic, IsFamily, IsAssembly, IsPrivate, false, false);
}
public string GetAccessModifiers(MethodInfo mi)
{
bool IsPublic = mi.IsPublic;
bool IsFamily = mi.IsFamily;
bool IsAssembly = mi.IsAssembly;
bool IsPrivate = mi.IsPrivate;
return GetAccessModifiersInternal(IsPublic, IsFamily, IsAssembly, IsPrivate, mi.IsAbstract, false);
}
public string GetAccessModifiers(FieldInfo mi)
{
bool IsPublic = mi.IsPublic;
bool IsFamily = mi.IsFamily;
bool IsAssembly = mi.IsAssembly;
bool IsPrivate = mi.IsPrivate;
return GetAccessModifiersInternal(IsPublic, IsFamily, IsAssembly, IsPrivate, false, false);
}
public string GetAccessModifiers(PropertyInfo mi)
{
bool IsPublic = (mi.GetGetMethod()?.IsPublic).GetValueOrDefault() || (mi.GetSetMethod()?.IsPublic).GetValueOrDefault();
bool IsFamily = (mi.GetGetMethod()?.IsFamily).GetValueOrDefault() && (mi.GetSetMethod()?.IsFamily).GetValueOrDefault();
bool IsAssembly = (mi.GetGetMethod()?.IsAssembly).GetValueOrDefault() && (mi.GetSetMethod()?.IsAssembly).GetValueOrDefault();
bool IsPrivate = (mi.GetGetMethod()?.IsPrivate).GetValueOrDefault() && (mi.GetSetMethod()?.IsPrivate).GetValueOrDefault();
return GetAccessModifiersInternal(IsPublic, IsFamily, IsAssembly, IsPrivate, false, false);
}
public string GetAccessModifiers(Type mi)
{
bool IsPublic = mi.IsPublic;
bool IsAbstract = mi.IsAbstract;
bool IsSealed = mi.IsSealed;
return GetAccessModifiersInternal(IsPublic, false, false, false, IsAbstract, IsSealed);
}
protected abstract string GetBeginBlockInternal(int indentLevel);
public string GetBeginBlock(int indentLevel)
{
return GetBeginBlockInternal(indentLevel);
}
protected abstract string GetBeginBlockInternal(Type type, int indentLevel);
public string GetBeginBlock(Type type, int indentLevel)
{
return GetBeginBlockInternal(type, indentLevel);
}
protected abstract string GetEndBlockInternal(string elementName, int indentLevel);
public string GetEndBlock(Type type, int indentLevel)
{
return GetEndBlockInternal(GetElementName(type), indentLevel);
}
protected abstract string GetBeginBlockInternal(System.Reflection.MethodInfo mi, int indentLevel);
public string GetBeginBlock(System.Reflection.MethodInfo mi, int indentLevel)
{
return GetBeginBlockInternal(mi, indentLevel);
}
protected abstract string GetEndBlockInternal(System.Reflection.MethodInfo mi, int indentLevel);
public string GetEndBlock(System.Reflection.MethodInfo mi, int indentLevel)
{
return GetEndBlockInternal(GetElementName(mi), indentLevel);
}
protected abstract string GetElementNameInternal(System.Reflection.MethodInfo mi);
public string GetElementName(System.Reflection.MethodInfo mi)
{
return GetElementNameInternal(mi);
}
protected abstract string GetElementNameInternal(Type type);
public string GetElementName(Type type)
{
return GetElementNameInternal(type);
}
protected abstract string GetSourceCodeInternal(Type mi, int indentLevel);
public string GetSourceCode(Type mi, int indentLevel)
{
return GetSourceCodeInternal(mi, indentLevel);
}
protected abstract string GetSourceCodeInternal(System.Reflection.EventInfo item, int indentLevel);
public string GetSourceCode(System.Reflection.EventInfo item, int indentLevel)
{
return GetSourceCodeInternal(item, indentLevel);
}
protected abstract string GetSourceCodeInternal(System.Reflection.FieldInfo mi, int indentLevel);
public string GetSourceCode(System.Reflection.FieldInfo mi, int indentLevel)
{
return GetSourceCodeInternal(mi, indentLevel);
}
protected abstract string GetSourceCodeInternal(System.Reflection.MethodInfo mi, int indentLevel);
public string GetSourceCode(System.Reflection.MethodInfo mi, int indentLevel)
{
return GetSourceCodeInternal(mi, indentLevel);
}
protected abstract string GetSourceCodeInternal(System.Reflection.PropertyInfo item, bool autoProperty, int indentLevel);
public string GetSourceCode(System.Reflection.PropertyInfo item, bool autoProperty, int indentLevel)
{
return GetSourceCodeInternal(item, autoProperty, indentLevel);
}
protected abstract string GetTypeNameInternal(Type type);
public string GetTypeName(Type type)
{
return GetTypeNameInternal(type);
}
protected abstract string GetMethodSignatureInternal(System.Reflection.MethodInfo mi);
public string GetMethodSignature(System.Reflection.MethodInfo mi)
{
return GetMethodSignatureInternal(mi);
}
private static BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
public MethodInfo[] GetMethods(Type type)
{
MethodInfo[] meths = type.GetMethods(bindingFlags);
List<MethodInfo> list = new List<MethodInfo>();
for (int j = 0; j < meths.Length; j++)
{
if (meths[j].IsSpecialName && (meths[j].Name.StartsWith("set_", StringComparison.OrdinalIgnoreCase) || meths[j].Name.StartsWith("get_", StringComparison.OrdinalIgnoreCase)) && (type.GetProperty(meths[j].Name.Substring(4), bindingFlags) != null))
{
// we can be REASONABLY sure that this is a property setter / getter,
// and as we've already gotten all the properties, ignore it
continue;
}
list.Add(meths[j]);
}
return list.ToArray();
}
public FieldInfo[] GetFields(Type type, out List<string> AutoPropertyNames)
{
List<FieldInfo> list = new List<FieldInfo>();
AutoPropertyNames = new List<string>();
FieldInfo[] fields = type.GetFields(bindingFlags);
for (int j = 0; j < fields.Length; j++)
{
if (fields[j].Name.StartsWith("<", StringComparison.OrdinalIgnoreCase) && fields[j].Name.Contains(">"))
{
// might be a backing field
int k__backingfield_name_start = fields[j].Name.IndexOf('<');
int k__backingfield_name_end = fields[j].Name.IndexOf('>', k__backingfield_name_start);
string k__backingfield_name = fields[j].Name.Substring(k__backingfield_name_start + 1, k__backingfield_name_end - k__backingfield_name_start - 1);
PropertyInfo pi = type.GetProperty(k__backingfield_name, bindingFlags);
if (pi != null)
{
AutoPropertyNames.Add(pi.Name);
continue;
}
}
else
{
list.Add(fields[j]);
}
}
return list.ToArray();
}
public string GetILOpcodeStr(short opcode)
{
return GetILOpcodeStr((ILOpcode)opcode);
}
public string GetILOpcodeStr(ILOpcode opcode)
{
switch (opcode)
{
case ILOpcode.Add: return "add";
case ILOpcode.AddOvf: return "add.ovf";
case ILOpcode.AddOvfUn: return "add.ovf.un";
case ILOpcode.And: return "and";
case ILOpcode.ArgList: return "arglist";
case ILOpcode.Beq: return "beq <int32 (target)>";
case ILOpcode.BeqS: return "beq <int32 (target)>";
case ILOpcode.Bge: return "bge <int32 (target)>";
case ILOpcode.BgeS: return "bge.s <int8 (target)>";
case ILOpcode.BgeUn: return "bge.un <int32 (target)>";
case ILOpcode.BgeUnS: return "bge.un.s <int8 (target)>";
case ILOpcode.Bgt: return "bgt <int32 (target)>";
case ILOpcode.BgtS: return "bgt.s <int8 (target)>";
case ILOpcode.BgtUn: return "bgt.un <int32 (target)>";
case ILOpcode.BgtUnS: return "bgt.un.s <int8 (target)>";
case ILOpcode.Ble: return "ble <int32 (target)>";
case ILOpcode.BleS: return "ble.s <int8 (target)>";
case ILOpcode.BleUn: return "ble.un <int32 (target)>";
case ILOpcode.BleUnS: return "ble.un.s <int8 (target)>";
case ILOpcode.Blt: return "blt <int32 (target)>";
case ILOpcode.BltS: return "blt.s <int8 (target)>";
case ILOpcode.BltUn: return "blt.un <int32 (target)>";
case ILOpcode.BltUnS: return "blt.un.s <int8 (target)>";
case ILOpcode.BneUn: return "bne.un <int32 (target)>";
case ILOpcode.BneUnS: return "bne.un.s <int8 (target)>";
case ILOpcode.Box: return "box <typeTok>";
case ILOpcode.Br: return "br <int32 (target)>";
case ILOpcode.BrS: return "br.s <int8 (target)>";
case ILOpcode.Break: return "break";
case ILOpcode.BrFalse: return "brfalse <int32 (target)>";
case ILOpcode.BrFalseS: return "brfalse.s <int8 (target)>";
case ILOpcode.BrTrue: return "brtrue <int32 (target)>";
case ILOpcode.BrTrueS: return "brtrue.s <int8 (target)>";
case ILOpcode.Call: return "call <method>";
case ILOpcode.CallI: return "calli <callsitedescr>";
case ILOpcode.CallVirt: return "callvirt <method>";
case ILOpcode.CastClass: return "castclass <class>";
case ILOpcode.Ceq: return "ceq";
case ILOpcode.Cgt: return "cgt";
case ILOpcode.CgtUn: return "cgt.un";
case ILOpcode.CkFinite: return "ckfinite";
case ILOpcode.Clt: return "clt";
case ILOpcode.CltUn: return "clt.un";
case ILOpcode.Constrained: return "constrained <thisType>";
case ILOpcode.ConvI: return "conv.i";
case ILOpcode.ConvI1: return "conv.i1";
case ILOpcode.ConvI2: return "conv.i2";
case ILOpcode.ConvI4: return "conv.i4";
case ILOpcode.ConvI8: return "conv.i8";
case ILOpcode.ConvOvfI: return "conv.ovf.i";
case ILOpcode.ConvOvfIUn: return "conv.ovf.i.un";
case ILOpcode.ConvOvfI1: return "conv.ovf.i1";
case ILOpcode.ConvOvfI1Un: return "conv.ovf.i1.un";
case ILOpcode.ConvOvfI2: return "conv.ovf.i2";
case ILOpcode.ConvOvfI2Un: return "conv.ovf.i2.un";
case ILOpcode.ConvOvfI4: return "conv.ovf.i4";
case ILOpcode.ConvOvfI4Un: return "conv.ovf.i4.un";
case ILOpcode.ConvOvfI8: return "conv.ovf.i8";
case ILOpcode.ConvOvfI8Un: return "conv.ovf.i8.un";
case ILOpcode.ConvOvfU: return "conv.ovf.u";
case ILOpcode.ConvOvfUUn: return "conv.ovf.u.un";
case ILOpcode.ConvOvfU1: return "conv.ovf.u1";
case ILOpcode.ConvOvfU1Un: return "conv.ovf.u1.un";
case ILOpcode.ConvOvfU2: return "conv.ovf.u2";
case ILOpcode.ConvOvfU2Un: return "conv.ovf.u2.un";
case ILOpcode.ConvOvfU4: return "conv.ovf.u4";
case ILOpcode.ConvOvfU4Un: return "conv.ovf.u4.un";
case ILOpcode.ConvOvfU8: return "conv.ovf.u8";
case ILOpcode.ConvOvfU8Un: return "conv.ovf.u8.un";
case ILOpcode.ConvRUn: return "conv.r.un";
case ILOpcode.ConvR4: return "conv.r4";
case ILOpcode.ConvR8: return "conv.r8";
case ILOpcode.ConvU: return "conv.u";
case ILOpcode.ConvU1: return "conv.u1";
case ILOpcode.ConvU2: return "conv.u2";
case ILOpcode.ConvU4: return "conv.u4";
case ILOpcode.ConvU8: return "conv.u8";
case ILOpcode.CpBlk: return "cpblk";
case ILOpcode.CpObj: return "cpobj <typeTok>";
case ILOpcode.Div: return "div";
case ILOpcode.DivUn: return "div.un";
case ILOpcode.Dup: return "dup";
case ILOpcode.EndFault: return "endfault";
case ILOpcode.EndFilter: return "endfilter";
// case ILOpcode.EndFinally: return "endfinally"; // same as endfault?
case ILOpcode.InitBlk: return "initblk";
case ILOpcode.InitObj: return "initobj <typeTok>";
case ILOpcode.IsInst: return "isinst <class>";
case ILOpcode.Jmp: return "jmp";
case ILOpcode.LdArg: return "ldarg <uint16 (num)>";
case ILOpcode.LdArg0: return "ldarg.0";
case ILOpcode.LdArg1: return "ldarg.1";
case ILOpcode.LdArg2: return "ldarg.2";
case ILOpcode.LdArg3: return "ldarg.3";
case ILOpcode.LdArgS: return "ldarg.s <uint8 (num)>";
case ILOpcode.LdArgA: return "ldarg.a <uint16 (num)>";
case ILOpcode.LdArgAS: return "ldarg.a.s <uint8 (num)>";
case ILOpcode.LdCI4: return "ldc.i4 <int32 (num)>";
case ILOpcode.LdCI4_M1: return "ldc.i4.m1";
case ILOpcode.LdCI4_0: return "ldc.i4.0";
case ILOpcode.LdCI4_1: return "ldc.i4.1";
case ILOpcode.LdCI4_2: return "ldc.i4.2";
case ILOpcode.LdCI4_3: return "ldc.i4.3";
case ILOpcode.LdCI4_4: return "ldc.i4.4";
case ILOpcode.LdCI4_5: return "ldc.i4.5";
case ILOpcode.LdCI4_6: return "ldc.i4.6";
case ILOpcode.LdCI4_7: return "ldc.i4.7";
case ILOpcode.LdCI4_8: return "ldc.i4.8";
case ILOpcode.LdCI4S: return "ldc.i4.s <int8 (num)>";
case ILOpcode.LdCI8: return "ldc.i8 <int64 (num)>";
case ILOpcode.LdCR4: return "ldc.r4 <float32 (num)>";
case ILOpcode.LdCR8: return "ldc.r8 <float64 (num)>";
case ILOpcode.LdElem: return "ldelem <typeTok>";
case ILOpcode.LdElemI: return "ldelem.i";
case ILOpcode.LdElemI1: return "ldelem.i1";
case ILOpcode.LdElemU1: return "ldelem.u1";
case ILOpcode.LdElemI2: return "ldelem.i2";
case ILOpcode.LdElemU2: return "ldelem.u2";
case ILOpcode.LdElemI4: return "ldelem.i4";
case ILOpcode.LdElemU4: return "ldelem.u4";
case ILOpcode.LdElemI8: return "ldelem.i8";
case ILOpcode.LdElemR4: return "ldelem.r4";
case ILOpcode.LdElemR8: return "ldelem.r8";
case ILOpcode.LdElemRef: return "ldelem.ref";
case ILOpcode.LdElemA: return "ldelema <class>";
case ILOpcode.LdFld: return "ldfld <field>";
case ILOpcode.LdFldA: return "ldflda <field>";
case ILOpcode.LdFtn: return "ldftn <method>";
case ILOpcode.LdIndI: return "ldind.i";
case ILOpcode.LdIndI1: return "ldind.i1";
case ILOpcode.LdIndU1: return "ldind.u1";
case ILOpcode.LdIndI2: return "ldind.i2";
case ILOpcode.LdIndU2: return "ldind.u2";
case ILOpcode.LdIndI4: return "ldind.i4";
case ILOpcode.LdIndU4: return "ldind.u4";
case ILOpcode.LdIndI8: return "ldind.i8";
case ILOpcode.LdIndR4: return "ldind.r4";
case ILOpcode.LdIndR8: return "ldind.r8";
case ILOpcode.LdLen: return "ldlen";
case ILOpcode.LdLoc: return "ldloc <uint16 (indx)>";
case ILOpcode.LdLoc0: return "ldloc.0";
case ILOpcode.LdLoc1: return "ldloc.1";
case ILOpcode.LdLoc2: return "ldloc.2";
case ILOpcode.LdLoc3: return "ldloc.3";
case ILOpcode.LdLocS: return "ldloc.s <uint8 (indx)>";
case ILOpcode.LdLocA: return "ldloca <uint16 (indx)>";
case ILOpcode.LdLocAS: return "ldloca.s <uint8 (indx)>";
case ILOpcode.LdNull: return "ldnull";
case ILOpcode.LdObj: return "ldobj <typeTok>";
case ILOpcode.LdSFld: return "ldsfld <field>";
case ILOpcode.LdSFldA: return "ldsflda <field>";
case ILOpcode.LdStr: return "ldstr <string>";
case ILOpcode.LdToken: return "ldtoken <token>";
case ILOpcode.LdVirtFtn: return "ldvirtftn <method>";
case ILOpcode.Leave: return "leave <int32 (target)>";
case ILOpcode.LeaveS: return "leave <int8 (target)>";
case ILOpcode.LocAlloc: return "localloc";
case ILOpcode.MkRefAny: return "mkrefany <class>";
case ILOpcode.Mul: return "mul";
case ILOpcode.MulOvf: return "mul.ovf";
case ILOpcode.MulOvfUn: return "mul.ovf.un";
case ILOpcode.Neg: return "neg";
case ILOpcode.NewArr: return "newarr <etype>";
case ILOpcode.NewObj: return "newobj <ctor>";
case ILOpcode.No: return "no.{typecheck, rangecheck, nullcheck}";
case ILOpcode.Nop: return "nop";
case ILOpcode.Not: return "not";
case ILOpcode.Or: return "or";
case ILOpcode.Pop: return "pop";
case ILOpcode.Readonly: return "readonly.";
case ILOpcode.RefAnyType: return "refanytype";
case ILOpcode.RefAnyVal: return "refanyval <type>";
case ILOpcode.Rem: return "rem";
case ILOpcode.RemUn: return "rem.un";
case ILOpcode.Ret: return "ret";
case ILOpcode.Rethrow: return "rethrow";
case ILOpcode.Shl: return "shl";
case ILOpcode.Shr: return "shl";
case ILOpcode.ShrUn: return "shl";
case ILOpcode.SizeOf: return "sizeof <typeTok>";
case ILOpcode.StArg: return "starg <uint16 (num)>";
case ILOpcode.StArgS: return "starg.s <uint8 (num)>";
case ILOpcode.StElem: return "stelem <typeTok>";
case ILOpcode.StElemI: return "stelem.i";
case ILOpcode.StElemI1: return "stelem.i1";
case ILOpcode.StElemI2: return "stelem.i2";
case ILOpcode.StElemI4: return "stelem.i4";
case ILOpcode.StElemI8: return "stelem.i8";
case ILOpcode.StElemR4: return "stelem.r4";
case ILOpcode.StElemR8: return "stelem.r8";
case ILOpcode.StElemRef: return "stelem.ref";
case ILOpcode.StFld: return "stfld <field>";
case ILOpcode.StIndI: return "stind.i";
case ILOpcode.StIndI1: return "stind.i1";
case ILOpcode.StIndI2: return "stind.i2";
case ILOpcode.StIndI4: return "stind.i4";
case ILOpcode.StIndI8: return "stind.i8";
case ILOpcode.StIndR4: return "stind.r4";
case ILOpcode.StIndR8: return "stind.r8";
case ILOpcode.StIndRef: return "stind.ref";
case ILOpcode.StLoc: return "stloc <uint16 (indx)>";
case ILOpcode.StLoc0: return "stloc.0";
case ILOpcode.StLoc1: return "stloc.1";
case ILOpcode.StLoc2: return "stloc.2";
case ILOpcode.StLoc3: return "stloc.3";
case ILOpcode.StLocS: return "stloc.s <uint8 (indx)>";
case ILOpcode.StObj: return "stobj <typeTok>";
case ILOpcode.StSFld: return "stsfld <field>";
case ILOpcode.Sub: return "sub";
case ILOpcode.SubOvf: return "sub.ovf";
case ILOpcode.SubOvfUn: return "sub.ovf.un";
case ILOpcode.Switch: return "switch <uint32, int32, int32 (t1..tN)>";
case ILOpcode.Tail: return "tail.";
case ILOpcode.Throw: return "throw";
case ILOpcode.Unaligned: return "unaligned.(alignment)";
case ILOpcode.Unbox: return "unbox <typeTok>";
case ILOpcode.UnboxAny: return "unbox.any <typeTok>";
case ILOpcode.Volatile: return "volatile.";
case ILOpcode.Xor: return "xor";
}
return "<OPCODE:" + ((short)opcode).ToString("X").PadLeft(2, '0') + ">";
}
public string GetVariableName(MethodInfo mi, LocalVariableInfo localVariableInfo)
{
// TODO: read the PDB file (if exists) to get the local variable info
return "local_" + localVariableInfo.LocalIndex.ToString();
}
}
}

View File

@ -0,0 +1,427 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using UniversalEditor.Accessors;
using UniversalEditor.IO;
namespace UniversalEditor.Plugins.Executable.UserInterface.Editors.Executable.CodeProviders
{
public class CSharpCodeProvider : CodeProvider
{
public override string Title => "C#";
public override string CodeFileExtension => ".cs";
protected override string GetAccessModifiersInternal(bool isPublic, bool isFamily, bool isAssembly, bool isPrivate, bool isAbstract, bool isSealed)
{
StringBuilder sb = new StringBuilder();
if (isPublic) sb.Append("public ");
if (isFamily) sb.Append("protected ");
if (isAssembly) sb.Append("internal ");
if (isPrivate) sb.Append("private ");
if (isAbstract) sb.Append("abstract ");
if (isSealed) sb.Append("sealed ");
return sb.ToString().Trim();
}
protected override string GetBeginBlockInternal(Type type, int indentLevel)
{
return GetBeginBlockInternal(indentLevel);
}
protected override string GetBeginBlockInternal(int indentLevel)
{
StringBuilder sb = new StringBuilder();
sb.Append(new string('\t', indentLevel));
sb.Append('{');
return sb.ToString();
}
protected override string GetEndBlockInternal(string elementName, int indentLevel)
{
StringBuilder sb = new StringBuilder();
sb.Append(new string('\t', indentLevel));
sb.Append('}');
return sb.ToString();
}
protected override string GetBeginBlockInternal(MethodInfo mi, int indentLevel)
{
return GetBeginBlockInternal(indentLevel);
}
protected override string GetEndBlockInternal(MethodInfo mi, int indentLevel)
{
return GetEndBlockInternal(GetElementName(mi), indentLevel);
}
protected override string GetElementNameInternal(Type type)
{
if (type.IsClass)
{
return "class";
}
else if (type.IsInterface)
{
return "interface";
}
else if (type.IsEnum)
{
return "enum";
}
else if (type.IsValueType)
{
return "struct";
}
throw new NotSupportedException();
}
protected override string GetElementNameInternal(MethodInfo mi)
{
return String.Empty;
}
protected override string GetMethodSignatureInternal(MethodInfo mi)
{
StringBuilder sb = new StringBuilder();
sb.Append(GetAccessModifiers(mi));
sb.Append(' ');
sb.Append(GetTypeName(mi.ReturnType));
sb.Append(' ');
sb.Append(mi.Name);
sb.Append('(');
ParameterInfo[] pis = mi.GetParameters();
for (int i = 0; i < pis.Length; i++)
{
if (pis[i].ParameterType.IsByRef && pis[i].IsOut)
{
sb.Append("out ");
}
else if (pis[i].ParameterType.IsByRef)
{
sb.Append("ref ");
}
sb.Append(GetTypeName(pis[i].ParameterType));
sb.Append(' ');
sb.Append(pis[i].Name);
if (i < pis.Length - 1)
sb.Append(", ");
}
sb.Append(')');
return sb.ToString();
}
protected override string GetSourceCodeInternal(MethodInfo mi, int indentLevel)
{
StringBuilder sb = new StringBuilder();
string indentStr = new string('\t', indentLevel);
sb.Append(indentStr);
sb.Append(GetMethodSignature(mi));
MethodBody mb = mi.GetMethodBody();
if (mb != null)
{
sb.AppendLine();
sb.Append(GetBeginBlock(mi, indentLevel));
sb.AppendLine();
for (int i = 0; i < mb.LocalVariables.Count; i++)
{
sb.Append(new string('\t', indentLevel + 1));
sb.Append(GetTypeName(mb.LocalVariables[i].LocalType));
sb.Append(' ');
sb.Append(GetVariableName(mi, mb.LocalVariables[i]));
sb.AppendLine(";");
}
if (mb.LocalVariables.Count > 0)
sb.AppendLine();
byte[] bytecode = mb.GetILAsByteArray();
MemoryAccessor ma = new MemoryAccessor(bytecode);
Reader r = new Reader(ma);
while (!r.EndOfStream)
{
int sz = 0;
ILOpcode opcode = ReadOpcode(r, out sz);
ILOpcode opcode2 = PeekOpcode(r);
sb.Append(new string('\t', indentLevel + 1));
if (opcode2 == ILOpcode.NewArr)
{
int? lit = OpcodeToLiteralInt(opcode);
sb.Append(String.Format("X[] = new X[{0}]", lit.GetValueOrDefault(0)));
}
else
{
sb.AppendLine(GetILOpcodeStr(opcode));
continue;
}
}
sb.Append(GetEndBlock(mi, indentLevel));
}
else
{
sb.Append(';');
}
return sb.ToString();
}
private int? OpcodeToLiteralInt(ILOpcode opcode)
{
switch (opcode)
{
case ILOpcode.LdCI4_0:
{
return 0;
}
case ILOpcode.LdCI4_1:
{
return 1;
}
case ILOpcode.LdCI4_2:
{
return 2;
}
case ILOpcode.LdCI4_3:
{
return 3;
}
case ILOpcode.LdCI4_4:
{
return 4;
}
case ILOpcode.LdCI4_5:
{
return 5;
}
case ILOpcode.LdCI4_6:
{
return 6;
}
case ILOpcode.LdCI4_7:
{
return 7;
}
case ILOpcode.LdCI4_8:
{
return 8;
}
case ILOpcode.LdCI4_M1:
{
return -1;
}
}
return null;
}
private ILOpcode PeekOpcode(Reader r)
{
int sz = 0;
ILOpcode opcode = ReadOpcode(r, out sz);
if (sz == 0)
return opcode;
r.Seek(-sz, SeekOrigin.Current);
return opcode;
}
private ILOpcode ReadOpcode(Reader r, out int size)
{
if (r.EndOfStream)
{
size = 0;
return ILOpcode.Nop;
}
byte bytecode_b = r.ReadByte();
short bytecode_s = bytecode_b;
size = 1;
if (bytecode_s == 0xFE)
{
bytecode_s = BitConverter.ToInt16(new byte[] { bytecode_b, r.ReadByte() }, 0);
size = 2;
}
return (ILOpcode)bytecode_s;
}
protected override string GetSourceCodeInternal(FieldInfo fi, int indentLevel)
{
StringBuilder sb = new StringBuilder();
sb.Append(new string('\t', indentLevel));
sb.Append(GetAccessModifiers(fi));
sb.Append(' ');
sb.Append(fi.FieldType.FullName);
sb.Append(' ');
sb.Append(fi.Name);
sb.Append(';');
return sb.ToString();
}
protected override string GetTypeNameInternal(Type type)
{
string fullyQualifiedTypeName = type.FullName ?? type.Name;
if (fullyQualifiedTypeName.Equals("System.Void")) return "void";
if (fullyQualifiedTypeName.Equals("System.Byte")) return "byte";
if (fullyQualifiedTypeName.Equals("System.SByte")) return "sbyte";
if (fullyQualifiedTypeName.Equals("System.Char")) return "char";
if (fullyQualifiedTypeName.Equals("System.Int16")) return "short";
if (fullyQualifiedTypeName.Equals("System.UInt16")) return "ushort";
if (fullyQualifiedTypeName.Equals("System.Int32")) return "int";
if (fullyQualifiedTypeName.Equals("System.UInt32")) return "uint";
if (fullyQualifiedTypeName.Equals("System.Int64")) return "long";
if (fullyQualifiedTypeName.Equals("System.UInt64")) return "ulong";
if (fullyQualifiedTypeName.Equals("System.String")) return "string";
if (fullyQualifiedTypeName.Equals("System.Single")) return "float";
if (fullyQualifiedTypeName.Equals("System.Double")) return "double";
if (fullyQualifiedTypeName.Equals("System.Decimal")) return "decimal";
if (fullyQualifiedTypeName.Equals("System.Boolean")) return "bool";
if (fullyQualifiedTypeName.Equals("System.Object")) return "object";
return fullyQualifiedTypeName;
}
protected override string GetSourceCodeInternal(Type item, int indentLevel)
{
string indentStr = new string('\t', indentLevel);
StringBuilder sb = new StringBuilder();
sb.Append(indentStr);
sb.Append(GetAccessModifiers(item));
sb.Append(' ');
sb.Append(GetElementName(item));
sb.Append(' ');
sb.Append(item.Name);
if (!item.IsValueType && (item.BaseType != null && item.BaseType != typeof(object) && item.BaseType != typeof(Enum)))
{
sb.Append(" : ");
sb.Append(GetTypeName(item.BaseType));
}
sb.AppendLine();
sb.Append(GetBeginBlock(indentLevel));
sb.AppendLine();
BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static | BindingFlags.DeclaredOnly;
if (item.IsEnum)
{
FieldInfo[] fields = item.GetFields(bindingFlags);
for (int j = 0; j < fields.Length; j++)
{
if (fields[j].FieldType == item)
{
sb.Append(new string('\t', indentLevel + 1));
sb.Append(fields[j].Name);
if (j < fields.Length - 1)
sb.Append(',');
sb.AppendLine();
}
}
}
else
{
List<string> AutoPropertyNames;
FieldInfo[] fields = GetFields(item, out AutoPropertyNames);
for (int j = 0; j < fields.Length; j++)
{
sb.AppendLine(GetSourceCode(fields[j], indentLevel + 1));
sb.AppendLine();
}
EventInfo[] events = item.GetEvents(bindingFlags);
for (int j = 0; j < events.Length; j++)
{
sb.AppendLine(GetSourceCode(events[j], indentLevel + 1));
sb.AppendLine();
}
PropertyInfo[] props = item.GetProperties(bindingFlags);
for (int j = 0; j < props.Length; j++)
{
sb.AppendLine(GetSourceCode(props[j], AutoPropertyNames.Contains(props[j].Name), indentLevel + 1));
sb.AppendLine();
}
MethodInfo[] meths = GetMethods(item);
for (int j = 0; j < meths.Length; j++)
{
sb.AppendLine(GetSourceCode(meths[j], indentLevel + 1));
sb.AppendLine();
}
}
sb.Append(GetEndBlock(item, indentLevel));
return sb.ToString();
}
protected override string GetSourceCodeInternal(EventInfo item, int indentLevel)
{
StringBuilder sb = new StringBuilder();
sb.Append(new string('\t', indentLevel));
sb.Append(GetAccessModifiers(item));
sb.Append(" event ");
sb.Append(GetTypeName(item.EventHandlerType));
sb.Append(' ');
sb.Append(item.Name);
return sb.ToString();
}
protected override string GetSourceCodeInternal(PropertyInfo item, bool autoProperty, int indentLevel)
{
StringBuilder sb = new StringBuilder();
sb.Append(new string('\t', indentLevel));
string amProp = GetAccessModifiers(item);
sb.Append(amProp);
sb.Append(' ');
sb.Append(GetTypeName(item.PropertyType));
sb.Append(' ');
sb.Append(item.Name);
sb.Append(' ');
sb.Append("{ ");
MethodInfo miGet = item.GetGetMethod();
if (miGet != null)
{
string am = GetAccessModifiers(miGet);
if (!String.IsNullOrEmpty(am) && amProp != am)
{
sb.Append(am);
sb.Append(' ');
}
sb.Append("get");
if (autoProperty)
{
sb.Append("; ");
}
else
{
sb.Append(" { ");
sb.Append(" } ");
}
}
MethodInfo miSet = item.GetSetMethod();
if (miSet != null)
{
string am = GetAccessModifiers(miSet);
if (!String.IsNullOrEmpty(am) && amProp != am)
sb.Append(am);
sb.Append(" set");
if (autoProperty)
{
sb.Append("; ");
}
else
{
sb.Append(" { ");
sb.Append(" }");
}
}
sb.Append('}');
return sb.ToString();
}
}
}

View File

@ -0,0 +1,245 @@
using System;
using System.Reflection;
using System.Text;
namespace UniversalEditor.Plugins.Executable.UserInterface.Editors.Executable.CodeProviders
{
public class VisualBasicCodeProvider : CodeProvider
{
public override string Title => "VB.NET";
public override string CodeFileExtension => ".vb";
protected override string GetAccessModifiersInternal(bool isPublic, bool isFamily, bool isAssembly, bool isPrivate, bool isAbstract, bool isSealed)
{
StringBuilder sb = new StringBuilder();
if (isPublic) sb.Append("Public ");
if (isFamily) sb.Append("Protected ");
if (isAssembly) sb.Append("Friend ");
if (isPrivate) sb.Append("Private ");
if (isAbstract) sb.Append("Abstract ");
if (isSealed) sb.Append("Sealed ");
return sb.ToString().Trim();
}
protected override string GetBeginBlockInternal(int indentLevel)
{
return new string('\t', indentLevel);
}
protected override string GetEndBlockInternal(string elementName, int indentLevel)
{
StringBuilder sb = new StringBuilder();
sb.Append(new string('\t', indentLevel));
sb.Append("End ");
sb.Append(elementName);
return sb.ToString();
}
protected override string GetBeginBlockInternal(MethodInfo mi, int indentLevel)
{
StringBuilder sb = new StringBuilder();
sb.Append(new string('\t', indentLevel));
string am = GetAccessModifiers(mi);
if (!String.IsNullOrEmpty(am))
{
sb.Append(am);
sb.Append(' ');
}
sb.Append(GetElementName(mi));
sb.Append(' ');
sb.Append(GetMethodSignature(mi));
if (mi.ReturnType != typeof(void))
{
sb.Append(" As ");
sb.Append(GetTypeName(mi.ReturnType));
}
return sb.ToString();
}
protected override string GetBeginBlockInternal(Type type, int indentLevel)
{
StringBuilder sb = new StringBuilder();
sb.Append(new string('\t', indentLevel));
string am = GetAccessModifiers(type);
sb.Append(' ');
sb.Append(GetElementName(type));
sb.Append(' ');
sb.Append(type.Name);
return sb.ToString();
}
protected override string GetEndBlockInternal(MethodInfo mi, int indentLevel)
{
return GetEndBlockInternal(GetElementName(mi), indentLevel);
}
protected override string GetElementNameInternal(Type type)
{
if (type.IsClass)
{
return "Class";
}
else if (type.IsInterface)
{
return "Interface";
}
else if (type.IsEnum)
{
return "Enum";
}
else if (type.IsValueType)
{
return "Structure";
}
throw new NotSupportedException();
}
protected override string GetElementNameInternal(MethodInfo mi)
{
if (mi.ReturnType == typeof(void))
{
return "Sub";
}
return "Function";
}
protected override string GetSourceCodeInternal(EventInfo item, int indentLevel)
{
StringBuilder sb = new StringBuilder();
/*
sb.Append(new string('\t', indentLevel));
string am = GetAccessModifiers(fi);
if (String.IsNullOrEmpty(am.Trim()))
{
sb.Append("Dim");
}
else
{
sb.Append(am);
}
sb.Append(' ');
sb.Append(fi.Name);
sb.Append(" As ");
sb.Append(fi.FieldType.FullName);
*/
return sb.ToString();
}
protected override string GetSourceCodeInternal(FieldInfo item, int indentLevel)
{
StringBuilder sb = new StringBuilder();
sb.Append(new string('\t', indentLevel));
string am = GetAccessModifiers(item);
if (String.IsNullOrEmpty(am.Trim()))
{
sb.Append("Dim");
}
else
{
sb.Append(am);
}
sb.Append(' ');
sb.Append(item.Name);
sb.Append(" As ");
sb.Append(item.FieldType.FullName);
return sb.ToString();
}
protected override string GetSourceCodeInternal(Type mi, int indentLevel)
{
StringBuilder sb = new StringBuilder();
sb.Append(GetBeginBlock(mi, indentLevel));
sb.AppendLine();
MethodInfo[] mis = mi.GetMethods();
for (int i = 0; i < mis.Length; i++)
{
sb.AppendLine(GetBeginBlock(mis[i], indentLevel + 1));
sb.AppendLine();
sb.AppendLine(GetEndBlock(mis[i], indentLevel + 1));
sb.AppendLine();
}
sb.AppendLine();
sb.Append(GetEndBlock(mi, indentLevel));
return sb.ToString();
}
protected override string GetSourceCodeInternal(MethodInfo mi, int indentLevel)
{
throw new NotImplementedException();
}
protected override string GetMethodSignatureInternal(MethodInfo mi)
{
StringBuilder sb = new StringBuilder();
sb.Append(mi.Name);
sb.Append('(');
ParameterInfo[] pis = mi.GetParameters();
for (int i = 0; i < pis.Length; i++)
{
if (pis[i].ParameterType.IsByRef)
{
sb.Append("ByRef ");
}
else
{
sb.Append("ByVal ");
}
sb.Append(pis[i].Name);
sb.Append(" As ");
sb.Append(GetTypeName(pis[i].ParameterType));
if (i < pis.Length - 1)
sb.Append(", ");
}
sb.Append(')');
return sb.ToString();
}
protected override string GetTypeNameInternal(Type type)
{
string fullyQualifiedTypeName = type.FullName ?? type.Name;
if (fullyQualifiedTypeName.Equals("System.Byte")) return "Byte";
if (fullyQualifiedTypeName.Equals("System.SByte")) return "SByte";
if (fullyQualifiedTypeName.Equals("System.Char")) return "Char";
if (fullyQualifiedTypeName.Equals("System.Int16")) return "Short";
if (fullyQualifiedTypeName.Equals("System.UInt16")) return "UShort";
if (fullyQualifiedTypeName.Equals("System.Int32")) return "Int";
if (fullyQualifiedTypeName.Equals("System.UInt32")) return "UInt";
if (fullyQualifiedTypeName.Equals("System.Int64")) return "Long";
if (fullyQualifiedTypeName.Equals("System.UInt64")) return "ULong";
if (fullyQualifiedTypeName.Equals("System.String")) return "String";
if (fullyQualifiedTypeName.Equals("System.Single")) return "Single";
if (fullyQualifiedTypeName.Equals("System.Double")) return "Double";
if (fullyQualifiedTypeName.Equals("System.Decimal")) return "Decimal";
if (fullyQualifiedTypeName.Equals("System.Boolean")) return "Boolean";
if (fullyQualifiedTypeName.Equals("System.Object")) return "Object";
return fullyQualifiedTypeName;
}
protected override string GetSourceCodeInternal(PropertyInfo item, bool autoProperty, int indentLevel)
{
StringBuilder sb = new StringBuilder();
string indentStr = new string('\t', indentLevel);
sb.Append(indentStr);
sb.Append(GetAccessModifiers(item));
sb.Append(' ');
sb.Append("Property ");
sb.Append(item.Name);
sb.Append(" As ");
sb.Append(GetTypeName(item.PropertyType));
sb.AppendLine();
sb.Append(new string('\t', indentLevel + 1));
sb.AppendLine("Get");
sb.Append(new string('\t', indentLevel + 1));
sb.AppendLine("End Get");
sb.Append(new string('\t', indentLevel + 1));
sb.AppendLine("Set");
sb.Append(new string('\t', indentLevel + 1));
sb.AppendLine("End Set");
sb.Append(new string('\t', indentLevel));
sb.Append("End Property");
return sb.ToString();
}
}
}

View File

@ -61,6 +61,7 @@ namespace UniversalEditor.Plugins.Executable.UserInterface.Editors.Executable
private TextBox txtAssemblyVersion = null;
private DefaultTreeModel tmOtherInformation = null;
private ManagedAssemblyPanel pnlManagedAssembly = null;
public ExecutableEditor()
{
@ -142,11 +143,14 @@ namespace UniversalEditor.Plugins.Executable.UserInterface.Editors.Executable
pnlMetadata.Layout = new GridLayout();
pnlMetadata.Controls.Add(lblAssemblyName, new GridLayout.Constraints(0, 0));
pnlMetadata.Controls.Add(txtAssemblyName, new GridLayout.Constraints(0, 1));
pnlMetadata.Controls.Add(txtAssemblyName, new GridLayout.Constraints(0, 1, 1, 1, ExpandMode.Horizontal));
pnlMetadata.Controls.Add(lblAssemblyVersion, new GridLayout.Constraints(1, 0));
pnlMetadata.Controls.Add(txtAssemblyVersion, new GridLayout.Constraints(1, 1));
pnlMetadata.Controls.Add(txtAssemblyVersion, new GridLayout.Constraints(1, 1, 1, 1, ExpandMode.Horizontal));
tabManagedAssembly.Controls.Add(pnlMetadata);
tabManagedAssembly.Controls.Add(pnlMetadata, new BoxLayout.Constraints(false, true));
pnlManagedAssembly = new ManagedAssemblyPanel();
tabManagedAssembly.Controls.Add(pnlManagedAssembly, new BoxLayout.Constraints(true, true));
tbs.TabPages.Add(tabManagedAssembly);
@ -241,6 +245,8 @@ namespace UniversalEditor.Plugins.Executable.UserInterface.Editors.Executable
txtAssemblyName.Text = executable.ManagedAssembly.GetName().Name;
txtAssemblyVersion.Text = executable.ManagedAssembly.GetName().Version.ToString();
pnlManagedAssembly.Assembly = executable.ManagedAssembly;
}
}
}

View File

@ -0,0 +1,925 @@
using System;
namespace UniversalEditor.Plugins.Executable.UserInterface.Editors.Executable
{
public enum ILOpcode : short
{
/// <summary>
/// add - Add two values, returning a new value.
/// </summary>
Add = 0x58,
/// <summary>
/// add.ovf - Add signed integer values with overflow check.
/// </summary>
AddOvf = 0xD6,
/// <summary>
/// add.ovf.un - Add unsigned integer values with overflow check.
/// </summary>
AddOvfUn = 0xD7,
/// <summary>
/// and - Bitwise AND of two integral values, returns an integral value.
/// </summary>
And = 0x5F,
/// <summary>
/// arglist - Return argument list handle for the current method.
/// </summary>
ArgList = 0x00FE,
/// <summary>
/// beq &lt;int32 (target)&gt; - Branch to target if equal.
/// </summary>
Beq = 0x3B,
/// <summary>
/// beq.s &lt;int8 (target)&gt; - Branch to target if equal, short form.
/// </summary>
BeqS = 0x2E,
/// <summary>
/// bge &lt;int32 (target)&gt; - Branch to target if greater than or equal to.
/// </summary>
Bge = 0x3C,
/// <summary>
/// bge.s &lt;int8 (target)&gt; - Branch to target if greater than or equal to, short form.
/// </summary>
BgeS = 0x2F,
/// <summary>
/// bge.un &lt;int32 (target)&gt; - Branch to target if greater than or equal to (unsigned or unordered).
/// </summary>
BgeUn = 0x41,
/// <summary>
/// bge.un.s &lt;int8 (target)&gt; - Branch to target if greater than or equal to (unsigned or unordered), short form
/// </summary>
BgeUnS = 0x34,
/// <summary>
/// bgt &lt;int32 (target)&gt; Branch to target if greater than.
/// </summary>
Bgt = 0x3D,
/// <summary>
/// bgt.s &lt;int8 (target)&gt; Branch to target if greater than, short form.
/// </summary>
BgtS = 0x30,
/// <summary>
/// bgt.un &lt;int32 (target)&gt; Branch to target if greater than (unsigned or unordered).
/// </summary>
BgtUn = 0x42,
/// <summary>
/// bgt.un.s &lt;int8 (target)&gt; Branch to target if greater than (unsigned or unordered), short form.
/// </summary>
BgtUnS = 0x35,
/// <summary>
/// ble &lt;int32 (target)&gt; Branch to target if less than or equal to.
/// </summary>
Ble = 0x3E,
/// <summary>
/// ble.s &lt;int8 (target)&gt; Branch to target if less than or equal to, short form.
/// </summary>
BleS = 0x31,
/// <summary>
/// ble.un &lt;int32 (target)&gt; Branch to target if less than or equal to (unsigned or unordered).
/// </summary>
BleUn = 0x43,
/// <summary>
/// ble.un.s &lt;int8 (target)&gt; Branch to target if less than or equal to (unsigned or unordered), short form.
/// </summary>
BleUnS = 0x36,
/// <summary>
/// blt &lt;int32 (target)&gt; Branch to target if less than.
/// </summary>
Blt = 0x3F,
/// <summary>
/// blt.s &lt;int8 (target)&gt; Branch to target if less than, short form.
/// </summary>
BltS = 0x32,
/// <summary>
/// blt.un &lt;int32 (target)&gt; Branch to target if less than (unsigned or unordered).
/// </summary>
BltUn = 0x44,
/// <summary>
/// blt.un.s &lt;int8 (target)&gt; Branch to target if less than (unsigned or unordered), short form.
/// </summary>
BltUnS = 0x37,
/// <summary>
/// bne.un &lt;int32 (target)&gt; Branch to target if unequal or unordered.
/// </summary>
BneUn = 0x40,
/// <summary>
/// bne.un.s &lt;int8 (target)&gt; Branch to target if unequal or unordered, short form.
/// </summary>
BneUnS = 0x33,
/// <summary>
/// Convert a boxable value to its boxed form
/// </summary>
Box = 0x8C,
/// <summary>
/// br &lt;int32 (target)&gt; Branch to target.
/// </summary>
Br = 0x38,
/// <summary>
/// br.s &lt;int8 (target)&gt; Branch to target, short form.
/// </summary>
BrS = 0x2B,
/// <summary>
/// break - Inform a debugger that a breakpoint has been reached.
/// </summary>
Break = 0x01,
/// <summary>
/// brfalse &lt;int32 (target)&gt; - Branch to target if value is zero (false).
/// </summary>
BrFalse = 0x39,
/// <summary>
/// brfalse.s &lt;int8 (target)&gt; - Branch to target if value is zero (false), short form.
/// </summary>
BrFalseS = 0x2C,
/// <summary>
/// brinst &lt;int32 (target)&gt; - Branch to target if value is a non-null object reference (alias for brtrue).
/// </summary>
BrInst = 0x3A,
/// <summary>
/// brinst.s &lt;int8 (target)&gt; - Branch to target if value is a non-null object reference, short form (alias for brtrue.s).
/// </summary>
BrInstS = 0x2D,
/// <summary>
/// brnull &lt;int32 (target)&gt; - Branch to target if value is null (alias for brfalse).
/// </summary>
BrNull = 0x39,
/// <summary>
/// brnull.s &lt;int8 (target)&gt; - Branch to target if value is null (alias for brfalse.s), short form.
/// </summary>
BrNullS = 0x2C,
/// <summary>
/// brtrue &lt;int32 (target)&gt; - Branch to target if value is non-zero (true).
/// </summary>
BrTrue = 0x3A,
/// <summary>
/// brtrue.s &lt;int8 (target)&gt; - Branch to target if value is non-zero (true), short form.
/// </summary>
BrTrueS = 0x2D,
/// <summary>
/// brzero &lt;int32 (target)&gt; - Branch to target if value is zero (alias for brfalse).
/// </summary>
BrZero = 0x39,
/// <summary>
/// brzero.s &lt;int8 (target)&gt; - Branch to target if value is zero (alias for brfalse.s), short form.
/// </summary>
BrZeroS = 0x2C,
/// <summary>
/// call &lt;method&gt; - Call method described by method.
/// </summary>
Call = 0x28,
/// <summary>
/// calli &lt;callsitedescr&gt; - Call method indicated on the stack with arguments described by callsitedescr.
/// </summary>
CallI = 0x29,
/// <summary>
/// callvirt &lt;method&gt; - Call a method associated with an object.
/// </summary>
CallVirt = 0x6F,
/// <summary>
/// castclass &lt;class&gt; - Cast obj to class.
/// </summary>
CastClass = 0x74,
/// <summary>
/// ceq - Push 1 (of type int32) if value1 equals value2, else push 0.
/// </summary>
Ceq = 0x01FE,
/// <summary>
/// cgt - Push 1 (of type int32) if value1 greater that value2, else push 0.
/// </summary>
Cgt = 0x02FE,
/// <summary>
/// cgt.un - Push 1 (of type int32) if value1 greater that value2, unsigned or unordered, else push 0.
/// </summary>
CgtUn = 0x03FE,
/// <summary>
/// Throw ArithmeticException if value is not a finite number.
/// </summary>
CkFinite = 0xC3,
/// <summary>
/// clt - Push 1 (of type int32) if value1 lower than value2, else push 0.
/// </summary>
Clt = 0x04FE,
/// <summary>
/// clt.un - Push 1 (of type int32) if value1 lower than value2, unsigned or unordered, else push 0.
/// </summary>
CltUn = 0x05FE,
/// <summary>
/// constrained &lt;thisType&gt; - Call a virtual method on a type constrained to be type T
/// </summary>
Constrained = 0x16FE,
/// <summary>
/// Convert to native int, pushing native int on stack.
/// </summary>
ConvI = 0xD3,
/// <summary>
/// conv.i1 - Convert to int8, pushing int32 on stack.
/// </summary>
ConvI1 = 0x67,
/// <summary>
/// conv.i2 - Convert to int16, pushing int32 on stack.
/// </summary>
ConvI2 = 0x68,
/// <summary>
/// conv.i4 - Convert to int32, pushing int32 on stack.
/// </summary>
ConvI4 = 0x69,
/// <summary>
/// conv.i8 - Convert to int64, pushing int64 on stack.
/// </summary>
ConvI8 = 0x6A,
/// <summary>
/// conv.ovf.i - Convert to a native int (on the stack as native int) and throw an exception on overflow.
/// </summary>
ConvOvfI = 0xD4,
/// <summary>
/// conv.ovf.i.un - Convert unsigned to a native int (on the stack as native int) and throw an exception on overflow.
/// </summary>
ConvOvfIUn = 0x8A,
/// <summary>
/// conv.ovf.i1 - Convert to an int8 (on the stack as int32) and throw an exception on overflow.
/// </summary>
ConvOvfI1 = 0xB3,
/// <summary>
/// conv.ovf.i1.un - Convert unsigned to an int8 (on the stack as int32) and throw an exception on overflow.
/// </summary>
ConvOvfI1Un = 0x82,
/// <summary>
/// conv.ovf.i2 - Convert to an int16 (on the stack as int32) and throw an exception on overflow.
/// </summary>
ConvOvfI2 = 0xB5,
/// <summary>
/// conv.ovf.i2.un - Convert unsigned to an int16 (on the stack as int32) and throw an exception on overflow.
/// </summary>
ConvOvfI2Un = 0x83,
/// <summary>
/// conv.ovf.i4 - Convert to an int32 (on the stack as int32) and throw an exception on overflow.
/// </summary>
ConvOvfI4 = 0xB7,
/// <summary>
/// conv.ovf.i4.un - Convert unsigned to an int32 (on the stack as int32) and throw an exception on overflow.
/// </summary>
ConvOvfI4Un = 0x84,
/// <summary>
/// conv.ovf.i8 - Convert to an int64 (on the stack as int64) and throw an exception on overflow.
/// </summary>
ConvOvfI8 = 0xB9,
/// <summary>
/// conv.ovf.i8.un - Convert unsigned to an int64 (on the stack as int64) and throw an exception on overflow.
/// </summary>
ConvOvfI8Un = 0x85,
/// <summary>
/// conv.ovf.u - Convert to a native unsigned int (on the stack as native int) and throw an exception on overflow.
/// </summary>
ConvOvfU = 0xD5,
/// <summary>
/// conv.ovf.u.un - Convert unsigned to a native unsigned int (on the stack as native int) and throw an exception on overflow.
/// </summary>
ConvOvfUUn = 0x8B,
/// <summary>
/// conv.ovf.u1 - Convert to an unsigned int8 (on the stack as int32) and throw an exception on overflow.
/// </summary>
ConvOvfU1 = 0xB4,
/// <summary>
/// conv.ovf.u1.un - Convert unsigned to an unsigned int8 (on the stack as int32) and throw an exception on overflow.
/// </summary>
ConvOvfU1Un = 0x86,
/// <summary>
/// conv.ovf.u2 - Convert to an unsigned int16 (on the stack as int32) and throw an exception on overflow.
/// </summary>
ConvOvfU2 = 0xB6,
/// <summary>
/// conv.ovf.u2.un - Convert unsigned to an unsigned int16 (on the stack as int32) and throw an exception on overflow.
/// </summary>
ConvOvfU2Un = 0x87,
/// <summary>
/// conv.ovf.u4 - Convert to an unsigned int32 (on the stack as int32) and throw an exception on overflow.
/// </summary>
ConvOvfU4 = 0xB8,
/// <summary>
/// conv.ovf.u4.un - Convert unsigned to an unsigned int32 (on the stack as int32) and throw an exception on overflow.
/// </summary>
ConvOvfU4Un = 0x88,
/// <summary>
/// conv.ovf.u8 - Convert to an unsigned int64 (on the stack as int64) and throw an exception on overflow.
/// </summary>
ConvOvfU8 = 0xBA,
/// <summary>
/// conv.ovf.u8.un - Convert unsigned to an unsigned int64 (on the stack as int64) and throw an exception on overflow.
/// </summary>
ConvOvfU8Un = 0x89,
/// <summary>
/// conv.r.un - Convert unsigned integer to floating-point, pushing F on stack.
/// </summary>
ConvRUn = 0x76,
/// <summary>
/// conv.r4 - Convert to float32, pushing F on stack.
/// </summary>
ConvR4 = 0x6B,
/// <summary>
/// conv.r8 - Convert to float64, pushing F on stack.
/// </summary>
ConvR8 = 0x6C,
/// <summary>
/// conv.u - Convert to native unsigned int, pushing native int on stack.
/// </summary>
ConvU = 0xE0,
/// <summary>
/// conv.u1 - Convert to unsigned int8, pushing int32 on stack.
/// </summary>
ConvU1 = 0xD2,
/// <summary>
/// conv.u2 - Convert to unsigned int16, pushing int32 on stack.
/// </summary>
ConvU2 = 0xD1,
/// <summary>
/// conv.u4 - Convert to unsigned int32, pushing int32 on stack.
/// </summary>
ConvU4 = 0x6D,
/// <summary>
/// conv.u8 - Convert to unsigned int64, pushing int64 on stack.
/// </summary>
ConvU8 = 0x6E,
/// <summary>
/// cpblk - Copy data from memory to memory.
/// </summary>
CpBlk = 0x17FE,
/// <summary>
/// cpobj &lt;typeTok&gt; - Copy a value type from src to dest.
/// </summary>
CpObj = 0x70,
/// <summary>
/// div - Divide two values to return a quotient or floating-point result.
/// </summary>
Div = 0x5B,
/// <summary>
/// div.un - Divide two values, unsigned, returning a quotient.
/// </summary>
DivUn = 0x5C,
/// <summary>
/// dup - Duplicate the value on the top of the stack.
/// </summary>
Dup = 0x25,
/// <summary>
/// endfault - End fault clause of an exception block.
/// </summary>
EndFault = 0xDC,
/// <summary>
/// endfilter - End an exception handling filter clause.
/// </summary>
EndFilter = 0x11FE,
/// <summary>
/// endfinally - End finally clause of an exception block.
/// </summary>
EndFinally = 0xDC,
/// <summary>
/// initblk - Set all bytes in a block of memory to a given byte value.
/// </summary>
InitBlk = 0x18FE,
/// <summary>
/// initobj &lt;typeTok&gt; - initialize the value at address dest.
/// </summary>
InitObj = 0x15FE,
/// <summary>
/// isinst &lt;class&gt; - Test if obj is an instance of class, returning null or an instance of that class or interface.
/// </summary>
IsInst = 0x75,
/// <summary>
/// jmp &lt;method&gt; - Exit current method and jump to the specified method.
/// </summary>
Jmp = 0x27,
/// <summary>
/// ldarg &lt;uint16 (num)&gt; - Load argument numbered num onto the stack.
/// </summary>
LdArg = 0x09FE,
/// <summary>
/// ldarg.0 - Load argument 0 onto the stack.
/// </summary>
LdArg0 = 0x02,
/// <summary>
/// ldarg.1 - Load argument 1 onto the stack.
/// </summary>
LdArg1 = 0x03,
/// <summary>
/// ldarg.2 - Load argument 2 onto the stack.
/// </summary>
LdArg2 = 0x04,
/// <summary>
/// ldarg.3 - Load argument 3 onto the stack.
/// </summary>
LdArg3 = 0x05,
/// <summary>
/// ldarg.s &lt;uint8 (num)&gt; Load argument numbered num onto the stack, short form.
/// </summary>
LdArgS = 0x0E,
/// <summary>
/// ldarga &lt;uint16 (argNum)&gt; - Fetch the address of argument argNum.
/// </summary>
LdArgA = 0x0AFE,
/// <summary>
/// ldarga.s &lt;uint8 (argNum)&gt; - Fetch the address of argument argNum, short form.
/// </summary>
LdArgAS = 0x0F,
/// <summary>
/// Push num of type int32 onto the stack as int32.
/// </summary>
LdCI4 = 0x20,
/// <summary>
/// ldc.i4.m1 - Push the constant value -1 onto the stack as int32.
/// </summary>
LdCI4_M1 = 0x15,
/// <summary>
/// ldc.i4.0 - Push the constant value 0 onto the stack as int32.
/// </summary>
LdCI4_0 = 0x16,
/// <summary>
/// ldc.i4.1 - Push the constant value 1 onto the stack as int32.
/// </summary>
LdCI4_1 = 0x17,
/// <summary>
/// ldc.i4.2 - Push the constant value 2 onto the stack as int32.
/// </summary>
LdCI4_2 = 0x18,
/// <summary>
/// ldc.i4.3 - Push the constant value 3 onto the stack as int32.
/// </summary>
LdCI4_3 = 0x19,
/// <summary>
/// ldc.i4.4 - Push the constant value 4 onto the stack as int32.
/// </summary>
LdCI4_4 = 0x1A,
/// <summary>
/// ldc.i4.5 - Push the constant value 5 onto the stack as int32.
/// </summary>
LdCI4_5 = 0x1B,
/// <summary>
/// ldc.i4.6 - Push the constant value 6 onto the stack as int32.
/// </summary>
LdCI4_6 = 0x1C,
/// <summary>
/// ldc.i4.7 - Push the constant value 7 onto the stack as int32.
/// </summary>
LdCI4_7 = 0x1D,
/// <summary>
/// ldc.i4.8 - Push the constant value 8 onto the stack as int32.
/// </summary>
LdCI4_8 = 0x1E,
/// <summary>
/// ldc.i4.s &lt;int8 (num)&gt; - Push num onto the stack as int32, short form.
/// </summary>
LdCI4S = 0x1F,
/// <summary>
/// ldc.i8 &lt;int64 (num)&gt; - Push num of type int64 onto the stack as int64.
/// </summary>
LdCI8 = 0x21,
/// <summary>
/// ldc.r4 &lt;float32 (num)&gt; - Push num of type float32 onto the stack as F.
/// </summary>
LdCR4 = 0x22,
/// <summary>
/// ldc.r8 &lt;float64 (num)&gt; - Push num of type float64 onto the stack as F.
/// </summary>
LdCR8 = 0x23,
/// <summary>
/// ldelem &lt;typeTok&gt; - Load the element at index onto the top of the stack.
/// </summary>
LdElem = 0xA3,
/// <summary>
/// ldelem.i - Load the element with type native int at index onto the top of the stack as a native int.
/// </summary>
LdElemI = 0x97,
/// <summary>
/// ldelem.i1 - Load the element with type int8 at index onto the top of the stack as an int32.
/// </summary>
LdElemI1 = 0x90,
/// <summary>
/// ldelem.u1 - Load the element with type unsigned int8 at index onto the top of the stack as an int32.
/// </summary>
LdElemU1 = 0x91,
/// <summary>
/// ldelem.i2 - Load the element with type int16 at index onto the top of the stack as an int32.
/// </summary>
LdElemI2 = 0x92,
/// <summary>
/// ldelem.u1 - Load the element with type unsigned int8 at index onto the top of the stack as an int32.
/// </summary>
LdElemU2 = 0x93,
/// <summary>
/// ldelem.i4 - Load the element with type int32 at index onto the top of the stack as an int32.
/// </summary>
LdElemI4 = 0x94,
/// <summary>
/// ldelem.u1 - Load the element with type unsigned int8 at index onto the top of the stack as an int32.
/// </summary>
LdElemU4 = 0x95,
/// <summary>
/// ldelem.i8 / ldelem.u8 - Load the element with type (unsigned) int64 at index onto the top of the stack as an int64.
/// </summary>
LdElemI8 = 0x96,
/// <summary>
/// ldelem.i4 - Load the element with type float32 at index onto the top of the stack as an F.
/// </summary>
LdElemR4 = 0x98,
/// <summary>
/// ldelem.i8 - Load the element with type float64 at index onto the top of the stack as an F.
/// </summary>
LdElemR8 = 0x99,
/// <summary>
/// ldelem.ref - Load the element at index onto the top of the stack as an O. The type of the O is the same as the element type of the array pushed on the CIL stack.
/// </summary>
LdElemRef = 0x9A,
/// <summary>
/// ldelema &lt;class&gt; - Load the address of element at index onto the top of the stack.
/// </summary>
LdElemA = 0x8F,
/// <summary>
/// ldfld &lt;field&gt; - Push the value of field of object (or value type) obj, onto the stack.
/// </summary>
LdFld = 0x7B,
/// <summary>
/// ldflda &lt;field&gt; - Push the address of field of object obj on the stack.
/// </summary>
LdFldA = 0x7C,
/// <summary>
/// ldftn &lt;method&gt; - Push a pointer to a method referenced by method, on the stack.
/// </summary>
LdFtn = 0x06FE,
/// <summary>
/// ldind.i - Indirect load value of type native int as native int on the stack
/// </summary>
LdIndI = 0x4D,
/// <summary>
/// ldind.i1 - Indirect load value of type int8 as int32 on the stack
/// </summary>
LdIndI1 = 0x46,
/// <summary>
/// ldind.u1 - Indirect load value of type unsigned int8 as int32 on the stack
/// </summary>
LdIndU1 = 0x47,
/// <summary>
/// ldind.i2 - Indirect load value of type int16 as int32 on the stack
/// </summary>
LdIndI2 = 0x48,
/// <summary>
/// ldind.u2 - Indirect load value of type unsigned int16 as int32 on the stack
/// </summary>
LdIndU2 = 0x49,
/// <summary>
/// ldind.i4 - Indirect load value of type int32 as int32 on the stack
/// </summary>
LdIndI4 = 0x4A,
/// <summary>
/// ldind.u4 - Indirect load value of type unsigned int32 as int32 on the stack
/// </summary>
LdIndU4 = 0x4B,
/// <summary>
/// ldind.i8 / ldind.u8 - Indirect load value of type (unsigned) int64 as int64 on the stack
/// </summary>
LdIndI8 = 0x4C,
/// <summary>
/// ldind.r8 - Indirect load value of type float32 as F on the stack
/// </summary>
LdIndR4 = 0x4E,
/// <summary>
/// ldind.r8 - Indirect load value of type float64 as F on the stack
/// </summary>
LdIndR8 = 0x4F,
/// <summary>
/// ldind.ref - Indirect load value of type object ref as O on the stack.
/// </summary>
LdIndRef = 0x50,
/// <summary>
/// ldlen - Push the length (of type native unsigned int) of array on the stack.
/// </summary>
LdLen = 0x8E,
/// <summary>
/// ldloc &lt;uint16 (indx)&gt; - Load local variable of index indx onto stack.
/// </summary>
LdLoc = 0x0CFE,
/// <summary>
/// ldloc.0 - Load local variable 0 onto stack.
/// </summary>
LdLoc0 = 0x06,
/// <summary>
/// ldloc.1 - Load local variable 1 onto stack.
/// </summary>
LdLoc1 = 0x07,
/// <summary>
/// ldloc.2 - Load local variable 2 onto stack.
/// </summary>
LdLoc2 = 0x08,
/// <summary>
/// ldloc.3 - Load local variable 3 onto stack.
/// </summary>
LdLoc3 = 0x09,
/// <summary>
/// ldloc.s &lt;uint8 (indx)&gt; - Load local variable of index indx onto stack, short form.
/// </summary>
LdLocS = 0x11,
/// <summary>
/// ldloca &lt;uint16 (indx)&gt; - Load address of local variable with index indx.
/// </summary>
LdLocA = 0x0DFE,
/// <summary>
/// ldloca.s &lt;uint16 (indx)&gt; - Load address of local variable with index indx, short form.
/// </summary>
LdLocAS = 0x12,
/// <summary>
/// ldnull - Push a null reference on the stack.
/// </summary>
LdNull = 0x14,
/// <summary>
/// ldobj &lt;typeTok&gt; - Copy the value stored at address src to the stack.
/// </summary>
LdObj = 0x71,
/// <summary>
/// ldsfld &lt;field&gt; - Push the value of the static field on the stack.
/// </summary>
LdSFld = 0x7E,
/// <summary>
/// ldsflda &lt;field&gt; - Push the address of the static field, field, on the stack.
/// </summary>
LdSFldA = 0x7F,
/// <summary>
/// ldstr &lt;string&gt; - Push a string object for the literal string.
/// </summary>
LdStr = 0x72,
/// <summary>
/// ldtoken &lt;token&gt; - Convert metadata token to its runtime representation.
/// </summary>
LdToken = 0xD0,
/// <summary>
/// ldvirtftn &lt;method&gt; - Push address of virtual method on the stack.
/// </summary>
LdVirtFtn = 0x07FE,
/// <summary>
/// leave &lt;int32 (target)&gt; - Exit a protected region of code.
/// </summary>
Leave = 0xDD,
/// <summary>
/// leave &lt;int8 (target)&gt; - Exit a protected region of code, short form.
/// </summary>
LeaveS = 0xDE,
/// <summary>
/// localloc - Allocate space from the local memory pool.
/// </summary>
LocAlloc = 0x0FFE,
/// <summary>
/// mkrefany &lt;class&gt; - Push a typed reference to ptr of type class onto the stack.
/// </summary>
MkRefAny = 0xC6,
/// <summary>
/// mul - Multiply values.
/// </summary>
Mul = 0x5A,
/// <summary>
/// mul.ovf - Multiply signed integer values. Signed result shall fit in same size.
/// </summary>
MulOvf = 0xD8,
/// <summary>
/// mul.ovf.un - Multiply unsigned integer values. Unsigned result shall fit in same size.
/// </summary>
MulOvfUn = 0xD9,
/// <summary>
/// neg - Negate value.
/// </summary>
Neg = 0x65,
/// <summary>
/// newarr &lt;etype&gt; - Create a new array with elements of type etype.
/// </summary>
NewArr = 0x8D,
/// <summary>
/// newobj &lt;ctor&gt; - Allocate an uninitialized object or value type and call ctor.
/// </summary>
NewObj = 0x73,
/// <summary>
/// no.{typecheck, rangecheck, nullcheck} - The specified fault check(s) normally performed as part of the execution of the subsequent instruction can/shall be skipped.
/// </summary>
No = 0x19FE,
/// <summary>
/// nop - Do nothing (No operation).
/// </summary>
Nop = 0x00,
/// <summary>
/// not - Bitwise complement (logical not).
/// </summary>
Not = 0x66,
/// <summary>
/// or - Bitwise OR of two integer values, returns an integer.
/// </summary>
Or = 0x60,
/// <summary>
/// pop - Pop value from the stack.
/// </summary>
Pop = 0x26,
/// <summary>
/// readonly. - Specify that the subsequent array address operation performs no type check at runtime, and that it returns a controlled-mutability managed pointer.
/// </summary>
Readonly = 0x1EFE,
/// <summary>
/// refanytype - Push the type token stored in a typed reference.
/// </summary>
RefAnyType = 0x1DFE,
/// <summary>
/// refanyval &lt;type&gt; - Push the address stored in a typed reference.
/// </summary>
RefAnyVal = 0xC2,
/// <summary>
/// rem - Remainder when dividing one value by another.
/// </summary>
Rem = 0x5D,
/// <summary>
/// rem.un - Remainder when dividing one unsigned value by another.
/// </summary>
RemUn = 0x5E,
/// <summary>
/// ret - Return from method, possibly with a value.
/// </summary>
Ret = 0x2A,
/// <summary>
/// rethrow - Rethrow the current exception.
/// </summary>
Rethrow = 0x1AFE,
/// <summary>
/// shl - Shift an integer left (shifting in zeros), return an integer.
/// </summary>
Shl = 0x62,
/// <summary>
/// shr - Shift an integer right (shift in sign), return an integer.
/// </summary>
Shr = 0x63,
/// <summary>
/// shr.un - Shift an integer right (shift in zero), return an integer.
/// </summary>
ShrUn = 0x64,
/// <summary>
/// sizeof &lt;typeTok&gt; - Push the size, in bytes, of a type as an unsigned int32.
/// </summary>
SizeOf = 0x1CFE,
/// <summary>
/// starg &lt;uint16 (num)&gt; - Store value to the argument numbered num.
/// </summary>
StArg = 0x0BFE,
/// <summary>
/// starg.s &lt;uint8 (num)&gt; - Store value to the argument numbered num, short form.
/// </summary>
StArgS = 0x10,
/// <summary>
/// stelem &lt;typeTok&gt; - Replace array element at index with the value on the stack
/// </summary>
StElem = 0xA4,
/// <summary>
/// stelem.i - Replace array element at index with the i value on the stack.
/// </summary>
StElemI = 0x9B,
/// <summary>
/// stelem.i1 - Replace array element at index with the int8 value on the stack.
/// </summary>
StElemI1 = 0x9C,
/// <summary>
/// stelem.i2 - Replace array element at index with the int16 value on the stack.
/// </summary>
StElemI2 = 0x9D,
/// <summary>
/// stelem.i1 - Replace array element at index with the int32 value on the stack.
/// </summary>
StElemI4 = 0x9E,
/// <summary>
/// stelem.i2 - Replace array element at index with the int64 value on the stack.
/// </summary>
StElemI8 = 0x9F,
/// <summary>
/// stelem.r4 - Replace array element at index with the float32 value on the stack.
/// </summary>
StElemR4 = 0xA0,
/// <summary>
/// stelem.r8 - Replace array element at index with the float64 value on the stack.
/// </summary>
StElemR8 = 0xA1,
/// <summary>
/// stelem.ref - Replace array element at index with the ref value on the stack.
/// </summary>
StElemRef = 0xA2,
/// <summary>
/// stfld &lt;field&gt; - Replace the value of field of the object obj with value.
/// </summary>
StFld = 0x7D,
/// <summary>
/// stind.i - Store value of type native int into memory at address
/// </summary>
StIndI = 0xDF,
/// <summary>
/// stind.i1 - Store value of type int8 into memory at address
/// </summary>
StIndI1 = 0x52,
/// <summary>
/// stind.i2 - Store value of type int16 into memory at address
/// </summary>
StIndI2 = 0x53,
/// <summary>
/// stind.i4 - Store value of type int32 into memory at address
/// </summary>
StIndI4 = 0x54,
/// <summary>
/// stind.i8 - Store value of type int64 into memory at address
/// </summary>
StIndI8 = 0x55,
/// <summary>
/// stind.r4 - Store value of type float32 into memory at address
/// </summary>
StIndR4 = 0x56,
/// <summary>
/// stind.r8 - Store value of type float64 into memory at address
/// </summary>
StIndR8 = 0x57,
/// <summary>
/// stind.ref - Store value of type object ref (type O) into memory at address
/// </summary>
StIndRef = 0x51,
/// <summary>
/// stloc &lt;uint16 (indx)&gt; - Pop a value from stack into local variable indx.
/// </summary>
StLoc = 0x0EFE,
/// <summary>
/// stloc.0 - Pop a value from stack into local variable 0.
/// </summary>
StLoc0 = 0x0A,
/// <summary>
/// stloc.1 - Pop a value from stack into local variable 1.
/// </summary>
StLoc1 = 0x0B,
/// <summary>
/// stloc.2 - Pop a value from stack into local variable 2.
/// </summary>
StLoc2 = 0x0C,
/// <summary>
/// stloc.3 - Pop a value from stack into local variable 3.
/// </summary>
StLoc3 = 0x0D,
/// <summary>
/// stloc.s &lt;uint8 (indx)&gt; - Pop a value from stack into local variable indx, short form.
/// </summary>
StLocS = 0x13,
/// <summary>
/// stobj &lt;typeTok&gt; - Store a value of type typeTok at an address.
/// </summary>
StObj = 0x81,
/// <summary>
/// stsfld &lt;field&gt; - Replace the value of the static field with val.
/// </summary>
StSFld = 0x80,
/// <summary>
/// sub - Subtract value2 from value1, returning a new value.
/// </summary>
Sub = 0x59,
/// <summary>
/// sub.ovf - Subtract native int from a native int. Signed result shall fit in same size.
/// </summary>
SubOvf = 0xDA,
/// <summary>
/// sub.ovf.un - Subtract native unsigned int from a native unsigned int. Unsigned result shall fit in same size.
/// </summary>
SubOvfUn = 0xDB,
/// <summary>
/// switch &lt;uint32, int32, int32 (t1..tN)&gt; - Jump to one of n values.
/// </summary>
Switch = 0x45,
/// <summary>
/// tail. - Subsequent call terminates current method.
/// </summary>
Tail = 0x14FE,
/// <summary>
/// throw - Throw an exception.
/// </summary>
Throw = 0x7A,
/// <summary>
/// unaligned.(alignment) - Subsequent pointer instruction might be unaligned.
/// </summary>
Unaligned = 0x12FE,
/// <summary>
/// unbox &lt;valuetype&gt; - Extract a value-type from obj, its boxed representation, and push a controlled-mutability managed pointer to it to the top of the stack.
/// </summary>
Unbox = 0x79,
/// <summary>
/// unbox.any &lt;typeTok&gt; - Extract a value-type from obj, its boxed representation, and copy to the top of the stack
/// </summary>
UnboxAny = 0xA5,
/// <summary>
/// Subsequent pointer reference is volatile.
/// </summary>
Volatile = 0x13FE,
/// <summary>
/// xor - Bitwise XOR of integer values, returns an integer.
/// </summary>
Xor = 0x61
}
}

View File

@ -0,0 +1,314 @@
using System;
using System.Reflection;
using System.Text;
using MBS.Framework.UserInterface;
using MBS.Framework.UserInterface.Controls;
using MBS.Framework.UserInterface.Dialogs;
using MBS.Framework.UserInterface.Layouts;
namespace UniversalEditor.Plugins.Executable.UserInterface.Editors.Executable
{
public class ManagedAssemblyPanel : Container
{
private TextBox txtSearch = null;
private ListView tvTypes = null;
private DefaultTreeModel tmTypes = null;
private TextBox txtSource = null;
private ComboBox cboLanguage = null;
private System.Reflection.Assembly _Assembly = null;
public System.Reflection.Assembly Assembly
{
get { return _Assembly; }
set
{
_Assembly = value;
UpdateTypeList();
}
}
private void UpdateTypeList()
{
tmTypes.Rows.Clear();
Type[] types = null;
try
{
types = _Assembly.GetTypes();
}
catch (System.Reflection.ReflectionTypeLoadException ex)
{
types = ex.Types;
}
for (int i = 0; i < types.Length; i++)
{
if (types[i] == null)
continue;
string[] nameParts = types[i].FullName.Split(new char[] { '.' });
bool nestedClass = false;
while (nameParts[nameParts.Length - 1].Contains("+"))
{
// handle the case of nested classes
nestedClass = true;
Array.Resize<string>(ref nameParts, nameParts.Length + 1);
string[] p = nameParts[nameParts.Length - 2].Split(new char[] { '+' });
nameParts[nameParts.Length - 2] = p[0];
nameParts[nameParts.Length - 1] = p[1];
}
TreeModelRow row = tmTypes.RecursiveCreateTreeModelRow(tmTypes.Columns[0], nameParts, new TreeModelRowColumn[]
{
new TreeModelRowColumn(tmTypes.Columns[1], "Namespace")
});
if (nestedClass)
row.ParentRow.RowColumns[1].Value = "Class";
row.RowColumns.Add(new TreeModelRowColumn(tmTypes.Columns[1], "Class"));
SetupTypeTreeModelRow(row, types[i]);
}
}
private void SetupTypeTreeModelRow(TreeModelRow row, Type type)
{
row.SetExtraData<Type>("item", type);
System.Reflection.BindingFlags bindingFlags = System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Static | BindingFlags.DeclaredOnly;
TreeModelRow rowBaseTypes = new TreeModelRow(new TreeModelRowColumn[]
{
new TreeModelRowColumn(tmTypes.Columns[0], "Base Types")
});
if (type.BaseType != null)
{
TreeModelRow rowBaseType = new TreeModelRow(new TreeModelRowColumn[]
{
new TreeModelRowColumn(tmTypes.Columns[0], type.BaseType.FullName)
});
SetupTypeTreeModelRow(rowBaseType, type.BaseType);
rowBaseTypes.Rows.Add(rowBaseType);
}
row.Rows.Add(rowBaseTypes);
TreeModelRow rowDerivedTypes = new TreeModelRow(new TreeModelRowColumn[]
{
new TreeModelRowColumn(tmTypes.Columns[0], "Derived Types")
});
row.Rows.Add(rowDerivedTypes);
System.Reflection.FieldInfo[] fields = type.GetFields(bindingFlags);
for (int j = 0; j < fields.Length; j++)
{
TreeModelRow row2 = new TreeModelRow(new TreeModelRowColumn[]
{
new TreeModelRowColumn(tmTypes.Columns[0], fields[j]),
new TreeModelRowColumn(tmTypes.Columns[1], "Field")
});
row2.SetExtraData<System.Reflection.FieldInfo>("item", fields[j]);
row.Rows.Add(row2);
}
System.Reflection.EventInfo[] events = type.GetEvents(bindingFlags);
for (int j = 0; j < events.Length; j++)
{
TreeModelRow row2 = new TreeModelRow(new TreeModelRowColumn[]
{
new TreeModelRowColumn(tmTypes.Columns[0], events[j]),
new TreeModelRowColumn(tmTypes.Columns[1], "Event")
});
row2.SetExtraData<System.Reflection.EventInfo>("item", events[j]);
row.Rows.Add(row2);
}
System.Reflection.PropertyInfo[] props = type.GetProperties(bindingFlags);
for (int j = 0; j < props.Length; j++)
{
TreeModelRow row2 = new TreeModelRow(new TreeModelRowColumn[]
{
new TreeModelRowColumn(tmTypes.Columns[0], props[j]),
new TreeModelRowColumn(tmTypes.Columns[1], "Property")
});
row2.SetExtraData<System.Reflection.PropertyInfo>("item", props[j]);
row.Rows.Add(row2);
}
System.Reflection.MethodInfo[] meths = type.GetMethods(bindingFlags);
for (int j = 0; j < meths.Length; j++)
{
if (meths[j].IsSpecialName && (meths[j].Name.StartsWith("set_", StringComparison.OrdinalIgnoreCase) || meths[j].Name.StartsWith("get_", StringComparison.OrdinalIgnoreCase)))
{
// we can be REASONABLY sure that this is a property setter / getter,
// and as we've already gotten all the properties, ignore it
continue;
}
TreeModelRow row2 = new TreeModelRow(new TreeModelRowColumn[]
{
new TreeModelRowColumn(tmTypes.Columns[0], GetMethodTitle(meths[j])),
new TreeModelRowColumn(tmTypes.Columns[1], "Method")
});
row2.SetExtraData<System.Reflection.MethodInfo>("item", meths[j]);
row.Rows.Add(row2);
}
}
private void tsbILSave_Click(object sender, EventArgs e)
{
MemberInfo t = tvTypes.SelectedRows[0].GetExtraData<MemberInfo>("item");
if (t == null)
return;
FileDialog dlg = new FileDialog();
dlg.Text = "Save Code File";
dlg.SelectedFileNames.Clear();
dlg.SelectedFileNames.Add(t.Name + Language.CodeFileExtension);
if (dlg.ShowDialog() == DialogResult.OK)
{
}
}
public ManagedAssemblyPanel()
{
Layout = new BoxLayout(Orientation.Vertical);
Container ctToolbarAndOthers = new Container();
ctToolbarAndOthers.Layout = new BoxLayout(Orientation.Horizontal);
Toolbar tb = new Toolbar();
tb.Items.Add(new ToolbarItemButton("tsbILSave", StockType.Save, tsbILSave_Click));
ctToolbarAndOthers.Controls.Add(tb, new BoxLayout.Constraints(false, true));
cboLanguage = new ComboBox();
cboLanguage.Changed += cboLanguage_Changed;
Type[] codeProviders = MBS.Framework.Reflection.GetAvailableTypes(new Type[] { typeof(CodeProvider) });
DefaultTreeModel tmLanguage = new DefaultTreeModel(new Type[] { typeof(string) });
/*
tmLanguage.Rows.Add(new TreeModelRow(new TreeModelRowColumn[]
{
new TreeModelRowColumn(tmLanguage.Columns[0], "Raw Bytes")
}));
*/
for (int i = 0; i < codeProviders.Length; i++)
{
CodeProvider codeProvider = (codeProviders[i].Assembly.CreateInstance(codeProviders[i].FullName) as CodeProvider);
TreeModelRow row = new TreeModelRow(new TreeModelRowColumn[]
{
new TreeModelRowColumn(tmLanguage.Columns[0], codeProvider.Title)
});
row.SetExtraData<CodeProvider>("provider", codeProvider);
tmLanguage.Rows.Add(row);
}
if (tmLanguage.Rows.Count > 0)
{
cboLanguage.SelectedItem = tmLanguage.Rows[0];
}
cboLanguage.ReadOnly = true;
cboLanguage.Model = tmLanguage;
ctToolbarAndOthers.Controls.Add(cboLanguage, new BoxLayout.Constraints(false, false));
Controls.Add(ctToolbarAndOthers, new BoxLayout.Constraints(false, true));
SplitContainer scLeftRight = new SplitContainer(Orientation.Vertical);
scLeftRight.SplitterPosition = 250;
txtSearch = new TextBox();
scLeftRight.Panel1.Layout = new BoxLayout(Orientation.Vertical);
scLeftRight.Panel1.Controls.Add(txtSearch, new BoxLayout.Constraints(false, true));
tvTypes = new ListView();
tvTypes.SelectionChanged += tvTypes_SelectionChanged;
tmTypes = new DefaultTreeModel(new Type[] { typeof(string), typeof(string) });
tvTypes.Model = tmTypes;
tvTypes.Columns.Add(new ListViewColumnText(tmTypes.Columns[0], "Name"));
tvTypes.Columns.Add(new ListViewColumnText(tmTypes.Columns[1], "Type"));
scLeftRight.Panel1.Controls.Add(tvTypes, new BoxLayout.Constraints(true, true));
scLeftRight.Panel2.Layout = new BoxLayout(Orientation.Vertical);
txtSource = new TextBox();
txtSource.Multiline = true;
scLeftRight.Panel2.Controls.Add(txtSource, new BoxLayout.Constraints(true, true));
Controls.Add(scLeftRight, new BoxLayout.Constraints(true, true));
}
void cboLanguage_Changed(object sender, EventArgs e)
{
CodeProvider provider = cboLanguage.SelectedItem.GetExtraData<CodeProvider>("provider");
Language = provider;
}
private CodeProvider _Language = CodeProvider.CSharp;
public CodeProvider Language
{
get { return _Language; }
set
{
_Language = value;
tvTypes_SelectionChanged(this, EventArgs.Empty);
}
}
private string GetAccessModifiersSourceCode(System.Reflection.PropertyInfo mi)
{
return Language.GetAccessModifiers(mi);
}
private string GetAccessModifiersSourceCode(System.Reflection.MethodInfo mi)
{
return Language.GetAccessModifiers(mi);
}
private string GetAccessModifiersSourceCode(System.Reflection.FieldInfo mi)
{
return Language.GetAccessModifiers(mi);
}
private string GetAccessModifiersSourceCode(Type mi)
{
return Language.GetAccessModifiers(mi);
}
private string GetMethodTitle(System.Reflection.MethodInfo mi)
{
StringBuilder sb = new StringBuilder();
string typeName = Language.GetTypeName(mi.ReturnType);
sb.Append(mi.Name);
sb.Append('(');
sb.Append(')');
sb.Append(" : ");
sb.Append(typeName);
return sb.ToString();
}
private void tvTypes_SelectionChanged(object sender, EventArgs e)
{
if (tvTypes.SelectedRows.Count == 0)
return;
object item = tvTypes.SelectedRows[0].GetExtraData("item");
if (item is Type)
{
Type typ = (item as Type);
txtSource.Text = Language.GetSourceCode(typ, 0);
}
else if (item is System.Reflection.MethodInfo)
{
txtSource.Text = Language.GetSourceCode(item as System.Reflection.MethodInfo, 0);
}
}
}
}

View File

@ -32,10 +32,16 @@
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Editors\Executable\ExecutableEditor.cs" />
<Compile Include="Editors\Executable\ManagedAssemblyPanel.cs" />
<Compile Include="Editors\Executable\CodeProvider.cs" />
<Compile Include="Editors\Executable\CodeProviders\CSharpCodeProvider.cs" />
<Compile Include="Editors\Executable\CodeProviders\VisualBasicCodeProvider.cs" />
<Compile Include="Editors\Executable\ILOpcode.cs" />
</ItemGroup>
<ItemGroup>
<Folder Include="Editors\" />
<Folder Include="Editors\Executable\" />
<Folder Include="Editors\Executable\CodeProviders\" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Libraries\UniversalEditor.Core\UniversalEditor.Core.csproj">