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()); }
/* ============================================================================= * 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; }
/// <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; }
/// <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(); }
/// <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); }
/// <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(); }
/// <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)); }
/// <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; }
/// <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))); }
/// <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(); }
/// <summary> /// Initializes a new instance of the <see cref="ud"/> class. /// </summary> public ud() { inp_buf = new AssemblyCodeArray(new byte[64]); }
/// <summary> /// Initializes a new instance of the <see cref="ud"/> class. /// </summary> public ud() { inp_buf = new AssemblyCodeArray(new byte[64]); }
/* ============================================================================= * 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; }
/// <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; }