Ejemplo n.º 1
0
        /// <summary>
        /// Encode given statements.
        /// </summary>
        /// <param name="toEncode">String that contains the statements to encode</param>
        /// <param name="address">Address of the first instruction.</param>
        /// <returns>Result of the assemble operation or null if it failed &amp;&amp; throwOnError is false.</returns>
        /// <exception cref="InvalidOperationException">If keystone return an error &amp;&amp; throwOnError is true</exception>
        public KeystoneEncoded Assemble(string toEncode, ulong address)
        {
            IntPtr encoding;
            uint   size;
            uint   statementCount;

            byte[] buffer;

            int result = KeystoneImports.Assemble(engine,
                                                  toEncode,
                                                  address,
                                                  out encoding,
                                                  out size,
                                                  out statementCount);

            if (result != 0)
            {
                if (throwOnError)
                {
                    throw new InvalidOperationException($"Error while assembling {toEncode}: {ErrorToString(GetLastKeystoneError())}");
                }
                return(null);
            }

            buffer = new byte[size];

            Marshal.Copy(encoding, buffer, 0, (int)size);
            KeystoneImports.Free(encoding);

            return(new KeystoneEncoded(buffer, statementCount, address));
        }
Ejemplo n.º 2
0
        public KeystoneEncoded Assemble(string toEncode, ulong address)
        {
            IntPtr encoding;
            uint   size;
            uint   statements;

            if (KeystoneImports.Assemble(this.engine, toEncode, address, out encoding, out size, out statements) != 0)
            {
                if (this.throwOnError)
                {
                    throw new InvalidOperationException(string.Format("Error while assembling {0}: {1}", (object)toEncode, (object)Keystone.ErrorToString(this.GetLastKeystoneError())));
                }
                return((KeystoneEncoded)null);
            }
            byte[] numArray = new byte[(int)size];
            Marshal.Copy(encoding, numArray, 0, (int)size);
            KeystoneImports.Free(encoding);
            return(new KeystoneEncoded(numArray, statements, address));
        }