Esempio n. 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);
     }
 }
Esempio n. 2
0
        public static NAPI.KaijuInfoState StateInfo()
        {
            var info = new NAPI.KaijuInfoState();

            NAPI.StateInfo(ref info);
            return(info);
        }
Esempio n. 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);
     }
 }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
 }
Esempio n. 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);
 }
Esempio n. 8
0
        public static UIntPtr?StateAllocMemory(uint size)
        {
            UIntPtr address = UIntPtr.Zero;

            if (NAPI.StateAllocMemory((UIntPtr)size, ref address))
            {
                return(address);
            }
            return(null);
        }
Esempio n. 9
0
        public static UIntPtr?StateStackAddress()
        {
            UIntPtr address = UIntPtr.Zero;

            if (NAPI.StateStackAddress(ref address))
            {
                return(address);
            }
            return(null);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 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);
        }
Esempio n. 13
0
 public static void ContextReturn()
 {
     NAPI.ContextReturn();
 }
Esempio n. 14
0
 public static bool ContextGoTo(string label)
 {
     return(NAPI.ContextGoTo(label));
 }
Esempio n. 15
0
 public static bool StatePopStack(uint size)
 {
     return(NAPI.StatePopStack((UIntPtr)size));
 }
Esempio n. 16
0
 public static uint StateSize()
 {
     return((uint)NAPI.StateSize());
 }
Esempio n. 17
0
 public static bool StateDeallocMemory(UIntPtr address)
 {
     return(NAPI.StateDeallocMemory(address));
 }
Esempio n. 18
0
 public static void Cancel(UIntPtr handle)
 {
     NAPI.Cancel(handle);
 }