Exemple #1
0
        public void Load(DarksVMContext ctx, out ExecutionState state)
        {
            var sp       = ctx.Registers[DarksVMConstants.REG_SP].U4;
            var typeSlot = ctx.Stack[sp--];
            var valSlot  = ctx.Stack[sp];

            var unboxPtr = (typeSlot.U4 & 0x80000000) != 0;
            var valType  = (Type)ctx.Instance.Data.LookupReference(typeSlot.U4 & ~0x80000000);

            if (unboxPtr)
            {
                unsafe
                {
                    TypedReference typedRef;
                    TypedReferenceHelpers.UnboxTypedRef(valSlot.O, &typedRef);
                    var reference = new TypedRef(typedRef);
                    valSlot       = DarksVMSlot.FromObject(valSlot.O, valType);
                    ctx.Stack[sp] = valSlot;
                }
            }
            else
            {
                if (valType == typeof(object) && valSlot.O != null)
                {
                    valType = valSlot.O.GetType();
                }
                valSlot       = DarksVMSlot.FromObject(valSlot.O, valType);
                ctx.Stack[sp] = valSlot;
            }

            ctx.Stack.SetTopPosition(sp);
            ctx.Registers[DarksVMConstants.REG_SP].U4 = sp;
            state = ExecutionState.Next;
        }
Exemple #2
0
        internal unsafe override void EmulateVCall(EmuContext ctx)
        {
            VMSlot slot  = ctx.Stack.Pop();
            VMSlot value = ctx.Stack.Pop();
            bool   flag  = (slot.U4 & 2147483648u) > 0u;
            Type   type  = (Type)ctx.Header.References[slot.U4 & 2147483647u];

            if (flag)
            {
                TypedReference typedRef;
                Helpers.TypedReferenceHelpers.UnboxTypedRef(value.O, (void *)(&typedRef));
                TypedRef typedRef2 = new TypedRef(typedRef);
                value = VMSlot.FromObject(value.O, type);
                ctx.Stack.Push(value);
            }
            else
            {
                bool flag3 = type == typeof(object) && value.O != null;
                if (flag3)
                {
                    type = value.O.GetType();
                }
                value = VMSlot.FromObject(value.O, type);
                ctx.Stack.Push(value);
            }
        }
Exemple #3
0
 public static unsafe void putObject(Unsafe @this, object ptr, long offset, object value)
 {
     if (ptr is Array arr)
     {
         arr.SetValue(value, offset / ArrayScale(ptr.GetType()));
     }
     else
     {
         var tr  = new TypedRef(new IntPtr(index(ptr, offset)), value?.GetType().TypeHandle.Value ?? typeof(object).TypeHandle.Value);
         var tr2 = *((TypedReference *)&tr);
         __refvalue(tr2, object) = value;
     }
 }
Exemple #4
0
        public static unsafe object getObject(Unsafe @this, object ptr, long offset)
        {
            if (ptr is Array arr)
            {
                return(arr.GetValue(offset / ArrayScale(ptr.GetType())));
            }

            var tr  = new TypedRef(new IntPtr(index(ptr, offset)), typeof(object).TypeHandle.Value);
            var tr2 = *((TypedReference *)&tr);
            var o   = __refvalue(tr2, object);

            return(o);
        }