This file is indexed.

/usr/include/fcml/fcml_disassembler.hpp is in libfcml-dev 1.1.3-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
/*
 * FCML - Free Code Manipulation Library.
 * Copyright (C) 2010-2015 Slawomir Wojtasiak
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

/** @file fcml_disassembler.hpp
 * C++ wrapper for the FCML disassembler.
 *
 * @copyright Copyright (C) 2010-2015 Slawomir Wojtasiak. All rights reserved.
 * This project is released under the GNU Lesser General Public License.
 */

#ifndef FCML_DISASSEMBLER_HPP_
#define FCML_DISASSEMBLER_HPP_

#include <string.h>

#include "fcml_disassembler.h"

#include "fcml_common.hpp"
#include "fcml_errors.hpp"
#include "fcml_dialect.hpp"

namespace fcml {

/**
 *  Component can not be initialized correctly.
 *  @since 1.1.0
 */
class DisassemblingFailedException: public ErrorContainerAwareException {
public:
    DisassemblingFailedException( const fcml_cstring &msg, const ErrorContainer &errorContainer, fcml_ceh_error error = FCML_CEH_GEC_NO_ERROR ) :
        ErrorContainerAwareException( msg, errorContainer, error ){
    }
};

/** Disassembler configuration.
 *
 * It's counterpart to the fcml_st_disassembler_conf structure.
 * @since 1.1.0
 */
class DisassemblerConf {
public:

    /**
     * Default constructor.
     * @since 1.1.0
     */
    DisassemblerConf() :
        _throwExceptionOnError(true),
        _incrementIP(true),
        _enableErrorMessages(true),
        _carryFlagConditionalSuffix(false),
        _conditionalGroup(false),
        _shortForms(false),
        _extendDispToASA(false),
        _failIfUnknownInstruction(false) {
    }

    /** @since 1.1.0 */
    bool isCarryFlagConditionalSuffix() const {
        return _carryFlagConditionalSuffix;
    }

    /** @since 1.1.0 */
    void setCarryFlagConditionalSuffix(bool carryFlagConditionalSuffix) {
        _carryFlagConditionalSuffix = carryFlagConditionalSuffix;
    }

    /** @since 1.1.0 */
    fcml_uint8_t getConditionalGroup() const {
        return _conditionalGroup;
    }

    /** @since 1.1.0 */
    void setConditionalGroup(fcml_uint8_t conditionalGroup) {
        _conditionalGroup = conditionalGroup;
    }

    /** @since 1.1.0 */
    bool isEnableErrorMessages() const {
        return _enableErrorMessages;
    }

    /** @since 1.1.0 */
    void setEnableErrorMessages(bool enableErrorMessages) {
        _enableErrorMessages = enableErrorMessages;
    }

    /** @since 1.1.0 */
    bool isExtendDispToAsa() const {
        return _extendDispToASA;
    }

    /** @since 1.1.0 */
    void setExtendDispToAsa(bool extendDispToAsa) {
        _extendDispToASA = extendDispToAsa;
    }

    /** @since 1.1.0 */
    bool isFailIfUnknownInstruction() const {
        return _failIfUnknownInstruction;
    }

    /** @since 1.1.0 */
    void setFailIfUnknownInstruction(bool failIfUnknownInstruction) {
        _failIfUnknownInstruction = failIfUnknownInstruction;
    }

    /** @since 1.1.0 */
    bool isIncrementIp() const {
        return _incrementIP;
    }

    /** @since 1.1.0 */
    void setIncrementIp(bool incrementIp) {
        _incrementIP = incrementIp;
    }

    /** @since 1.1.0 */
    bool isShortForms() const {
        return _shortForms;
    }

    /** @since 1.1.0 */
    void setShortForms(bool shortForms) {
        _shortForms = shortForms;
    }

    /**
     * Returns true if exception should be thrown when disassembling fails.
     *
     * @return True if exception is the preferred way of error handling in case of failure.
     * @since 1.1.0
     */
    bool isThrowExceptionOnError() const {
        return _throwExceptionOnError;
    }

    /**
     * Sets the way how the error handling is done.
     *
     * @param throwExceptionOnError True if exception should be thrown in case of failure.
     * @since 1.1.0
     */
    void setThrowExceptionOnError(bool throwExceptionOnError) {
        _throwExceptionOnError = throwExceptionOnError;
    }

private:
    bool _throwExceptionOnError;
    bool _incrementIP;
    bool _enableErrorMessages;
    bool _carryFlagConditionalSuffix;
    fcml_uint8_t _conditionalGroup;
    bool _shortForms;
    bool _extendDispToASA;
    bool _failIfUnknownInstruction;

};

/** Disassembler context.
 * @since 1.1.0
 */
class DisassemblerContext {
public:

    /**
     * Creates empty disassembler context.
     * @since 1.1.0
     */
    DisassemblerContext() :
        _code(NULL),
        _codeLength(0) {
    }

    /**
     * Creates disassembler context for given piece of machine code.
     *
     * @param code A buffer with the machine code.
     * @param codeLength Size of the buffer in bytes.
     * @since 1.1.0
     */
    DisassemblerContext( fcml_ptr code, fcml_usize codeLength ) :
        _code(code),
        _codeLength(codeLength) {
    }

public:

    /**
     * Gets pointer to the machine code buffer.
     *
     * @return A pointer to the machine code.
     * @since 1.1.0
     */
    fcml_ptr getCode() const {
        return _code;
    }

    /**
     * Sets a new buffer with machine code for the context.
     *
     * @param code The new code buffer.
     * @since 1.1.0
     */
    void setCode(fcml_ptr code) {
        _code = code;
    }

    /**
     * Gets length of the buffer in bytes.
     *
     * @return Size of the buffer.
     * @since 1.1.0
     */
    fcml_usize getCodeLength() const {
        return _codeLength;
    }

    /**
     * Sets length of the code buffer in bytes.
     *
     * @param codeLength Size of the code.
     * @since 1.1.0
     */
    void setCodeLength(fcml_usize codeLength) {
        _codeLength = codeLength;
    }

    /**
     * Gets a reference to the configuration object associated with the context.
     *
     * @return The disassembler configuration.
     * @since 1.1.0
     */
    const DisassemblerConf& getDisassemblerConf() const {
        return _disassemblerConf;
    }

    /**
     * Gets a reference to the configuration object associated with the context.
     *
     * @return The disassembler configuration.
     * @since 1.1.0
     */
    DisassemblerConf& getDisassemblerConf() {
        return _disassemblerConf;
    }

    /**
     * Sets a new disassembler configuration for the context.
     *
     * @param disassemblerConf The new disassembler configuration.
     * @since 1.1.0
     */
    void setDisassemblerConf(DisassemblerConf disassemblerConf) {
        _disassemblerConf = disassemblerConf;
    }

    /**
     * Gets reference to the constant entry point instance associated with the context.
     *
     * @return Reference to the constant entry point.
     * @since 1.1.0
     */
    const EntryPoint& getEntryPoint() const {
        return _entryPoint;
    }

    /**
     * Gets reference to the entry point instance associated with the context.
     *
     * @return Reference to the entry point.
     * @since 1.1.0
     */
    EntryPoint& getEntryPoint() {
        return _entryPoint;
    }
    /**
     * Copies given entry point to the instance associated with the context.
     * Deep copy is performed, so passed object not need to be maintained as
     * long as the context is used.
     *
     * @param entryPoint The entry point which is copied to the context.
     * @since 1.1.0
     */
    void setEntryPoint(const EntryPoint& entryPoint) {
        _entryPoint = entryPoint;
    }

    /**
     * Sets instruction pointer directly into the entry point.
     *
     * @param ip The new IP.
     * @since 1.1.0
     */
    void setIP( fcml_ip ip ) {
        _entryPoint.setIP(ip);
    }

    /**
     * Increments entry point by given number of bytes.
     *
     * @param ip Number of bytes the instruction pointer has to be incremented by.
     * @since 1.1.0
     */
    void incrementIP( fcml_ip ip ) {
        _entryPoint.incrementIP( ip );
    }

    /**
     * Sets processor operating mode directly into the entry point.
     *
     * @param operatingMode Processor operating mode to be set.
     * @since 1.1.0
     */
    void setOperatingMode( EntryPoint::OperatingMode operatingMode ) {
        _entryPoint.setOpMode( operatingMode );
    }

    /**
     * Sets a new address size attribute for the entry point.
     *
     * @param addressSizeAttribute The address size attribute.
     * @since 1.1.0
     */
    void setAddressSizeAttribute( fcml_usize addressSizeAttribute ) {
       _entryPoint.setAddressSizeAttribute( addressSizeAttribute );
    }

    /**
     * Sets a new operand size attribute for the entry point.
     *
     * @param operandSizeAttribute The operand size attribute.
     * @since 1.1.0
     */
    void setOperandSizeAttribute( fcml_usize operandSizeAttribute ) {
       _entryPoint.setOperandSizeAttribute( operandSizeAttribute );
    }

private:
    /** Disassembler configuration. */
    DisassemblerConf _disassemblerConf;
    /** Entry point. */
    EntryPoint _entryPoint;
    /** Code buffer. */
    fcml_ptr _code;
    /** Code length. */
    fcml_usize _codeLength;
};

/** Instruction prefix.
 * @since 1.1.0
 */
class InstructionPrefixDetails {
public:

    /** Type of the instruction prefix.
     * @since 1.1.0
     */
    enum PrefixType {
        PT_GROUP_UNKNOWN = FCML_PT_GROUP_UNKNOWN,
        PT_GROUP_1 = FCML_PT_GROUP_1,
        PT_GROUP_2 = FCML_PT_GROUP_2,
        PT_GROUP_3 = FCML_PT_GROUP_3,
        PT_GROUP_4 = FCML_PT_GROUP_4,
        PT_REX = FCML_PT_REX,
        PT_VEX = FCML_PT_VEX,
        PT_XOP = FCML_PT_XOP
    };

    /**
     * Returns true if it's a mandatory prefix.
     *
     * @return True if it's a mandatory prefix.
     * @since 1.1.0
     */
    bool isMandatoryPrefix() const {
        return _mandatoryPrefix;
    }

    /**
     * Sets mandatory prefix flag for the prefix.
     *
     * @param mandatoryPrefix Set to true in order to make the prefix mandatory one.
     * @since 1.1.0
     */
    void setMandatoryPrefix(bool mandatoryPrefix) {
        _mandatoryPrefix = mandatoryPrefix;
    }

    /**
     * Gets the prefix byte.
     *
     * @return The prefix byte.
     * @since 1.1.0
     */
    fcml_uint8_t getPrefix() const {
        return _prefix;
    }

    /**
     * Sets the prefix byte.
     *
     * @param prefix The prefix byte.
     * @since 1.1.0
     */
    void setPrefix(fcml_uint8_t prefix) {
        _prefix = prefix;
    }

    /**
     * Gets the prefix type.
     *
     * @return The prefix byte.
     * @since 1.1.0
     */
    PrefixType getPrefixType() const {
        return _prefixType;
    }

    /**
     * Sets a new prefix type.
     *
     * @param prefixType The prefix byte to be set.
     * @since 1.1.0
     */
    void setPrefixType(PrefixType prefixType) {
        _prefixType = prefixType;
    }

    /**
     * Gets the second and third bytes of the XOP/VEX prefix.
     *
     * @return A pointer to the VEX/XOP bytes.
     * @since 1.1.0
     */
    const fcml_uint8_t* getVexXopBytes() const {
        return _vexXOPBytes;
    }

    /**
     * Gets the second and third bytes of the XOP/VEX prefix.
     *
     * @return A pointer to the VEX/XOP bytes.
     * @since 1.1.0
     */
    fcml_uint8_t* getVexXopBytes() {
        return _vexXOPBytes;
    }

private:
    /** The first byte of the prefix. */
    fcml_uint8_t _prefix;
    /** Tye type of the prefix. */
    PrefixType _prefixType;
    /** True if the prefix is a mandatory one. */
    bool _mandatoryPrefix;
    /** The second and third byte of the prefix. */
    fcml_uint8_t _vexXOPBytes[2];
};

/** Prefixes details.
 * @since 1.1.0
 */
class PrefixesDetails {
public:

    /**
     * Default constructor.
     * @since 1.1.0
     */
    PrefixesDetails() :
        _prefixesCount(0),
        _prefixesBytesCount(0),
        _isBranch(false),
        _isNobranch(false),
        _isLock(false),
        _isRep(false),
        _isRepne(false),
        _isXrelease(false),
        _isXacquire(false),
        _isVex(false),
        _isXop(false),
        _isRex(false),
        _vexXopFirstByte(false),
        _r(0),
        _x(0),
        _b(0),
        _w(0),
        _l(0),
        _mmmm(0),
        _vvvv(0),
        _pp(0) {
    }

    /**
     * Gets reference to the instruction prefix at given index.
     * @param index Number of the prefix.
     * @return The instruction prefix for given index.
     * @throw IllegalArgumentException Index out of bound.
     * @since 1.1.0
     */
    const InstructionPrefixDetails& operator[](fcml_usize index) const {
        if( index >= FCML_DASM_PREFIXES_COUNT ) {
            throw IllegalArgumentException( FCML_TEXT( "Index out of bound." ) );
        }
        return _prefixes[index];
    }

    /**
     * Gets reference to the instruction prefix at given index.
     * @param index Number of the prefix.
     * @return The instruction prefix for given index.
     * @throw IllegalArgumentException Index out of bound.
     * @since 1.1.0
     */
    InstructionPrefixDetails& operator[](fcml_usize index) {
        if( index >= FCML_DASM_PREFIXES_COUNT ) {
            throw IllegalArgumentException( FCML_TEXT( "Index out of bound." ) );
        }
        return _prefixes[index];
    }

    /**
     * Gets b flag.
     *
     * @return The B flag.
     * @since 1.1.0
     */
    fcml_uint8_t getB() const {
        return _b;
    }

    /**
     * Sets B flag.
     *
     * @param b The B flag.
     * @since 1.1.0
     */
    void setB(fcml_uint8_t b) {
        _b = b;
    }

    /**
     * Gets true if branch prefix is available.
     *
     * @return True if branch prefix is available.
     * @since 1.1.0
     */
    bool isBranch() const {
        return _isBranch;
    }

    /**
     * Sets branch prefix availability.
     *
     * @param isBranch True if branch prefix is available.
     * @since 1.1.0
     */
    void setBranch(bool isBranch) {
        _isBranch = isBranch;
    }

    /**
     * Gets true if lock prefix is available.
     *
     * @return True if lock prefix is available.
     * @since 1.1.0
     */
    bool isLock() const {
        return _isLock;
    }

    /**
     * Sets lock prefix availability.
     *
     * @param isLock True if lock prefix is available.
     * @since 1.1.0
     */
    void setLock(bool isLock) {
        _isLock = isLock;
    }

    /**
     * Gets true if no-branch prefix is available.
     *
     * @return True if no-branch prefix is available.
     * @since 1.1.0
     */
    bool isNobranch() const {
        return _isNobranch;
    }

    /**
     * Sets no-branch prefix availability.
     *
     * @param isNobranch True if no-branch prefix is available.
     * @since 1.1.0
     */
    void setNobranch(bool isNobranch) {
        _isNobranch = isNobranch;
    }

    /**
     * Gets true if Rep prefix is available.
     *
     * @return True if Rep prefix is available.
     * @since 1.1.0
     */
    bool isRep() const {
        return _isRep;
    }

    /**
     * Sets Rep prefix availability.
     *
     * @param isRep True if Rep prefix is available.
     * @since 1.1.0
     */
    void setRep(bool isRep) {
        _isRep = isRep;
    }

    /**
     * Gets true if Repne prefix is available.
     *
     * @return True if Repne prefix is available.
     * @since 1.1.0
     */
    bool isRepne() const {
        return _isRepne;
    }

    /**
     * Sets Repne prefix availability.
     *
     * @param isRepne True if branch prefix is available.
     * @since 1.1.0
     */
    void setRepne(bool isRepne) {
        _isRepne = isRepne;
    }

    /**
     * Gets true if Rex prefix is available.
     *
     * @return True if Rex prefix is available.
     * @since 1.1.0
     */
    bool isRex() const {
        return _isRex;
    }

    /**
     * Sets REX prefix availability.
     *
     * @param isRex True if REX prefix is available.
     * @since 1.1.0
     */
    void setRex(bool isRex) {
        _isRex = isRex;
    }

    /**
     * Gets true if Vex prefix is available.
     *
     * @return True if Vex prefix is available.
     * @since 1.1.0
     */
    bool isVex() const {
        return _isVex;
    }

    /**
     * Sets VEX prefix availability.
     *
     * @param isVex True if VEX prefix is available.
     * @since 1.1.0
     */
    void setVex(bool isVex) {
        _isVex = isVex;
    }

    /**
     * Gets true if xacquire prefix is available.
     *
     * @return True if xacquire prefix is available.
     * @since 1.1.0
     */
    bool isXacquire() const {
        return _isXacquire;
    }

    /**
     * Sets xacquire prefix availability.
     *
     * @param isXacquire True if xacquire prefix is available.
     * @since 1.1.0
     */
    void setXacquire(bool isXacquire) {
        _isXacquire = isXacquire;
    }

    /**
     * Gets true if Xop prefix is available.
     *
     * @return True if Xop prefix is available.
     * @since 1.1.0
     */
    bool isXop() const {
        return _isXop;
    }

    /**
     * Sets Xop prefix availability.
     *
     * @param isXop True if XOP prefix is available.
     * @since 1.1.0
     */
    void setXop(bool isXop) {
        _isXop = isXop;
    }

    /**
     * Gets true if xrelease prefix is available.
     *
     * @return True if xrelease prefix is available.
     * @since 1.1.0
     */
    bool isXrelease() const {
        return _isXrelease;
    }

    /**
     * Sets xrelease prefix availability.
     *
     * @param isXrelease True if xrelease prefix is available.
     * @since 1.1.0
     */
    void setXrelease(bool isXrelease) {
        _isXrelease = isXrelease;
    }

    /**
     * Gets L flag.
     *
     * @return The L flag.
     * @since 1.1.0
     */
    fcml_uint8_t getL() const {
        return _l;
    }

    /**
     * Sets L flag.
     *
     * @param l The L flag.
     * @since 1.1.0
     */
    void setL(fcml_uint8_t l) {
        _l = l;
    }

    /**
     * Gets MMMM field.
     *
     * @return MMMM field.
     * @since 1.1.0
     */
    fcml_uint8_t getMmmm() const {
        return _mmmm;
    }

    /**
     * Sets MMMM field.
     *
     * @param mmmm MMMM field.
     * @since 1.1.0
     */
    void setMmmm(fcml_uint8_t mmmm) {
        _mmmm = mmmm;
    }

    /**
     * Gets PP field.
     *
     * @return The PP field.
     * @since 1.1.0
     */
    fcml_uint8_t getPp() const {
        return _pp;
    }

    /**
     * Sets PP field.
     *
     * @param pp PP field.
     * @since 1.1.0
     */
    void setPp(fcml_uint8_t pp) {
        _pp = pp;
    }

    /**
     * Gets a reference to the prefix of the given index.
     *
     * @param index Index for the prefix.
     * @return The prefix at given index.
     * @throw BadArgumentException Array index out of bound.
     * @since 1.1.0
     */
    const InstructionPrefixDetails& getPrefixes( fcml_usize index ) const {
        if( index > FCML_DASM_PREFIXES_COUNT ) {
            throw BadArgumentException(FCML_TEXT("Array index out of bound."), FCML_CEH_GEC_VALUE_OUT_OF_RANGE);
        }
        return _prefixes[index];
    }

    /**
     * Gets a reference to the prefix of the given index.
     *
     * @param index Index for the prefix.
     * @return The prefix at given index.
     * @throw BadArgumentException Array index out of bound.
     * @since 1.1.0
     */
    InstructionPrefixDetails& getPrefixes( fcml_usize index ) {
        if( index > FCML_DASM_PREFIXES_COUNT ) {
            throw BadArgumentException(FCML_TEXT("Array index out of bound."), FCML_CEH_GEC_VALUE_OUT_OF_RANGE);
        }
        return _prefixes[index];
    }

    /**
     * Gets number of bytes interpreted to be prefixes.
     *
     * @return Number of prefixes bytes.
     * @since 1.1.0
     */
    fcml_int getPrefixesBytesCount() const {
        return _prefixesBytesCount;
    }

    /**
     * Sets number of prefixes bytes available for the instruction.
     *
     * @param prefixesBytesCount Number of the prefixes bytes.
     * @since 1.1.0
     */
    void setPrefixesBytesCount(fcml_int prefixesBytesCount) {
        _prefixesBytesCount = prefixesBytesCount;
    }

    /**
     * Gets number of prefixes available for the instruction.
     *
     * @return Number of the prefixes for the instruction.
     * @since 1.1.0
     */
    fcml_int getPrefixesCount() const {
        return _prefixesCount;
    }

    /**
     * Sets number of prefixes available for the instruction.
     *
     * @param prefixesCount Number of the available prefixes.
     * @since 1.1.0
     */
    void setPrefixesCount(fcml_int prefixesCount) {
        _prefixesCount = prefixesCount;
    }

    /**
     * Gets R flag.
     *
     * @return The R flag.
     * @since 1.1.0
     */
    fcml_uint8_t getR() const {
        return _r;
    }

    /**
     * Sets R flag.
     *
     * @param r The R flag.
     * @since 1.1.0
     */
    void setR(fcml_uint8_t r) {
        _r = r;
    }

    /**
     * Gets the first byte of the VEX/XOP prefix.
     *
     * @return The first byte of the VEX/XOP prefix.
     * @since 1.1.0
     */
    fcml_uint8_t getVexXopFirstByte() const {
        return _vexXopFirstByte;
    }

    /**
     * Sets a first byte of the XOP/VEX prefix.
     *
     * @param vexXopFirstByte The first XOP/VEX prefix byte.
     * @since 1.1.0
     */
    void setVexXopFirstByte(fcml_uint8_t vexXopFirstByte) {
        _vexXopFirstByte = vexXopFirstByte;
    }

    /**
     * Gets VVVV field of the XOP/VEX prefix.
     *
     * @return VVVV field of the XOP/VEX prefix.
     * @since 1.1.0
     */
    fcml_uint8_t getVvvv() const {
        return _vvvv;
    }

    /**
     * Sets VVVV field of the XOP/VEX prefix.
     *
     * @param vvvv The VVVV field.
     * @since 1.1.0
     */
    void setVvvv(fcml_uint8_t vvvv) {
        _vvvv = vvvv;
    }

    /**
     * Gets W flag.
     *
     * @return The W flag.
     * @since 1.1.0
     */
    fcml_uint8_t getW() const {
        return _w;
    }

    /**
     * Sets W flag.
     *
     * @param w The W flag.
     * @since 1.1.0
     */
    void setW(fcml_uint8_t w) {
        _w = w;
    }

    /**
     * Gets X flag.
     *
     * @return The X flag.
     * @since 1.1.0
     */
    fcml_uint8_t getX() const {
        return _x;
    }

    /**
     * Sets X flag.
     *
     * @param x The X flag.
     * @since 1.1.0
     */
    void setX(fcml_uint8_t x) {
        _x = x;
    }

private:
    /** Array with decoded prefixes. */
    InstructionPrefixDetails _prefixes[FCML_DASM_PREFIXES_COUNT];
    /** Number of decoded prefixes. */
    fcml_int _prefixesCount;
    /** Number of bytes used by all decoded prefixes. */
    fcml_int _prefixesBytesCount;
    /** FCML_TRUE if branch prefix exists. */
    bool _isBranch;
    /** FCML_TRUE if nobranch prefix exists. */
    bool _isNobranch;
    /** FCML_TRUE if lock explicit prefix exists. */
    bool _isLock;
    /** FCML_TRUE if rep explicit prefix exists. */
    bool _isRep;
    /** FCML_TRUE if repne explicit prefix exists. */
    bool _isRepne;
    /** FCML_TRUE if xrelease explicit prefix exists. */
    bool _isXrelease;
    /** FCML_TRUE if xacquire explicit prefix exists. */
    bool _isXacquire;
    /** FCML_TRUE if VEX prefix exists. */
    bool _isVex;
    /** FCML_TRUE if XOP prefix exists. */
    bool _isXop;
    /** FCML_TRUE if REX prefix exists. */
    bool _isRex;
    /** Various fields encoded inside decoded prefixes.*/
    fcml_uint8_t _vexXopFirstByte;
    /** R field of REX,XOP or VEX prefix. */
    fcml_uint8_t _r;
    /** X field of REX,XOP or VEX prefix. */
    fcml_uint8_t _x;
    /** B field of REX,XOP or VEX prefix. */
    fcml_uint8_t _b;
    /** W field of REX,XOP or VEX prefix. */
    fcml_uint8_t _w;
    /** L field of XOP or VEX prefix. */
    fcml_uint8_t _l;
    /** m-mmmm field of XOP or VEX prefix. */
    fcml_uint8_t _mmmm;
    /** vvvv field of XOP or VEX prefix. */
    fcml_uint8_t _vvvv;
    /** pp field of XOP or VEX prefix. */
    fcml_uint8_t _pp;
};

/** Operand details.
 * @since 1.1.0
 */
class OperandDetails {
public:

    /** @since 1.1.0 */
    enum AccessMode {
        /** Undefined mode. */
        AM_ACCESS_MODE_UNDEFINED = FCML_AM_ACCESS_MODE_UNDEFINED,
        /** Operand is read by instruction. */
        AM_READ = FCML_AM_READ,
        /** Operand is set by instruction */
        AM_WRITE = FCML_AM_WRITE,
        /** Operand is read but can be also set. */
        AM_READ_WRITE = AM_READ | AM_WRITE
    };

    /**
     * Creates default operand details with an undefined access mode.
     * @since 1.1.0
     */
    OperandDetails() :
        _accessMode( AM_ACCESS_MODE_UNDEFINED ) {
    }

    /**
     * Creates operand details for given access mode.
     *
     * @param accessMode Access mode.
     * @since 1.1.0
     */
    OperandDetails( AccessMode accessMode ) :
        _accessMode( accessMode ) {
    }

    /**
     * Gets access mode for the operand.
     *
     * @return Access mode.
     * @since 1.1.0
     */
    AccessMode getAccessMode() const {
        return _accessMode;
    }

    /**
     * Sets an access mode for the operand.
     *
     * @param accessMode The access mode for the operand.
     * @since 1.1.0
     */
    void setAccessMode(AccessMode accessMode) {
        _accessMode = accessMode;
    }

private:
    /** Operan's access mode. */
    AccessMode _accessMode;
};

/** ModRM details.
 * @since 1.1.0
 */
class DecodedModRMDetails {
public:

    /**
     * Creates an empty ModR/M details.
     * @since 1.1.0
     */
    DecodedModRMDetails() :
        _modRM(0),
        _sib(0),
        _isRip(false) {
    }

    /**
     * Gets true if RIP byte is available.
     *
     * @return True if RIP byte is available.
     * @since 1.1.0
     */
    bool isRip() const {
        return _isRip;
    }

    /**
     * Sets RIP byte availability.
     *
     * @param isRip True if RIP byte is available.
     * @since 1.1.0
     */
    void setRip( bool isRip ) {
        _isRip = isRip;
    }

    /**
     * Gets ModR/M nullable byte.
     *
     * @return ModR/M nullable byte.
     * @since 1.1.0
     */
    const Nullable<fcml_uint8_t>& getModRM() const {
        return _modRM;
    }

    /**
     * Gets ModR/M nullable byte.
     *
     * @return ModR/M nullable byte.
     * @since 1.1.0
     */
    Nullable<fcml_uint8_t>& getModRM() {
        return _modRM;
    }

    /**
     * Sets ModR/M nullable byte.
     *
     * @param modRM ModR/M nullable byte.
     * @since 1.1.0
     */
    void setModRM( const Nullable<fcml_uint8_t> &modRM ) {
        _modRM = modRM;
    }

    /**
     * Gets SIB nullable byte.
     *
     * @return SIB nullable byte.
     * @since 1.1.0
     */
    const Nullable<fcml_uint8_t>& getSib() const {
        return _sib;
    }

    /**
     * Gets SIB nullable byte.
     *
     * @return SIB nullable byte.
     * @since 1.1.0
     */
    Nullable<fcml_uint8_t>& getSib() {
        return _sib;
    }

    /**
     * Sets SIB nullable byte.
     *
     * @param sib The SIB nullable byte.
     * @since 1.1.0
     */
    void setSib( const Nullable<fcml_uint8_t> &sib ) {
        _sib = sib;
    }

private:
    /** ModR/M byte if exists.*/
    Nullable<fcml_uint8_t> _modRM;
    /** SIB byte if exists.*/
    Nullable<fcml_uint8_t> _sib;
    /** True if RIP encoding is used by decoded instruction. This flag is used only in 64 bit mode. */
    bool _isRip;
};

/** Additional details about an instruction.
 * @since 1.1.0
 */
class InstructionDetails {
public:

    /**
     * Gets address mode/instruction form. This information is used
     * internally and is rather useless in day to day usage, but if
     * you are interested in it do not hesitate to take a look at
     * the manual.
     *
     * @return Instruction form.
     * @since 1.1.0
     */
    fcml_uint16_t getAddrMode() const {
        return _addrMode;
    }

    /**
     * Sets instruction form.
     *
     * @param addrMode Addressing mode.
     * @since 1.1.0
     */
    void setAddrMode(fcml_uint16_t addrMode) {
        _addrMode = addrMode;
    }

    /**
     * Gets instruction code. See fcml_en_instruction for more details.
     *
     * @return Instruction code.
     * @since 1.1.0
     */
    fcml_en_instruction getInstruction() const {
        return _instruction;
    }

    /**
     * Gets a new instruction code for the instruction.
     *
     * @param instruction The new instruction code.
     * @since 1.1.0
     */
    void setInstruction(fcml_en_instruction instruction) {
        _instruction = instruction;
    }

    /**
     * Gets a pointer to the instruction code. See fcml_en_instruction for more details.
     *
     * @return The pointer to the instruction code.
     * @since 1.1.0
     */
    const fcml_uint8_t* getInstructionCode() const {
        return _instructionCode;
    }

    /**
     * Gets a pointer to the instruction code. See fcml_en_instruction for more details.
     *
     * @return The pointer to the instruction code.
     * @since 1.1.0
     */
    fcml_uint8_t* getInstructionCode() {
        return _instructionCode;
    }

    /**
     * Gets instruction group. See fcml_instructions.h for all available groups.
     *
     * @return The instruction group.
     * @since 1.1.0
     */
    fcml_uint64_t getInstructionGroup() const {
        return _instructionGroup;
    }

    /**
     * Sets an instruction group. See fcml_instructions.h for all available groups.
     *
     * @param instructionGroup The instruction group.
     * @since 1.1.0
     */
    void setInstructionGroup(fcml_uint64_t instructionGroup) {
        _instructionGroup = instructionGroup;
    }

    /**
     * Instruction size in bytes.
     *
     * @return Size of the instruction in bytes.
     * @since 1.1.0
     */
    fcml_usize getInstructionSize() const {
        return _instructionSize;
    }

    /**
     * Sets the instruction size in bytes.
     *
     * @param instructionSize The instruction size.
     * @since 1.1.0
     */
    void setInstructionSize(fcml_usize instructionSize) {
        _instructionSize = instructionSize;
    }

    /**
     * Gets true if it's a shortcut instruction.
     *
     * @return True if it's a shortcut instruction.
     * @since 1.1.0
     */
    bool isShortcut() const {
        return _isShortcut;
    }

    /**
     * Marks the instruction as a shortcut.
     *
     * @param isShortcut True if it's a shortcut instruction.
     * @since 1.1.0
     */
    void setShortcut(bool isShortcut) {
        _isShortcut = isShortcut;
    }

    /**
     * Gets ModR/M instruction details.
     *
     * @return ModR/M details.
     * @since 1.1.0
     */
    const DecodedModRMDetails& getModRmDetails() const {
        return _modRMDetails;
    }

    /**
     * Gets ModR/M instruction details.
     *
     * @return ModR/M details.
     * @since 1.1.0
     */
    DecodedModRMDetails& getModRmDetails() {
        return _modRMDetails;
    }

    /**
     * Sets a new instruction details for the instruction.
     *
     * @param modRmDetails The new instruction details.
     * @since 1.1.0
     */
    void setModRmDetails(const DecodedModRMDetails& modRmDetails) {
        _modRMDetails = modRmDetails;
    }

    /**
     * Gets opcode field 'S'.
     *
     * @return 'S' opcode field.
     * @since 1.1.0
     */
    bool isOpcodeFieldSBit() const {
        return _opcodeFieldSBit;
    }

    /**
     * Sets 'S' field of the opcode byte.
     *
     * @param opcodeFieldSBit 'S' opcode byte field.
     * @since 1.1.0
     */
    void setOpcodeFieldSBit(bool opcodeFieldSBit) {
        _opcodeFieldSBit = opcodeFieldSBit;
    }

    /**
     * Gets opcode field 'W'.
     *
     * @return 'W' opcode field.
     * @since 1.1.0
     */
    bool isOpcodeFieldWBit() const {
        return _opcodeFieldWBit;
    }

    /**
     * Sets 'W' field of the opcode byte.
     *
     * @param opcodeFieldWBit 'W' opcode byte field.
     * @since 1.1.0
     */
    void setOpcodeFieldWBit(bool opcodeFieldWBit) {
        _opcodeFieldWBit = opcodeFieldWBit;
    }

    /**
     * Gets the operand details for given index.
     *
     * @param index Index of the instruction details.
     * @return The operand details for the given index.
     * @throw BadArgumentException Array index out of bound.
     * @since 1.1.0
     */
    const OperandDetails& getOperandDetails( fcml_usize index ) const {
        if( index > FCML_OPERANDS_COUNT ) {
            throw BadArgumentException(FCML_TEXT("Array index out of bound."), FCML_CEH_GEC_VALUE_OUT_OF_RANGE);
        }
        return _operandDetails[index];
    }

    /**
     * Gets the operand details for given index.
     *
     * @param index Index of the instruction details.
     * @return The operand details for the given index.
     * @throw BadArgumentException Array index out of bound.
     * @since 1.1.0
     */
    OperandDetails& getOperandDetails( fcml_usize index ) {
        if( index > FCML_OPERANDS_COUNT ) {
            throw BadArgumentException(FCML_TEXT("Array index out of bound."), FCML_CEH_GEC_VALUE_OUT_OF_RANGE);
        }
        return _operandDetails[index];
    }

    /**
     * Gets instruction prefixes details.
     *
     * @return The instruction prefix details.
     * @since 1.1.0
     */
    const PrefixesDetails& getPrefixesDetails() const {
        return _prefixesDetails;
    }

    /**
     * Gets instruction prefixes details.
     *
     * @return The instruction prefix details.
     * @since 1.1.0
     */
    PrefixesDetails& getPrefixesDetails() {
        return _prefixesDetails;
    }

    /**
     * Sets a new instruction prefixes details.
     *
     * @param prefixesDetails The new prefixes details.
     * @since 1.1.0
     */
    void setPrefixesDetails(const PrefixesDetails& prefixesDetails) {
        _prefixesDetails = prefixesDetails;
    }

    /**
     * Gets pseudo operation code.
     *
     * @return The pseudo operation associated with the instruction.
     * @since 1.1.0
     */
    fcml_en_pseudo_operations getPseudoOp() const {
        return _pseudoOp;
    }

    /**
     * Sets pseudo operation for the instruction.
     *
     * @param pseudoOp The pseudo operation.
     * @since 1.1.0
     */
    void setPseudoOp(fcml_en_pseudo_operations pseudoOp) {
        _pseudoOp = pseudoOp;
    }

    /**
     * Gets true is it's a pseudo operation.
     *
     * @return True if the instruction is a pseudo operation.
     * @since 1.1.0
     */
    bool isPseudoOp() const {
        return _isPseudoOp;
    }

    /**
     * Sets pseudo operation flag.
     *
     * @param isPseudoOp True if the instruction is a pseudo operation.
     * @since 1.1.0
     */
    void setIsPseudoOp(bool isPseudoOp) {
        _isPseudoOp = isPseudoOp;
    }

private:

    /**
     * True if this is a shortcut.
     * A good example of such instruction is 'cmpsb' as opposed to 'cmps byte ptr [si],byte ptr [di]'.
     * It is very important to take this information into consideration when instruction
     * models are analyzed because there is no operands in the GIM for shortcuts.
     */
    bool _isShortcut;
    /**
     * True if given instruction is a short form of pseudo-ops instructions. See 'vcmpunordsd' for instance.
     */
    bool _isPseudoOp;
    /**
     *  Code of the disassembled instruction.
     */
    fcml_uint8_t _instructionCode[FCML_INSTRUCTION_SIZE];
    /**
     *  Instruction size in bytes.
     */
    fcml_usize _instructionSize;
    /**
     *  Some additional information about decoded instruction prefixes.
     */
    PrefixesDetails _prefixesDetails;
    /**
     * All disassembler specific information about operands going there.
     */
    OperandDetails _operandDetails[FCML_OPERANDS_COUNT];
    /**
     * Details about decoded ModR/M and SIB bytes.
     */
    DecodedModRMDetails _modRMDetails;
    /** Opcode field 's'.
     * This is set only for informational purpose only and you should not use it for any critical functionality.
     */
    bool _opcodeFieldSBit;
    /** Opcode field 'w'.
     * This is set only for informational purpose only and you should not use it for any critical functionality.
     */
    bool _opcodeFieldWBit;
    /**
     * Instruction code/number. @see fcml_instructions.h header file.
     */
    fcml_en_instruction _instruction;
    /**
     * Pseudo operation code.
     */
    fcml_en_pseudo_operations _pseudoOp;
    /**
     *  Code of the instruction form/addressing mode of the instruction above.
     */
    fcml_uint16_t _addrMode;
    /**
     * Instruction group.
     */
    fcml_uint64_t _instructionGroup;

};

/** Disassembler result.
 *
 * It's a counterpart to the fcml_st_disassembler_result structure.
 * @since 1.1.0
 */
class DisassemblerResult {

public:

    /**
     * Gets errors container with errors related to the failed disassembling process.
     *
     * @return The error container.
     * @since 1.1.0
     */
    const ErrorContainer& getErrorContainer() const {
        return _errorContainer;
    }

    /**
     * Gets errors container with errors related to the failed disassembling process.
     *
     * @return The error container.
     * @since 1.1.0
     */
    const Instruction& getInstruction() const {
        return _instruction;
    }

    /**
     * Gets instruction details associated with the instruction.
     *
     * @return The instruction details.
     * @since 1.1.0
     */
    const InstructionDetails& getInstructionDetails() const {
        return _instructionDetails;
    }

    /**
     * Cleans the disassembling result.
     * @since 1.1.0
     */
    void clean() {
        _errorContainer.clean();
        _instructionDetails = InstructionDetails();
        _instruction = Instruction();
    }

protected:

    friend class Disassembler;
    friend class DisassemblerTypeConverter;

    /**
     * Gets mutable instruction details.
     * @return Instruction details.
     * @since 1.1.0
     */
    InstructionDetails& getInstructionDetails() {
        return _instructionDetails;
    }

    /**
     * Sets new instruction details for the disassembler.
     * @param instructionDetails The instruction details.
     * @since 1.1.0
     */
    void setInstructionDetails(const InstructionDetails& instructionDetails) {
        _instructionDetails = instructionDetails;
    }

    /**
     * Gets mutable instruction.
     * @return The mutable instruction.
     * @since 1.1.0
     */
    Instruction& getInstructionInternal() {
        return _instruction;
    }

    /**
     * Sets a new instruction for the result.
     * @param instruction The instruction to be copied to the result.
     * @since 1.1.0
     */
    void setInstruction(const Instruction& instruction) {
        _instruction = instruction;
    }

    /**
     * Sets error container.
     * @param errorContainer The error container.
     * @since 1.1.0
     */
    void setErrorContainer(const ErrorContainer& errorContainer) {
        _errorContainer = errorContainer;
    }

private:

    /** Errors container */
    ErrorContainer _errorContainer;
    /** Instruction details. */
    InstructionDetails _instructionDetails;
    /** The disassembled instruction. */
    Instruction _instruction;

};

/**
 * Converts objects to their structures counterparts.
 * @since 1.1.0
 * @remarks Internal API, not intended to be used outside.
 */
class DisassemblerTypeConverter {

protected:

    friend class Disassembler;
    friend class Renderer;

    static void convert( const DisassemblerContext &src, fcml_st_disassembler_context &dest ) {
        dest.code = src.getCode();
        dest.code_length = src.getCodeLength();
        TypeConverter::convert( src.getEntryPoint(), dest.entry_point );
        convert( src.getDisassemblerConf(), dest.configuration );
    }

    static void convert( const DisassemblerConf &src, fcml_st_disassembler_conf &dest ) {
        dest.conditional_group = src.getConditionalGroup();
        dest.carry_flag_conditional_suffix = src.isCarryFlagConditionalSuffix();
        dest.enable_error_messages = src.isEnableErrorMessages();
        dest.extend_disp_to_asa = src.isExtendDispToAsa();
        dest.fail_if_unknown_instruction = src.isFailIfUnknownInstruction();
        dest.increment_ip = src.isIncrementIp();
        dest.short_forms = src.isShortForms();
    }

    static void convert( const fcml_st_decoded_modrm_details &src, DecodedModRMDetails &dest ) {
        dest.setRip( FCML_TO_CPP_BOOL( src.is_rip ) );
        Nullable<fcml_uint8_t> modRM;
        modRM.setNotNull( FCML_TO_CPP_BOOL( src.is_modrm ) );
        modRM.setValue( src.modrm );
        Nullable<fcml_uint8_t> &sib = dest.getSib();
        sib.setNotNull( FCML_TO_CPP_BOOL( src.sib.is_not_null ) );
        sib.setValue( src.sib.value );
    }

    static void convert( const DecodedModRMDetails &src, fcml_st_decoded_modrm_details &dest ) {
        dest.is_modrm = src.getModRM().isNotNull();
        dest.is_rip = src.isRip();
        dest.modrm = src.getModRM().getValue();
        fcml_nuint8_t &sib = dest.sib;
        sib.is_not_null = src.getSib().isNotNull();
        sib.value = src.getSib().getValue();
    }

    static void convert( const fcml_st_operand_details &src, OperandDetails &dest ) {
        dest.setAccessMode( static_cast<OperandDetails::AccessMode>( src.access_mode ) );
    }

    static void convert( const OperandDetails &src, fcml_st_operand_details &dest ) {
        dest.access_mode = static_cast<fcml_en_access_mode>( src.getAccessMode() );
    }

    static void convert( const fcml_st_instruction_prefix &src, InstructionPrefixDetails &dest ) {
        dest.setMandatoryPrefix( FCML_TO_CPP_BOOL( src.mandatory_prefix ) );
        dest.setPrefix( src.prefix );
        dest.setPrefixType( dest.getPrefixType() );
        ::memcpy( dest.getVexXopBytes(), src.vex_xop_bytes, 2 );
    }

    static void convert( const InstructionPrefixDetails &src, fcml_st_instruction_prefix &dest ) {
        dest.mandatory_prefix = src.isMandatoryPrefix();
        dest.prefix = src.getPrefix();
        dest.prefix_type = static_cast<fcml_en_prefix_types>( src.getPrefixType() );
        ::memcpy( dest.vex_xop_bytes, src.getVexXopBytes(), 2 );
    }

    static void convert( const fcml_st_prefixes_details src, PrefixesDetails &dest ) {
        for( int i = 0; i < FCML_DASM_PREFIXES_COUNT; i++ ) {
            convert( src.prefixes[i], dest.getPrefixes( i ) );
        }
        dest.setPrefixesCount( src.prefixes_count );
        dest.setPrefixesBytesCount( src.prefixes_bytes_count );
        dest.setBranch( FCML_TO_CPP_BOOL( src.is_branch ) );
        dest.setNobranch( FCML_TO_CPP_BOOL( src.is_nobranch ) );
        dest.setLock( FCML_TO_CPP_BOOL( src.is_lock ) );
        dest.setRep( FCML_TO_CPP_BOOL( src.is_rep ) );
        dest.setRepne( FCML_TO_CPP_BOOL( src.is_repne ) );
        dest.setXrelease( FCML_TO_CPP_BOOL( src.is_xrelease ) );
        dest.setXacquire( FCML_TO_CPP_BOOL( src.is_xacquire ) );
        dest.setVex( FCML_TO_CPP_BOOL( src.is_vex ) );
        dest.setXop( FCML_TO_CPP_BOOL( src.is_xop ) );
        dest.setRex( FCML_TO_CPP_BOOL( src.is_rex ) );
        dest.setVexXopFirstByte( src.vex_xop_first_byte );
        dest.setR( src.r );
        dest.setX( src.x );
        dest.setB( src.b );
        dest.setW( src.w );
        dest.setL( src.l );
        dest.setMmmm( src.mmmm );
        dest.setVvvv( src.vvvv );
        dest.setPp( src.pp );
    }

    static void convert( const PrefixesDetails src, fcml_st_prefixes_details &dest ) {
        for( int i = 0; i < FCML_DASM_PREFIXES_COUNT; i++ ) {
            convert( src.getPrefixes(i), dest.prefixes[i] );
        }
        dest.prefixes_count  = src.getPrefixesCount();
        dest.prefixes_bytes_count  = src.getPrefixesBytesCount();
        dest.is_branch  = src.isBranch();
        dest.is_nobranch  = src.isNobranch();
        dest.is_lock  = src.isLock();
        dest.is_rep  = src.isRep();
        dest.is_repne  = src.isRepne();
        dest.is_xrelease  = src.isXrelease();
        dest.is_xacquire  = src.isXacquire();
        dest.is_vex  = src.isVex();
        dest.is_xop  = src.isXop();
        dest.is_rex  = src.isRex();
        dest.vex_xop_first_byte  = src.getVexXopFirstByte();
        dest.r  = src.getR();
        dest.x  = src.getX();
        dest.b  = src.getB();
        dest.w  = src.getW();
        dest.l  = src.getL();
        dest.mmmm  = src.getMmmm();
        dest.vvvv  = src.getVvvv();
        dest.pp  = src.getPp();
    }

    static void convert( const fcml_st_instruction_details &src, InstructionDetails &dest ) {
        dest.setAddrMode( src.addr_mode );
        dest.setInstruction( src.instruction );
        dest.setInstructionGroup( src.instruction_group );
        dest.setInstructionSize( src.instruction_size );
        dest.setOpcodeFieldSBit( FCML_TO_CPP_BOOL( src.opcode_field_s_bit ) );
        dest.setOpcodeFieldWBit( FCML_TO_CPP_BOOL( src.opcode_field_w_bit ) );
        dest.setIsPseudoOp( FCML_TO_CPP_BOOL( src.is_pseudo_op ) );
        dest.setPseudoOp( src.pseudo_op );
        dest.setShortcut( FCML_TO_CPP_BOOL( src.is_shortcut ) );
        convert( src.modrm_details, dest.getModRmDetails() );
        for( int i = 0; i < FCML_OPERANDS_COUNT; i++ ) {
            convert( src.operand_details[i], dest.getOperandDetails(i) );
        }
        convert( src.prefixes_details, dest.getPrefixesDetails() );
    }

    static void convert( const InstructionDetails &src, fcml_st_instruction_details &dest ) {
        dest.addr_mode = src.getAddrMode();
        dest.instruction = src.getInstruction();
        dest.instruction_group = src.getInstructionGroup();
        dest.instruction_size = src.getInstructionSize();
        dest.opcode_field_s_bit = src.isOpcodeFieldSBit();
        dest.opcode_field_w_bit = src.isOpcodeFieldWBit();
        dest.is_pseudo_op = src.isPseudoOp();
        dest.pseudo_op = src.getPseudoOp();
        dest.is_shortcut = src.isShortcut();
        convert( src.getModRmDetails(), dest.modrm_details );
        for( int i = 0; i < FCML_OPERANDS_COUNT; i++ ) {
            convert( src.getOperandDetails(i), dest.operand_details[i] );
        }
        convert( src.getPrefixesDetails(), dest.prefixes_details );
    }

    static void convert( const fcml_st_disassembler_result &src, DisassemblerResult &dest ) {
        TypeConverter::convert( src.instruction, dest.getInstructionInternal() );
        convert( src.instruction_details, dest.getInstructionDetails() );
    }

    static void convert( const DisassemblerResult &src, fcml_st_disassembler_result &dest ) {
        TypeConverter::convert( src.getInstruction(), dest.instruction );
        convert( src.getInstructionDetails(), dest.instruction_details );
    }

    static void free( fcml_st_disassembler_result &src ) {
        TypeConverter::free( src.instruction );
    }

};

/** Disassembler wrapper.
 * @since 1.1.0
 */
class Disassembler : public NonCopyable, protected DialectAware {
public:

    /**
     * Creates a disassembler instance for the given dialect.
     *
     * @param dialect The dialect for the disassembler.
     * @throw InitException Cannot initialize the disassembler.
     * @since 1.1.0
     */
    Disassembler(Dialect &dialect) :
            _dialect(dialect) {
        fcml_ceh_error error = ::fcml_fn_disassembler_init( extractDialect( dialect ), &_disassembler);
        if (error) {
            throw InitException(FCML_TEXT("Cannot initialize the disassembler."), error);
        }
    }

    /**
     * Destructor.
     * @since 1.1.0
     */
    virtual ~Disassembler() {
        if (_disassembler) {
            ::fcml_fn_disassembler_free(_disassembler);
            _disassembler = NULL;
        }
    }

public:

    /**
     * Disassembled the next instruction from the context.
     *
     * @param ctx Context describing the next instruction to disassemble.
     * @param[out] disassemblerResult Disassembler result.
     * @throw DisassemblingFailedException Disassemblation failed.
     * @return Error code.
     * @since 1.1.0
     */
    fcml_ceh_error disassemble( DisassemblerContext &ctx, DisassemblerResult &disassemblerResult ) {

        fcml_ceh_error error = FCML_CEH_GEC_NO_ERROR;

        fcml_st_disassembler_context context;
        DisassemblerTypeConverter::convert( ctx, context );

        context.disassembler = _disassembler;

        /* Prepare assembler result. */
        fcml_st_disassembler_result disassembler_result;
        ::fcml_fn_disassembler_result_prepare( &disassembler_result );

        try {

            disassemblerResult.clean();

            error = ::fcml_fn_disassemble( &context, &disassembler_result );

            ErrorContainer errorContainer;
            ErrorTypeConverter::convert( disassembler_result.errors, errorContainer );

            disassemblerResult.setErrorContainer( errorContainer );

            if( error && ctx.getDisassemblerConf().isThrowExceptionOnError() ) {
                ::fcml_fn_disassembler_result_free( &disassembler_result );
                throw DisassemblingFailedException( FCML_TEXT("Assembling failed."), errorContainer, error );
            }

            if( !error ) {

                // Convert result.
                DisassemblerTypeConverter::convert( disassembler_result, disassemblerResult );

                ctx.getEntryPoint().setIP( context.entry_point.ip );
                ctx.setCode( context.code );
                ctx.setCodeLength( context.code_length );

            }

            ::fcml_fn_disassembler_result_free( &disassembler_result );

        } catch( std::exception &exc ) {
            // If anything failed, free assembler results.
            ::fcml_fn_disassembler_result_free( &disassembler_result );
            throw exc;
        }

        return error;
    }

    /**
     * Gets dialect associated with the disassembler.
     * @return The dialect instance associated with the disassembler.
     * @since 1.1.0
     */
    Dialect& getDialect() const {
        return _dialect;
    }

private:

    /** The dialect associated with the disassembler. */
    Dialect &_dialect;
    /** The disassembler instance. */
    fcml_st_disassembler *_disassembler;

};

}

#endif //FCML_DISASSEMBLER_HPP_