public void MemUnmap(ulong address, ulong size) { var err = UcNative.UcMemUnmap(Handle, address, size); if (err != UcErr.UC_ERR_OK) { throw new UcException(err); } }
public void HookDel(IntPtr hookHandle) { var err = UcNative.UcHookDel(Handle, hookHandle); if (err != UcErr.UC_ERR_OK) { throw new UcException(err); } }
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); } }
public void EmuStop() { var err = UcNative.UcEmuStop(Handle); if (err != UcErr.UC_ERR_OK) { throw new UcException(err); } }
public void ContextRestore(IntPtr context) { var err = UcNative.UcContextRestore(Handle, context); if (err != UcErr.UC_ERR_OK) { throw new UcException(err); } }
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); } }
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); } }
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); } }
/// <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); } }
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); } }
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); }
public IntPtr ContextAlloc() { var err = UcNative.UcContextAlloc(Handle, out var context); if (err != UcErr.UC_ERR_OK) { throw new UcException(err); } return(context); }
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); }
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); } } }
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); } } }
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); }
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)); }
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); }
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))); } }
public UcErr Errno() { return(UcNative.UcErrno(Handle)); }
public ulong ContextSize(IntPtr context) { return(UcNative.UcContextSize(Handle)); }