2 Intel Open Source License
4 Copyright (c) 2002-2007 Intel Corporation
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions are
10 Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer. Redistributions
12 in binary form must reproduce the above copyright notice, this list of
13 conditions and the following disclaimer in the documentation and/or
14 other materials provided with the distribution. Neither the name of
15 the Intel Corporation nor the names of its contributors may be used to
16 endorse or promote products derived from this software without
17 specific prior written permission.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INTEL OR
23 ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 /// @author Mark Charney <mark.charney@intel.com>
34 // decoder example. C++ version of xed-ex4.c
37 #include "xed-interface.h"
45 int main(int argc, char** argv);
47 int main(int argc, char** argv) {
48 xed_bool_t long_mode = false;
52 unsigned char itext[XED_MAX_INSTRUCTION_BYTES];
55 xed_decoded_inst_t xedd;
60 xed_state_zero(&dstate);
61 xed_set_verbosity( 99 );
63 if (argc > 2 && strcmp(argv[1], "-64") == 0)
68 dstate.mmode=XED_MACHINE_MODE_LONG_64;
72 xed_state_init(&dstate,
73 XED_MACHINE_MODE_LEGACY_32,
74 XED_ADDRESS_WIDTH_32b,
75 XED_ADDRESS_WIDTH_32b);
77 xed_decoded_inst_zero_set_mode(&xedd, &dstate);
78 for( i=first_argv ;i < argc; i++) {
80 istringstream s(argv[i]);
83 assert(bytes < XED_MAX_INSTRUCTION_BYTES);
84 itext[bytes++] = STATIC_CAST(xed_uint8_t,x);
87 cout << "Must supply some hex bytes" << endl;
91 cout << "PARSING BYTES: ";
92 for( i=0;i<bytes; i++)
93 cout << hex << setw(2) << setfill('0')
94 << STATIC_CAST(unsigned int,itext[i]) << " ";
95 cout << endl << setfill(' ');
97 xed_error_enum_t xed_error = xed_decode(&xedd,
98 REINTERPRET_CAST(xed_uint8_t*,itext),
104 case XED_ERROR_BUFFER_TOO_SHORT:
105 cout << "Not enough bytes provided" << endl;
107 case XED_ERROR_GENERAL_ERROR:
108 cout << "Could not decode given input." << endl;
111 cout << "Unhandled error code " << xed_error_enum_t2str(xed_error) << endl;
115 xed_decoded_inst_dump(&xedd,buffer,BUFLEN);
116 cout << buffer << endl;
119 for(u= XED_SYNTAX_XED; u < XED_SYNTAX_LAST; u++) {
120 xed_syntax_enum_t syntax = static_cast<xed_syntax_enum_t>(u);
121 ok = xed_format(syntax, &xedd, buffer, BUFLEN, 0);
123 cout << xed_syntax_enum_t2str(syntax) << " syntax: " << buffer << endl;
125 cout << "Error disassembling " << xed_syntax_enum_t2str(syntax) << " syntax" << endl;