Esempio n. 1
0
        public static ExecutionState Load(DarksVMContext ctx)
        {
            ExecutionState state      = ExecutionState.Next;
            bool           isAbnormal = true;

            do
            {
                try
                {
                    state = DarkInternal(ctx);
                    switch (state)
                    {
                    case ExecutionState.Throw:
                    {
                        uint        sp = ctx.Registers[DarksVMConstants.REG_SP].U4;
                        DarksVMSlot ex = ctx.Stack[sp--];
                        ctx.Registers[DarksVMConstants.REG_SP].U4 = sp;
                        DoThrow(ctx, ex.O);
                        break;
                    }

                    case ExecutionState.Rethrow:
                    {
                        uint        sp = ctx.Registers[DarksVMConstants.REG_SP].U4;
                        DarksVMSlot ex = ctx.Stack[sp--];
                        ctx.Registers[DarksVMConstants.REG_SP].U4 = sp;
                        HandleRethrow(ctx, ex.O);
                        return(state);
                    }
                    }
                    isAbnormal = false;
                }
                catch (Exception ex)
                {
                    // Patched to catch object
                    SetupEHState(ctx, ex);
                    isAbnormal = false;
                }
                finally
                {
                    if (isAbnormal)
                    {
                        HandleAbnormalExit(ctx);
                        state = ExecutionState.Exit;
                    }
                    else if (ctx.EHStates.Count > 0)
                    {
                        do
                        {
                            HandleEH(ctx, ref state);
                        } while(state == ExecutionState.Rethrow);
                    }
                }
            } while(state != ExecutionState.Exit);
            return(state);
        }
Esempio n. 2
0
        public DarksVMSlot GetValue(DarksVMContext ctx, PointerType type)
        {
            object inst = this.instance;

            if (this.field.DeclaringType.IsValueType && this.instance is IReference)
            {
                inst = ((IReference)this.instance).GetValue(ctx, PointerType.OBJECT).ToObject(this.field.DeclaringType);
            }
            return(DarksVMSlot.FromObject(this.field.GetValue(inst), this.field.FieldType));
        }
Esempio n. 3
0
 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));
     }
 }
Esempio n. 4
0
        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)));
        }
Esempio n. 5
0
 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;
 }
Esempio n. 6
0
        private static void HandleAbnormalExit(DarksVMContext ctx)
        {
            DarksVMSlot oldBP = ctx.Registers[DarksVMConstants.REG_BP];
            DarksVMSlot oldSP = ctx.Registers[DarksVMConstants.REG_SP];

            for (int i = ctx.EHStack.Count - 1; i >= 0; i--)
            {
                EHFrame frame = ctx.EHStack[i];
                if (frame.EHType == DarksVMConstants.EH_FAULT || frame.EHType == DarksVMConstants.EH_FINALLY)
                {
                    SetupFinallyFrame(ctx, frame);
                    Load(ctx);
                }
            }
            ctx.EHStack.Clear();
        }
Esempio n. 7
0
        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);
        }
Esempio n. 8
0
        public DarksVMSlot GetValue(DarksVMContext ctx, PointerType type)
        {
            DarksVMSlot slot = ctx.Stack[this.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);
        }
Esempio n. 9
0
 public void SetValue(DarksVMContext ctx, DarksVMSlot slot, PointerType type)
 {
     throw new NotSupportedException();
 }