Exemple #1
0
 public extern static bool Consume(
     UIntPtr handle,
     [MarshalAs(UnmanagedType.FunctionPtr)]
     OnProcessOp onProcessOp,
     IntPtr processorContext,
     [MarshalAs(UnmanagedType.FunctionPtr)]
     OnError onError,
     IntPtr errorContext
     );
Exemple #2
0
 public extern static bool Run(
     IntPtr bytes,
     UIntPtr size,
     [MarshalAs(UnmanagedType.LPStr)]
     string entry,
     UIntPtr memSize,
     UIntPtr stackSize,
     [MarshalAs(UnmanagedType.FunctionPtr)]
     OnProcessOp onProcessOp,
     IntPtr processorContext,
     [MarshalAs(UnmanagedType.FunctionPtr)]
     OnError onError,
     IntPtr errorContext
     );
Exemple #3
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);
        }
Exemple #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);
        }