Пример #1
0
 public static void StateStoreBytes(UIntPtr address, byte[] bytes)
 {
     if ((ulong)address + (ulong)bytes.Length <= (ulong)NAPI.StateSize())
     {
         Marshal.Copy(bytes, 0, NAPI.StatePtrMut(address), bytes.Length);
     }
 }
Пример #2
0
        public static NAPI.KaijuInfoState StateInfo()
        {
            var info = new NAPI.KaijuInfoState();

            NAPI.StateInfo(ref info);
            return(info);
        }
Пример #3
0
 public static void StateStore <T>(UIntPtr address, T value) where T : struct
 {
     if ((ulong)address + (ulong)Marshal.SizeOf <T>() <= (ulong)NAPI.StateSize())
     {
         Marshal.StructureToPtr(value, NAPI.StatePtr(address), false);
     }
 }
Пример #4
0
        public static bool Run(byte[] bytes, string entry, uint memSize, uint stackSize, OnProcessOp onProcessOp, OnError onError = null)
        {
            IntPtr buffer = Marshal.AllocHGlobal(bytes.Length);

            Marshal.Copy(bytes, 0, buffer, bytes.Length);
            var result = false;

            try
            {
                result = NAPI.Run(
                    buffer,
                    (UIntPtr)bytes.Length,
                    entry,
                    (UIntPtr)memSize,
                    (UIntPtr)stackSize,
                    (context, op, paramsPtrs, paramsCount, targetsPtrs, targetsCount) =>
                {
                    onProcessOp?.Invoke(op, MakePointers(paramsPtrs, paramsCount), MakePointers(targetsPtrs, targetsCount));
                },
                    IntPtr.Zero,
                    (context, error) => onError?.Invoke(error),
                    IntPtr.Zero
                    );
            }
            catch (Exception error)
            {
                onError?.Invoke(error.Message);
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
            return(result);
        }
Пример #5
0
        public static UIntPtr Start(byte[] bytes, string entry, uint memSize, uint stackSize, OnError onError = null)
        {
            IntPtr buffer = Marshal.AllocHGlobal(bytes.Length);

            Marshal.Copy(bytes, 0, buffer, bytes.Length);
            var result = UIntPtr.Zero;

            try
            {
                result = NAPI.Start(
                    buffer,
                    (UIntPtr)bytes.Length,
                    entry,
                    (UIntPtr)memSize,
                    (UIntPtr)stackSize,
                    (context, error) => onError?.Invoke(error),
                    IntPtr.Zero
                    );
            }
            catch (Exception error)
            {
                onError?.Invoke(error.Message);
            }
            finally
            {
                Marshal.FreeHGlobal(buffer);
            }
            return(result);
        }
Пример #6
0
 public static T?StateLoad <T>(UIntPtr address) where T : struct
 {
     if ((ulong)address + (ulong)Marshal.SizeOf <T>() <= (ulong)NAPI.StateSize())
     {
         return(Marshal.PtrToStructure <T>(NAPI.StatePtr(address)));
     }
     return(null);
 }
Пример #7
0
 public static byte[] StateLoadBytes(UIntPtr address, int size)
 {
     if ((ulong)address + (ulong)size <= (ulong)NAPI.StateSize())
     {
         var result = new byte[size];
         Marshal.Copy(NAPI.StatePtrMut(address), result, 0, size);
         return(result);
     }
     return(null);
 }
Пример #8
0
        public static UIntPtr?StateAllocMemory(uint size)
        {
            UIntPtr address = UIntPtr.Zero;

            if (NAPI.StateAllocMemory((UIntPtr)size, ref address))
            {
                return(address);
            }
            return(null);
        }
Пример #9
0
        public static UIntPtr?StateStackAddress()
        {
            UIntPtr address = UIntPtr.Zero;

            if (NAPI.StateStackAddress(ref address))
            {
                return(address);
            }
            return(null);
        }
Пример #10
0
        public static bool With(UIntPtr handle, OnPerform onPerform, OnError onError = null)
        {
            var result = false;

            try
            {
                result = NAPI.With(
                    handle,
                    (context) => onPerform?.Invoke(),
                    IntPtr.Zero,
                    (context, error) => onError?.Invoke(error),
                    IntPtr.Zero
                    );
            }
            catch (Exception error)
            {
                onError?.Invoke(error.Message);
            }
            return(result);
        }
Пример #11
0
        public static UIntPtr Fork(UIntPtr handle, string entry, uint memSize, uint stackSize, OnError onError = null)
        {
            var result = UIntPtr.Zero;

            try
            {
                result = NAPI.Fork(
                    handle,
                    entry,
                    (UIntPtr)memSize,
                    (UIntPtr)stackSize,
                    (context, error) => onError?.Invoke(error),
                    IntPtr.Zero
                    );
            }
            catch (Exception error)
            {
                onError?.Invoke(error.Message);
            }
            return(result);
        }
Пример #12
0
        public static bool Resume(UIntPtr handle, OnProcessOp onProcessOp, OnError onError = null)
        {
            var result = false;

            try
            {
                result = NAPI.Resume(
                    handle,
                    (context, op, paramsPtrs, paramsCount, targetsPtrs, targetsCount) =>
                {
                    onProcessOp?.Invoke(op, MakePointers(paramsPtrs, paramsCount), MakePointers(targetsPtrs, targetsCount));
                },
                    IntPtr.Zero,
                    (context, error) => onError?.Invoke(error),
                    IntPtr.Zero
                    );
            }
            catch (Exception error)
            {
                onError?.Invoke(error.Message);
            }
            return(result);
        }
Пример #13
0
 public static void ContextReturn()
 {
     NAPI.ContextReturn();
 }
Пример #14
0
 public static bool ContextGoTo(string label)
 {
     return(NAPI.ContextGoTo(label));
 }
Пример #15
0
 public static bool StatePopStack(uint size)
 {
     return(NAPI.StatePopStack((UIntPtr)size));
 }
Пример #16
0
 public static uint StateSize()
 {
     return((uint)NAPI.StateSize());
 }
Пример #17
0
 public static bool StateDeallocMemory(UIntPtr address)
 {
     return(NAPI.StateDeallocMemory(address));
 }
Пример #18
0
 public static void Cancel(UIntPtr handle)
 {
     NAPI.Cancel(handle);
 }