private static void SetupFinallyFrame(DarksVMContext ctx, EHFrame frame) { frame.SP.U4++; ctx.Registers[DarksVMConstants.REG_K1].U1 = 0; ctx.Registers[DarksVMConstants.REG_SP] = frame.SP; ctx.Registers[DarksVMConstants.REG_BP] = frame.BP; ctx.Registers[DarksVMConstants.REG_IP].U8 = frame.HandlerAddr; ctx.Stack[frame.SP.U4] = new DarksVMSlot { U8 = 1 }; }
public unsafe void SetValue(DarksVMContext ctx, DarksVMSlot slot, PointerType type) { if (this.field.DeclaringType.IsValueType && this.instance is IReference) { TypedReference typedRef; ((IReference)this.instance).ToTypedReference(ctx, &typedRef, this.field.DeclaringType); this.field.SetValueDirect(typedRef, slot.ToObject(this.field.FieldType)); } else { this.field.SetValue(this.instance, slot.ToObject(this.field.FieldType)); } }
public DarksVMSlot GetValue(DarksVMContext ctx, PointerType type) { TypedReference typedRef; if (this._ptr != null) { *&typedRef = *(TypedReference *)this._ptr.Value; } else { *(PseudoTypedRef *)&typedRef = this._typedRef; } return(DarksVMSlot.FromObject(TypedReference.ToObject(typedRef), __reftype(typedRef))); }
private static void HandleAbnormalExit(DarksVMContext ctx) { var oldBP = ctx.Registers[DarksVMConstants.REG_BP]; var oldSP = ctx.Registers[DarksVMConstants.REG_SP]; for (var i = ctx.EHStack.Count - 1; i >= 0; i--) { var frame = ctx.EHStack[i]; if (frame.EHType == DarksVMConstants.EH_FAULT || frame.EHType == DarksVMConstants.EH_FINALLY) { SetupFinallyFrame(ctx, frame); Load(ctx); } } ctx.EHStack.Clear(); }
public void SetValue(DarksVMContext ctx, DarksVMSlot slot, PointerType type) { if (type == PointerType.BYTE) { slot.U8 = slot.U1; } else if (type == PointerType.WORD) { slot.U8 = slot.U2; } else if (type == PointerType.DWORD) { slot.U8 = slot.U4; } ctx.Stack[StackPos] = slot; }
public void SetValue(DarksVMContext ctx, DarksVMSlot slot, PointerType type) { TypedReference typedRef; if (this._ptr != null) { *&typedRef = *(TypedReference *)this._ptr.Value; } else { *(PseudoTypedRef *)&typedRef = this._typedRef; } Type refType = __reftype(typedRef); object value = slot.ToObject(refType); TypedReferenceHelpers.SetTypedRef(value, &typedRef); }
private static ExecutionState DarkInternal(DarksVMContext ctx) { ExecutionState state; while (true) { var op = ctx.ReadByte(); var p = ctx.ReadByte(); // For key fixup OpCodeMap.Lookup(op).Load(ctx, out state); if (ctx.Registers[DarksVMConstants.REG_IP].U8 == 1) { state = ExecutionState.Exit; } if (state != ExecutionState.Next) { return(state); } } }
public DarksVMSlot GetValue(DarksVMContext ctx, PointerType type) { var slot = ctx.Stack[StackPos]; if (type == PointerType.BYTE) { slot.U8 = slot.U1; } else if (type == PointerType.WORD) { slot.U8 = slot.U2; } else if (type == PointerType.DWORD) { slot.U8 = slot.U4; } else if (slot.O is IValueTypeBox) { slot.O = ((IValueTypeBox)slot.O).Clone(); } return(slot); }
private static void HandleEH(DarksVMContext ctx, ref ExecutionState state) { var ehState = ctx.EHStates[ctx.EHStates.Count - 1]; switch (ehState.CurrentProcess) { case EHState.EHProcess.Searching: { if (ehState.CurrentFrame != null) { // Return from filter var filterResult = ctx.Registers[DarksVMConstants.REG_R1].U1 != 0; if (filterResult) { ehState.CurrentProcess = EHState.EHProcess.Unwinding; ehState.HandlerFrame = ehState.CurrentFrame; ehState.CurrentFrame = ctx.EHStack.Count; state = ExecutionState.Next; goto case EHState.EHProcess.Unwinding; } ehState.CurrentFrame--; } else { ehState.CurrentFrame = ctx.EHStack.Count - 1; } var exType = ehState.ExceptionObj.GetType(); for (; ehState.CurrentFrame >= 0 && ehState.HandlerFrame == null; ehState.CurrentFrame--) { var frame = ctx.EHStack[ehState.CurrentFrame.Value]; if (frame.EHType == DarksVMConstants.EH_FILTER) { // Run filter var sp = ehState.OldSP.U4; ctx.Stack.SetTopPosition(++sp); ctx.Stack[sp] = new DarksVMSlot { O = ehState.ExceptionObj }; ctx.Registers[DarksVMConstants.REG_K1].U1 = 0; ctx.Registers[DarksVMConstants.REG_SP].U4 = sp; ctx.Registers[DarksVMConstants.REG_BP] = frame.BP; ctx.Registers[DarksVMConstants.REG_IP].U8 = frame.FilterAddr; break; } if (frame.EHType == DarksVMConstants.EH_CATCH) { if (frame.CatchType.IsAssignableFrom(exType)) { ehState.CurrentProcess = EHState.EHProcess.Unwinding; ehState.HandlerFrame = ehState.CurrentFrame; ehState.CurrentFrame = ctx.EHStack.Count; goto case EHState.EHProcess.Unwinding; } } } if (ehState.CurrentFrame == -1 && ehState.HandlerFrame == null) { ctx.EHStates.RemoveAt(ctx.EHStates.Count - 1); state = ExecutionState.Rethrow; if (ctx.EHStates.Count == 0) { HandleRethrow(ctx, ehState.ExceptionObj); } } else { state = ExecutionState.Next; } break; } case EHState.EHProcess.Unwinding: { ehState.CurrentFrame--; int i; for (i = ehState.CurrentFrame.Value; i > ehState.HandlerFrame.Value; i--) { var frame = ctx.EHStack[i]; ctx.EHStack.RemoveAt(i); if (frame.EHType == DarksVMConstants.EH_FAULT || frame.EHType == DarksVMConstants.EH_FINALLY) { // Run finally SetupFinallyFrame(ctx, frame); break; } } ehState.CurrentFrame = i; if (ehState.CurrentFrame == ehState.HandlerFrame) { var frame = ctx.EHStack[ehState.HandlerFrame.Value]; ctx.EHStack.RemoveAt(ehState.HandlerFrame.Value); // Run handler frame.SP.U4++; ctx.Stack.SetTopPosition(frame.SP.U4); ctx.Stack[frame.SP.U4] = new DarksVMSlot { O = ehState.ExceptionObj }; ctx.Registers[DarksVMConstants.REG_K1].U1 = 0; ctx.Registers[DarksVMConstants.REG_SP] = frame.SP; ctx.Registers[DarksVMConstants.REG_BP] = frame.BP; ctx.Registers[DarksVMConstants.REG_IP].U8 = frame.HandlerAddr; ctx.EHStates.RemoveAt(ctx.EHStates.Count - 1); } state = ExecutionState.Next; break; } default: throw new ExecutionEngineException(); } }
public void ToTypedReference(DarksVMContext ctx, TypedRefPtr typedRef, Type type) { ctx.Stack.ToTypedReference(StackPos, typedRef, type); }
public void ToTypedReference(DarksVMContext ctx, TypedRefPtr typedRef, Type type) { TypedReferenceHelpers.GetFieldAddr(ctx, this.instance, this.field, typedRef); }
public void ToTypedReference(DarksVMContext ctx, TypedRefPtr typedRef, Type type) { TypedReferenceHelpers.MakeTypedRef(this.ptr, typedRef, type); }
public void SetValue(DarksVMContext ctx, DarksVMSlot slot, PointerType type) { throw new NotSupportedException(); }
public DarksVMSlot GetValue(DarksVMContext ctx, PointerType type) { throw new NotSupportedException(); }