Coverage Report

Created: 2025-07-18 06:43

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