Coverage Report

Created: 2025-07-01 07:03

/src/capstonenext/arch/X86/X86IntelInstPrinter.c
Line
Count
Source (jump to first uncovered line)
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
#ifdef _MSC_VER
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
69.4k
{
66
69.4k
  if (MI->csh->detail_opt != CS_OPT_ON)
67
0
    return;
68
69
69.4k
  MI->csh->doing_mem = status;
70
69.4k
  if (!status)
71
    // done, create the next operand slot
72
34.7k
    MI->flat_insn->detail->x86.op_count++;
73
74
69.4k
}
75
76
static void printopaquemem(MCInst *MI, unsigned OpNo, SStream *O)
77
3.94k
{
78
  // FIXME: do this with autogen
79
  // printf(">>> ID = %u\n", MI->flat_insn->id);
80
3.94k
  switch(MI->flat_insn->id) {
81
1.57k
    default:
82
1.57k
      SStream_concat0(O, "ptr ");
83
1.57k
      break;
84
427
    case X86_INS_SGDT:
85
931
    case X86_INS_SIDT:
86
1.25k
    case X86_INS_LGDT:
87
1.38k
    case X86_INS_LIDT:
88
1.44k
    case X86_INS_FXRSTOR:
89
1.46k
    case X86_INS_FXSAVE:
90
1.82k
    case X86_INS_LJMP:
91
2.37k
    case X86_INS_LCALL:
92
      // do not print "ptr"
93
2.37k
      break;
94
3.94k
  }
95
96
3.94k
  switch(MI->csh->mode) {
97
885
    case CS_MODE_16:
98
885
      switch(MI->flat_insn->id) {
99
249
        default:
100
249
          MI->x86opsize = 2;
101
249
          break;
102
84
        case X86_INS_LJMP:
103
324
        case X86_INS_LCALL:
104
324
          MI->x86opsize = 4;
105
324
          break;
106
80
        case X86_INS_SGDT:
107
195
        case X86_INS_SIDT:
108
272
        case X86_INS_LGDT:
109
312
        case X86_INS_LIDT:
110
312
          MI->x86opsize = 6;
111
312
          break;
112
885
      }
113
885
      break;
114
1.64k
    case CS_MODE_32:
115
1.64k
      switch(MI->flat_insn->id) {
116
703
        default:
117
703
          MI->x86opsize = 4;
118
703
          break;
119
204
        case X86_INS_LJMP:
120
457
        case X86_INS_JMP:
121
649
        case X86_INS_LCALL:
122
718
        case X86_INS_SGDT:
123
809
        case X86_INS_SIDT:
124
883
        case X86_INS_LGDT:
125
941
        case X86_INS_LIDT:
126
941
          MI->x86opsize = 6;
127
941
          break;
128
1.64k
      }
129
1.64k
      break;
130
1.64k
    case CS_MODE_64:
131
1.41k
      switch(MI->flat_insn->id) {
132
442
        default:
133
442
          MI->x86opsize = 8;
134
442
          break;
135
75
        case X86_INS_LJMP:
136
190
        case X86_INS_LCALL:
137
468
        case X86_INS_SGDT:
138
766
        case X86_INS_SIDT:
139
942
        case X86_INS_LGDT:
140
974
        case X86_INS_LIDT:
141
974
          MI->x86opsize = 10;
142
974
          break;
143
1.41k
      }
144
1.41k
      break;
145
1.41k
    default:  // never reach
146
0
      break;
147
3.94k
  }
148
149
3.94k
  printMemReference(MI, OpNo, O);
150
3.94k
}
151
152
static void printi8mem(MCInst *MI, unsigned OpNo, SStream *O)
153
50.5k
{
154
50.5k
  SStream_concat0(O, "byte ptr ");
155
50.5k
  MI->x86opsize = 1;
156
50.5k
  printMemReference(MI, OpNo, O);
157
50.5k
}
158
159
static void printi16mem(MCInst *MI, unsigned OpNo, SStream *O)
160
10.3k
{
161
10.3k
  MI->x86opsize = 2;
162
10.3k
  SStream_concat0(O, "word ptr ");
163
10.3k
  printMemReference(MI, OpNo, O);
164
10.3k
}
165
166
static void printi32mem(MCInst *MI, unsigned OpNo, SStream *O)
167
18.7k
{
168
18.7k
  MI->x86opsize = 4;
169
18.7k
  SStream_concat0(O, "dword ptr ");
170
18.7k
  printMemReference(MI, OpNo, O);
171
18.7k
}
172
173
static void printi64mem(MCInst *MI, unsigned OpNo, SStream *O)
174
6.23k
{
175
6.23k
  SStream_concat0(O, "qword ptr ");
176
6.23k
  MI->x86opsize = 8;
177
6.23k
  printMemReference(MI, OpNo, O);
178
6.23k
}
179
180
static void printi128mem(MCInst *MI, unsigned OpNo, SStream *O)
181
2.19k
{
182
2.19k
  SStream_concat0(O, "xmmword ptr ");
183
2.19k
  MI->x86opsize = 16;
184
2.19k
  printMemReference(MI, OpNo, O);
185
2.19k
}
186
187
static void printi512mem(MCInst *MI, unsigned OpNo, SStream *O)
188
1.24k
{
189
1.24k
  SStream_concat0(O, "zmmword ptr ");
190
1.24k
  MI->x86opsize = 64;
191
1.24k
  printMemReference(MI, OpNo, O);
192
1.24k
}
193
194
#ifndef CAPSTONE_X86_REDUCE
195
static void printi256mem(MCInst *MI, unsigned OpNo, SStream *O)
196
1.06k
{
197
1.06k
  SStream_concat0(O, "ymmword ptr ");
198
1.06k
  MI->x86opsize = 32;
199
1.06k
  printMemReference(MI, OpNo, O);
200
1.06k
}
201
202
static void printf32mem(MCInst *MI, unsigned OpNo, SStream *O)
203
2.03k
{
204
2.03k
  switch(MCInst_getOpcode(MI)) {
205
1.38k
    default:
206
1.38k
      SStream_concat0(O, "dword ptr ");
207
1.38k
      MI->x86opsize = 4;
208
1.38k
      break;
209
187
    case X86_FSTENVm:
210
648
    case X86_FLDENVm:
211
      // TODO: fix this in tablegen instead
212
648
      switch(MI->csh->mode) {
213
0
        default:    // never reach
214
0
          break;
215
189
        case CS_MODE_16:
216
189
          MI->x86opsize = 14;
217
189
          break;
218
226
        case CS_MODE_32:
219
459
        case CS_MODE_64:
220
459
          MI->x86opsize = 28;
221
459
          break;
222
648
      }
223
648
      break;
224
2.03k
  }
225
226
2.03k
  printMemReference(MI, OpNo, O);
227
2.03k
}
228
229
static void printf64mem(MCInst *MI, unsigned OpNo, SStream *O)
230
1.81k
{
231
  // TODO: fix COMISD in Tablegen instead (#1456)
232
1.81k
  if (MI->op1_size == 16) {
233
    // printf("printf64mem id = %u\n", MCInst_getOpcode(MI));
234
913
    switch(MCInst_getOpcode(MI)) {
235
851
      default:
236
851
        SStream_concat0(O, "qword ptr ");
237
851
        MI->x86opsize = 8;
238
851
        break;
239
0
      case X86_MOVPQI2QImr:
240
62
      case X86_COMISDrm:
241
62
        SStream_concat0(O, "xmmword ptr ");
242
62
        MI->x86opsize = 16;
243
62
        break;
244
913
    }
245
913
  } else {
246
903
    SStream_concat0(O, "qword ptr ");
247
903
    MI->x86opsize = 8;
248
903
  }
249
250
1.81k
  printMemReference(MI, OpNo, O);
251
1.81k
}
252
253
static void printf80mem(MCInst *MI, unsigned OpNo, SStream *O)
254
208
{
255
208
  switch(MCInst_getOpcode(MI)) {
256
50
    default:
257
50
      SStream_concat0(O, "xword ptr ");
258
50
      break;
259
153
    case X86_FBLDm:
260
158
    case X86_FBSTPm:
261
158
      break;
262
208
  }
263
264
208
  MI->x86opsize = 10;
265
208
  printMemReference(MI, OpNo, O);
266
208
}
267
268
static void printf128mem(MCInst *MI, unsigned OpNo, SStream *O)
269
1.22k
{
270
1.22k
  SStream_concat0(O, "xmmword ptr ");
271
1.22k
  MI->x86opsize = 16;
272
1.22k
  printMemReference(MI, OpNo, O);
273
1.22k
}
274
275
static void printf256mem(MCInst *MI, unsigned OpNo, SStream *O)
276
1.37k
{
277
1.37k
  SStream_concat0(O, "ymmword ptr ");
278
1.37k
  MI->x86opsize = 32;
279
1.37k
  printMemReference(MI, OpNo, O);
280
1.37k
}
281
282
static void printf512mem(MCInst *MI, unsigned OpNo, SStream *O)
283
168
{
284
168
  SStream_concat0(O, "zmmword ptr ");
285
168
  MI->x86opsize = 64;
286
168
  printMemReference(MI, OpNo, O);
287
168
}
288
#endif
289
290
static const char *getRegisterName(unsigned RegNo);
291
static void printRegName(SStream *OS, unsigned RegNo)
292
351k
{
293
351k
  SStream_concat0(OS, getRegisterName(RegNo));
294
351k
}
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
94.4k
{
312
94.4k
  if (positive) {
313
    // always print this number in positive form
314
79.8k
    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
79.8k
    } else { // Intel syntax
348
79.8k
      if (imm < 0) {
349
1.36k
        if (MI->op1_size) {
350
185
          switch(MI->op1_size) {
351
185
            default:
352
185
              break;
353
185
            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
185
          }
363
185
        }
364
365
1.36k
        SStream_concat(O, "0x%"PRIx64, imm);
366
78.5k
      } else {
367
78.5k
        if (imm > HEX_THRESHOLD)
368
73.7k
          SStream_concat(O, "0x%"PRIx64, imm);
369
4.77k
        else
370
4.77k
          SStream_concat(O, "%"PRIu64, imm);
371
78.5k
      }
372
79.8k
    }
373
79.8k
  } else {
374
14.5k
    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.5k
    } else { // Intel syntax
395
14.5k
      if (imm < 0) {
396
1.76k
        if (imm == 0x8000000000000000LL)  // imm == -imm
397
0
          SStream_concat0(O, "0x8000000000000000");
398
1.76k
        else if (imm < -HEX_THRESHOLD)
399
1.66k
          SStream_concat(O, "-0x%"PRIx64, -imm);
400
95
        else
401
95
          SStream_concat(O, "-%"PRIu64, -imm);
402
403
12.8k
      } else {
404
12.8k
        if (imm > HEX_THRESHOLD)
405
10.6k
          SStream_concat(O, "0x%"PRIx64, imm);
406
2.16k
        else
407
2.16k
          SStream_concat(O, "%"PRIu64, imm);
408
12.8k
      }
409
14.5k
    }
410
14.5k
  }
411
94.4k
}
412
413
// local printOperand, without updating public operands
414
static void _printOperand(MCInst *MI, unsigned OpNo, SStream *O)
415
131k
{
416
131k
  MCOperand *Op  = MCInst_getOperand(MI, OpNo);
417
131k
  if (MCOperand_isReg(Op)) {
418
131k
    printRegName(O, MCOperand_getReg(Op));
419
131k
  } 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
131k
}
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
647k
{
429
647k
#ifndef CAPSTONE_DIET
430
647k
  uint8_t i;
431
647k
  const uint8_t *arr = X86_get_op_access(h, id, eflags);
432
433
  // initialize access
434
647k
  memset(access, 0, CS_X86_MAXIMUM_OPERAND_SIZE * sizeof(access[0]));
435
436
647k
  if (!arr) {
437
0
    access[0] = 0;
438
0
    return;
439
0
  }
440
441
  // copy to access but zero out CS_AC_IGNORE
442
1.83M
  for(i = 0; arr[i]; i++) {
443
1.18M
    if (arr[i] != CS_AC_IGNORE)
444
1.00M
      access[i] = arr[i];
445
180k
    else
446
180k
      access[i] = 0;
447
1.18M
  }
448
449
  // mark the end of array
450
647k
  access[i] = 0;
451
647k
#endif
452
647k
}
453
#endif
454
455
static void printSrcIdx(MCInst *MI, unsigned Op, SStream *O)
456
15.8k
{
457
15.8k
  MCOperand *SegReg;
458
15.8k
  int reg;
459
460
15.8k
  if (MI->csh->detail_opt) {
461
15.8k
#ifndef CAPSTONE_DIET
462
15.8k
    uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE];
463
15.8k
#endif
464
465
15.8k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
466
15.8k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->x86opsize;
467
15.8k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_INVALID;
468
15.8k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_REG_INVALID;
469
15.8k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.index = X86_REG_INVALID;
470
15.8k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = 1;
471
15.8k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = 0;
472
473
15.8k
#ifndef CAPSTONE_DIET
474
15.8k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
475
15.8k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
476
15.8k
#endif
477
15.8k
  }
478
479
15.8k
  SegReg = MCInst_getOperand(MI, Op + 1);
480
15.8k
  reg = MCOperand_getReg(SegReg);
481
482
  // If this has a segment register, print it.
483
15.8k
  if (reg) {
484
384
    _printOperand(MI, Op + 1, O);
485
384
    if (MI->csh->detail_opt) {
486
384
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_register_map(reg);
487
384
    }
488
384
    SStream_concat0(O, ":");
489
384
  }
490
491
15.8k
  SStream_concat0(O, "[");
492
15.8k
  set_mem_access(MI, true);
493
15.8k
  printOperand(MI, Op, O);
494
15.8k
  SStream_concat0(O, "]");
495
15.8k
  set_mem_access(MI, false);
496
15.8k
}
497
498
static void printDstIdx(MCInst *MI, unsigned Op, SStream *O)
499
18.8k
{
500
18.8k
  if (MI->csh->detail_opt) {
501
18.8k
#ifndef CAPSTONE_DIET
502
18.8k
    uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE];
503
18.8k
#endif
504
505
18.8k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
506
18.8k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->x86opsize;
507
18.8k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_INVALID;
508
18.8k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_REG_INVALID;
509
18.8k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.index = X86_REG_INVALID;
510
18.8k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = 1;
511
18.8k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = 0;
512
513
18.8k
#ifndef CAPSTONE_DIET
514
18.8k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
515
18.8k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
516
18.8k
#endif
517
18.8k
  }
518
519
  // DI accesses are always ES-based on non-64bit mode
520
18.8k
  if (MI->csh->mode != CS_MODE_64) {
521
13.0k
    SStream_concat0(O, "es:[");
522
13.0k
    if (MI->csh->detail_opt) {
523
13.0k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_ES;
524
13.0k
    }
525
13.0k
  } else
526
5.84k
    SStream_concat0(O, "[");
527
528
18.8k
  set_mem_access(MI, true);
529
18.8k
  printOperand(MI, Op, O);
530
18.8k
  SStream_concat0(O, "]");
531
18.8k
  set_mem_access(MI, false);
532
18.8k
}
533
534
static void printSrcIdx8(MCInst *MI, unsigned OpNo, SStream *O)
535
4.70k
{
536
4.70k
  SStream_concat0(O, "byte ptr ");
537
4.70k
  MI->x86opsize = 1;
538
4.70k
  printSrcIdx(MI, OpNo, O);
539
4.70k
}
540
541
static void printSrcIdx16(MCInst *MI, unsigned OpNo, SStream *O)
542
2.87k
{
543
2.87k
  SStream_concat0(O, "word ptr ");
544
2.87k
  MI->x86opsize = 2;
545
2.87k
  printSrcIdx(MI, OpNo, O);
546
2.87k
}
547
548
static void printSrcIdx32(MCInst *MI, unsigned OpNo, SStream *O)
549
7.40k
{
550
7.40k
  SStream_concat0(O, "dword ptr ");
551
7.40k
  MI->x86opsize = 4;
552
7.40k
  printSrcIdx(MI, OpNo, O);
553
7.40k
}
554
555
static void printSrcIdx64(MCInst *MI, unsigned OpNo, SStream *O)
556
862
{
557
862
  SStream_concat0(O, "qword ptr ");
558
862
  MI->x86opsize = 8;
559
862
  printSrcIdx(MI, OpNo, O);
560
862
}
561
562
static void printDstIdx8(MCInst *MI, unsigned OpNo, SStream *O)
563
7.93k
{
564
7.93k
  SStream_concat0(O, "byte ptr ");
565
7.93k
  MI->x86opsize = 1;
566
7.93k
  printDstIdx(MI, OpNo, O);
567
7.93k
}
568
569
static void printDstIdx16(MCInst *MI, unsigned OpNo, SStream *O)
570
3.71k
{
571
3.71k
  SStream_concat0(O, "word ptr ");
572
3.71k
  MI->x86opsize = 2;
573
3.71k
  printDstIdx(MI, OpNo, O);
574
3.71k
}
575
576
static void printDstIdx32(MCInst *MI, unsigned OpNo, SStream *O)
577
6.41k
{
578
6.41k
  SStream_concat0(O, "dword ptr ");
579
6.41k
  MI->x86opsize = 4;
580
6.41k
  printDstIdx(MI, OpNo, O);
581
6.41k
}
582
583
static void printDstIdx64(MCInst *MI, unsigned OpNo, SStream *O)
584
794
{
585
794
  SStream_concat0(O, "qword ptr ");
586
794
  MI->x86opsize = 8;
587
794
  printDstIdx(MI, OpNo, O);
588
794
}
589
590
static void printMemOffset(MCInst *MI, unsigned Op, SStream *O)
591
3.14k
{
592
3.14k
  MCOperand *DispSpec = MCInst_getOperand(MI, Op);
593
3.14k
  MCOperand *SegReg = MCInst_getOperand(MI, Op + 1);
594
3.14k
  int reg;
595
596
3.14k
  if (MI->csh->detail_opt) {
597
3.14k
#ifndef CAPSTONE_DIET
598
3.14k
    uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE];
599
3.14k
#endif
600
601
3.14k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
602
3.14k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->x86opsize;
603
3.14k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_INVALID;
604
3.14k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_REG_INVALID;
605
3.14k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.index = X86_REG_INVALID;
606
3.14k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = 1;
607
3.14k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = 0;
608
609
3.14k
#ifndef CAPSTONE_DIET
610
3.14k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
611
3.14k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
612
3.14k
#endif
613
3.14k
  }
614
615
  // If this has a segment register, print it.
616
3.14k
  reg = MCOperand_getReg(SegReg);
617
3.14k
  if (reg) {
618
270
    _printOperand(MI, Op + 1, O);
619
270
    SStream_concat0(O, ":");
620
270
    if (MI->csh->detail_opt) {
621
270
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_register_map(reg);
622
270
    }
623
270
  }
624
625
3.14k
  SStream_concat0(O, "[");
626
627
3.14k
  if (MCOperand_isImm(DispSpec)) {
628
3.14k
    int64_t imm = MCOperand_getImm(DispSpec);
629
3.14k
    if (MI->csh->detail_opt)
630
3.14k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = imm;
631
632
3.14k
    if (imm < 0)
633
574
      printImm(MI, O, arch_masks[MI->csh->mode] & imm, true);
634
2.56k
    else
635
2.56k
      printImm(MI, O, imm, true);
636
3.14k
  }
637
638
3.14k
  SStream_concat0(O, "]");
639
640
3.14k
  if (MI->csh->detail_opt)
641
3.14k
    MI->flat_insn->detail->x86.op_count++;
642
643
3.14k
  if (MI->op1_size == 0)
644
3.14k
    MI->op1_size = MI->x86opsize;
645
3.14k
}
646
647
static void printU8Imm(MCInst *MI, unsigned Op, SStream *O)
648
10.2k
{
649
10.2k
  uint8_t val = MCOperand_getImm(MCInst_getOperand(MI, Op)) & 0xff;
650
651
10.2k
  printImm(MI, O, val, true);
652
653
10.2k
  if (MI->csh->detail_opt) {
654
10.2k
#ifndef CAPSTONE_DIET
655
10.2k
    uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE];
656
10.2k
#endif
657
658
10.2k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_IMM;
659
10.2k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].imm = val;
660
10.2k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = 1;
661
662
10.2k
#ifndef CAPSTONE_DIET
663
10.2k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
664
10.2k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
665
10.2k
#endif
666
667
10.2k
    MI->flat_insn->detail->x86.op_count++;
668
10.2k
  }
669
10.2k
}
670
671
static void printMemOffs8(MCInst *MI, unsigned OpNo, SStream *O)
672
1.61k
{
673
1.61k
  SStream_concat0(O, "byte ptr ");
674
1.61k
  MI->x86opsize = 1;
675
1.61k
  printMemOffset(MI, OpNo, O);
676
1.61k
}
677
678
static void printMemOffs16(MCInst *MI, unsigned OpNo, SStream *O)
679
504
{
680
504
  SStream_concat0(O, "word ptr ");
681
504
  MI->x86opsize = 2;
682
504
  printMemOffset(MI, OpNo, O);
683
504
}
684
685
static void printMemOffs32(MCInst *MI, unsigned OpNo, SStream *O)
686
877
{
687
877
  SStream_concat0(O, "dword ptr ");
688
877
  MI->x86opsize = 4;
689
877
  printMemOffset(MI, OpNo, O);
690
877
}
691
692
static void printMemOffs64(MCInst *MI, unsigned OpNo, SStream *O)
693
146
{
694
146
  SStream_concat0(O, "qword ptr ");
695
146
  MI->x86opsize = 8;
696
146
  printMemOffset(MI, OpNo, O);
697
146
}
698
699
static void printInstruction(MCInst *MI, SStream *O);
700
701
void X86_Intel_printInst(MCInst *MI, SStream *O, void *Info)
702
261k
{
703
261k
  x86_reg reg, reg2;
704
261k
  enum cs_ac_type access1, access2;
705
706
  // printf("opcode = %u\n", MCInst_getOpcode(MI));
707
708
  // perhaps this instruction does not need printer
709
261k
  if (MI->assembly[0]) {
710
0
    strncpy(O->buffer, MI->assembly, sizeof(O->buffer));
711
0
    return;
712
0
  }
713
714
261k
  X86_lockrep(MI, O);
715
261k
  printInstruction(MI, O);
716
717
261k
  reg = X86_insn_reg_intel(MCInst_getOpcode(MI), &access1);
718
261k
  if (MI->csh->detail_opt) {
719
261k
#ifndef CAPSTONE_DIET
720
261k
    uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE] = {0};
721
261k
#endif
722
723
    // first op can be embedded in the asm by llvm.
724
    // so we have to add the missing register as the first operand
725
261k
    if (reg) {
726
      // shift all the ops right to leave 1st slot for this new register op
727
30.8k
      memmove(&(MI->flat_insn->detail->x86.operands[1]), &(MI->flat_insn->detail->x86.operands[0]),
728
30.8k
          sizeof(MI->flat_insn->detail->x86.operands[0]) * (ARR_SIZE(MI->flat_insn->detail->x86.operands) - 1));
729
30.8k
      MI->flat_insn->detail->x86.operands[0].type = X86_OP_REG;
730
30.8k
      MI->flat_insn->detail->x86.operands[0].reg = reg;
731
30.8k
      MI->flat_insn->detail->x86.operands[0].size = MI->csh->regsize_map[reg];
732
30.8k
      MI->flat_insn->detail->x86.operands[0].access = access1;
733
30.8k
      MI->flat_insn->detail->x86.op_count++;
734
230k
    } else {
735
230k
      if (X86_insn_reg_intel2(MCInst_getOpcode(MI), &reg, &access1, &reg2, &access2)) {
736
6.42k
        MI->flat_insn->detail->x86.operands[0].type = X86_OP_REG;
737
6.42k
        MI->flat_insn->detail->x86.operands[0].reg = reg;
738
6.42k
        MI->flat_insn->detail->x86.operands[0].size = MI->csh->regsize_map[reg];
739
6.42k
        MI->flat_insn->detail->x86.operands[0].access = access1;
740
6.42k
        MI->flat_insn->detail->x86.operands[1].type = X86_OP_REG;
741
6.42k
        MI->flat_insn->detail->x86.operands[1].reg = reg2;
742
6.42k
        MI->flat_insn->detail->x86.operands[1].size = MI->csh->regsize_map[reg2];
743
6.42k
        MI->flat_insn->detail->x86.operands[1].access = access2;
744
6.42k
        MI->flat_insn->detail->x86.op_count = 2;
745
6.42k
      }
746
230k
    }
747
748
261k
#ifndef CAPSTONE_DIET
749
261k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
750
261k
    MI->flat_insn->detail->x86.operands[0].access = access[0];
751
261k
    MI->flat_insn->detail->x86.operands[1].access = access[1];
752
261k
#endif
753
261k
  }
754
755
261k
  if (MI->op1_size == 0 && reg)
756
23.4k
    MI->op1_size = MI->csh->regsize_map[reg];
757
261k
}
758
759
/// printPCRelImm - This is used to print an immediate value that ends up
760
/// being encoded as a pc-relative value.
761
static void printPCRelImm(MCInst *MI, unsigned OpNo, SStream *O)
762
17.5k
{
763
17.5k
  MCOperand *Op = MCInst_getOperand(MI, OpNo);
764
17.5k
  if (MCOperand_isImm(Op)) {
765
17.5k
    int64_t imm = MCOperand_getImm(Op) + MI->flat_insn->size + MI->address;
766
17.5k
    uint8_t opsize = X86_immediate_size(MI->Opcode, NULL);
767
768
    // truncate imm for non-64bit
769
17.5k
    if (MI->csh->mode != CS_MODE_64) {
770
11.2k
      imm = imm & 0xffffffff;
771
11.2k
    }
772
773
17.5k
    printImm(MI, O, imm, true);
774
775
17.5k
    if (MI->csh->detail_opt) {
776
17.5k
#ifndef CAPSTONE_DIET
777
17.5k
      uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE];
778
17.5k
#endif
779
780
17.5k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_IMM;
781
      // if op_count > 0, then this operand's size is taken from the destination op
782
17.5k
      if (MI->flat_insn->detail->x86.op_count > 0)
783
0
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->flat_insn->detail->x86.operands[0].size;
784
17.5k
      else if (opsize > 0)
785
391
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = opsize;
786
17.1k
      else
787
17.1k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->imm_size;
788
17.5k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].imm = imm;
789
790
17.5k
#ifndef CAPSTONE_DIET
791
17.5k
      get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
792
17.5k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
793
17.5k
#endif
794
795
17.5k
      MI->flat_insn->detail->x86.op_count++;
796
17.5k
    }
797
798
17.5k
    if (MI->op1_size == 0)
799
17.5k
      MI->op1_size = MI->imm_size;
800
17.5k
  }
801
17.5k
}
802
803
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
804
250k
{
805
250k
  MCOperand *Op  = MCInst_getOperand(MI, OpNo);
806
807
250k
  if (MCOperand_isReg(Op)) {
808
220k
    unsigned int reg = MCOperand_getReg(Op);
809
810
220k
    printRegName(O, reg);
811
220k
    if (MI->csh->detail_opt) {
812
220k
      if (MI->csh->doing_mem) {
813
34.7k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_register_map(reg);
814
185k
      } else {
815
185k
#ifndef CAPSTONE_DIET
816
185k
        uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE];
817
185k
#endif
818
819
185k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_REG;
820
185k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].reg = X86_register_map(reg);
821
185k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->csh->regsize_map[X86_register_map(reg)];
822
823
185k
#ifndef CAPSTONE_DIET
824
185k
        get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
825
185k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
826
185k
#endif
827
828
185k
        MI->flat_insn->detail->x86.op_count++;
829
185k
      }
830
220k
    }
831
832
220k
    if (MI->op1_size == 0)
833
115k
      MI->op1_size = MI->csh->regsize_map[X86_register_map(reg)];
834
220k
  } else if (MCOperand_isImm(Op)) {
835
30.3k
    uint8_t encsize;
836
30.3k
    int64_t imm = MCOperand_getImm(Op);
837
30.3k
    uint8_t opsize = X86_immediate_size(MCInst_getOpcode(MI), &encsize);
838
839
30.3k
    if (opsize == 1)    // print 1 byte immediate in positive form
840
14.2k
      imm = imm & 0xff;
841
842
    // printf(">>> id = %u\n", MI->flat_insn->id);
843
30.3k
    switch(MI->flat_insn->id) {
844
14.5k
      default:
845
14.5k
        printImm(MI, O, imm, MI->csh->imm_unsigned);
846
14.5k
        break;
847
848
60
      case X86_INS_MOVABS:
849
4.43k
      case X86_INS_MOV:
850
        // do not print number in negative form
851
4.43k
        printImm(MI, O, imm, true);
852
4.43k
        break;
853
854
0
      case X86_INS_IN:
855
0
      case X86_INS_OUT:
856
0
      case X86_INS_INT:
857
        // do not print number in negative form
858
0
        imm = imm & 0xff;
859
0
        printImm(MI, O, imm, true);
860
0
        break;
861
862
776
      case X86_INS_LCALL:
863
1.36k
      case X86_INS_LJMP:
864
1.36k
      case X86_INS_JMP:
865
        // always print address in positive form
866
1.36k
        if (OpNo == 1) { // ptr16 part
867
684
          imm = imm & 0xffff;
868
684
          opsize = 2;
869
684
        } else
870
684
          opsize = 4;
871
1.36k
        printImm(MI, O, imm, true);
872
1.36k
        break;
873
874
2.65k
      case X86_INS_AND:
875
4.74k
      case X86_INS_OR:
876
6.64k
      case X86_INS_XOR:
877
        // do not print number in negative form
878
6.64k
        if (imm >= 0 && imm <= HEX_THRESHOLD)
879
780
          printImm(MI, O, imm, true);
880
5.86k
        else {
881
5.86k
          imm = arch_masks[opsize? opsize : MI->imm_size] & imm;
882
5.86k
          printImm(MI, O, imm, true);
883
5.86k
        }
884
6.64k
        break;
885
886
2.91k
      case X86_INS_RET:
887
3.34k
      case X86_INS_RETF:
888
        // RET imm16
889
3.34k
        if (imm >= 0 && imm <= HEX_THRESHOLD)
890
138
          printImm(MI, O, imm, true);
891
3.20k
        else {
892
3.20k
          imm = 0xffff & imm;
893
3.20k
          printImm(MI, O, imm, true);
894
3.20k
        }
895
3.34k
        break;
896
30.3k
    }
897
898
30.3k
    if (MI->csh->detail_opt) {
899
30.3k
      if (MI->csh->doing_mem) {
900
0
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = imm;
901
30.3k
      } else {
902
30.3k
#ifndef CAPSTONE_DIET
903
30.3k
        uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE];
904
30.3k
#endif
905
906
30.3k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_IMM;
907
30.3k
        if (opsize > 0) {
908
25.3k
          MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = opsize;
909
25.3k
          MI->flat_insn->detail->x86.encoding.imm_size = encsize;
910
25.3k
        } else if (MI->flat_insn->detail->x86.op_count > 0) {
911
1.20k
          if (MI->flat_insn->id != X86_INS_LCALL && MI->flat_insn->id != X86_INS_LJMP) {
912
1.20k
            MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size =
913
1.20k
              MI->flat_insn->detail->x86.operands[0].size;
914
1.20k
          } else
915
0
            MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->imm_size;
916
1.20k
        } else
917
3.82k
          MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->imm_size;
918
30.3k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].imm = imm;
919
920
30.3k
#ifndef CAPSTONE_DIET
921
30.3k
        get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
922
30.3k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
923
30.3k
#endif
924
925
30.3k
        MI->flat_insn->detail->x86.op_count++;
926
30.3k
      }
927
30.3k
    }
928
30.3k
  }
929
250k
}
930
931
static void printMemReference(MCInst *MI, unsigned Op, SStream *O)
932
105k
{
933
105k
  bool NeedPlus = false;
934
105k
  MCOperand *BaseReg  = MCInst_getOperand(MI, Op + X86_AddrBaseReg);
935
105k
  uint64_t ScaleVal = MCOperand_getImm(MCInst_getOperand(MI, Op + X86_AddrScaleAmt));
936
105k
  MCOperand *IndexReg  = MCInst_getOperand(MI, Op + X86_AddrIndexReg);
937
105k
  MCOperand *DispSpec = MCInst_getOperand(MI, Op + X86_AddrDisp);
938
105k
  MCOperand *SegReg = MCInst_getOperand(MI, Op + X86_AddrSegmentReg);
939
105k
  int reg;
940
941
105k
  if (MI->csh->detail_opt) {
942
105k
#ifndef CAPSTONE_DIET
943
105k
    uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE];
944
105k
#endif
945
946
105k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
947
105k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->x86opsize;
948
105k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_INVALID;
949
105k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_register_map(MCOperand_getReg(BaseReg));
950
105k
        if (MCOperand_getReg(IndexReg) != X86_EIZ) {
951
104k
            MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.index = X86_register_map(MCOperand_getReg(IndexReg));
952
104k
        }
953
105k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = (int)ScaleVal;
954
105k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = 0;
955
956
105k
#ifndef CAPSTONE_DIET
957
105k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
958
105k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
959
105k
#endif
960
105k
  }
961
962
  // If this has a segment register, print it.
963
105k
  reg = MCOperand_getReg(SegReg);
964
105k
  if (reg) {
965
2.69k
    _printOperand(MI, Op + X86_AddrSegmentReg, O);
966
2.69k
    if (MI->csh->detail_opt) {
967
2.69k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_register_map(reg);
968
2.69k
    }
969
2.69k
    SStream_concat0(O, ":");
970
2.69k
  }
971
972
105k
  SStream_concat0(O, "[");
973
974
105k
  if (MCOperand_getReg(BaseReg)) {
975
102k
    _printOperand(MI, Op + X86_AddrBaseReg, O);
976
102k
    NeedPlus = true;
977
102k
  }
978
979
105k
  if (MCOperand_getReg(IndexReg) && MCOperand_getReg(IndexReg) != X86_EIZ) {
980
24.9k
    if (NeedPlus) SStream_concat0(O, " + ");
981
24.9k
    _printOperand(MI, Op + X86_AddrIndexReg, O);
982
24.9k
    if (ScaleVal != 1)
983
3.49k
      SStream_concat(O, "*%u", ScaleVal);
984
24.9k
    NeedPlus = true;
985
24.9k
  }
986
987
105k
  if (MCOperand_isImm(DispSpec)) {
988
105k
    int64_t DispVal = MCOperand_getImm(DispSpec);
989
105k
    if (MI->csh->detail_opt)
990
105k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = DispVal;
991
105k
    if (DispVal) {
992
33.2k
      if (NeedPlus) {
993
31.4k
        if (DispVal < 0) {
994
12.3k
          SStream_concat0(O, " - ");
995
12.3k
          printImm(MI, O, -DispVal, true);
996
19.0k
        } else {
997
19.0k
          SStream_concat0(O, " + ");
998
19.0k
          printImm(MI, O, DispVal, true);
999
19.0k
        }
1000
31.4k
      } else {
1001
        // memory reference to an immediate address
1002
1.78k
        if (MI->csh->mode == CS_MODE_64)
1003
96
          MI->op1_size = 8;
1004
1.78k
        if (DispVal < 0) {
1005
478
          printImm(MI, O, arch_masks[MI->csh->mode] & DispVal, true);
1006
1.30k
        } else {
1007
1.30k
          printImm(MI, O, DispVal, true);
1008
1.30k
        }
1009
1.78k
      }
1010
1011
71.9k
    } else {
1012
      // DispVal = 0
1013
71.9k
      if (!NeedPlus)  // [0]
1014
236
        SStream_concat0(O, "0");
1015
71.9k
    }
1016
105k
  }
1017
1018
105k
  SStream_concat0(O, "]");
1019
1020
105k
  if (MI->csh->detail_opt)
1021
105k
    MI->flat_insn->detail->x86.op_count++;
1022
1023
105k
  if (MI->op1_size == 0)
1024
71.0k
    MI->op1_size = MI->x86opsize;
1025
105k
}
1026
1027
static void printanymem(MCInst *MI, unsigned OpNo, SStream *O)
1028
4.11k
{
1029
4.11k
  switch(MI->Opcode) {
1030
25
    default: break;
1031
1.30k
    case X86_LEA16r:
1032
1.30k
         MI->x86opsize = 2;
1033
1.30k
         break;
1034
734
    case X86_LEA32r:
1035
1.28k
    case X86_LEA64_32r:
1036
1.28k
         MI->x86opsize = 4;
1037
1.28k
         break;
1038
451
    case X86_LEA64r:
1039
451
         MI->x86opsize = 8;
1040
451
         break;
1041
0
#ifndef CAPSTONE_X86_REDUCE
1042
28
    case X86_BNDCL32rm:
1043
51
    case X86_BNDCN32rm:
1044
215
    case X86_BNDCU32rm:
1045
449
    case X86_BNDSTXmr:
1046
761
    case X86_BNDLDXrm:
1047
825
    case X86_BNDCL64rm:
1048
893
    case X86_BNDCN64rm:
1049
1.05k
    case X86_BNDCU64rm:
1050
1.05k
         MI->x86opsize = 16;
1051
1.05k
         break;
1052
4.11k
#endif
1053
4.11k
  }
1054
1055
4.11k
  printMemReference(MI, OpNo, O);
1056
4.11k
}
1057
1058
#ifdef CAPSTONE_X86_REDUCE
1059
#include "X86GenAsmWriter1_reduce.inc"
1060
#else
1061
#include "X86GenAsmWriter1.inc"
1062
#endif
1063
1064
#include "X86GenRegisterName1.inc"
1065
1066
#endif