コード例 #1
0
        public void MemUnmap(ulong address, ulong size)
        {
            var err = UcNative.UcMemUnmap(Handle, address, size);

            if (err != UcErr.UC_ERR_OK)
            {
                throw new UcException(err);
            }
        }
コード例 #2
0
        public void HookDel(IntPtr hookHandle)
        {
            var err = UcNative.UcHookDel(Handle, hookHandle);

            if (err != UcErr.UC_ERR_OK)
            {
                throw new UcException(err);
            }
        }
コード例 #3
0
        public void MemMapPtr(ulong address, ulong size, IntPtr ptr, UcProt perms = UcProt.UC_PROT_ALL)
        {
            var err = UcNative.UcMemMapPtr(Handle, address, size, perms, ptr);

            if (err != UcErr.UC_ERR_OK)
            {
                throw new UcException(err);
            }
        }
コード例 #4
0
        public void EmuStop()
        {
            var err = UcNative.UcEmuStop(Handle);

            if (err != UcErr.UC_ERR_OK)
            {
                throw new UcException(err);
            }
        }
コード例 #5
0
        public void ContextRestore(IntPtr context)
        {
            var err = UcNative.UcContextRestore(Handle, context);

            if (err != UcErr.UC_ERR_OK)
            {
                throw new UcException(err);
            }
        }
コード例 #6
0
        public void EmuStart(ulong begin, ulong until, ulong timeout = 0, ulong size = 0)
        {
            var err = UcNative.UcEmuStart(Handle, begin, until, timeout, size);

            if (err != UcErr.UC_ERR_OK)
            {
                throw new UcException(err);
            }
        }
コード例 #7
0
        public void Dispose()
        {
            var err = UcNative.UcClose(Handle);

            if (err != UcErr.UC_ERR_OK)
            {
                throw new UcException($"Failed to close native Unicorn instance, error {err}.", err);
            }
        }
コード例 #8
0
        public void RegWrite(int registerId, ulong data)
        {
            var err = UcNative.UcRegWrite(Handle, registerId, ref data);

            if (err != UcErr.UC_ERR_OK)
            {
                throw new UcException(err);
            }
        }
コード例 #9
0
        /// <summary>
        ///     Free the memory allocated by uc_context_alloc & uc_mem_regions.
        /// </summary>
        /// <param name="mem">
        ///     memory allocated by uc_context_alloc (returned in *context),
        ///     or by uc_mem_regions (returned in *regions)
        /// </param>
        public void Free(IntPtr mem)
        {
            var err = UcNative.UcFree(mem);

            if (err != UcErr.UC_ERR_OK)
            {
                throw new UcException(err);
            }
        }
コード例 #10
0
        public void MemProtect(ulong address, ulong size, UcProt perms = UcProt.UC_PROT_ALL)
        {
            var err = UcNative.UcMemProtect(Handle, address, size, perms);

            if (err != UcErr.UC_ERR_OK)
            {
                throw new UcException(err);
            }
        }
コード例 #11
0
        public ulong RegRead(int registerId)
        {
            var err = UcNative.UcRegRead(Handle, registerId, out var result);

            if (err != UcErr.UC_ERR_OK)
            {
                throw new UcException(err);
            }

            return(result);
        }
コード例 #12
0
        public IntPtr ContextAlloc()
        {
            var err = UcNative.UcContextAlloc(Handle, out var context);

            if (err != UcErr.UC_ERR_OK)
            {
                throw new UcException(err);
            }

            return(context);
        }
コード例 #13
0
        public ulong Query(UcQueryType type)
        {
            var err = UcNative.UcQuery(Handle, type, out var result);

            if (err != UcErr.UC_ERR_OK)
            {
                throw new UcException(err);
            }

            return(result);
        }
コード例 #14
0
        public unsafe void MemWrite(ulong address, Span <byte> bytes)
        {
            fixed(byte *pBytes = bytes)
            {
                var err = UcNative.UcMemWrite(Handle, address, pBytes, (ulong)bytes.Length);

                if (err != UcErr.UC_ERR_OK)
                {
                    throw new UcException(err);
                }
            }
        }
コード例 #15
0
        public unsafe void MemRead(ulong address, ulong size, Span <byte> dest)
        {
            fixed(byte *destPtr = dest)
            {
                var err = UcNative.UcMemRead(Handle, address, destPtr, size);

                if (err != UcErr.UC_ERR_OK)
                {
                    throw new UcException(err);
                }
            }
        }
コード例 #16
0
        private IntPtr HookAdd(UcHookType type, Delegate callback, Delegate userCallback, object userData = null, ulong begin = 1, ulong end = 0)
        {
            var callbackId   = _callbackId++;
            var callbackData = new UnicornCallbackData(callback, userCallback, userData);
            var err          = UcNative.UcHookAdd(Handle, out var result, type, callback, new IntPtr(callbackId), begin, end);

            if (err != UcErr.UC_ERR_OK)
            {
                throw new UcException(err);
            }

            _callbacks.Add(callbackId, callbackData);

            return(result);
        }
コード例 #17
0
        public Unicorn(UcArch arch, UcMode mode)
        {
            _callbacks  = new Dictionary <int, UnicornCallbackData>();
            _callbackId = 0;

            var result = Marshal.AllocHGlobal(Marshal.SizeOf <IntPtr>());
            var err    = UcNative.UcOpen(arch, mode, result);

            if (err != UcErr.UC_ERR_OK)
            {
                throw new UcException($"Failed to create native Unicorn instance, error {err}.", err);
            }

            Handle = (IntPtr)Marshal.PtrToStructure(result, typeof(IntPtr));
        }
コード例 #18
0
        public unsafe byte[] MemRead(ulong address, ulong size)
        {
            var result = new byte[size];

            fixed(byte *pBytes = result)
            {
                var err = UcNative.UcMemRead(Handle, address, pBytes, size);

                if (err != UcErr.UC_ERR_OK)
                {
                    throw new UcException(err);
                }
            }

            return(result);
        }
コード例 #19
0
        public IEnumerable <UcMemRegion> MemRegions()
        {
            var err = UcNative.UcMemRegions(Handle, out var regions, out var count);

            if (err != UcErr.UC_ERR_OK)
            {
                throw new UcException(err);
            }

            var size   = Marshal.SizeOf <UcMemRegion>();
            var result = new UcMemRegion[count];

            for (var i = 0; i < count; i++)
            {
                yield return(Marshal.PtrToStructure <UcMemRegion>(regions + (i * size)));
            }
        }
コード例 #20
0
 public UcErr Errno()
 {
     return(UcNative.UcErrno(Handle));
 }
コード例 #21
0
 public ulong ContextSize(IntPtr context)
 {
     return(UcNative.UcContextSize(Handle));
 }