public void Dispose() { IntPtr intPtr = Interlocked.Exchange(ref engine, IntPtr.Zero); if (intPtr != IntPtr.Zero) { KeystoneImports.Close(intPtr); } GC.SuppressFinalize(this); }
public static string ErrorToString(KeystoneError result) { IntPtr intPtr = KeystoneImports.ErrorToString(result); if (intPtr != IntPtr.Zero) { return(Marshal.PtrToStringAnsi(intPtr)); } return(string.Empty); }
public Keystone(KeystoneArchitecture architecture, KeystoneMode mode, bool throwOnKeystoneError = true) { internalImpl = this.SymbolResolver; throwOnError = throwOnKeystoneError; KeystoneError keystoneError = KeystoneImports.Open(architecture, (int)mode, ref engine); if (keystoneError != 0 && throwOnKeystoneError) { throw new InvalidOperationException($"Error while initializing keystone: {ErrorToString(keystoneError)}"); } }
public bool SetOption(KeystoneOptionType type, uint value) { KeystoneError keystoneError = KeystoneImports.SetOption(engine, type, (IntPtr)(long)value); if (keystoneError != 0) { if (throwOnError) { throw new InvalidOperationException($"Error while setting option in keystone: {ErrorToString(keystoneError)}"); } return(false); } return(true); }
public KeystoneEncoded Assemble(string toEncode, ulong address) { if (KeystoneImports.Assemble(engine, toEncode, address, out IntPtr encoding, out uint size, out uint statements) != 0) { if (throwOnError) { throw new InvalidOperationException($"Error while assembling {toEncode}: {ErrorToString(GetLastKeystoneError())}"); } return(null); } byte[] array = new byte[size]; Marshal.Copy(encoding, array, 0, (int)size); KeystoneImports.Free(encoding); return(new KeystoneEncoded(array, statements, address)); }
public static uint GetKeystoneVersion(ref uint major, ref uint minor) { return(KeystoneImports.Version(ref major, ref minor)); }
public static bool IsArchitectureSupported(KeystoneArchitecture architecture) { return(KeystoneImports.IsArchitectureSupported(architecture)); }
public KeystoneError GetLastKeystoneError() { return(KeystoneImports.GetLastKeystoneError(engine)); }