Пример #1
0
        ud_insn_hex(ref ud u)
        {
            //u.insn_hexcode[0] = '\0';
            StringBuilder src_hex = new StringBuilder();

            if (u.error == 0)
            {
                int           i;
                IAssemblyCode src_ptr = ud_insn_ptr(ref u);
                unsafe
                {
                    //byte* src = (byte*)src_ptr.ToPointer();
                    for (i = 0; i < ud_insn_len(ref u); i++)
                    {
                        src_hex.AppendFormat("{0:2X", src_ptr[i]);
                    }
                }
                //byte[] src_ptr = ud_insn_ptr(ref u);
                // //char[] src_hex;
                // /* for each byte used to decode instruction */
                //for (i = 0; i < src_ptr.Length; // && i < u.insn_hexcode.Length / 2;
                //     ++i)
                //{
                //    src_hex.Append(String.Format("{0:2x}", src_ptr[i] & 0xFF));
                //}
            }
            return(src_hex.ToString());
        }
Пример #2
0
 /* =============================================================================
  * ud_inp_set_buffer
  *    Set buffer as input.
  * =============================================================================
  */
 /// <summary>
 /// Set the buffer as input
 /// </summary>
 /// <param name="u">The u.</param>
 /// <param name="code">The code.</param>
 public static unsafe void ud_set_input_buffer(ref ud u, IAssemblyCode code)
 {
     ud_inp_init(ref u);
     u.inp_buf       = code;
     u.inp_buf_size  = code.Length;
     u.inp_buf_index = 0;
 }
Пример #3
0
		/// <summary>
		/// Copies to bytes.
		/// </summary>
		/// <param name="source">The source.</param>
		/// <param name="offset">The offset.</param>
		/// <param name="length">The length.</param>
		/// <returns></returns>
		public static byte[] CopyToBytes(IAssemblyCode source, int offset, int length)
		{
			var bytes = new byte[length];

			for (int i = 0; i < length; i++)
			{
				bytes[i] = source[offset + i];
			}

			return bytes;
		}
Пример #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Disassembler"/> class.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="architecture">The architecture.</param>
        /// <param name="address">The address.</param>
        /// <param name="copyBinaryToInstruction">if set to <c>true</c> [copy binary to instruction].</param>
        /// <param name="vendor">The vendor.</param>
        public Disassembler(IAssemblyCode code, ArchitectureMode architecture, ulong address = 0x0, bool copyBinaryToInstruction = false, Vendor vendor = Vendor.Any)
        {
            this.code = code;

            this.Architecture            = architecture;
            this.Address                 = address;
            this.CopyBinaryToInstruction = copyBinaryToInstruction;
            this.Vendor = vendor;

            InitUdis86();
        }
Пример #5
0
        /// <summary>
        /// Copies to bytes.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="offset">The offset.</param>
        /// <param name="length">The length.</param>
        /// <returns></returns>
        public static byte[] CopyToBytes(IAssemblyCode source, int offset, int length)
        {
            var bytes = new byte[length];

            for (int i = 0; i < length; i++)
            {
                bytes[i] = source[offset + i];
            }

            return(bytes);
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Disassembler"/> class.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="architecture">The architecture.</param>
        /// <param name="address">The address.</param>
        /// <param name="copyBinaryToInstruction">if set to <c>true</c> [copy binary to instruction].</param>
        /// <param name="vendor">The vendor.</param>
        /// <param name="instructionFactory">The instruction factory. if null InstructionFactory is used.</param>
        public Disassembler(IAssemblyCode code, ArchitectureMode architecture, ulong address = 0x0,
                            bool copyBinaryToInstruction = false,
                            Vendor vendor = Vendor.Any, IInstructionFactory instructionFactory = null)
        {
            this.code = code;

            this.Architecture            = architecture;
            this.Address                 = address;
            this.CopyBinaryToInstruction = copyBinaryToInstruction;
            this.Vendor = vendor;
            if (instructionFactory == null)
            {
                this.InstructionFactory = new InstructionFactory();
            }
            else
            {
                this.InstructionFactory = instructionFactory;
            }

            InitUdis86();
        }
Пример #7
0
		/// <summary>
		/// Copies the specified source.
		/// </summary>
		/// <param name="source">The source.</param>
		/// <param name="offset">The offset.</param>
		/// <param name="length">The length.</param>
		/// <returns></returns>
		public static IAssemblyCode Copy(IAssemblyCode source, int offset, int length)
		{
			return new AssemblyCodeArray(CopyToBytes(source, offset, length));
		}
Пример #8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssemblyCodeArray" /> class.
 /// </summary>
 /// <param name="code">The code.</param>
 /// <param name="offset">The offset.</param>
 public AssemblyCodeOffset(IAssemblyCode code, int offset)
 {
     this.code   = code;
     this.offset = offset;
 }
Пример #9
0
 /// <summary>
 /// Copies the specified source.
 /// </summary>
 /// <param name="source">The source.</param>
 /// <param name="offset">The offset.</param>
 /// <param name="length">The length.</param>
 /// <returns></returns>
 public static IAssemblyCode Copy(IAssemblyCode source, int offset, int length)
 {
     return(new AssemblyCodeArray(CopyToBytes(source, offset, length)));
 }
Пример #10
0
        /// <summary>
        /// Initializes a new instance of the <see cref="Disassembler"/> class.
        /// </summary>
        /// <param name="code">The code.</param>
        /// <param name="architecture">The architecture.</param>
        /// <param name="address">The address.</param>
        /// <param name="copyBinaryToInstruction">if set to <c>true</c> [copy binary to instruction].</param>
        /// <param name="vendor">The vendor.</param>
        public Disassembler(IAssemblyCode code, ArchitectureMode architecture, ulong address = 0x0, bool copyBinaryToInstruction = false, Vendor vendor = Vendor.Any)
        {
            this.code = code;

            this.Architecture = architecture;
            this.Address = address;
            this.CopyBinaryToInstruction = copyBinaryToInstruction;
            this.Vendor = vendor;

            InitUdis86();
        }
Пример #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ud"/> class.
 /// </summary>
 public ud()
 {
     inp_buf = new AssemblyCodeArray(new byte[64]);
 }
Пример #12
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ud"/> class.
 /// </summary>
 public ud()
 {
     inp_buf = new AssemblyCodeArray(new byte[64]);
 }
Пример #13
0
 /* =============================================================================
  * ud_inp_set_buffer
  *    Set buffer as input.
  * =============================================================================
  */
 /// <summary>
 /// Set the buffer as input
 /// </summary>
 /// <param name="u">The u.</param>
 /// <param name="code">The code.</param>
 public static unsafe void ud_set_input_buffer(ref ud u, IAssemblyCode code)
 {
     ud_inp_init(ref u);
     u.inp_buf = code;
     u.inp_buf_size = code.Length;
     u.inp_buf_index = 0;
 }
Пример #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AssemblyCodeArray" /> class.
 /// </summary>
 /// <param name="code">The code.</param>
 /// <param name="offset">The offset.</param>
 public AssemblyCodeOffset(IAssemblyCode code, int offset)
 {
     this.code = code;
     this.offset = offset;
 }