Coverage Report

Created: 2026-01-10 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/capstonev5/arch/X86/X86IntelInstPrinter.c
Line
Count
Source
1
//===-- X86IntelInstPrinter.cpp - Intel assembly instruction printing -----===//
2
//
3
//                     The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
//
10
// This file includes code for rendering MCInst instances as Intel-style
11
// assembly.
12
//
13
//===----------------------------------------------------------------------===//
14
15
/* Capstone Disassembly Engine */
16
/* By Nguyen Anh Quynh <aquynh@gmail.com>, 2013-2019 */
17
18
#ifdef CAPSTONE_HAS_X86
19
20
#if defined (WIN32) || defined (WIN64) || defined (_WIN32) || defined (_WIN64)
21
#pragma warning(disable:4996)     // disable MSVC's warning on strncpy()
22
#pragma warning(disable:28719)    // disable MSVC's warning on strncpy()
23
#endif
24
25
#if !defined(CAPSTONE_HAS_OSXKERNEL)
26
#include <ctype.h>
27
#endif
28
#include <capstone/platform.h>
29
30
#if defined(CAPSTONE_HAS_OSXKERNEL)
31
#include <Availability.h>
32
#include <libkern/libkern.h>
33
#else
34
#include <stdio.h>
35
#include <stdlib.h>
36
#endif
37
#include <string.h>
38
39
#include "../../utils.h"
40
#include "../../MCInst.h"
41
#include "../../SStream.h"
42
#include "../../MCRegisterInfo.h"
43
44
#include "X86InstPrinter.h"
45
#include "X86Mapping.h"
46
#include "X86InstPrinterCommon.h"
47
48
#define GET_INSTRINFO_ENUM
49
#ifdef CAPSTONE_X86_REDUCE
50
#include "X86GenInstrInfo_reduce.inc"
51
#else
52
#include "X86GenInstrInfo.inc"
53
#endif
54
55
#define GET_REGINFO_ENUM
56
#include "X86GenRegisterInfo.inc"
57
58
#include "X86BaseInfo.h"
59
60
static void printMemReference(MCInst *MI, unsigned Op, SStream *O);
61
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O);
62
63
64
static void set_mem_access(MCInst *MI, bool status)
65
48.0k
{
66
48.0k
  if (MI->csh->detail != CS_OPT_ON)
67
0
    return;
68
69
48.0k
  MI->csh->doing_mem = status;
70
48.0k
  if (!status)
71
    // done, create the next operand slot
72
24.0k
    MI->flat_insn->detail->x86.op_count++;
73
74
48.0k
}
75
76
static void printopaquemem(MCInst *MI, unsigned OpNo, SStream *O)
77
5.63k
{
78
  // FIXME: do this with autogen
79
  // printf(">>> ID = %u\n", MI->flat_insn->id);
80
5.63k
  switch(MI->flat_insn->id) {
81
1.35k
    default:
82
1.35k
      SStream_concat0(O, "ptr ");
83
1.35k
      break;
84
795
    case X86_INS_SGDT:
85
1.60k
    case X86_INS_SIDT:
86
2.35k
    case X86_INS_LGDT:
87
2.75k
    case X86_INS_LIDT:
88
2.96k
    case X86_INS_FXRSTOR:
89
3.22k
    case X86_INS_FXSAVE:
90
4.03k
    case X86_INS_LJMP:
91
4.28k
    case X86_INS_LCALL:
92
      // do not print "ptr"
93
4.28k
      break;
94
5.63k
  }
95
96
5.63k
  switch(MI->csh->mode) {
97
1.44k
    case CS_MODE_16:
98
1.44k
      switch(MI->flat_insn->id) {
99
447
        default:
100
447
          MI->x86opsize = 2;
101
447
          break;
102
233
        case X86_INS_LJMP:
103
322
        case X86_INS_LCALL:
104
322
          MI->x86opsize = 4;
105
322
          break;
106
65
        case X86_INS_SGDT:
107
519
        case X86_INS_SIDT:
108
592
        case X86_INS_LGDT:
109
672
        case X86_INS_LIDT:
110
672
          MI->x86opsize = 6;
111
672
          break;
112
1.44k
      }
113
1.44k
      break;
114
2.39k
    case CS_MODE_32:
115
2.39k
      switch(MI->flat_insn->id) {
116
701
        default:
117
701
          MI->x86opsize = 4;
118
701
          break;
119
299
        case X86_INS_LJMP:
120
686
        case X86_INS_JMP:
121
768
        case X86_INS_LCALL:
122
1.08k
        case X86_INS_SGDT:
123
1.36k
        case X86_INS_SIDT:
124
1.60k
        case X86_INS_LGDT:
125
1.69k
        case X86_INS_LIDT:
126
1.69k
          MI->x86opsize = 6;
127
1.69k
          break;
128
2.39k
      }
129
2.39k
      break;
130
2.39k
    case CS_MODE_64:
131
1.79k
      switch(MI->flat_insn->id) {
132
294
        default:
133
294
          MI->x86opsize = 8;
134
294
          break;
135
277
        case X86_INS_LJMP:
136
353
        case X86_INS_LCALL:
137
770
        case X86_INS_SGDT:
138
843
        case X86_INS_SIDT:
139
1.27k
        case X86_INS_LGDT:
140
1.50k
        case X86_INS_LIDT:
141
1.50k
          MI->x86opsize = 10;
142
1.50k
          break;
143
1.79k
      }
144
1.79k
      break;
145
1.79k
    default:  // never reach
146
0
      break;
147
5.63k
  }
148
149
5.63k
  printMemReference(MI, OpNo, O);
150
5.63k
}
151
152
static void printi8mem(MCInst *MI, unsigned OpNo, SStream *O)
153
41.7k
{
154
41.7k
  SStream_concat0(O, "byte ptr ");
155
41.7k
  MI->x86opsize = 1;
156
41.7k
  printMemReference(MI, OpNo, O);
157
41.7k
}
158
159
static void printi16mem(MCInst *MI, unsigned OpNo, SStream *O)
160
10.8k
{
161
10.8k
  MI->x86opsize = 2;
162
10.8k
  SStream_concat0(O, "word ptr ");
163
10.8k
  printMemReference(MI, OpNo, O);
164
10.8k
}
165
166
static void printi32mem(MCInst *MI, unsigned OpNo, SStream *O)
167
22.9k
{
168
22.9k
  MI->x86opsize = 4;
169
22.9k
  SStream_concat0(O, "dword ptr ");
170
22.9k
  printMemReference(MI, OpNo, O);
171
22.9k
}
172
173
static void printi64mem(MCInst *MI, unsigned OpNo, SStream *O)
174
11.5k
{
175
11.5k
  SStream_concat0(O, "qword ptr ");
176
11.5k
  MI->x86opsize = 8;
177
11.5k
  printMemReference(MI, OpNo, O);
178
11.5k
}
179
180
static void printi128mem(MCInst *MI, unsigned OpNo, SStream *O)
181
4.74k
{
182
4.74k
  SStream_concat0(O, "xmmword ptr ");
183
4.74k
  MI->x86opsize = 16;
184
4.74k
  printMemReference(MI, OpNo, O);
185
4.74k
}
186
187
static void printi512mem(MCInst *MI, unsigned OpNo, SStream *O)
188
2.50k
{
189
2.50k
  SStream_concat0(O, "zmmword ptr ");
190
2.50k
  MI->x86opsize = 64;
191
2.50k
  printMemReference(MI, OpNo, O);
192
2.50k
}
193
194
#ifndef CAPSTONE_X86_REDUCE
195
static void printi256mem(MCInst *MI, unsigned OpNo, SStream *O)
196
3.17k
{
197
3.17k
  SStream_concat0(O, "ymmword ptr ");
198
3.17k
  MI->x86opsize = 32;
199
3.17k
  printMemReference(MI, OpNo, O);
200
3.17k
}
201
202
static void printf32mem(MCInst *MI, unsigned OpNo, SStream *O)
203
3.46k
{
204
3.46k
  switch(MCInst_getOpcode(MI)) {
205
2.68k
    default:
206
2.68k
      SStream_concat0(O, "dword ptr ");
207
2.68k
      MI->x86opsize = 4;
208
2.68k
      break;
209
275
    case X86_FSTENVm:
210
780
    case X86_FLDENVm:
211
      // TODO: fix this in tablegen instead
212
780
      switch(MI->csh->mode) {
213
0
        default:    // never reach
214
0
          break;
215
225
        case CS_MODE_16:
216
225
          MI->x86opsize = 14;
217
225
          break;
218
289
        case CS_MODE_32:
219
555
        case CS_MODE_64:
220
555
          MI->x86opsize = 28;
221
555
          break;
222
780
      }
223
780
      break;
224
3.46k
  }
225
226
3.46k
  printMemReference(MI, OpNo, O);
227
3.46k
}
228
229
static void printf64mem(MCInst *MI, unsigned OpNo, SStream *O)
230
2.42k
{
231
  // TODO: fix COMISD in Tablegen instead (#1456)
232
2.42k
  if (MI->op1_size == 16) {
233
    // printf("printf64mem id = %u\n", MCInst_getOpcode(MI));
234
1.23k
    switch(MCInst_getOpcode(MI)) {
235
1.11k
      default:
236
1.11k
        SStream_concat0(O, "qword ptr ");
237
1.11k
        MI->x86opsize = 8;
238
1.11k
        break;
239
0
      case X86_MOVPQI2QImr:
240
121
      case X86_COMISDrm:
241
121
        SStream_concat0(O, "xmmword ptr ");
242
121
        MI->x86opsize = 16;
243
121
        break;
244
1.23k
    }
245
1.23k
  } else {
246
1.19k
    SStream_concat0(O, "qword ptr ");
247
1.19k
    MI->x86opsize = 8;
248
1.19k
  }
249
250
2.42k
  printMemReference(MI, OpNo, O);
251
2.42k
}
252
253
static void printf80mem(MCInst *MI, unsigned OpNo, SStream *O)
254
170
{
255
170
  switch(MCInst_getOpcode(MI)) {
256
68
    default:
257
68
      SStream_concat0(O, "xword ptr ");
258
68
      break;
259
35
    case X86_FBLDm:
260
102
    case X86_FBSTPm:
261
102
      break;
262
170
  }
263
264
170
  MI->x86opsize = 10;
265
170
  printMemReference(MI, OpNo, O);
266
170
}
267
268
static void printf128mem(MCInst *MI, unsigned OpNo, SStream *O)
269
1.72k
{
270
1.72k
  SStream_concat0(O, "xmmword ptr ");
271
1.72k
  MI->x86opsize = 16;
272
1.72k
  printMemReference(MI, OpNo, O);
273
1.72k
}
274
275
static void printf256mem(MCInst *MI, unsigned OpNo, SStream *O)
276
1.96k
{
277
1.96k
  SStream_concat0(O, "ymmword ptr ");
278
1.96k
  MI->x86opsize = 32;
279
1.96k
  printMemReference(MI, OpNo, O);
280
1.96k
}
281
282
static void printf512mem(MCInst *MI, unsigned OpNo, SStream *O)
283
772
{
284
772
  SStream_concat0(O, "zmmword ptr ");
285
772
  MI->x86opsize = 64;
286
772
  printMemReference(MI, OpNo, O);
287
772
}
288
#endif
289
290
static const char *getRegisterName(unsigned RegNo);
291
static void printRegName(SStream *OS, unsigned RegNo)
292
384k
{
293
384k
  SStream_concat0(OS, getRegisterName(RegNo));
294
384k
}
295
296
// for MASM syntax, 0x123 = 123h, 0xA123 = 0A123h
297
// this function tell us if we need to have prefix 0 in front of a number
298
static bool need_zero_prefix(uint64_t imm)
299
0
{
300
  // find the first hex letter representing imm
301
0
  while(imm >= 0x10)
302
0
    imm >>= 4;
303
304
0
  if (imm < 0xa)
305
0
    return false;
306
0
  else  // this need 0 prefix
307
0
    return true;
308
0
}
309
310
static void printImm(MCInst *MI, SStream *O, int64_t imm, bool positive)
311
97.9k
{
312
97.9k
  if (positive) {
313
    // always print this number in positive form
314
83.1k
    if (MI->csh->syntax == CS_OPT_SYNTAX_MASM) {
315
0
      if (imm < 0) {
316
0
        if (MI->op1_size) {
317
0
          switch(MI->op1_size) {
318
0
            default:
319
0
              break;
320
0
            case 1:
321
0
              imm &= 0xff;
322
0
              break;
323
0
            case 2:
324
0
              imm &= 0xffff;
325
0
              break;
326
0
            case 4:
327
0
              imm &= 0xffffffff;
328
0
              break;
329
0
          }
330
0
        }
331
332
0
        if (imm == 0x8000000000000000LL)  // imm == -imm
333
0
          SStream_concat0(O, "8000000000000000h");
334
0
        else if (need_zero_prefix(imm))
335
0
          SStream_concat(O, "0%"PRIx64"h", imm);
336
0
        else
337
0
          SStream_concat(O, "%"PRIx64"h", imm);
338
0
      } else {
339
0
        if (imm > HEX_THRESHOLD) {
340
0
          if (need_zero_prefix(imm))
341
0
            SStream_concat(O, "0%"PRIx64"h", imm);
342
0
          else
343
0
            SStream_concat(O, "%"PRIx64"h", imm);
344
0
        } else
345
0
          SStream_concat(O, "%"PRIu64, imm);
346
0
      }
347
83.1k
    } else { // Intel syntax
348
83.1k
      if (imm < 0) {
349
1.17k
        if (MI->op1_size) {
350
284
          switch(MI->op1_size) {
351
284
            default:
352
284
              break;
353
284
            case 1:
354
0
              imm &= 0xff;
355
0
              break;
356
0
            case 2:
357
0
              imm &= 0xffff;
358
0
              break;
359
0
            case 4:
360
0
              imm &= 0xffffffff;
361
0
              break;
362
284
          }
363
284
        }
364
365
1.17k
        SStream_concat(O, "0x%"PRIx64, imm);
366
81.9k
      } else {
367
81.9k
        if (imm > HEX_THRESHOLD)
368
77.3k
          SStream_concat(O, "0x%"PRIx64, imm);
369
4.66k
        else
370
4.66k
          SStream_concat(O, "%"PRIu64, imm);
371
81.9k
      }
372
83.1k
    }
373
83.1k
  } else {
374
14.8k
    if (MI->csh->syntax == CS_OPT_SYNTAX_MASM) {
375
0
      if (imm < 0) {
376
0
        if (imm == 0x8000000000000000LL)  // imm == -imm
377
0
          SStream_concat0(O, "8000000000000000h");
378
0
        else if (imm < -HEX_THRESHOLD) {
379
0
          if (need_zero_prefix(imm))
380
0
            SStream_concat(O, "-0%"PRIx64"h", -imm);
381
0
          else
382
0
            SStream_concat(O, "-%"PRIx64"h", -imm);
383
0
        } else
384
0
          SStream_concat(O, "-%"PRIu64, -imm);
385
0
      } else {
386
0
        if (imm > HEX_THRESHOLD) {
387
0
          if (need_zero_prefix(imm))
388
0
            SStream_concat(O, "0%"PRIx64"h", imm);
389
0
          else
390
0
            SStream_concat(O, "%"PRIx64"h", imm);
391
0
        } else
392
0
          SStream_concat(O, "%"PRIu64, imm);
393
0
      }
394
14.8k
    } else { // Intel syntax
395
14.8k
      if (imm < 0) {
396
2.36k
        if (imm == 0x8000000000000000LL)  // imm == -imm
397
0
          SStream_concat0(O, "0x8000000000000000");
398
2.36k
        else if (imm < -HEX_THRESHOLD)
399
2.00k
          SStream_concat(O, "-0x%"PRIx64, -imm);
400
368
        else
401
368
          SStream_concat(O, "-%"PRIu64, -imm);
402
403
12.4k
      } else {
404
12.4k
        if (imm > HEX_THRESHOLD)
405
10.4k
          SStream_concat(O, "0x%"PRIx64, imm);
406
2.06k
        else
407
2.06k
          SStream_concat(O, "%"PRIu64, imm);
408
12.4k
      }
409
14.8k
    }
410
14.8k
  }
411
97.9k
}
412
413
// local printOperand, without updating public operands
414
static void _printOperand(MCInst *MI, unsigned OpNo, SStream *O)
415
146k
{
416
146k
  MCOperand *Op  = MCInst_getOperand(MI, OpNo);
417
146k
  if (MCOperand_isReg(Op)) {
418
146k
    printRegName(O, MCOperand_getReg(Op));
419
146k
  } else if (MCOperand_isImm(Op)) {
420
0
    int64_t imm = MCOperand_getImm(Op);
421
0
    printImm(MI, O, imm, MI->csh->imm_unsigned);
422
0
  }
423
146k
}
424
425
#ifndef CAPSTONE_DIET
426
// copy & normalize access info
427
static void get_op_access(cs_struct *h, unsigned int id, uint8_t *access, uint64_t *eflags)
428
682k
{
429
682k
#ifndef CAPSTONE_DIET
430
682k
  uint8_t i;
431
682k
  const uint8_t *arr = X86_get_op_access(h, id, eflags);
432
433
682k
  if (!arr) {
434
0
    access[0] = 0;
435
0
    return;
436
0
  }
437
438
  // copy to access but zero out CS_AC_IGNORE
439
1.99M
  for(i = 0; arr[i]; i++) {
440
1.31M
    if (arr[i] != CS_AC_IGNORE)
441
1.10M
      access[i] = arr[i];
442
208k
    else
443
208k
      access[i] = 0;
444
1.31M
  }
445
446
  // mark the end of array
447
682k
  access[i] = 0;
448
682k
#endif
449
682k
}
450
#endif
451
452
static void printSrcIdx(MCInst *MI, unsigned Op, SStream *O)
453
10.0k
{
454
10.0k
  MCOperand *SegReg;
455
10.0k
  int reg;
456
457
10.0k
  if (MI->csh->detail) {
458
10.0k
#ifndef CAPSTONE_DIET
459
10.0k
    uint8_t access[6];
460
10.0k
#endif
461
462
10.0k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
463
10.0k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->x86opsize;
464
10.0k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_INVALID;
465
10.0k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_REG_INVALID;
466
10.0k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.index = X86_REG_INVALID;
467
10.0k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = 1;
468
10.0k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = 0;
469
470
10.0k
#ifndef CAPSTONE_DIET
471
10.0k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
472
10.0k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
473
10.0k
#endif
474
10.0k
  }
475
476
10.0k
  SegReg = MCInst_getOperand(MI, Op + 1);
477
10.0k
  reg = MCOperand_getReg(SegReg);
478
479
  // If this has a segment register, print it.
480
10.0k
  if (reg) {
481
200
    _printOperand(MI, Op + 1, O);
482
200
    if (MI->csh->detail) {
483
200
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_register_map(reg);
484
200
    }
485
200
    SStream_concat0(O, ":");
486
200
  }
487
488
10.0k
  SStream_concat0(O, "[");
489
10.0k
  set_mem_access(MI, true);
490
10.0k
  printOperand(MI, Op, O);
491
10.0k
  SStream_concat0(O, "]");
492
10.0k
  set_mem_access(MI, false);
493
10.0k
}
494
495
static void printDstIdx(MCInst *MI, unsigned Op, SStream *O)
496
13.9k
{
497
13.9k
  if (MI->csh->detail) {
498
13.9k
#ifndef CAPSTONE_DIET
499
13.9k
    uint8_t access[6];
500
13.9k
#endif
501
502
13.9k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
503
13.9k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->x86opsize;
504
13.9k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_INVALID;
505
13.9k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_REG_INVALID;
506
13.9k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.index = X86_REG_INVALID;
507
13.9k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = 1;
508
13.9k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = 0;
509
510
13.9k
#ifndef CAPSTONE_DIET
511
13.9k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
512
13.9k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
513
13.9k
#endif
514
13.9k
  }
515
516
  // DI accesses are always ES-based on non-64bit mode
517
13.9k
  if (MI->csh->mode != CS_MODE_64) {
518
8.84k
    SStream_concat0(O, "es:[");
519
8.84k
    if (MI->csh->detail) {
520
8.84k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_ES;
521
8.84k
    }
522
8.84k
  } else
523
5.08k
    SStream_concat0(O, "[");
524
525
13.9k
  set_mem_access(MI, true);
526
13.9k
  printOperand(MI, Op, O);
527
13.9k
  SStream_concat0(O, "]");
528
13.9k
  set_mem_access(MI, false);
529
13.9k
}
530
531
static void printSrcIdx8(MCInst *MI, unsigned OpNo, SStream *O)
532
4.04k
{
533
4.04k
  SStream_concat0(O, "byte ptr ");
534
4.04k
  MI->x86opsize = 1;
535
4.04k
  printSrcIdx(MI, OpNo, O);
536
4.04k
}
537
538
static void printSrcIdx16(MCInst *MI, unsigned OpNo, SStream *O)
539
1.72k
{
540
1.72k
  SStream_concat0(O, "word ptr ");
541
1.72k
  MI->x86opsize = 2;
542
1.72k
  printSrcIdx(MI, OpNo, O);
543
1.72k
}
544
545
static void printSrcIdx32(MCInst *MI, unsigned OpNo, SStream *O)
546
3.54k
{
547
3.54k
  SStream_concat0(O, "dword ptr ");
548
3.54k
  MI->x86opsize = 4;
549
3.54k
  printSrcIdx(MI, OpNo, O);
550
3.54k
}
551
552
static void printSrcIdx64(MCInst *MI, unsigned OpNo, SStream *O)
553
769
{
554
769
  SStream_concat0(O, "qword ptr ");
555
769
  MI->x86opsize = 8;
556
769
  printSrcIdx(MI, OpNo, O);
557
769
}
558
559
static void printDstIdx8(MCInst *MI, unsigned OpNo, SStream *O)
560
5.86k
{
561
5.86k
  SStream_concat0(O, "byte ptr ");
562
5.86k
  MI->x86opsize = 1;
563
5.86k
  printDstIdx(MI, OpNo, O);
564
5.86k
}
565
566
static void printDstIdx16(MCInst *MI, unsigned OpNo, SStream *O)
567
1.84k
{
568
1.84k
  SStream_concat0(O, "word ptr ");
569
1.84k
  MI->x86opsize = 2;
570
1.84k
  printDstIdx(MI, OpNo, O);
571
1.84k
}
572
573
static void printDstIdx32(MCInst *MI, unsigned OpNo, SStream *O)
574
5.22k
{
575
5.22k
  SStream_concat0(O, "dword ptr ");
576
5.22k
  MI->x86opsize = 4;
577
5.22k
  printDstIdx(MI, OpNo, O);
578
5.22k
}
579
580
static void printDstIdx64(MCInst *MI, unsigned OpNo, SStream *O)
581
998
{
582
998
  SStream_concat0(O, "qword ptr ");
583
998
  MI->x86opsize = 8;
584
998
  printDstIdx(MI, OpNo, O);
585
998
}
586
587
static void printMemOffset(MCInst *MI, unsigned Op, SStream *O)
588
2.89k
{
589
2.89k
  MCOperand *DispSpec = MCInst_getOperand(MI, Op);
590
2.89k
  MCOperand *SegReg = MCInst_getOperand(MI, Op + 1);
591
2.89k
  int reg;
592
593
2.89k
  if (MI->csh->detail) {
594
2.89k
#ifndef CAPSTONE_DIET
595
2.89k
    uint8_t access[6];
596
2.89k
#endif
597
598
2.89k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
599
2.89k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->x86opsize;
600
2.89k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_INVALID;
601
2.89k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_REG_INVALID;
602
2.89k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.index = X86_REG_INVALID;
603
2.89k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = 1;
604
2.89k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = 0;
605
606
2.89k
#ifndef CAPSTONE_DIET
607
2.89k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
608
2.89k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
609
2.89k
#endif
610
2.89k
  }
611
612
  // If this has a segment register, print it.
613
2.89k
  reg = MCOperand_getReg(SegReg);
614
2.89k
  if (reg) {
615
117
    _printOperand(MI, Op + 1, O);
616
117
    SStream_concat0(O, ":");
617
117
    if (MI->csh->detail) {
618
117
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_register_map(reg);
619
117
    }
620
117
  }
621
622
2.89k
  SStream_concat0(O, "[");
623
624
2.89k
  if (MCOperand_isImm(DispSpec)) {
625
2.89k
    int64_t imm = MCOperand_getImm(DispSpec);
626
2.89k
    if (MI->csh->detail)
627
2.89k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = imm;
628
629
2.89k
    if (imm < 0)
630
581
      printImm(MI, O, arch_masks[MI->csh->mode] & imm, true);
631
2.31k
    else
632
2.31k
      printImm(MI, O, imm, true);
633
2.89k
  }
634
635
2.89k
  SStream_concat0(O, "]");
636
637
2.89k
  if (MI->csh->detail)
638
2.89k
    MI->flat_insn->detail->x86.op_count++;
639
640
2.89k
  if (MI->op1_size == 0)
641
2.89k
    MI->op1_size = MI->x86opsize;
642
2.89k
}
643
644
static void printU8Imm(MCInst *MI, unsigned Op, SStream *O)
645
16.9k
{
646
16.9k
  uint8_t val = MCOperand_getImm(MCInst_getOperand(MI, Op)) & 0xff;
647
648
16.9k
  printImm(MI, O, val, true);
649
650
16.9k
  if (MI->csh->detail) {
651
16.9k
#ifndef CAPSTONE_DIET
652
16.9k
    uint8_t access[6];
653
16.9k
#endif
654
655
16.9k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_IMM;
656
16.9k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].imm = val;
657
16.9k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = 1;
658
659
16.9k
#ifndef CAPSTONE_DIET
660
16.9k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
661
16.9k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
662
16.9k
#endif
663
664
16.9k
    MI->flat_insn->detail->x86.op_count++;
665
16.9k
  }
666
16.9k
}
667
668
static void printMemOffs8(MCInst *MI, unsigned OpNo, SStream *O)
669
1.14k
{
670
1.14k
  SStream_concat0(O, "byte ptr ");
671
1.14k
  MI->x86opsize = 1;
672
1.14k
  printMemOffset(MI, OpNo, O);
673
1.14k
}
674
675
static void printMemOffs16(MCInst *MI, unsigned OpNo, SStream *O)
676
324
{
677
324
  SStream_concat0(O, "word ptr ");
678
324
  MI->x86opsize = 2;
679
324
  printMemOffset(MI, OpNo, O);
680
324
}
681
682
static void printMemOffs32(MCInst *MI, unsigned OpNo, SStream *O)
683
1.15k
{
684
1.15k
  SStream_concat0(O, "dword ptr ");
685
1.15k
  MI->x86opsize = 4;
686
1.15k
  printMemOffset(MI, OpNo, O);
687
1.15k
}
688
689
static void printMemOffs64(MCInst *MI, unsigned OpNo, SStream *O)
690
268
{
691
268
  SStream_concat0(O, "qword ptr ");
692
268
  MI->x86opsize = 8;
693
268
  printMemOffset(MI, OpNo, O);
694
268
}
695
696
static void printInstruction(MCInst *MI, SStream *O);
697
698
void X86_Intel_printInst(MCInst *MI, SStream *O, void *Info)
699
258k
{
700
258k
  x86_reg reg, reg2;
701
258k
  enum cs_ac_type access1, access2;
702
703
  // printf("opcode = %u\n", MCInst_getOpcode(MI));
704
705
  // perhaps this instruction does not need printer
706
258k
  if (MI->assembly[0]) {
707
0
    strncpy(O->buffer, MI->assembly, sizeof(O->buffer));
708
0
    return;
709
0
  }
710
711
258k
  X86_lockrep(MI, O);
712
258k
  printInstruction(MI, O);
713
714
258k
  reg = X86_insn_reg_intel(MCInst_getOpcode(MI), &access1);
715
258k
  if (MI->csh->detail) {
716
258k
#ifndef CAPSTONE_DIET
717
258k
    uint8_t access[6] = {0};
718
258k
#endif
719
720
    // first op can be embedded in the asm by llvm.
721
    // so we have to add the missing register as the first operand
722
258k
    if (reg) {
723
      // shift all the ops right to leave 1st slot for this new register op
724
26.8k
      memmove(&(MI->flat_insn->detail->x86.operands[1]), &(MI->flat_insn->detail->x86.operands[0]),
725
26.8k
          sizeof(MI->flat_insn->detail->x86.operands[0]) * (ARR_SIZE(MI->flat_insn->detail->x86.operands) - 1));
726
26.8k
      MI->flat_insn->detail->x86.operands[0].type = X86_OP_REG;
727
26.8k
      MI->flat_insn->detail->x86.operands[0].reg = reg;
728
26.8k
      MI->flat_insn->detail->x86.operands[0].size = MI->csh->regsize_map[reg];
729
26.8k
      MI->flat_insn->detail->x86.operands[0].access = access1;
730
26.8k
      MI->flat_insn->detail->x86.op_count++;
731
231k
    } else {
732
231k
      if (X86_insn_reg_intel2(MCInst_getOpcode(MI), &reg, &access1, &reg2, &access2)) {
733
2.74k
        MI->flat_insn->detail->x86.operands[0].type = X86_OP_REG;
734
2.74k
        MI->flat_insn->detail->x86.operands[0].reg = reg;
735
2.74k
        MI->flat_insn->detail->x86.operands[0].size = MI->csh->regsize_map[reg];
736
2.74k
        MI->flat_insn->detail->x86.operands[0].access = access1;
737
2.74k
        MI->flat_insn->detail->x86.operands[1].type = X86_OP_REG;
738
2.74k
        MI->flat_insn->detail->x86.operands[1].reg = reg2;
739
2.74k
        MI->flat_insn->detail->x86.operands[1].size = MI->csh->regsize_map[reg2];
740
2.74k
        MI->flat_insn->detail->x86.operands[1].access = access2;
741
2.74k
        MI->flat_insn->detail->x86.op_count = 2;
742
2.74k
      }
743
231k
    }
744
745
258k
#ifndef CAPSTONE_DIET
746
258k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
747
258k
    MI->flat_insn->detail->x86.operands[0].access = access[0];
748
258k
    MI->flat_insn->detail->x86.operands[1].access = access[1];
749
258k
#endif
750
258k
  }
751
752
258k
  if (MI->op1_size == 0 && reg)
753
19.2k
    MI->op1_size = MI->csh->regsize_map[reg];
754
258k
}
755
756
/// printPCRelImm - This is used to print an immediate value that ends up
757
/// being encoded as a pc-relative value.
758
static void printPCRelImm(MCInst *MI, unsigned OpNo, SStream *O)
759
17.7k
{
760
17.7k
  MCOperand *Op = MCInst_getOperand(MI, OpNo);
761
17.7k
  if (MCOperand_isImm(Op)) {
762
17.7k
    int64_t imm = MCOperand_getImm(Op) + MI->flat_insn->size + MI->address;
763
17.7k
    uint8_t opsize = X86_immediate_size(MI->Opcode, NULL);
764
765
    // truncat imm for non-64bit
766
17.7k
    if (MI->csh->mode != CS_MODE_64) {
767
12.9k
      imm = imm & 0xffffffff;
768
12.9k
    }
769
770
17.7k
    printImm(MI, O, imm, true);
771
772
17.7k
    if (MI->csh->detail) {
773
17.7k
#ifndef CAPSTONE_DIET
774
17.7k
      uint8_t access[6];
775
17.7k
#endif
776
777
17.7k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_IMM;
778
      // if op_count > 0, then this operand's size is taken from the destination op
779
17.7k
      if (MI->flat_insn->detail->x86.op_count > 0)
780
0
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->flat_insn->detail->x86.operands[0].size;
781
17.7k
      else if (opsize > 0)
782
654
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = opsize;
783
17.0k
      else
784
17.0k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->imm_size;
785
17.7k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].imm = imm;
786
787
17.7k
#ifndef CAPSTONE_DIET
788
17.7k
      get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
789
17.7k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
790
17.7k
#endif
791
792
17.7k
      MI->flat_insn->detail->x86.op_count++;
793
17.7k
    }
794
795
17.7k
    if (MI->op1_size == 0)
796
17.7k
      MI->op1_size = MI->imm_size;
797
17.7k
  }
798
17.7k
}
799
800
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
801
270k
{
802
270k
  MCOperand *Op  = MCInst_getOperand(MI, OpNo);
803
804
270k
  if (MCOperand_isReg(Op)) {
805
238k
    unsigned int reg = MCOperand_getReg(Op);
806
807
238k
    printRegName(O, reg);
808
238k
    if (MI->csh->detail) {
809
238k
      if (MI->csh->doing_mem) {
810
24.0k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_register_map(reg);
811
214k
      } else {
812
214k
#ifndef CAPSTONE_DIET
813
214k
        uint8_t access[6];
814
214k
#endif
815
816
214k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_REG;
817
214k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].reg = X86_register_map(reg);
818
214k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->csh->regsize_map[X86_register_map(reg)];
819
820
214k
#ifndef CAPSTONE_DIET
821
214k
        get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
822
214k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
823
214k
#endif
824
825
214k
        MI->flat_insn->detail->x86.op_count++;
826
214k
      }
827
238k
    }
828
829
238k
    if (MI->op1_size == 0)
830
117k
      MI->op1_size = MI->csh->regsize_map[X86_register_map(reg)];
831
238k
  } else if (MCOperand_isImm(Op)) {
832
32.0k
    uint8_t encsize;
833
32.0k
    int64_t imm = MCOperand_getImm(Op);
834
32.0k
    uint8_t opsize = X86_immediate_size(MCInst_getOpcode(MI), &encsize);
835
836
32.0k
    if (opsize == 1)    // print 1 byte immediate in positive form
837
14.3k
      imm = imm & 0xff;
838
839
    // printf(">>> id = %u\n", MI->flat_insn->id);
840
32.0k
    switch(MI->flat_insn->id) {
841
14.8k
      default:
842
14.8k
        printImm(MI, O, imm, MI->csh->imm_unsigned);
843
14.8k
        break;
844
845
86
      case X86_INS_MOVABS:
846
3.93k
      case X86_INS_MOV:
847
        // do not print number in negative form
848
3.93k
        printImm(MI, O, imm, true);
849
3.93k
        break;
850
851
0
      case X86_INS_IN:
852
0
      case X86_INS_OUT:
853
0
      case X86_INS_INT:
854
        // do not print number in negative form
855
0
        imm = imm & 0xff;
856
0
        printImm(MI, O, imm, true);
857
0
        break;
858
859
690
      case X86_INS_LCALL:
860
1.99k
      case X86_INS_LJMP:
861
1.99k
      case X86_INS_JMP:
862
        // always print address in positive form
863
1.99k
        if (OpNo == 1) { // ptr16 part
864
998
          imm = imm & 0xffff;
865
998
          opsize = 2;
866
998
        } else
867
998
          opsize = 4;
868
1.99k
        printImm(MI, O, imm, true);
869
1.99k
        break;
870
871
4.04k
      case X86_INS_AND:
872
5.87k
      case X86_INS_OR:
873
7.99k
      case X86_INS_XOR:
874
        // do not print number in negative form
875
7.99k
        if (imm >= 0 && imm <= HEX_THRESHOLD)
876
1.13k
          printImm(MI, O, imm, true);
877
6.85k
        else {
878
6.85k
          imm = arch_masks[opsize? opsize : MI->imm_size] & imm;
879
6.85k
          printImm(MI, O, imm, true);
880
6.85k
        }
881
7.99k
        break;
882
883
2.40k
      case X86_INS_RET:
884
3.33k
      case X86_INS_RETF:
885
        // RET imm16
886
3.33k
        if (imm >= 0 && imm <= HEX_THRESHOLD)
887
246
          printImm(MI, O, imm, true);
888
3.09k
        else {
889
3.09k
          imm = 0xffff & imm;
890
3.09k
          printImm(MI, O, imm, true);
891
3.09k
        }
892
3.33k
        break;
893
32.0k
    }
894
895
32.0k
    if (MI->csh->detail) {
896
32.0k
      if (MI->csh->doing_mem) {
897
0
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = imm;
898
32.0k
      } else {
899
32.0k
#ifndef CAPSTONE_DIET
900
32.0k
        uint8_t access[6];
901
32.0k
#endif
902
903
32.0k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_IMM;
904
32.0k
        if (opsize > 0) {
905
27.2k
          MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = opsize;
906
27.2k
          MI->flat_insn->detail->x86.encoding.imm_size = encsize;
907
27.2k
        } else if (MI->flat_insn->detail->x86.op_count > 0) {
908
1.16k
          if (MI->flat_insn->id != X86_INS_LCALL && MI->flat_insn->id != X86_INS_LJMP) {
909
1.16k
            MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size =
910
1.16k
              MI->flat_insn->detail->x86.operands[0].size;
911
1.16k
          } else
912
0
            MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->imm_size;
913
1.16k
        } else
914
3.72k
          MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->imm_size;
915
32.0k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].imm = imm;
916
917
32.0k
#ifndef CAPSTONE_DIET
918
32.0k
        get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
919
32.0k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
920
32.0k
#endif
921
922
32.0k
        MI->flat_insn->detail->x86.op_count++;
923
32.0k
      }
924
32.0k
    }
925
32.0k
  }
926
270k
}
927
928
static void printMemReference(MCInst *MI, unsigned Op, SStream *O)
929
116k
{
930
116k
  bool NeedPlus = false;
931
116k
  MCOperand *BaseReg  = MCInst_getOperand(MI, Op + X86_AddrBaseReg);
932
116k
  uint64_t ScaleVal = MCOperand_getImm(MCInst_getOperand(MI, Op + X86_AddrScaleAmt));
933
116k
  MCOperand *IndexReg  = MCInst_getOperand(MI, Op + X86_AddrIndexReg);
934
116k
  MCOperand *DispSpec = MCInst_getOperand(MI, Op + X86_AddrDisp);
935
116k
  MCOperand *SegReg = MCInst_getOperand(MI, Op + X86_AddrSegmentReg);
936
116k
  int reg;
937
938
116k
  if (MI->csh->detail) {
939
116k
#ifndef CAPSTONE_DIET
940
116k
    uint8_t access[6];
941
116k
#endif
942
943
116k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
944
116k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->x86opsize;
945
116k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_INVALID;
946
116k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_register_map(MCOperand_getReg(BaseReg));
947
116k
        if (MCOperand_getReg(IndexReg) != X86_EIZ) {
948
116k
            MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.index = X86_register_map(MCOperand_getReg(IndexReg));
949
116k
        }
950
116k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = (int)ScaleVal;
951
116k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = 0;
952
953
116k
#ifndef CAPSTONE_DIET
954
116k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
955
116k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
956
116k
#endif
957
116k
  }
958
959
  // If this has a segment register, print it.
960
116k
  reg = MCOperand_getReg(SegReg);
961
116k
  if (reg) {
962
2.58k
    _printOperand(MI, Op + X86_AddrSegmentReg, O);
963
2.58k
    if (MI->csh->detail) {
964
2.58k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_register_map(reg);
965
2.58k
    }
966
2.58k
    SStream_concat0(O, ":");
967
2.58k
  }
968
969
116k
  SStream_concat0(O, "[");
970
971
116k
  if (MCOperand_getReg(BaseReg)) {
972
114k
    _printOperand(MI, Op + X86_AddrBaseReg, O);
973
114k
    NeedPlus = true;
974
114k
  }
975
976
116k
  if (MCOperand_getReg(IndexReg) && MCOperand_getReg(IndexReg) != X86_EIZ) {
977
28.6k
    if (NeedPlus) SStream_concat0(O, " + ");
978
28.6k
    _printOperand(MI, Op + X86_AddrIndexReg, O);
979
28.6k
    if (ScaleVal != 1)
980
6.50k
      SStream_concat(O, "*%u", ScaleVal);
981
28.6k
    NeedPlus = true;
982
28.6k
  }
983
984
116k
  if (MCOperand_isImm(DispSpec)) {
985
116k
    int64_t DispVal = MCOperand_getImm(DispSpec);
986
116k
    if (MI->csh->detail)
987
116k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = DispVal;
988
116k
    if (DispVal) {
989
28.3k
      if (NeedPlus) {
990
26.7k
        if (DispVal < 0) {
991
10.7k
          SStream_concat0(O, " - ");
992
10.7k
          printImm(MI, O, -DispVal, true);
993
15.9k
        } else {
994
15.9k
          SStream_concat0(O, " + ");
995
15.9k
          printImm(MI, O, DispVal, true);
996
15.9k
        }
997
26.7k
      } else {
998
        // memory reference to an immediate address
999
1.63k
        if (MI->csh->mode == CS_MODE_64)
1000
66
          MI->op1_size = 8;
1001
1.63k
        if (DispVal < 0) {
1002
462
          printImm(MI, O, arch_masks[MI->csh->mode] & DispVal, true);
1003
1.17k
        } else {
1004
1.17k
          printImm(MI, O, DispVal, true);
1005
1.17k
        }
1006
1.63k
      }
1007
1008
88.2k
    } else {
1009
      // DispVal = 0
1010
88.2k
      if (!NeedPlus)  // [0]
1011
57
        SStream_concat0(O, "0");
1012
88.2k
    }
1013
116k
  }
1014
1015
116k
  SStream_concat0(O, "]");
1016
1017
116k
  if (MI->csh->detail)
1018
116k
    MI->flat_insn->detail->x86.op_count++;
1019
1020
116k
  if (MI->op1_size == 0)
1021
73.0k
    MI->op1_size = MI->x86opsize;
1022
116k
}
1023
1024
static void printanymem(MCInst *MI, unsigned OpNo, SStream *O)
1025
2.91k
{
1026
2.91k
  switch(MI->Opcode) {
1027
128
    default: break;
1028
181
    case X86_LEA16r:
1029
181
         MI->x86opsize = 2;
1030
181
         break;
1031
177
    case X86_LEA32r:
1032
797
    case X86_LEA64_32r:
1033
797
         MI->x86opsize = 4;
1034
797
         break;
1035
43
    case X86_LEA64r:
1036
43
         MI->x86opsize = 8;
1037
43
         break;
1038
140
    case X86_BNDCL32rm:
1039
323
    case X86_BNDCN32rm:
1040
523
    case X86_BNDCU32rm:
1041
852
    case X86_BNDSTXmr:
1042
1.15k
    case X86_BNDLDXrm:
1043
1.35k
    case X86_BNDCL64rm:
1044
1.55k
    case X86_BNDCN64rm:
1045
1.77k
    case X86_BNDCU64rm:
1046
1.77k
         MI->x86opsize = 16;
1047
1.77k
         break;
1048
2.91k
  }
1049
1050
2.91k
  printMemReference(MI, OpNo, O);
1051
2.91k
}
1052
1053
#ifdef CAPSTONE_X86_REDUCE
1054
#include "X86GenAsmWriter1_reduce.inc"
1055
#else
1056
#include "X86GenAsmWriter1.inc"
1057
#endif
1058
1059
#include "X86GenRegisterName1.inc"
1060
1061
#endif