Ejemplo n.º 1
0
    public void Dispose()
    {
        IntPtr intPtr = Interlocked.Exchange(ref engine, IntPtr.Zero);

        if (intPtr != IntPtr.Zero)
        {
            KeystoneImports.Close(intPtr);
        }
        GC.SuppressFinalize(this);
    }
Ejemplo n.º 2
0
    public static string ErrorToString(KeystoneError result)
    {
        IntPtr intPtr = KeystoneImports.ErrorToString(result);

        if (intPtr != IntPtr.Zero)
        {
            return(Marshal.PtrToStringAnsi(intPtr));
        }
        return(string.Empty);
    }
Ejemplo n.º 3
0
    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)}");
        }
    }
Ejemplo n.º 4
0
    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);
    }
Ejemplo n.º 5
0
 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));
 }
Ejemplo n.º 6
0
 public static uint GetKeystoneVersion(ref uint major, ref uint minor)
 {
     return(KeystoneImports.Version(ref major, ref minor));
 }
Ejemplo n.º 7
0
 public static bool IsArchitectureSupported(KeystoneArchitecture architecture)
 {
     return(KeystoneImports.IsArchitectureSupported(architecture));
 }
Ejemplo n.º 8
0
 public KeystoneError GetLastKeystoneError()
 {
     return(KeystoneImports.GetLastKeystoneError(engine));
 }