本文整理汇总了C#中Drivers.Compiler.IL.ILOp类的典型用法代码示例。如果您正苦于以下问题:C# ILOp类的具体用法?C# ILOp怎么用?C# ILOp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ILOp类属于Drivers.Compiler.IL命名空间,在下文中一共展示了ILOp类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if either or both values to not are floating point values or
/// if the values are 8 bytes in size.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
//Pop item to negate
StackItem itemA = conversionState.CurrentStackFrame.Stack.Peek();
if (itemA.isFloat)
{
//SUPPORT - floats
throw new NotSupportedException("Negate float vals not suppported yet!");
}
if (itemA.sizeOnStackInBytes == 4)
{
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Word, Dest = "$t0" });
//To not, arg Xor -1
conversionState.Append(new ASMOps.Mov() { Dest = "$t4", Src = "0xFFFFFFFF", MoveType = ASMOps.Mov.MoveTypes.ImmediateToReg });
conversionState.Append(new ASMOps.Xor() { Dest = "$t0", Src1 = "$t0", Src2 = "$t4" });
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$t0" });
}
else if (itemA.sizeOnStackInBytes == 8)
{
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Word, Dest = "$t0" });
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Word, Dest = "$t3" });
conversionState.Append(new ASMOps.Mov() { Dest = "$t4", Src = "0xFFFFFFFF", MoveType = ASMOps.Mov.MoveTypes.ImmediateToReg });
conversionState.Append(new ASMOps.Xor() { Dest = "$t0", Src1 = "$t0", Src2 = "$t4" });
conversionState.Append(new ASMOps.Xor() { Dest = "$t3", Src1 = "$t3", Src2 = "$t4" });
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$t3" });
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$t0" });
}
else
{
throw new NotSupportedException("Stack item size not supported by neg op!");
}
}
示例2: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown when loading a static float field.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
//Load static field
//Load the metadata token used to get the type info
int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0);
//Get the type info for the object to load
Type theType = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveType(metadataToken);
Types.TypeInfo theTypeInfo = conversionState.TheILLibrary.GetTypeInfo(theType);
//Get the object size information
int size = theTypeInfo.SizeOnStackInBytes;
//Load the object onto the stack
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "ECX" });
for (int i = size - 4; i >= 0; i -= 4)
{
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "[ECX+" + i.ToString() + "]", Dest = "EAX" });
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "EAX" });
}
int extra = size % 4;
for (int i = extra - 1; i >= 0; i--)
{
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Byte, Src = "[ECX+" + i.ToString() + "]", Dest = "AL" });
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Byte, Src = "AL" });
}
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = false,
sizeOnStackInBytes = size,
isGCManaged = false
});
}
示例3: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if divide operands are floating point numbers or if attempting to divide 64-bit numbers.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// Thrown if either operand is < 4 bytes long.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
StackItem testItem = conversionState.CurrentStackFrame.Stack.Pop();
if (testItem.isFloat)
{
//TODO - Support floats
throw new NotSupportedException("Switch for floats no supported!");
}
else if (testItem.sizeOnStackInBytes != 4)
{
//TODO - Support other sizes
throw new NotSupportedException("Switch for non-int32s not supported!");
}
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EAX" });
for (int i = 0; i < theOp.ValueBytes.Length / 4; i++)
{
int branchOffset = theOp.NextOffset + Utilities.ReadInt32(theOp.ValueBytes, i * 4);
ILOp opToGoTo = conversionState.Input.At(branchOffset);
int branchPos = conversionState.PositionOf(opToGoTo);
conversionState.Append(new ASMOps.Cmp() { Arg1 = "EAX", Arg2 = i.ToString() });
conversionState.Append(new ASMOps.Jmp() { JumpType = ASMOps.JmpOp.JumpEqual, DestILPosition = branchPos });
}
}
示例4: InsertPageFaultDetection
public static void InsertPageFaultDetection(ILConversionState conversionState, string reg, int offset, ILOp.OpCodes opCode)
{
if (PageFaultDetectionEnabled)
{
conversionState.Append(new ASMOps.Call() { Target = PageFaultDetectionMethod });
}
}
示例5: PerformStackOperations
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp)
{
int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0);
FieldInfo theField = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveField(metadataToken);
bool valueisFloat = Utilities.IsFloat(theField.FieldType);
Types.TypeInfo fieldTypeInfo = conversionState.TheILLibrary.GetTypeInfo(theField.FieldType);
int stackSize = fieldTypeInfo.SizeOnStackInBytes;
StackItem objPointer = conversionState.CurrentStackFrame.Stack.Pop();
if ((OpCodes)theOp.opCode.Value == OpCodes.Ldflda)
{
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = false,
sizeOnStackInBytes = 4,
isGCManaged = false
});
}
else
{
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = valueisFloat,
sizeOnStackInBytes = stackSize,
isGCManaged = fieldTypeInfo.IsGCManaged
});
}
}
示例6: PerformStackOperations
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp)
{
//Pop in reverse order to push
StackItem itemB = conversionState.CurrentStackFrame.Stack.Pop();
StackItem itemA = conversionState.CurrentStackFrame.Stack.Pop();
if (itemA.sizeOnStackInBytes == 4 &&
itemB.sizeOnStackInBytes == 4)
{
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = false,
sizeOnStackInBytes = 4,
isGCManaged = false,
isValue = itemA.isValue && itemB.isValue
});
}
else if (itemA.sizeOnStackInBytes == 8 &&
itemB.sizeOnStackInBytes == 8)
{
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = false,
isNewGCObject = false,
sizeOnStackInBytes = 8,
isGCManaged = false,
isValue = itemA.isValue && itemB.isValue
});
}
}
示例7: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown when the metadata token is not for method metadata.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
//Load token i.e. typeref
//It should also support methodref and fieldrefs
int metadataToken = Utilities.ReadInt32(theOp.ValueBytes, 0);
try
{
Type theType = conversionState.Input.TheMethodInfo.UnderlyingInfo.Module.ResolveType(metadataToken);
if (theType == null)
{
throw new NullReferenceException();
}
string typeTableId = conversionState.TheILLibrary.GetTypeInfo(theType).ID;
conversionState.AddExternalLabel(typeTableId);
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = typeTableId });
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = false,
sizeOnStackInBytes = 4,
isGCManaged = false,
isValue = false
});
}
catch
{
throw new NotSupportedException("The metadata token specifies a fieldref or methodref which isn't supported yet!");
}
}
示例8: PerformStackOperations
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp)
{
StackItem itemToConvert = conversionState.CurrentStackFrame.Stack.Pop();
int numBytesToConvertTo = 0;
switch ((OpCodes)theOp.opCode.Value)
{
case OpCodes.Conv_U:
numBytesToConvertTo = 4;
break;
case OpCodes.Conv_U1:
numBytesToConvertTo = 1;
break;
case OpCodes.Conv_U2:
numBytesToConvertTo = 2;
break;
case OpCodes.Conv_U4:
numBytesToConvertTo = 4;
break;
case OpCodes.Conv_U8:
numBytesToConvertTo = 8;
break;
}
bool pushEDX = numBytesToConvertTo == 8;
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
sizeOnStackInBytes = (pushEDX ? 8 : 4),
isFloat = false,
isGCManaged = false
});
}
示例9: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotSupportedException">
/// Thrown if either or both values to shift left are floating point values or
/// if the values are 8 bytes in size.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// Thrown if either or both values to multiply are not 4 or 8 bytes
/// in size or if the values are of different size.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
StackItem theItem = conversionState.CurrentStackFrame.Stack.Peek();
if (theItem.isFloat)
{
//SUPPORT - Not op for floats
throw new NotSupportedException("Not op not supported for float operands!");
}
if (theItem.sizeOnStackInBytes == 4)
{
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EAX" });
conversionState.Append(new ASMOps.Not() { Dest = "EAX" });
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "EAX" });
}
else if (theItem.sizeOnStackInBytes == 8)
{
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EAX" });
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "EBX" });
conversionState.Append(new ASMOps.Not() { Dest = "EAX" });
conversionState.Append(new ASMOps.Not() { Dest = "EBX" });
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "EBX" });
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "EAX" });
}
else
{
throw new NotSupportedException("Not op not supported for operand size!");
}
}
示例10: PerformStackOperations
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp)
{
StackItem addressItem = conversionState.CurrentStackFrame.Stack.Pop();
int bytesToLoad = 0;
switch ((OpCodes)theOp.opCode.Value)
{
case OpCodes.Ldind_U1:
case OpCodes.Ldind_I1:
bytesToLoad = 1;
break;
case OpCodes.Ldind_U2:
case OpCodes.Ldind_I2:
bytesToLoad = 2;
break;
case OpCodes.Ldind_U4:
case OpCodes.Ldind_I4:
case OpCodes.Ldind_I:
bytesToLoad = 4;
break;
case OpCodes.Ldind_I8:
bytesToLoad = 8;
break;
case OpCodes.Ldind_Ref:
bytesToLoad = Options.AddressSizeInBytes;
break;
}
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
sizeOnStackInBytes = bytesToLoad == 8 ? 8 : 4,
isFloat = false,
isGCManaged = false
});
}
示例11: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
int dwordsToRotate = theOp.ValueBytes == null ? 2 : BitConverter.ToInt32(theOp.ValueBytes, 0);
int bytesShift = 0;
for (int i = 0; i < dwordsToRotate; i++)
{
if (i == 0)
{
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "[ESP+" + bytesShift.ToString() + "]", Dest = "EAX" });
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "[ESP+" + (bytesShift + 4).ToString() + "]", Dest = "EBX" });
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "EBX", Dest = "[ESP+" + bytesShift.ToString() + "]" });
}
else if (i == dwordsToRotate - 1)
{
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "EAX", Dest = "[ESP+" + bytesShift.ToString() + "]" });
}
else
{
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "[ESP+" + (bytesShift + 4).ToString() + "]", Dest = "EBX" });
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "EBX", Dest = "[ESP+" + bytesShift.ToString() + "]" });
}
bytesShift += 4;
}
rotateStackItems(conversionState, theOp.StackSwitch_Items, 1);
}
示例12: Convert
/// <summary>
/// See base class documentation.
/// <para>To Do's:</para>
/// <list type="bullet">
/// <item>
/// <term>To do</term>
/// <description>Implement storing of float arguments.</description>
/// </item>
/// </list>
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
/// <exception cref="System.NotImplementedException">
/// Thrown when storing a float argument is required as it currently hasn't been
/// implemented.
/// </exception>
/// <exception cref="System.ArgumentException">
/// Thrown when an invalid number of bytes is specified for the argument to store.
/// </exception>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
//Get the index of the argument to load
Int16 index = 0;
switch ((OpCodes)theOp.opCode.Value)
{
case OpCodes.Starg:
index = Utilities.ReadInt16(theOp.ValueBytes, 0);
break;
case OpCodes.Starg_S:
index = (Int16)theOp.ValueBytes[0];
break;
}
Types.VariableInfo argInfo = conversionState.Input.TheMethodInfo.ArgumentInfos[index];
//Used to store the number of bytes to add to EBP to get to the arg
int BytesOffsetFromEBP = argInfo.Offset;
//Pop the argument value from the stack
int bytesForArg = argInfo.TheTypeInfo.SizeOnStackInBytes;
for (int i = 0; i < bytesForArg; i += 4)
{
conversionState.Append(new ASMOps.Pop() { Size = ASMOps.OperandSize.Dword, Dest = "[EBP+" + (BytesOffsetFromEBP+i) + "]" });
}
//Pop the arg value from our stack
conversionState.CurrentStackFrame.Stack.Pop();
}
示例13: Convert
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
//Save return address
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$ra" });
//Push the previous method's fp
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$fp" });
//Set fp for this method
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Word, Src = "$sp", Dest = "$fp", MoveType = ASMOps.Mov.MoveTypes.RegToReg });
//Allocate stack space for locals
//Only bother if there are any locals
if (conversionState.Input.TheMethodInfo.LocalInfos.Count > 0)
{
int totalBytes = 0;
foreach (Types.VariableInfo aLocal in conversionState.Input.TheMethodInfo.LocalInfos)
{
totalBytes += aLocal.TheTypeInfo.SizeOnStackInBytes;
}
//We do not use "sub esp, X" (see below) because that leaves
//junk memory - we need memory to be "initialised" to 0
//so that local variables are null unless properly initialised.
//This prevents errors in the GC.
for (int i = 0; i < totalBytes / 4; i++)
{
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Word, Src = "$zero" });
}
//result.AppendLine(string.Format("sub esp, {0}", totalBytes));
}
}
示例14: Convert
/// <summary>
/// See base class documentation.
/// </summary>
/// <param name="theOp">See base class documentation.</param>
/// <param name="conversionState">See base class documentation.</param>
/// <returns>See base class documentation.</returns>
public override void Convert(ILConversionState conversionState, ILOp theOp)
{
//Push the previous method's ebp
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "EBP" });
//Set ebp for this method
//See calling convention spec - this allows easy access of
//args and locals within the method without having to track
//temporary values (which would be a nightmare with the
//exception handling implementation that the kernel uses!)
conversionState.Append(new ASMOps.Mov() { Size = ASMOps.OperandSize.Dword, Src = "ESP", Dest = "EBP" });
//Allocate stack space for locals
//Only bother if there are any locals
if (conversionState.Input.TheMethodInfo.LocalInfos.Count > 0)
{
int totalBytes = 0;
foreach (Types.VariableInfo aLocal in conversionState.Input.TheMethodInfo.LocalInfos)
{
totalBytes += aLocal.TheTypeInfo.SizeOnStackInBytes;
}
//We do not use "sub esp, X" (see below) because that leaves
//junk memory - we need memory to be "initialised" to 0
//so that local variables are null unless properly initialised.
//This prevents errors in the GC.
for (int i = 0; i < totalBytes / 4; i++)
{
conversionState.Append(new ASMOps.Push() { Size = ASMOps.OperandSize.Dword, Src = "0" });
}
//result.AppendLine(string.Format("sub esp, {0}", totalBytes));
}
}
示例15: PerformStackOperations
public override void PerformStackOperations(ILPreprocessState conversionState, ILOp theOp)
{
MethodBase constructorMethod = theOp.MethodToCall;
Type objectType = constructorMethod.DeclaringType;
if (typeof(Delegate).IsAssignableFrom(objectType))
{
StackItem funcPtrItem = conversionState.CurrentStackFrame.Stack.Pop(); ;
conversionState.CurrentStackFrame.Stack.Pop();
conversionState.CurrentStackFrame.Stack.Push(funcPtrItem);
return;
}
Types.MethodInfo constructorMethodInfo = conversionState.TheILLibrary.GetMethodInfo(constructorMethod);
ParameterInfo[] allParams = constructorMethod.GetParameters();
foreach (ParameterInfo aParam in allParams)
{
conversionState.CurrentStackFrame.Stack.Pop();
}
conversionState.CurrentStackFrame.Stack.Push(new StackItem()
{
isFloat = false,
sizeOnStackInBytes = 4,
isNewGCObject = true,
isGCManaged = true,
isValue = false
});
}