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. This is the "C" version of xed-ex2.cpp (which is C++).
36 #include "xed-interface.h"
37 #include "xed-examples-util.h"
40 #include <string.h> //strcmp
43 int main(int argc, char** argv);
46 main(int argc, char** argv)
48 xed_error_enum_t xed_error;
50 xed_bool_t long_mode = 0;
52 unsigned int first_argv;
53 unsigned int bytes = 0;
54 unsigned char itext[XED_MAX_INSTRUCTION_BYTES];
57 xed_decoded_inst_t xedd;
61 xed_syntax_enum_t syntax;
64 xed_state_zero(&dstate);
65 xed_set_verbosity( 99 );
67 if (argc > 2 && strcmp(argv[1], "-64") == 0)
72 dstate.mmode=XED_MACHINE_MODE_LONG_64;
76 xed_state_init(&dstate,
77 XED_MACHINE_MODE_LEGACY_32,
78 XED_ADDRESS_WIDTH_32b,
79 XED_ADDRESS_WIDTH_32b);
82 xed_decoded_inst_zero_set_mode(&xedd, &dstate);
83 for( i=first_argv ;i < argc; i++) {
84 xed_uint8_t x = (xed_uint8_t)(xed_atoi_hex(argv[i]));
85 assert(bytes < XED_MAX_INSTRUCTION_BYTES);
89 fprintf(stderr, "Must supply some hex bytes\n");
93 printf("PARSING BYTES: ");
94 for( u=0;u<bytes; u++)
95 printf("%02x ", STATIC_CAST(unsigned int,itext[u]));
98 xed_error = xed_decode(&xedd,
99 REINTERPRET_CAST(const xed_uint8_t*,itext),
105 case XED_ERROR_BUFFER_TOO_SHORT:
106 fprintf(stderr,"Not enough bytes provided\n");
108 case XED_ERROR_GENERAL_ERROR:
109 fprintf(stderr,"Could not decode given input.\n");
112 fprintf(stderr,"Unhandled error code %s\n", xed_error_enum_t2str(xed_error));
116 //memset(buffer,0,BUFLEN);
117 xed_decoded_inst_dump(&xedd,buffer, BUFLEN);
118 printf("%s\n",buffer);
121 for(syntax= XED_SYNTAX_XED; syntax < XED_SYNTAX_LAST; syntax++) {
122 ok = xed_format(syntax, &xedd, buffer, BUFLEN, 0);
124 printf("%s syntax: %s\n", xed_syntax_enum_t2str(syntax), buffer);
126 printf("Error disassembling %s syntax\n", xed_syntax_enum_t2str(syntax));