Coverage Report

Created: 2025-08-26 06:30

/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
83.7k
{
66
83.7k
  if (MI->csh->detail_opt != CS_OPT_ON)
67
0
    return;
68
69
83.7k
  MI->csh->doing_mem = status;
70
83.7k
  if (!status)
71
    // done, create the next operand slot
72
41.8k
    MI->flat_insn->detail->x86.op_count++;
73
74
83.7k
}
75
76
static void printopaquemem(MCInst *MI, unsigned OpNo, SStream *O)
77
5.85k
{
78
  // FIXME: do this with autogen
79
  // printf(">>> ID = %u\n", MI->flat_insn->id);
80
5.85k
  switch(MI->flat_insn->id) {
81
1.96k
    default:
82
1.96k
      SStream_concat0(O, "ptr ");
83
1.96k
      break;
84
684
    case X86_INS_SGDT:
85
1.40k
    case X86_INS_SIDT:
86
1.67k
    case X86_INS_LGDT:
87
2.34k
    case X86_INS_LIDT:
88
2.55k
    case X86_INS_FXRSTOR:
89
2.64k
    case X86_INS_FXSAVE:
90
3.17k
    case X86_INS_LJMP:
91
3.88k
    case X86_INS_LCALL:
92
      // do not print "ptr"
93
3.88k
      break;
94
5.85k
  }
95
96
5.85k
  switch(MI->csh->mode) {
97
1.87k
    case CS_MODE_16:
98
1.87k
      switch(MI->flat_insn->id) {
99
592
        default:
100
592
          MI->x86opsize = 2;
101
592
          break;
102
224
        case X86_INS_LJMP:
103
499
        case X86_INS_LCALL:
104
499
          MI->x86opsize = 4;
105
499
          break;
106
218
        case X86_INS_SGDT:
107
474
        case X86_INS_SIDT:
108
555
        case X86_INS_LGDT:
109
779
        case X86_INS_LIDT:
110
779
          MI->x86opsize = 6;
111
779
          break;
112
1.87k
      }
113
1.87k
      break;
114
2.21k
    case CS_MODE_32:
115
2.21k
      switch(MI->flat_insn->id) {
116
846
        default:
117
846
          MI->x86opsize = 4;
118
846
          break;
119
68
        case X86_INS_LJMP:
120
344
        case X86_INS_JMP:
121
539
        case X86_INS_LCALL:
122
780
        case X86_INS_SGDT:
123
1.01k
        case X86_INS_SIDT:
124
1.13k
        case X86_INS_LGDT:
125
1.36k
        case X86_INS_LIDT:
126
1.36k
          MI->x86opsize = 6;
127
1.36k
          break;
128
2.21k
      }
129
2.21k
      break;
130
2.21k
    case CS_MODE_64:
131
1.76k
      switch(MI->flat_insn->id) {
132
549
        default:
133
549
          MI->x86opsize = 8;
134
549
          break;
135
241
        case X86_INS_LJMP:
136
478
        case X86_INS_LCALL:
137
703
        case X86_INS_SGDT:
138
928
        case X86_INS_SIDT:
139
1.00k
        case X86_INS_LGDT:
140
1.21k
        case X86_INS_LIDT:
141
1.21k
          MI->x86opsize = 10;
142
1.21k
          break;
143
1.76k
      }
144
1.76k
      break;
145
1.76k
    default:  // never reach
146
0
      break;
147
5.85k
  }
148
149
5.85k
  printMemReference(MI, OpNo, O);
150
5.85k
}
151
152
static void printi8mem(MCInst *MI, unsigned OpNo, SStream *O)
153
57.4k
{
154
57.4k
  SStream_concat0(O, "byte ptr ");
155
57.4k
  MI->x86opsize = 1;
156
57.4k
  printMemReference(MI, OpNo, O);
157
57.4k
}
158
159
static void printi16mem(MCInst *MI, unsigned OpNo, SStream *O)
160
13.8k
{
161
13.8k
  MI->x86opsize = 2;
162
13.8k
  SStream_concat0(O, "word ptr ");
163
13.8k
  printMemReference(MI, OpNo, O);
164
13.8k
}
165
166
static void printi32mem(MCInst *MI, unsigned OpNo, SStream *O)
167
25.1k
{
168
25.1k
  MI->x86opsize = 4;
169
25.1k
  SStream_concat0(O, "dword ptr ");
170
25.1k
  printMemReference(MI, OpNo, O);
171
25.1k
}
172
173
static void printi64mem(MCInst *MI, unsigned OpNo, SStream *O)
174
9.37k
{
175
9.37k
  SStream_concat0(O, "qword ptr ");
176
9.37k
  MI->x86opsize = 8;
177
9.37k
  printMemReference(MI, OpNo, O);
178
9.37k
}
179
180
static void printi128mem(MCInst *MI, unsigned OpNo, SStream *O)
181
3.78k
{
182
3.78k
  SStream_concat0(O, "xmmword ptr ");
183
3.78k
  MI->x86opsize = 16;
184
3.78k
  printMemReference(MI, OpNo, O);
185
3.78k
}
186
187
static void printi512mem(MCInst *MI, unsigned OpNo, SStream *O)
188
2.13k
{
189
2.13k
  SStream_concat0(O, "zmmword ptr ");
190
2.13k
  MI->x86opsize = 64;
191
2.13k
  printMemReference(MI, OpNo, O);
192
2.13k
}
193
194
#ifndef CAPSTONE_X86_REDUCE
195
static void printi256mem(MCInst *MI, unsigned OpNo, SStream *O)
196
2.28k
{
197
2.28k
  SStream_concat0(O, "ymmword ptr ");
198
2.28k
  MI->x86opsize = 32;
199
2.28k
  printMemReference(MI, OpNo, O);
200
2.28k
}
201
202
static void printf32mem(MCInst *MI, unsigned OpNo, SStream *O)
203
4.48k
{
204
4.48k
  switch(MCInst_getOpcode(MI)) {
205
3.57k
    default:
206
3.57k
      SStream_concat0(O, "dword ptr ");
207
3.57k
      MI->x86opsize = 4;
208
3.57k
      break;
209
296
    case X86_FSTENVm:
210
910
    case X86_FLDENVm:
211
      // TODO: fix this in tablegen instead
212
910
      switch(MI->csh->mode) {
213
0
        default:    // never reach
214
0
          break;
215
387
        case CS_MODE_16:
216
387
          MI->x86opsize = 14;
217
387
          break;
218
297
        case CS_MODE_32:
219
523
        case CS_MODE_64:
220
523
          MI->x86opsize = 28;
221
523
          break;
222
910
      }
223
910
      break;
224
4.48k
  }
225
226
4.48k
  printMemReference(MI, OpNo, O);
227
4.48k
}
228
229
static void printf64mem(MCInst *MI, unsigned OpNo, SStream *O)
230
2.85k
{
231
  // TODO: fix COMISD in Tablegen instead (#1456)
232
2.85k
  if (MI->op1_size == 16) {
233
    // printf("printf64mem id = %u\n", MCInst_getOpcode(MI));
234
1.24k
    switch(MCInst_getOpcode(MI)) {
235
1.24k
      default:
236
1.24k
        SStream_concat0(O, "qword ptr ");
237
1.24k
        MI->x86opsize = 8;
238
1.24k
        break;
239
0
      case X86_MOVPQI2QImr:
240
0
        SStream_concat0(O, "xmmword ptr ");
241
0
        MI->x86opsize = 16;
242
0
        break;
243
1.24k
    }
244
1.60k
  } else {
245
1.60k
    SStream_concat0(O, "qword ptr ");
246
1.60k
    MI->x86opsize = 8;
247
1.60k
  }
248
249
2.85k
  printMemReference(MI, OpNo, O);
250
2.85k
}
251
252
static void printf80mem(MCInst *MI, unsigned OpNo, SStream *O)
253
357
{
254
357
  switch(MCInst_getOpcode(MI)) {
255
91
    default:
256
91
      SStream_concat0(O, "xword ptr ");
257
91
      break;
258
77
    case X86_FBLDm:
259
266
    case X86_FBSTPm:
260
266
      break;
261
357
  }
262
263
357
  MI->x86opsize = 10;
264
357
  printMemReference(MI, OpNo, O);
265
357
}
266
267
static void printf128mem(MCInst *MI, unsigned OpNo, SStream *O)
268
2.46k
{
269
2.46k
  SStream_concat0(O, "xmmword ptr ");
270
2.46k
  MI->x86opsize = 16;
271
2.46k
  printMemReference(MI, OpNo, O);
272
2.46k
}
273
274
static void printf256mem(MCInst *MI, unsigned OpNo, SStream *O)
275
1.90k
{
276
1.90k
  SStream_concat0(O, "ymmword ptr ");
277
1.90k
  MI->x86opsize = 32;
278
1.90k
  printMemReference(MI, OpNo, O);
279
1.90k
}
280
281
static void printf512mem(MCInst *MI, unsigned OpNo, SStream *O)
282
1.28k
{
283
1.28k
  SStream_concat0(O, "zmmword ptr ");
284
1.28k
  MI->x86opsize = 64;
285
1.28k
  printMemReference(MI, OpNo, O);
286
1.28k
}
287
#endif
288
289
static const char *getRegisterName(unsigned RegNo);
290
static void printRegName(SStream *OS, unsigned RegNo)
291
479k
{
292
479k
  SStream_concat0(OS, getRegisterName(RegNo));
293
479k
}
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
122k
{
311
122k
  if (positive) {
312
    // always print this number in positive form
313
104k
    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
104k
    } else { // Intel syntax
347
104k
      if (imm < 0) {
348
1.93k
        if (MI->op1_size) {
349
674
          switch(MI->op1_size) {
350
674
            default:
351
674
              break;
352
674
            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
674
          }
362
674
        }
363
364
1.93k
        SStream_concat(O, "0x%"PRIx64, imm);
365
102k
      } else {
366
102k
        if (imm > HEX_THRESHOLD)
367
96.5k
          SStream_concat(O, "0x%"PRIx64, imm);
368
6.27k
        else
369
6.27k
          SStream_concat(O, "%"PRIu64, imm);
370
102k
      }
371
104k
    }
372
104k
  } else {
373
18.0k
    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
18.0k
    } else { // Intel syntax
394
18.0k
      if (imm < 0) {
395
1.81k
        if (imm == 0x8000000000000000LL)  // imm == -imm
396
0
          SStream_concat0(O, "0x8000000000000000");
397
1.81k
        else if (imm < -HEX_THRESHOLD)
398
1.57k
          SStream_concat(O, "-0x%"PRIx64, -imm);
399
237
        else
400
237
          SStream_concat(O, "-%"PRIu64, -imm);
401
402
16.2k
      } else {
403
16.2k
        if (imm > HEX_THRESHOLD)
404
13.9k
          SStream_concat(O, "0x%"PRIx64, imm);
405
2.30k
        else
406
2.30k
          SStream_concat(O, "%"PRIu64, imm);
407
16.2k
      }
408
18.0k
    }
409
18.0k
  }
410
122k
}
411
412
// local printOperand, without updating public operands
413
static void _printOperand(MCInst *MI, unsigned OpNo, SStream *O)
414
176k
{
415
176k
  MCOperand *Op  = MCInst_getOperand(MI, OpNo);
416
176k
  if (MCOperand_isReg(Op)) {
417
176k
    printRegName(O, MCOperand_getReg(Op));
418
176k
  } 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
176k
}
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
863k
{
428
863k
#ifndef CAPSTONE_DIET
429
863k
  uint8_t i;
430
863k
  const uint8_t *arr = X86_get_op_access(h, id, eflags);
431
432
  // initialize access
433
863k
  memset(access, 0, CS_X86_MAXIMUM_OPERAND_SIZE * sizeof(access[0]));
434
435
863k
  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.46M
  for(i = 0; arr[i]; i++) {
442
1.60M
    if (arr[i] != CS_AC_IGNORE)
443
1.36M
      access[i] = arr[i];
444
234k
    else
445
234k
      access[i] = 0;
446
1.60M
  }
447
448
  // mark the end of array
449
863k
  access[i] = 0;
450
863k
#endif
451
863k
}
452
#endif
453
454
static void printSrcIdx(MCInst *MI, unsigned Op, SStream *O)
455
18.1k
{
456
18.1k
  MCOperand *SegReg;
457
18.1k
  int reg;
458
459
18.1k
  if (MI->csh->detail_opt) {
460
18.1k
#ifndef CAPSTONE_DIET
461
18.1k
    uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE];
462
18.1k
#endif
463
464
18.1k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
465
18.1k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->x86opsize;
466
18.1k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_INVALID;
467
18.1k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_REG_INVALID;
468
18.1k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.index = X86_REG_INVALID;
469
18.1k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = 1;
470
18.1k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = 0;
471
472
18.1k
#ifndef CAPSTONE_DIET
473
18.1k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
474
18.1k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
475
18.1k
#endif
476
18.1k
  }
477
478
18.1k
  SegReg = MCInst_getOperand(MI, Op + 1);
479
18.1k
  reg = MCOperand_getReg(SegReg);
480
481
  // If this has a segment register, print it.
482
18.1k
  if (reg) {
483
567
    _printOperand(MI, Op + 1, O);
484
567
    if (MI->csh->detail_opt) {
485
567
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_register_map(reg);
486
567
    }
487
567
    SStream_concat0(O, ":");
488
567
  }
489
490
18.1k
  SStream_concat0(O, "[");
491
18.1k
  set_mem_access(MI, true);
492
18.1k
  printOperand(MI, Op, O);
493
18.1k
  SStream_concat0(O, "]");
494
18.1k
  set_mem_access(MI, false);
495
18.1k
}
496
497
static void printDstIdx(MCInst *MI, unsigned Op, SStream *O)
498
23.7k
{
499
23.7k
  if (MI->csh->detail_opt) {
500
23.7k
#ifndef CAPSTONE_DIET
501
23.7k
    uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE];
502
23.7k
#endif
503
504
23.7k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
505
23.7k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->x86opsize;
506
23.7k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_INVALID;
507
23.7k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_REG_INVALID;
508
23.7k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.index = X86_REG_INVALID;
509
23.7k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = 1;
510
23.7k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = 0;
511
512
23.7k
#ifndef CAPSTONE_DIET
513
23.7k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
514
23.7k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
515
23.7k
#endif
516
23.7k
  }
517
518
  // DI accesses are always ES-based on non-64bit mode
519
23.7k
  if (MI->csh->mode != CS_MODE_64) {
520
17.3k
    SStream_concat0(O, "es:[");
521
17.3k
    if (MI->csh->detail_opt) {
522
17.3k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_ES;
523
17.3k
    }
524
17.3k
  } else
525
6.36k
    SStream_concat0(O, "[");
526
527
23.7k
  set_mem_access(MI, true);
528
23.7k
  printOperand(MI, Op, O);
529
23.7k
  SStream_concat0(O, "]");
530
23.7k
  set_mem_access(MI, false);
531
23.7k
}
532
533
static void printSrcIdx8(MCInst *MI, unsigned OpNo, SStream *O)
534
4.44k
{
535
4.44k
  SStream_concat0(O, "byte ptr ");
536
4.44k
  MI->x86opsize = 1;
537
4.44k
  printSrcIdx(MI, OpNo, O);
538
4.44k
}
539
540
static void printSrcIdx16(MCInst *MI, unsigned OpNo, SStream *O)
541
5.97k
{
542
5.97k
  SStream_concat0(O, "word ptr ");
543
5.97k
  MI->x86opsize = 2;
544
5.97k
  printSrcIdx(MI, OpNo, O);
545
5.97k
}
546
547
static void printSrcIdx32(MCInst *MI, unsigned OpNo, SStream *O)
548
6.24k
{
549
6.24k
  SStream_concat0(O, "dword ptr ");
550
6.24k
  MI->x86opsize = 4;
551
6.24k
  printSrcIdx(MI, OpNo, O);
552
6.24k
}
553
554
static void printSrcIdx64(MCInst *MI, unsigned OpNo, SStream *O)
555
1.47k
{
556
1.47k
  SStream_concat0(O, "qword ptr ");
557
1.47k
  MI->x86opsize = 8;
558
1.47k
  printSrcIdx(MI, OpNo, O);
559
1.47k
}
560
561
static void printDstIdx8(MCInst *MI, unsigned OpNo, SStream *O)
562
7.30k
{
563
7.30k
  SStream_concat0(O, "byte ptr ");
564
7.30k
  MI->x86opsize = 1;
565
7.30k
  printDstIdx(MI, OpNo, O);
566
7.30k
}
567
568
static void printDstIdx16(MCInst *MI, unsigned OpNo, SStream *O)
569
6.70k
{
570
6.70k
  SStream_concat0(O, "word ptr ");
571
6.70k
  MI->x86opsize = 2;
572
6.70k
  printDstIdx(MI, OpNo, O);
573
6.70k
}
574
575
static void printDstIdx32(MCInst *MI, unsigned OpNo, SStream *O)
576
8.17k
{
577
8.17k
  SStream_concat0(O, "dword ptr ");
578
8.17k
  MI->x86opsize = 4;
579
8.17k
  printDstIdx(MI, OpNo, O);
580
8.17k
}
581
582
static void printDstIdx64(MCInst *MI, unsigned OpNo, SStream *O)
583
1.54k
{
584
1.54k
  SStream_concat0(O, "qword ptr ");
585
1.54k
  MI->x86opsize = 8;
586
1.54k
  printDstIdx(MI, OpNo, O);
587
1.54k
}
588
589
static void printMemOffset(MCInst *MI, unsigned Op, SStream *O)
590
3.90k
{
591
3.90k
  MCOperand *DispSpec = MCInst_getOperand(MI, Op);
592
3.90k
  MCOperand *SegReg = MCInst_getOperand(MI, Op + 1);
593
3.90k
  int reg;
594
595
3.90k
  if (MI->csh->detail_opt) {
596
3.90k
#ifndef CAPSTONE_DIET
597
3.90k
    uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE];
598
3.90k
#endif
599
600
3.90k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
601
3.90k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->x86opsize;
602
3.90k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_INVALID;
603
3.90k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_REG_INVALID;
604
3.90k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.index = X86_REG_INVALID;
605
3.90k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = 1;
606
3.90k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = 0;
607
608
3.90k
#ifndef CAPSTONE_DIET
609
3.90k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
610
3.90k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
611
3.90k
#endif
612
3.90k
  }
613
614
  // If this has a segment register, print it.
615
3.90k
  reg = MCOperand_getReg(SegReg);
616
3.90k
  if (reg) {
617
265
    _printOperand(MI, Op + 1, O);
618
265
    SStream_concat0(O, ":");
619
265
    if (MI->csh->detail_opt) {
620
265
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_register_map(reg);
621
265
    }
622
265
  }
623
624
3.90k
  SStream_concat0(O, "[");
625
626
3.90k
  if (MCOperand_isImm(DispSpec)) {
627
3.90k
    int64_t imm = MCOperand_getImm(DispSpec);
628
3.90k
    if (MI->csh->detail_opt)
629
3.90k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = imm;
630
631
3.90k
    if (imm < 0)
632
803
      printImm(MI, O, arch_masks[MI->csh->mode] & imm, true);
633
3.10k
    else
634
3.10k
      printImm(MI, O, imm, true);
635
3.90k
  }
636
637
3.90k
  SStream_concat0(O, "]");
638
639
3.90k
  if (MI->csh->detail_opt)
640
3.90k
    MI->flat_insn->detail->x86.op_count++;
641
642
3.90k
  if (MI->op1_size == 0)
643
3.90k
    MI->op1_size = MI->x86opsize;
644
3.90k
}
645
646
static void printU8Imm(MCInst *MI, unsigned Op, SStream *O)
647
18.2k
{
648
18.2k
  uint8_t val = MCOperand_getImm(MCInst_getOperand(MI, Op)) & 0xff;
649
650
18.2k
  printImm(MI, O, val, true);
651
652
18.2k
  if (MI->csh->detail_opt) {
653
18.2k
#ifndef CAPSTONE_DIET
654
18.2k
    uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE];
655
18.2k
#endif
656
657
18.2k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_IMM;
658
18.2k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].imm = val;
659
18.2k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = 1;
660
661
18.2k
#ifndef CAPSTONE_DIET
662
18.2k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
663
18.2k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
664
18.2k
#endif
665
666
18.2k
    MI->flat_insn->detail->x86.op_count++;
667
18.2k
  }
668
18.2k
}
669
670
static void printMemOffs8(MCInst *MI, unsigned OpNo, SStream *O)
671
2.32k
{
672
2.32k
  SStream_concat0(O, "byte ptr ");
673
2.32k
  MI->x86opsize = 1;
674
2.32k
  printMemOffset(MI, OpNo, O);
675
2.32k
}
676
677
static void printMemOffs16(MCInst *MI, unsigned OpNo, SStream *O)
678
324
{
679
324
  SStream_concat0(O, "word ptr ");
680
324
  MI->x86opsize = 2;
681
324
  printMemOffset(MI, OpNo, O);
682
324
}
683
684
static void printMemOffs32(MCInst *MI, unsigned OpNo, SStream *O)
685
1.05k
{
686
1.05k
  SStream_concat0(O, "dword ptr ");
687
1.05k
  MI->x86opsize = 4;
688
1.05k
  printMemOffset(MI, OpNo, O);
689
1.05k
}
690
691
static void printMemOffs64(MCInst *MI, unsigned OpNo, SStream *O)
692
207
{
693
207
  SStream_concat0(O, "qword ptr ");
694
207
  MI->x86opsize = 8;
695
207
  printMemOffset(MI, OpNo, O);
696
207
}
697
698
static void printInstruction(MCInst *MI, SStream *O);
699
700
void X86_Intel_printInst(MCInst *MI, SStream *O, void *Info)
701
338k
{
702
338k
  x86_reg reg, reg2;
703
338k
  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
338k
  if (MI->assembly[0]) {
709
0
    strncpy(O->buffer, MI->assembly, sizeof(O->buffer));
710
0
    return;
711
0
  }
712
713
338k
  X86_lockrep(MI, O);
714
338k
  printInstruction(MI, O);
715
716
338k
  reg = X86_insn_reg_intel(MCInst_getOpcode(MI), &access1);
717
338k
  if (MI->csh->detail_opt) {
718
338k
#ifndef CAPSTONE_DIET
719
338k
    uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE] = {0};
720
338k
#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
338k
    if (reg) {
725
      // shift all the ops right to leave 1st slot for this new register op
726
35.0k
      memmove(&(MI->flat_insn->detail->x86.operands[1]), &(MI->flat_insn->detail->x86.operands[0]),
727
35.0k
          sizeof(MI->flat_insn->detail->x86.operands[0]) * (ARR_SIZE(MI->flat_insn->detail->x86.operands) - 1));
728
35.0k
      MI->flat_insn->detail->x86.operands[0].type = X86_OP_REG;
729
35.0k
      MI->flat_insn->detail->x86.operands[0].reg = reg;
730
35.0k
      MI->flat_insn->detail->x86.operands[0].size = MI->csh->regsize_map[reg];
731
35.0k
      MI->flat_insn->detail->x86.operands[0].access = access1;
732
35.0k
      MI->flat_insn->detail->x86.op_count++;
733
303k
    } else {
734
303k
      if (X86_insn_reg_intel2(MCInst_getOpcode(MI), &reg, &access1, &reg2, &access2)) {
735
5.26k
        MI->flat_insn->detail->x86.operands[0].type = X86_OP_REG;
736
5.26k
        MI->flat_insn->detail->x86.operands[0].reg = reg;
737
5.26k
        MI->flat_insn->detail->x86.operands[0].size = MI->csh->regsize_map[reg];
738
5.26k
        MI->flat_insn->detail->x86.operands[0].access = access1;
739
5.26k
        MI->flat_insn->detail->x86.operands[1].type = X86_OP_REG;
740
5.26k
        MI->flat_insn->detail->x86.operands[1].reg = reg2;
741
5.26k
        MI->flat_insn->detail->x86.operands[1].size = MI->csh->regsize_map[reg2];
742
5.26k
        MI->flat_insn->detail->x86.operands[1].access = access2;
743
5.26k
        MI->flat_insn->detail->x86.op_count = 2;
744
5.26k
      }
745
303k
    }
746
747
338k
#ifndef CAPSTONE_DIET
748
338k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
749
338k
    MI->flat_insn->detail->x86.operands[0].access = access[0];
750
338k
    MI->flat_insn->detail->x86.operands[1].access = access[1];
751
338k
#endif
752
338k
  }
753
754
338k
  if (MI->op1_size == 0 && reg)
755
23.9k
    MI->op1_size = MI->csh->regsize_map[reg];
756
338k
}
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
21.9k
{
762
21.9k
  MCOperand *Op = MCInst_getOperand(MI, OpNo);
763
21.9k
  if (MCOperand_isImm(Op)) {
764
21.9k
    int64_t imm = MCOperand_getImm(Op) + MI->flat_insn->size + MI->address;
765
21.9k
    uint8_t opsize = X86_immediate_size(MI->Opcode, NULL);
766
767
    // truncate imm for non-64bit
768
21.9k
    if (MI->csh->mode != CS_MODE_64) {
769
15.2k
      imm = imm & 0xffffffff;
770
15.2k
    }
771
772
21.9k
    printImm(MI, O, imm, true);
773
774
21.9k
    if (MI->csh->detail_opt) {
775
21.9k
#ifndef CAPSTONE_DIET
776
21.9k
      uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE];
777
21.9k
#endif
778
779
21.9k
      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
21.9k
      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
21.9k
      else if (opsize > 0)
784
628
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = opsize;
785
21.3k
      else
786
21.3k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->imm_size;
787
21.9k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].imm = imm;
788
789
21.9k
#ifndef CAPSTONE_DIET
790
21.9k
      get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
791
21.9k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
792
21.9k
#endif
793
794
21.9k
      MI->flat_insn->detail->x86.op_count++;
795
21.9k
    }
796
797
21.9k
    if (MI->op1_size == 0)
798
21.9k
      MI->op1_size = MI->imm_size;
799
21.9k
  }
800
21.9k
}
801
802
static void printOperand(MCInst *MI, unsigned OpNo, SStream *O)
803
342k
{
804
342k
  MCOperand *Op  = MCInst_getOperand(MI, OpNo);
805
806
342k
  if (MCOperand_isReg(Op)) {
807
303k
    unsigned int reg = MCOperand_getReg(Op);
808
809
303k
    printRegName(O, reg);
810
303k
    if (MI->csh->detail_opt) {
811
303k
      if (MI->csh->doing_mem) {
812
41.8k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_register_map(reg);
813
261k
      } else {
814
261k
#ifndef CAPSTONE_DIET
815
261k
        uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE];
816
261k
#endif
817
818
261k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_REG;
819
261k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].reg = X86_register_map(reg);
820
261k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->csh->regsize_map[X86_register_map(reg)];
821
822
261k
#ifndef CAPSTONE_DIET
823
261k
        get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
824
261k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
825
261k
#endif
826
827
261k
        MI->flat_insn->detail->x86.op_count++;
828
261k
      }
829
303k
    }
830
831
303k
    if (MI->op1_size == 0)
832
158k
      MI->op1_size = MI->csh->regsize_map[X86_register_map(reg)];
833
303k
  } else if (MCOperand_isImm(Op)) {
834
39.1k
    uint8_t encsize;
835
39.1k
    int64_t imm = MCOperand_getImm(Op);
836
39.1k
    uint8_t opsize = X86_immediate_size(MCInst_getOpcode(MI), &encsize);
837
838
39.1k
    if (opsize == 1)    // print 1 byte immediate in positive form
839
17.1k
      imm = imm & 0xff;
840
841
    // printf(">>> id = %u\n", MI->flat_insn->id);
842
39.1k
    switch(MI->flat_insn->id) {
843
18.0k
      default:
844
18.0k
        printImm(MI, O, imm, MI->csh->imm_unsigned);
845
18.0k
        break;
846
847
226
      case X86_INS_MOVABS:
848
6.25k
      case X86_INS_MOV:
849
        // do not print number in negative form
850
6.25k
        printImm(MI, O, imm, true);
851
6.25k
        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
660
      case X86_INS_LCALL:
862
1.33k
      case X86_INS_LJMP:
863
1.33k
      case X86_INS_JMP:
864
        // always print address in positive form
865
1.33k
        if (OpNo == 1) { // ptr16 part
866
666
          imm = imm & 0xffff;
867
666
          opsize = 2;
868
666
        } else
869
666
          opsize = 4;
870
1.33k
        printImm(MI, O, imm, true);
871
1.33k
        break;
872
873
4.08k
      case X86_INS_AND:
874
6.95k
      case X86_INS_OR:
875
9.72k
      case X86_INS_XOR:
876
        // do not print number in negative form
877
9.72k
        if (imm >= 0 && imm <= HEX_THRESHOLD)
878
978
          printImm(MI, O, imm, true);
879
8.74k
        else {
880
8.74k
          imm = arch_masks[opsize? opsize : MI->imm_size] & imm;
881
8.74k
          printImm(MI, O, imm, true);
882
8.74k
        }
883
9.72k
        break;
884
885
2.90k
      case X86_INS_RET:
886
3.72k
      case X86_INS_RETF:
887
        // RET imm16
888
3.72k
        if (imm >= 0 && imm <= HEX_THRESHOLD)
889
336
          printImm(MI, O, imm, true);
890
3.39k
        else {
891
3.39k
          imm = 0xffff & imm;
892
3.39k
          printImm(MI, O, imm, true);
893
3.39k
        }
894
3.72k
        break;
895
39.1k
    }
896
897
39.1k
    if (MI->csh->detail_opt) {
898
39.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
39.1k
      } else {
901
39.1k
#ifndef CAPSTONE_DIET
902
39.1k
        uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE];
903
39.1k
#endif
904
905
39.1k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_IMM;
906
39.1k
        if (opsize > 0) {
907
33.5k
          MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = opsize;
908
33.5k
          MI->flat_insn->detail->x86.encoding.imm_size = encsize;
909
33.5k
        } else if (MI->flat_insn->detail->x86.op_count > 0) {
910
1.19k
          if (MI->flat_insn->id != X86_INS_LCALL && MI->flat_insn->id != X86_INS_LJMP) {
911
1.19k
            MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size =
912
1.19k
              MI->flat_insn->detail->x86.operands[0].size;
913
1.19k
          } else
914
0
            MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->imm_size;
915
1.19k
        } else
916
4.39k
          MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->imm_size;
917
39.1k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].imm = imm;
918
919
39.1k
#ifndef CAPSTONE_DIET
920
39.1k
        get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
921
39.1k
        MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
922
39.1k
#endif
923
924
39.1k
        MI->flat_insn->detail->x86.op_count++;
925
39.1k
      }
926
39.1k
    }
927
39.1k
  }
928
342k
}
929
930
static void printMemReference(MCInst *MI, unsigned Op, SStream *O)
931
138k
{
932
138k
  bool NeedPlus = false;
933
138k
  MCOperand *BaseReg  = MCInst_getOperand(MI, Op + X86_AddrBaseReg);
934
138k
  uint64_t ScaleVal = MCOperand_getImm(MCInst_getOperand(MI, Op + X86_AddrScaleAmt));
935
138k
  MCOperand *IndexReg  = MCInst_getOperand(MI, Op + X86_AddrIndexReg);
936
138k
  MCOperand *DispSpec = MCInst_getOperand(MI, Op + X86_AddrDisp);
937
138k
  MCOperand *SegReg = MCInst_getOperand(MI, Op + X86_AddrSegmentReg);
938
138k
  int reg;
939
940
138k
  if (MI->csh->detail_opt) {
941
138k
#ifndef CAPSTONE_DIET
942
138k
    uint8_t access[CS_X86_MAXIMUM_OPERAND_SIZE];
943
138k
#endif
944
945
138k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].type = X86_OP_MEM;
946
138k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].size = MI->x86opsize;
947
138k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_REG_INVALID;
948
138k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.base = X86_register_map(MCOperand_getReg(BaseReg));
949
138k
        if (MCOperand_getReg(IndexReg) != X86_EIZ) {
950
137k
            MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.index = X86_register_map(MCOperand_getReg(IndexReg));
951
137k
        }
952
138k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.scale = (int)ScaleVal;
953
138k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = 0;
954
955
138k
#ifndef CAPSTONE_DIET
956
138k
    get_op_access(MI->csh, MCInst_getOpcode(MI), access, &MI->flat_insn->detail->x86.eflags);
957
138k
    MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].access = access[MI->flat_insn->detail->x86.op_count];
958
138k
#endif
959
138k
  }
960
961
  // If this has a segment register, print it.
962
138k
  reg = MCOperand_getReg(SegReg);
963
138k
  if (reg) {
964
4.12k
    _printOperand(MI, Op + X86_AddrSegmentReg, O);
965
4.12k
    if (MI->csh->detail_opt) {
966
4.12k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.segment = X86_register_map(reg);
967
4.12k
    }
968
4.12k
    SStream_concat0(O, ":");
969
4.12k
  }
970
971
138k
  SStream_concat0(O, "[");
972
973
138k
  if (MCOperand_getReg(BaseReg)) {
974
135k
    _printOperand(MI, Op + X86_AddrBaseReg, O);
975
135k
    NeedPlus = true;
976
135k
  }
977
978
138k
  if (MCOperand_getReg(IndexReg) && MCOperand_getReg(IndexReg) != X86_EIZ) {
979
35.5k
    if (NeedPlus) SStream_concat0(O, " + ");
980
35.5k
    _printOperand(MI, Op + X86_AddrIndexReg, O);
981
35.5k
    if (ScaleVal != 1)
982
4.99k
      SStream_concat(O, "*%u", ScaleVal);
983
35.5k
    NeedPlus = true;
984
35.5k
  }
985
986
138k
  if (MCOperand_isImm(DispSpec)) {
987
138k
    int64_t DispVal = MCOperand_getImm(DispSpec);
988
138k
    if (MI->csh->detail_opt)
989
138k
      MI->flat_insn->detail->x86.operands[MI->flat_insn->detail->x86.op_count].mem.disp = DispVal;
990
138k
    if (DispVal) {
991
39.6k
      if (NeedPlus) {
992
37.4k
        if (DispVal < 0) {
993
15.4k
          SStream_concat0(O, " - ");
994
15.4k
          printImm(MI, O, -DispVal, true);
995
22.0k
        } else {
996
22.0k
          SStream_concat0(O, " + ");
997
22.0k
          printImm(MI, O, DispVal, true);
998
22.0k
        }
999
37.4k
      } else {
1000
        // memory reference to an immediate address
1001
2.14k
        if (MI->csh->mode == CS_MODE_64)
1002
89
          MI->op1_size = 8;
1003
2.14k
        if (DispVal < 0) {
1004
812
          printImm(MI, O, arch_masks[MI->csh->mode] & DispVal, true);
1005
1.33k
        } else {
1006
1.33k
          printImm(MI, O, DispVal, true);
1007
1.33k
        }
1008
2.14k
      }
1009
1010
98.6k
    } else {
1011
      // DispVal = 0
1012
98.6k
      if (!NeedPlus)  // [0]
1013
236
        SStream_concat0(O, "0");
1014
98.6k
    }
1015
138k
  }
1016
1017
138k
  SStream_concat0(O, "]");
1018
1019
138k
  if (MI->csh->detail_opt)
1020
138k
    MI->flat_insn->detail->x86.op_count++;
1021
1022
138k
  if (MI->op1_size == 0)
1023
90.8k
    MI->op1_size = MI->x86opsize;
1024
138k
}
1025
1026
static void printanymem(MCInst *MI, unsigned OpNo, SStream *O)
1027
5.12k
{
1028
5.12k
  switch(MI->Opcode) {
1029
303
    default: break;
1030
439
    case X86_LEA16r:
1031
439
         MI->x86opsize = 2;
1032
439
         break;
1033
257
    case X86_LEA32r:
1034
591
    case X86_LEA64_32r:
1035
591
         MI->x86opsize = 4;
1036
591
         break;
1037
268
    case X86_LEA64r:
1038
268
         MI->x86opsize = 8;
1039
268
         break;
1040
0
#ifndef CAPSTONE_X86_REDUCE
1041
295
    case X86_BNDCL32rm:
1042
495
    case X86_BNDCN32rm:
1043
892
    case X86_BNDCU32rm:
1044
1.33k
    case X86_BNDSTXmr:
1045
2.23k
    case X86_BNDLDXrm:
1046
2.56k
    case X86_BNDCL64rm:
1047
2.99k
    case X86_BNDCN64rm:
1048
3.51k
    case X86_BNDCU64rm:
1049
3.51k
         MI->x86opsize = 16;
1050
3.51k
         break;
1051
5.12k
#endif
1052
5.12k
  }
1053
1054
5.12k
  printMemReference(MI, OpNo, O);
1055
5.12k
}
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