fcml  1.1.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules
fcml_disassembler.hpp
Go to the documentation of this file.
1 /*
2  * FCML - Free Code Manipulation Library.
3  * Copyright (C) 2010-2015 Slawomir Wojtasiak
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
27 #ifndef FCML_DISASSEMBLER_HPP_
28 #define FCML_DISASSEMBLER_HPP_
29 
30 #include <string.h>
31 
32 #include "fcml_disassembler.h"
33 
34 #include "fcml_common.hpp"
35 #include "fcml_errors.hpp"
36 #include "fcml_dialect.hpp"
37 
38 namespace fcml {
39 
45 public:
46  DisassemblingFailedException( const fcml_cstring &msg, const ErrorContainer &errorContainer, fcml_ceh_error error = FCML_CEH_GEC_NO_ERROR ) :
47  ErrorContainerAwareException( msg, errorContainer, error ){
48  }
49 };
50 
57 public:
58 
64  _throwExceptionOnError(true),
65  _incrementIP(true),
66  _enableErrorMessages(true),
67  _carryFlagConditionalSuffix(false),
68  _conditionalGroup(false),
69  _shortForms(false),
70  _extendDispToASA(false),
71  _failIfUnknownInstruction(false) {
72  }
73 
76  return _carryFlagConditionalSuffix;
77  }
78 
80  void setCarryFlagConditionalSuffix(bool carryFlagConditionalSuffix) {
81  _carryFlagConditionalSuffix = carryFlagConditionalSuffix;
82  }
83 
85  fcml_uint8_t getConditionalGroup() const {
86  return _conditionalGroup;
87  }
88 
90  void setConditionalGroup(fcml_uint8_t conditionalGroup) {
91  _conditionalGroup = conditionalGroup;
92  }
93 
95  bool isEnableErrorMessages() const {
96  return _enableErrorMessages;
97  }
98 
100  void setEnableErrorMessages(bool enableErrorMessages) {
101  _enableErrorMessages = enableErrorMessages;
102  }
103 
105  bool isExtendDispToAsa() const {
106  return _extendDispToASA;
107  }
108 
110  void setExtendDispToAsa(bool extendDispToAsa) {
111  _extendDispToASA = extendDispToAsa;
112  }
113 
116  return _failIfUnknownInstruction;
117  }
118 
120  void setFailIfUnknownInstruction(bool failIfUnknownInstruction) {
121  _failIfUnknownInstruction = failIfUnknownInstruction;
122  }
123 
125  bool isIncrementIp() const {
126  return _incrementIP;
127  }
128 
130  void setIncrementIp(bool incrementIp) {
131  _incrementIP = incrementIp;
132  }
133 
135  bool isShortForms() const {
136  return _shortForms;
137  }
138 
140  void setShortForms(bool shortForms) {
141  _shortForms = shortForms;
142  }
143 
150  bool isThrowExceptionOnError() const {
151  return _throwExceptionOnError;
152  }
153 
160  void setThrowExceptionOnError(bool throwExceptionOnError) {
161  _throwExceptionOnError = throwExceptionOnError;
162  }
163 
164 private:
165  bool _throwExceptionOnError;
166  bool _incrementIP;
167  bool _enableErrorMessages;
168  bool _carryFlagConditionalSuffix;
169  fcml_uint8_t _conditionalGroup;
170  bool _shortForms;
171  bool _extendDispToASA;
172  bool _failIfUnknownInstruction;
173 
174 };
175 
180 public:
181 
187  _code(NULL),
188  _codeLength(0) {
189  }
190 
198  DisassemblerContext( fcml_ptr code, fcml_usize codeLength ) :
199  _code(code),
200  _codeLength(codeLength) {
201  }
202 
203 public:
204 
211  fcml_ptr getCode() const {
212  return _code;
213  }
214 
221  void setCode(fcml_ptr code) {
222  _code = code;
223  }
224 
231  fcml_usize getCodeLength() const {
232  return _codeLength;
233  }
234 
241  void setCodeLength(fcml_usize codeLength) {
242  _codeLength = codeLength;
243  }
244 
252  return _disassemblerConf;
253  }
254 
262  return _disassemblerConf;
263  }
264 
271  void setDisassemblerConf(DisassemblerConf disassemblerConf) {
272  _disassemblerConf = disassemblerConf;
273  }
274 
281  const EntryPoint& getEntryPoint() const {
282  return _entryPoint;
283  }
284 
292  return _entryPoint;
293  }
302  void setEntryPoint(const EntryPoint& entryPoint) {
303  _entryPoint = entryPoint;
304  }
305 
312  void setIP( fcml_ip ip ) {
313  _entryPoint.setIP(ip);
314  }
315 
322  void incrementIP( fcml_ip ip ) {
323  _entryPoint.incrementIP( ip );
324  }
325 
333  _entryPoint.setOpMode( operatingMode );
334  }
335 
342  void setAddressSizeAttribute( fcml_usize addressSizeAttribute ) {
343  _entryPoint.setAddressSizeAttribute( addressSizeAttribute );
344  }
345 
352  void setOperandSizeAttribute( fcml_usize operandSizeAttribute ) {
353  _entryPoint.setOperandSizeAttribute( operandSizeAttribute );
354  }
355 
356 private:
358  DisassemblerConf _disassemblerConf;
360  EntryPoint _entryPoint;
362  fcml_ptr _code;
364  fcml_usize _codeLength;
365 };
366 
371 public:
372 
376  enum PrefixType {
377  PT_GROUP_UNKNOWN = FCML_PT_GROUP_UNKNOWN,
378  PT_GROUP_1 = FCML_PT_GROUP_1,
379  PT_GROUP_2 = FCML_PT_GROUP_2,
380  PT_GROUP_3 = FCML_PT_GROUP_3,
381  PT_GROUP_4 = FCML_PT_GROUP_4,
382  PT_REX = FCML_PT_REX,
383  PT_VEX = FCML_PT_VEX,
384  PT_XOP = FCML_PT_XOP
385  };
386 
393  bool isMandatoryPrefix() const {
394  return _mandatoryPrefix;
395  }
396 
403  void setMandatoryPrefix(bool mandatoryPrefix) {
404  _mandatoryPrefix = mandatoryPrefix;
405  }
406 
413  fcml_uint8_t getPrefix() const {
414  return _prefix;
415  }
416 
423  void setPrefix(fcml_uint8_t prefix) {
424  _prefix = prefix;
425  }
426 
434  return _prefixType;
435  }
436 
443  void setPrefixType(PrefixType prefixType) {
444  _prefixType = prefixType;
445  }
446 
453  const fcml_uint8_t* getVexXopBytes() const {
454  return _vexXOPBytes;
455  }
456 
463  fcml_uint8_t* getVexXopBytes() {
464  return _vexXOPBytes;
465  }
466 
467 private:
469  fcml_uint8_t _prefix;
471  PrefixType _prefixType;
473  bool _mandatoryPrefix;
475  fcml_uint8_t _vexXOPBytes[2];
476 };
477 
482 public:
483 
489  _prefixesCount(0),
490  _prefixesBytesCount(0),
491  _isBranch(false),
492  _isNobranch(false),
493  _isLock(false),
494  _isRep(false),
495  _isRepne(false),
496  _isXrelease(false),
497  _isXacquire(false),
498  _isVex(false),
499  _isXop(false),
500  _isRex(false),
501  _vexXopFirstByte(false),
502  _r(0),
503  _x(0),
504  _b(0),
505  _w(0),
506  _l(0),
507  _mmmm(0),
508  _vvvv(0),
509  _pp(0) {
510  }
511 
519  const InstructionPrefixDetails& operator[](fcml_usize index) const {
520  if( index >= FCML_DASM_PREFIXES_COUNT ) {
521  throw IllegalArgumentException( FCML_TEXT( "Index out of bound." ) );
522  }
523  return _prefixes[index];
524  }
525 
534  if( index >= FCML_DASM_PREFIXES_COUNT ) {
535  throw IllegalArgumentException( FCML_TEXT( "Index out of bound." ) );
536  }
537  return _prefixes[index];
538  }
539 
546  fcml_uint8_t getB() const {
547  return _b;
548  }
549 
556  void setB(fcml_uint8_t b) {
557  _b = b;
558  }
559 
566  bool isBranch() const {
567  return _isBranch;
568  }
569 
576  void setBranch(bool isBranch) {
577  _isBranch = isBranch;
578  }
579 
586  bool isLock() const {
587  return _isLock;
588  }
589 
596  void setLock(bool isLock) {
597  _isLock = isLock;
598  }
599 
606  bool isNobranch() const {
607  return _isNobranch;
608  }
609 
616  void setNobranch(bool isNobranch) {
617  _isNobranch = isNobranch;
618  }
619 
626  bool isRep() const {
627  return _isRep;
628  }
629 
636  void setRep(bool isRep) {
637  _isRep = isRep;
638  }
639 
646  bool isRepne() const {
647  return _isRepne;
648  }
649 
656  void setRepne(bool isRepne) {
657  _isRepne = isRepne;
658  }
659 
666  bool isRex() const {
667  return _isRex;
668  }
669 
676  void setRex(bool isRex) {
677  _isRex = isRex;
678  }
679 
686  bool isVex() const {
687  return _isVex;
688  }
689 
696  void setVex(bool isVex) {
697  _isVex = isVex;
698  }
699 
706  bool isXacquire() const {
707  return _isXacquire;
708  }
709 
716  void setXacquire(bool isXacquire) {
717  _isXacquire = isXacquire;
718  }
719 
726  bool isXop() const {
727  return _isXop;
728  }
729 
736  void setXop(bool isXop) {
737  _isXop = isXop;
738  }
739 
746  bool isXrelease() const {
747  return _isXrelease;
748  }
749 
756  void setXrelease(bool isXrelease) {
757  _isXrelease = isXrelease;
758  }
759 
766  fcml_uint8_t getL() const {
767  return _l;
768  }
769 
776  void setL(fcml_uint8_t l) {
777  _l = l;
778  }
779 
786  fcml_uint8_t getMmmm() const {
787  return _mmmm;
788  }
789 
796  void setMmmm(fcml_uint8_t mmmm) {
797  _mmmm = mmmm;
798  }
799 
806  fcml_uint8_t getPp() const {
807  return _pp;
808  }
809 
816  void setPp(fcml_uint8_t pp) {
817  _pp = pp;
818  }
819 
828  const InstructionPrefixDetails& getPrefixes( fcml_usize index ) const {
829  if( index > FCML_DASM_PREFIXES_COUNT ) {
830  throw BadArgumentException(FCML_TEXT("Array index out of bound."), FCML_CEH_GEC_VALUE_OUT_OF_RANGE);
831  }
832  return _prefixes[index];
833  }
834 
843  InstructionPrefixDetails& getPrefixes( fcml_usize index ) {
844  if( index > FCML_DASM_PREFIXES_COUNT ) {
845  throw BadArgumentException(FCML_TEXT("Array index out of bound."), FCML_CEH_GEC_VALUE_OUT_OF_RANGE);
846  }
847  return _prefixes[index];
848  }
849 
856  fcml_int getPrefixesBytesCount() const {
857  return _prefixesBytesCount;
858  }
859 
866  void setPrefixesBytesCount(fcml_int prefixesBytesCount) {
867  _prefixesBytesCount = prefixesBytesCount;
868  }
869 
876  fcml_int getPrefixesCount() const {
877  return _prefixesCount;
878  }
879 
886  void setPrefixesCount(fcml_int prefixesCount) {
887  _prefixesCount = prefixesCount;
888  }
889 
896  fcml_uint8_t getR() const {
897  return _r;
898  }
899 
906  void setR(fcml_uint8_t r) {
907  _r = r;
908  }
909 
916  fcml_uint8_t getVexXopFirstByte() const {
917  return _vexXopFirstByte;
918  }
919 
926  void setVexXopFirstByte(fcml_uint8_t vexXopFirstByte) {
927  _vexXopFirstByte = vexXopFirstByte;
928  }
929 
936  fcml_uint8_t getVvvv() const {
937  return _vvvv;
938  }
939 
946  void setVvvv(fcml_uint8_t vvvv) {
947  _vvvv = vvvv;
948  }
949 
956  fcml_uint8_t getW() const {
957  return _w;
958  }
959 
966  void setW(fcml_uint8_t w) {
967  _w = w;
968  }
969 
976  fcml_uint8_t getX() const {
977  return _x;
978  }
979 
986  void setX(fcml_uint8_t x) {
987  _x = x;
988  }
989 
990 private:
994  fcml_int _prefixesCount;
996  fcml_int _prefixesBytesCount;
998  bool _isBranch;
1000  bool _isNobranch;
1002  bool _isLock;
1004  bool _isRep;
1006  bool _isRepne;
1008  bool _isXrelease;
1010  bool _isXacquire;
1012  bool _isVex;
1014  bool _isXop;
1016  bool _isRex;
1018  fcml_uint8_t _vexXopFirstByte;
1020  fcml_uint8_t _r;
1022  fcml_uint8_t _x;
1024  fcml_uint8_t _b;
1026  fcml_uint8_t _w;
1028  fcml_uint8_t _l;
1030  fcml_uint8_t _mmmm;
1032  fcml_uint8_t _vvvv;
1034  fcml_uint8_t _pp;
1035 };
1036 
1041 public:
1042 
1044  enum AccessMode {
1053  };
1054 
1060  _accessMode( AM_ACCESS_MODE_UNDEFINED ) {
1061  }
1062 
1069  OperandDetails( AccessMode accessMode ) :
1070  _accessMode( accessMode ) {
1071  }
1072 
1080  return _accessMode;
1081  }
1082 
1089  void setAccessMode(AccessMode accessMode) {
1090  _accessMode = accessMode;
1091  }
1092 
1093 private:
1095  AccessMode _accessMode;
1096 };
1097 
1102 public:
1103 
1109  _modRM(0),
1110  _sib(0),
1111  _isRip(false) {
1112  }
1113 
1120  bool isRip() const {
1121  return _isRip;
1122  }
1123 
1130  void setRip( bool isRip ) {
1131  _isRip = isRip;
1132  }
1133 
1141  return _modRM;
1142  }
1143 
1151  return _modRM;
1152  }
1153 
1160  void setModRM( const Nullable<fcml_uint8_t> &modRM ) {
1161  _modRM = modRM;
1162  }
1163 
1171  return _sib;
1172  }
1173 
1181  return _sib;
1182  }
1183 
1190  void setSib( const Nullable<fcml_uint8_t> &sib ) {
1191  _sib = sib;
1192  }
1193 
1194 private:
1196  Nullable<fcml_uint8_t> _modRM;
1200  bool _isRip;
1201 };
1202 
1207 public:
1208 
1218  fcml_uint16_t getAddrMode() const {
1219  return _addrMode;
1220  }
1221 
1228  void setAddrMode(fcml_uint16_t addrMode) {
1229  _addrMode = addrMode;
1230  }
1231 
1239  return _instruction;
1240  }
1241 
1249  _instruction = instruction;
1250  }
1251 
1258  const fcml_uint8_t* getInstructionCode() const {
1259  return _instructionCode;
1260  }
1261 
1268  fcml_uint8_t* getInstructionCode() {
1269  return _instructionCode;
1270  }
1271 
1278  fcml_uint64_t getInstructionGroup() const {
1279  return _instructionGroup;
1280  }
1281 
1288  void setInstructionGroup(fcml_uint64_t instructionGroup) {
1289  _instructionGroup = instructionGroup;
1290  }
1291 
1298  fcml_usize getInstructionSize() const {
1299  return _instructionSize;
1300  }
1301 
1308  void setInstructionSize(fcml_usize instructionSize) {
1309  _instructionSize = instructionSize;
1310  }
1311 
1318  bool isShortcut() const {
1319  return _isShortcut;
1320  }
1321 
1329  _isShortcut = isShortcut;
1330  }
1331 
1339  return _modRMDetails;
1340  }
1341 
1349  return _modRMDetails;
1350  }
1351 
1358  void setModRmDetails(const DecodedModRMDetails& modRmDetails) {
1359  _modRMDetails = modRmDetails;
1360  }
1361 
1368  bool isOpcodeFieldSBit() const {
1369  return _opcodeFieldSBit;
1370  }
1371 
1378  void setOpcodeFieldSBit(bool opcodeFieldSBit) {
1379  _opcodeFieldSBit = opcodeFieldSBit;
1380  }
1381 
1388  bool isOpcodeFieldWBit() const {
1389  return _opcodeFieldWBit;
1390  }
1391 
1398  void setOpcodeFieldWBit(bool opcodeFieldWBit) {
1399  _opcodeFieldWBit = opcodeFieldWBit;
1400  }
1401 
1410  const OperandDetails& getOperandDetails( fcml_usize index ) const {
1411  if( index > FCML_OPERANDS_COUNT ) {
1412  throw BadArgumentException(FCML_TEXT("Array index out of bound."), FCML_CEH_GEC_VALUE_OUT_OF_RANGE);
1413  }
1414  return _operandDetails[index];
1415  }
1416 
1425  OperandDetails& getOperandDetails( fcml_usize index ) {
1426  if( index > FCML_OPERANDS_COUNT ) {
1427  throw BadArgumentException(FCML_TEXT("Array index out of bound."), FCML_CEH_GEC_VALUE_OUT_OF_RANGE);
1428  }
1429  return _operandDetails[index];
1430  }
1431 
1439  return _prefixesDetails;
1440  }
1441 
1449  return _prefixesDetails;
1450  }
1451 
1458  void setPrefixesDetails(const PrefixesDetails& prefixesDetails) {
1459  _prefixesDetails = prefixesDetails;
1460  }
1461 
1469  return _pseudoOp;
1470  }
1471 
1479  _pseudoOp = pseudoOp;
1480  }
1481 
1488  bool isPseudoOp() const {
1489  return _isPseudoOp;
1490  }
1491 
1499  _isPseudoOp = isPseudoOp;
1500  }
1501 
1502 private:
1503 
1510  bool _isShortcut;
1514  bool _isPseudoOp;
1518  fcml_uint8_t _instructionCode[FCML_INSTRUCTION_SIZE];
1522  fcml_usize _instructionSize;
1526  PrefixesDetails _prefixesDetails;
1530  OperandDetails _operandDetails[FCML_OPERANDS_COUNT];
1534  DecodedModRMDetails _modRMDetails;
1538  bool _opcodeFieldSBit;
1542  bool _opcodeFieldWBit;
1546  fcml_en_instruction _instruction;
1550  fcml_en_pseudo_operations _pseudoOp;
1554  fcml_uint16_t _addrMode;
1558  fcml_uint64_t _instructionGroup;
1559 
1560 };
1561 
1568 
1569 public:
1570 
1578  return _errorContainer;
1579  }
1580 
1587  const Instruction& getInstruction() const {
1588  return _instruction;
1589  }
1590 
1598  return _instructionDetails;
1599  }
1600 
1605  void clean() {
1606  _errorContainer.clean();
1607  _instructionDetails = InstructionDetails();
1608  _instruction = Instruction();
1609  }
1610 
1611 protected:
1612 
1613  friend class Disassembler;
1614  friend class DisassemblerTypeConverter;
1615 
1622  return _instructionDetails;
1623  }
1624 
1630  void setInstructionDetails(const InstructionDetails& instructionDetails) {
1631  _instructionDetails = instructionDetails;
1632  }
1633 
1640  return _instruction;
1641  }
1642 
1648  void setInstruction(const Instruction& instruction) {
1649  _instruction = instruction;
1650  }
1651 
1657  void setErrorContainer(const ErrorContainer& errorContainer) {
1658  _errorContainer = errorContainer;
1659  }
1660 
1661 private:
1662 
1664  ErrorContainer _errorContainer;
1666  InstructionDetails _instructionDetails;
1668  Instruction _instruction;
1669 
1670 };
1671 
1678 
1679 protected:
1680 
1681  friend class Disassembler;
1682  friend class Renderer;
1683 
1684  static void convert( const DisassemblerContext &src, fcml_st_disassembler_context &dest ) {
1685  dest.code = src.getCode();
1686  dest.code_length = src.getCodeLength();
1687  TypeConverter::convert( src.getEntryPoint(), dest.entry_point );
1688  convert( src.getDisassemblerConf(), dest.configuration );
1689  }
1690 
1691  static void convert( const DisassemblerConf &src, fcml_st_disassembler_conf &dest ) {
1697  dest.increment_ip = src.isIncrementIp();
1698  dest.short_forms = src.isShortForms();
1699  }
1700 
1701  static void convert( const fcml_st_decoded_modrm_details &src, DecodedModRMDetails &dest ) {
1702  dest.setRip( FCML_TO_CPP_BOOL( src.is_rip ) );
1703  Nullable<fcml_uint8_t> modRM;
1704  modRM.setNotNull( FCML_TO_CPP_BOOL( src.is_modrm ) );
1705  modRM.setValue( src.modrm );
1706  Nullable<fcml_uint8_t> &sib = dest.getSib();
1707  sib.setNotNull( FCML_TO_CPP_BOOL( src.sib.is_not_null ) );
1708  sib.setValue( src.sib.value );
1709  }
1710 
1711  static void convert( const DecodedModRMDetails &src, fcml_st_decoded_modrm_details &dest ) {
1712  dest.is_modrm = src.getModRM().isNotNull();
1713  dest.is_rip = src.isRip();
1714  dest.modrm = src.getModRM().getValue();
1715  fcml_nuint8_t &sib = dest.sib;
1716  sib.is_not_null = src.getSib().isNotNull();
1717  sib.value = src.getSib().getValue();
1718  }
1719 
1720  static void convert( const fcml_st_operand_details &src, OperandDetails &dest ) {
1721  dest.setAccessMode( static_cast<OperandDetails::AccessMode>( src.access_mode ) );
1722  }
1723 
1724  static void convert( const OperandDetails &src, fcml_st_operand_details &dest ) {
1725  dest.access_mode = static_cast<fcml_en_access_mode>( src.getAccessMode() );
1726  }
1727 
1728  static void convert( const fcml_st_instruction_prefix &src, InstructionPrefixDetails &dest ) {
1729  dest.setMandatoryPrefix( FCML_TO_CPP_BOOL( src.mandatory_prefix ) );
1730  dest.setPrefix( src.prefix );
1731  dest.setPrefixType( dest.getPrefixType() );
1732  ::memcpy( dest.getVexXopBytes(), src.vex_xop_bytes, 2 );
1733  }
1734 
1735  static void convert( const InstructionPrefixDetails &src, fcml_st_instruction_prefix &dest ) {
1736  dest.mandatory_prefix = src.isMandatoryPrefix();
1737  dest.prefix = src.getPrefix();
1738  dest.prefix_type = static_cast<fcml_en_prefix_types>( src.getPrefixType() );
1739  ::memcpy( dest.vex_xop_bytes, src.getVexXopBytes(), 2 );
1740  }
1741 
1742  static void convert( const fcml_st_prefixes_details src, PrefixesDetails &dest ) {
1743  for( int i = 0; i < FCML_DASM_PREFIXES_COUNT; i++ ) {
1744  convert( src.prefixes[i], dest.getPrefixes( i ) );
1745  }
1746  dest.setPrefixesCount( src.prefixes_count );
1748  dest.setBranch( FCML_TO_CPP_BOOL( src.is_branch ) );
1749  dest.setNobranch( FCML_TO_CPP_BOOL( src.is_nobranch ) );
1750  dest.setLock( FCML_TO_CPP_BOOL( src.is_lock ) );
1751  dest.setRep( FCML_TO_CPP_BOOL( src.is_rep ) );
1752  dest.setRepne( FCML_TO_CPP_BOOL( src.is_repne ) );
1753  dest.setXrelease( FCML_TO_CPP_BOOL( src.is_xrelease ) );
1754  dest.setXacquire( FCML_TO_CPP_BOOL( src.is_xacquire ) );
1755  dest.setVex( FCML_TO_CPP_BOOL( src.is_vex ) );
1756  dest.setXop( FCML_TO_CPP_BOOL( src.is_xop ) );
1757  dest.setRex( FCML_TO_CPP_BOOL( src.is_rex ) );
1759  dest.setR( src.r );
1760  dest.setX( src.x );
1761  dest.setB( src.b );
1762  dest.setW( src.w );
1763  dest.setL( src.l );
1764  dest.setMmmm( src.mmmm );
1765  dest.setVvvv( src.vvvv );
1766  dest.setPp( src.pp );
1767  }
1768 
1769  static void convert( const PrefixesDetails src, fcml_st_prefixes_details &dest ) {
1770  for( int i = 0; i < FCML_DASM_PREFIXES_COUNT; i++ ) {
1771  convert( src.getPrefixes(i), dest.prefixes[i] );
1772  }
1773  dest.prefixes_count = src.getPrefixesCount();
1775  dest.is_branch = src.isBranch();
1776  dest.is_nobranch = src.isNobranch();
1777  dest.is_lock = src.isLock();
1778  dest.is_rep = src.isRep();
1779  dest.is_repne = src.isRepne();
1780  dest.is_xrelease = src.isXrelease();
1781  dest.is_xacquire = src.isXacquire();
1782  dest.is_vex = src.isVex();
1783  dest.is_xop = src.isXop();
1784  dest.is_rex = src.isRex();
1786  dest.r = src.getR();
1787  dest.x = src.getX();
1788  dest.b = src.getB();
1789  dest.w = src.getW();
1790  dest.l = src.getL();
1791  dest.mmmm = src.getMmmm();
1792  dest.vvvv = src.getVvvv();
1793  dest.pp = src.getPp();
1794  }
1795 
1796  static void convert( const fcml_st_instruction_details &src, InstructionDetails &dest ) {
1797  dest.setAddrMode( src.addr_mode );
1798  dest.setInstruction( src.instruction );
1801  dest.setOpcodeFieldSBit( FCML_TO_CPP_BOOL( src.opcode_field_s_bit ) );
1802  dest.setOpcodeFieldWBit( FCML_TO_CPP_BOOL( src.opcode_field_w_bit ) );
1803  dest.setIsPseudoOp( FCML_TO_CPP_BOOL( src.is_pseudo_op ) );
1804  dest.setPseudoOp( src.pseudo_op );
1805  dest.setShortcut( FCML_TO_CPP_BOOL( src.is_shortcut ) );
1806  convert( src.modrm_details, dest.getModRmDetails() );
1807  for( int i = 0; i < FCML_OPERANDS_COUNT; i++ ) {
1808  convert( src.operand_details[i], dest.getOperandDetails(i) );
1809  }
1810  convert( src.prefixes_details, dest.getPrefixesDetails() );
1811  }
1812 
1813  static void convert( const InstructionDetails &src, fcml_st_instruction_details &dest ) {
1814  dest.addr_mode = src.getAddrMode();
1815  dest.instruction = src.getInstruction();
1817  dest.instruction_size = src.getInstructionSize();
1820  dest.is_pseudo_op = src.isPseudoOp();
1821  dest.pseudo_op = src.getPseudoOp();
1822  dest.is_shortcut = src.isShortcut();
1823  convert( src.getModRmDetails(), dest.modrm_details );
1824  for( int i = 0; i < FCML_OPERANDS_COUNT; i++ ) {
1825  convert( src.getOperandDetails(i), dest.operand_details[i] );
1826  }
1827  convert( src.getPrefixesDetails(), dest.prefixes_details );
1828  }
1829 
1830  static void convert( const fcml_st_disassembler_result &src, DisassemblerResult &dest ) {
1831  TypeConverter::convert( src.instruction, dest.getInstructionInternal() );
1832  convert( src.instruction_details, dest.getInstructionDetails() );
1833  }
1834 
1835  static void convert( const DisassemblerResult &src, fcml_st_disassembler_result &dest ) {
1836  TypeConverter::convert( src.getInstruction(), dest.instruction );
1837  convert( src.getInstructionDetails(), dest.instruction_details );
1838  }
1839 
1840  static void free( fcml_st_disassembler_result &src ) {
1841  TypeConverter::free( src.instruction );
1842  }
1843 
1844 };
1845 
1849 class Disassembler : public NonCopyable, protected DialectAware {
1850 public:
1851 
1859  Disassembler(Dialect &dialect) :
1860  _dialect(dialect) {
1861  fcml_ceh_error error = ::fcml_fn_disassembler_init( extractDialect( dialect ), &_disassembler);
1862  if (error) {
1863  throw InitException(FCML_TEXT("Cannot initialize the disassembler."), error);
1864  }
1865  }
1866 
1871  virtual ~Disassembler() {
1872  if (_disassembler) {
1873  ::fcml_fn_disassembler_free(_disassembler);
1874  _disassembler = NULL;
1875  }
1876  }
1877 
1878 public:
1879 
1890 
1892 
1894  DisassemblerTypeConverter::convert( ctx, context );
1895 
1896  context.disassembler = _disassembler;
1897 
1898  /* Prepare assembler result. */
1899  fcml_st_disassembler_result disassembler_result;
1900  ::fcml_fn_disassembler_result_prepare( &disassembler_result );
1901 
1902  try {
1903 
1904  disassemblerResult.clean();
1905 
1906  error = ::fcml_fn_disassemble( &context, &disassembler_result );
1907 
1908  ErrorContainer errorContainer;
1909  ErrorTypeConverter::convert( disassembler_result.errors, errorContainer );
1910 
1911  disassemblerResult.setErrorContainer( errorContainer );
1912 
1913  if( error && ctx.getDisassemblerConf().isThrowExceptionOnError() ) {
1914  ::fcml_fn_disassembler_result_free( &disassembler_result );
1915  throw DisassemblingFailedException( FCML_TEXT("Assembling failed."), errorContainer, error );
1916  }
1917 
1918  if( !error ) {
1919 
1920  // Convert result.
1921  DisassemblerTypeConverter::convert( disassembler_result, disassemblerResult );
1922 
1923  ctx.getEntryPoint().setIP( context.entry_point.ip );
1924  ctx.setCode( context.code );
1925  ctx.setCodeLength( context.code_length );
1926 
1927  }
1928 
1929  ::fcml_fn_disassembler_result_free( &disassembler_result );
1930 
1931  } catch( std::exception &exc ) {
1932  // If anything failed, free assembler results.
1933  ::fcml_fn_disassembler_result_free( &disassembler_result );
1934  throw exc;
1935  }
1936 
1937  return error;
1938  }
1939 
1945  Dialect& getDialect() const {
1946  return _dialect;
1947  }
1948 
1949 private:
1950 
1952  Dialect &_dialect;
1954  fcml_st_disassembler *_disassembler;
1955 
1956 };
1957 
1958 }
1959 
1960 #endif //FCML_DISASSEMBLER_HPP_
1961 
void setX(fcml_uint8_t x)
Sets X flag.
Definition: fcml_disassembler.hpp:986
DecodedModRMDetails & getModRmDetails()
Gets ModR/M instruction details.
Definition: fcml_disassembler.hpp:1348
void setIsPseudoOp(bool isPseudoOp)
Sets pseudo operation flag.
Definition: fcml_disassembler.hpp:1498
bool isRex() const
Gets true if Rex prefix is available.
Definition: fcml_disassembler.hpp:666
DisassemblerContext()
Creates empty disassembler context.
Definition: fcml_disassembler.hpp:186
fcml_uint8_t mmmm
m-mmmm field of XOP or VEX prefix.
Definition: fcml_disassembler.h:155
void setAccessMode(AccessMode accessMode)
Sets an access mode for the operand.
Definition: fcml_disassembler.hpp:1089
fcml_ip ip
Instruction pointer EIP/RIP.
Definition: fcml_common.h:657
void clean()
Cleans the disassembling result.
Definition: fcml_disassembler.hpp:1605
fcml_bool is_xacquire
FCML_TRUE if xacquire explicit prefix exists.
Definition: fcml_disassembler.h:135
bool isRepne() const
Gets true if Repne prefix is available.
Definition: fcml_disassembler.hpp:646
fcml_en_access_mode access_mode
Instruction operand access mode READ, WRITE or both.
Definition: fcml_disassembler.h:165
void setOperatingMode(EntryPoint::OperatingMode operatingMode)
Sets processor operating mode directly into the entry point.
Definition: fcml_disassembler.hpp:332
fcml_bool is_rep
FCML_TRUE if rep explicit prefix exists.
Definition: fcml_disassembler.h:129
Operand is set by instruction.
Definition: fcml_common.h:418
void setCodeLength(fcml_usize codeLength)
Sets length of the code buffer in bytes.
Definition: fcml_disassembler.hpp:241
fcml_bool opcode_field_s_bit
Opcode field 's'.
Definition: fcml_disassembler.h:203
bool isThrowExceptionOnError() const
Returns true if exception should be thrown when disassembling fails.
Definition: fcml_disassembler.hpp:150
fcml_st_instruction instruction
Decoded instruction in its generic form.
Definition: fcml_disassembler.h:225
const fcml_uint8_t * getVexXopBytes() const
Gets the second and third bytes of the XOP/VEX prefix.
Definition: fcml_disassembler.hpp:453
void setPseudoOp(fcml_en_pseudo_operations pseudoOp)
Sets pseudo operation for the instruction.
Definition: fcml_disassembler.hpp:1478
void setPrefix(fcml_uint8_t prefix)
Sets the prefix byte.
Definition: fcml_disassembler.hpp:423
void setInstructionGroup(fcml_uint64_t instructionGroup)
Sets an instruction group.
Definition: fcml_disassembler.hpp:1288
C++ wrappers common classes.
Disassembler wrapper.
Definition: fcml_disassembler.hpp:1849
fcml_uint8_t vvvv
vvvv field of XOP or VEX prefix.
Definition: fcml_disassembler.h:157
Operand is read by instruction.
Definition: fcml_disassembler.hpp:1048
fcml_uint8_t vex_xop_first_byte
Various fields encoded inside decoded prefixes.
Definition: fcml_disassembler.h:143
void setIP(fcml_ip ip)
Sets a new instruction pointer for the entry point.
Definition: fcml_common.hpp:626
void setOperandSizeAttribute(fcml_usize operandSizeAttribute)
Sets a new operand size attribute for the entry point.
Definition: fcml_common.hpp:606
void setCode(fcml_ptr code)
Sets a new buffer with machine code for the context.
Definition: fcml_disassembler.hpp:221
void incrementIP(fcml_ip ip)
Increments entry point by given number of bytes.
Definition: fcml_disassembler.hpp:322
fcml_bool is_vex
FCML_TRUE if VEX prefix exists.
Definition: fcml_disassembler.h:137
void setCarryFlagConditionalSuffix(bool carryFlagConditionalSuffix)
Definition: fcml_disassembler.hpp:80
fcml_bool is_rip
True if RIP encoding is used by decoded instruction.
Definition: fcml_disassembler.h:175
void setInstructionSize(fcml_usize instructionSize)
Sets the instruction size in bytes.
Definition: fcml_disassembler.hpp:1308
void setEntryPoint(const EntryPoint &entryPoint)
Copies given entry point to the instance associated with the context.
Definition: fcml_disassembler.hpp:302
const DisassemblerConf & getDisassemblerConf() const
Gets a reference to the configuration object associated with the context.
Definition: fcml_disassembler.hpp:251
fcml_en_instruction
Instruction codes.
Definition: fcml_instructions.h:181
fcml_bool is_repne
FCML_TRUE if repne explicit prefix exists.
Definition: fcml_disassembler.h:131
void setRepne(bool isRepne)
Sets Repne prefix availability.
Definition: fcml_disassembler.hpp:656
void setW(fcml_uint8_t w)
Sets W flag.
Definition: fcml_disassembler.hpp:966
bool isVex() const
Gets true if Vex prefix is available.
Definition: fcml_disassembler.hpp:686
fcml_st_disassembler_conf configuration
Disassembler configuration.
Definition: fcml_disassembler.h:79
Nullable< fcml_uint8_t > & getModRM()
Gets ModR/M nullable byte.
Definition: fcml_disassembler.hpp:1150
bool isFailIfUnknownInstruction() const
Definition: fcml_disassembler.hpp:115
fcml_en_pseudo_operations
Pseudo operations.
Definition: fcml_instructions.h:1238
bool isOpcodeFieldWBit() const
Gets opcode field 'W'.
Definition: fcml_disassembler.hpp:1388
void setRip(bool isRip)
Sets RIP byte availability.
Definition: fcml_disassembler.hpp:1130
Contains some additional information about all decoded instruction prefixes.
Definition: fcml_disassembler.h:115
fcml_en_pseudo_operations pseudo_op
Pseudo operation code.
Definition: fcml_disassembler.h:211
fcml_uint8_t getPp() const
Gets PP field.
Definition: fcml_disassembler.hpp:806
fcml_st_instruction_details instruction_details
Additional disassembler specific information about decoded instruction.
Definition: fcml_disassembler.h:223
fcml_int prefixes_bytes_count
Number of bytes used by all decoded prefixes.
Definition: fcml_disassembler.h:121
void incrementIP(fcml_ip ip)
Increments the instruction pointer by given number of bytes.
Definition: fcml_common.hpp:656
Disassembler context.
Definition: fcml_disassembler.h:75
Converts objects to their structures counterparts.
Definition: fcml_disassembler.hpp:1677
void setL(fcml_uint8_t l)
Sets L flag.
Definition: fcml_disassembler.hpp:776
Definition: fcml_types.h:217
void setFailIfUnknownInstruction(bool failIfUnknownInstruction)
Definition: fcml_disassembler.hpp:120
const InstructionDetails & getInstructionDetails() const
Gets instruction details associated with the instruction.
Definition: fcml_disassembler.hpp:1597
DecodedModRMDetails()
Creates an empty ModR/M details.
Definition: fcml_disassembler.hpp:1108
Disassembler configuration.
Definition: fcml_disassembler.hpp:56
void setShortForms(bool shortForms)
Definition: fcml_disassembler.hpp:140
fcml_en_prefix_types
Available types of instruction prefixes.
Definition: fcml_disassembler.h:91
const InstructionPrefixDetails & operator[](fcml_usize index) const
Gets reference to the instruction prefix at given index.
Definition: fcml_disassembler.hpp:519
fcml_uint8_t w
W field of REX,XOP or VEX prefix.
Definition: fcml_disassembler.h:151
Additional details about an instruction.
Definition: fcml_disassembler.hpp:1206
fcml_uint64_t instruction_group
Instruction group.
Definition: fcml_disassembler.h:215
AccessMode getAccessMode() const
Gets access mode for the operand.
Definition: fcml_disassembler.hpp:1079
fcml_en_access_mode
Operand access mode.
Definition: fcml_common.h:412
PrefixesDetails & getPrefixesDetails()
Gets instruction prefixes details.
Definition: fcml_disassembler.hpp:1448
#define FCML_TEXT(x)
Used to code literal strings.
Definition: fcml_types.h:61
void setPrefixType(PrefixType prefixType)
Sets a new prefix type.
Definition: fcml_disassembler.hpp:443
fcml_bool is_nobranch
FCML_TRUE if nobranch prefix exists.
Definition: fcml_disassembler.h:125
LIB_EXPORT void LIB_CALL fcml_fn_disassembler_free(fcml_st_disassembler *disassembler)
Frees disassembler instance.
void setR(fcml_uint8_t r)
Sets R flag.
Definition: fcml_disassembler.hpp:906
void setXacquire(bool isXacquire)
Sets xacquire prefix availability.
Definition: fcml_disassembler.hpp:716
void setPrefixesBytesCount(fcml_int prefixesBytesCount)
Sets number of prefixes bytes available for the instruction.
Definition: fcml_disassembler.hpp:866
void setModRM(const Nullable< fcml_uint8_t > &modRM)
Sets ModR/M nullable byte.
Definition: fcml_disassembler.hpp:1160
bool isXop() const
Gets true if Xop prefix is available.
Definition: fcml_disassembler.hpp:726
fcml_en_instruction instruction
Instruction code/number.
Definition: fcml_disassembler.h:209
fcml_bool is_modrm
True if ModR/M exists.
Definition: fcml_disassembler.h:177
const ErrorContainer & getErrorContainer() const
Gets errors container with errors related to the failed disassembling process.
Definition: fcml_disassembler.hpp:1577
bool isNobranch() const
Gets true if no-branch prefix is available.
Definition: fcml_disassembler.hpp:606
Holds instruction pointer, processor operating mode and memory segment flags.
Definition: fcml_common.hpp:499
fcml_int prefixes_count
Number of decoded prefixes.
Definition: fcml_disassembler.h:119
fcml_bool is_pseudo_op
True if given instruction is a short form of pseudo-ops instructions.
Definition: fcml_disassembler.h:189
Base class for all exceptions that are aware of ErrorContainer.
Definition: fcml_errors.hpp:347
fcml_uint8_t getMmmm() const
Gets MMMM field.
Definition: fcml_disassembler.hpp:786
void setAddressSizeAttribute(fcml_usize addressSizeAttribute)
Sets a new address size attribute for the entry point.
Definition: fcml_common.hpp:586
fcml_bool is_xop
FCML_TRUE if XOP prefix exists.
Definition: fcml_disassembler.h:139
void setMmmm(fcml_uint8_t mmmm)
Sets MMMM field.
Definition: fcml_disassembler.hpp:796
PrefixType getPrefixType() const
Gets the prefix type.
Definition: fcml_disassembler.hpp:433
Disassembler configuration.
Definition: fcml_disassembler.h:53
void setOpcodeFieldSBit(bool opcodeFieldSBit)
Sets 'S' field of the opcode byte.
Definition: fcml_disassembler.hpp:1378
bool isShortForms() const
Definition: fcml_disassembler.hpp:135
fcml_usize getInstructionSize() const
Instruction size in bytes.
Definition: fcml_disassembler.hpp:1298
void setInstructionDetails(const InstructionDetails &instructionDetails)
Sets new instruction details for the disassembler.
Definition: fcml_disassembler.hpp:1630
bool isXrelease() const
Gets true if xrelease prefix is available.
Definition: fcml_disassembler.hpp:746
bool isXacquire() const
Gets true if xacquire prefix is available.
Definition: fcml_disassembler.hpp:706
Instruction prefix.
Definition: fcml_disassembler.hpp:370
fcml_ptr code
Pointer to the encoded instruction.
Definition: fcml_disassembler.h:83
fcml_bool increment_ip
Set to true in order to make disassembler to increment IP address by length of the disassembled instr...
Definition: fcml_disassembler.h:55
const OperandDetails & getOperandDetails(fcml_usize index) const
Gets the operand details for given index.
Definition: fcml_disassembler.hpp:1410
fcml_uint8_t getW() const
Gets W flag.
Definition: fcml_disassembler.hpp:956
void setOperandSizeAttribute(fcml_usize operandSizeAttribute)
Sets a new operand size attribute for the entry point.
Definition: fcml_disassembler.hpp:352
Some basic information about decoded ModR/M and SIB bytes.
Definition: fcml_disassembler.h:169
fcml_uint8_t l
L field of XOP or VEX prefix.
Definition: fcml_disassembler.h:153
Definition: fcml_assembler.hpp:39
Operand is read but can be also set.
Definition: fcml_disassembler.hpp:1052
void setModRmDetails(const DecodedModRMDetails &modRmDetails)
Sets a new instruction details for the instruction.
Definition: fcml_disassembler.hpp:1358
void setIncrementIp(bool incrementIp)
Definition: fcml_disassembler.hpp:130
virtual ~Disassembler()
Destructor.
Definition: fcml_disassembler.hpp:1871
void setVvvv(fcml_uint8_t vvvv)
Sets VVVV field of the XOP/VEX prefix.
Definition: fcml_disassembler.hpp:946
fcml_uint8_t getConditionalGroup() const
Definition: fcml_disassembler.hpp:85
bool isPseudoOp() const
Gets true is it's a pseudo operation.
Definition: fcml_disassembler.hpp:1488
fcml_uint8_t getVvvv() const
Gets VVVV field of the XOP/VEX prefix.
Definition: fcml_disassembler.hpp:936
#define FCML_OPERANDS_COUNT
Maximal number of the instruction operands.
Definition: fcml_common.h:35
fcml_bool enable_error_messages
True if optional error and warning messages should be collected during processing.
Definition: fcml_disassembler.h:57
fcml_uint8_t getL() const
Gets L flag.
Definition: fcml_disassembler.hpp:766
DisassemblerContext(fcml_ptr code, fcml_usize codeLength)
Creates disassembler context for given piece of machine code.
Definition: fcml_disassembler.hpp:198
void setBranch(bool isBranch)
Sets branch prefix availability.
Definition: fcml_disassembler.hpp:576
Some additional disassembler specific information about decoded operands.
Definition: fcml_disassembler.h:163
Component can not be initialized correctly.
Definition: fcml_disassembler.hpp:44
const DecodedModRMDetails & getModRmDetails() const
Gets ModR/M instruction details.
Definition: fcml_disassembler.hpp:1338
Inherit from this class in order to get access to the native FCML dialect structure.
Definition: fcml_dialect.hpp:97
EntryPoint & getEntryPoint()
Gets reference to the entry point instance associated with the context.
Definition: fcml_disassembler.hpp:291
Used mainly in case of integers and offsets.
Definition: fcml_errors.h:54
fcml_ptr getCode() const
Gets pointer to the machine code buffer.
Definition: fcml_disassembler.hpp:211
DisassemblerConf & getDisassemblerConf()
Gets a reference to the configuration object associated with the context.
Definition: fcml_disassembler.hpp:261
Operand is set by instruction.
Definition: fcml_disassembler.hpp:1050
bool isBranch() const
Gets true if branch prefix is available.
Definition: fcml_disassembler.hpp:566
const PrefixesDetails & getPrefixesDetails() const
Gets instruction prefixes details.
Definition: fcml_disassembler.hpp:1438
void setVexXopFirstByte(fcml_uint8_t vexXopFirstByte)
Sets a first byte of the XOP/VEX prefix.
Definition: fcml_disassembler.hpp:926
Structures and functions declarations related to FCML disassembler.
void setXrelease(bool isXrelease)
Sets xrelease prefix availability.
Definition: fcml_disassembler.hpp:756
fcml_bool extend_disp_to_asa
True if displacement should be sign extended to effective address size; otherwise false...
Definition: fcml_disassembler.h:67
void setEnableErrorMessages(bool enableErrorMessages)
Definition: fcml_disassembler.hpp:100
void setB(fcml_uint8_t b)
Sets B flag.
Definition: fcml_disassembler.hpp:556
fcml_int getPrefixesCount() const
Gets number of prefixes available for the instruction.
Definition: fcml_disassembler.hpp:876
bool isMandatoryPrefix() const
Returns true if it's a mandatory prefix.
Definition: fcml_disassembler.hpp:393
fcml_st_decoded_modrm_details modrm_details
Details about decoded ModR/M and SIB bytes.
Definition: fcml_disassembler.h:199
void setLock(bool isLock)
Sets lock prefix availability.
Definition: fcml_disassembler.hpp:596
ModRM details.
Definition: fcml_disassembler.hpp:1101
fcml_uint64_t getInstructionGroup() const
Gets instruction group.
Definition: fcml_disassembler.hpp:1278
Disassembler(Dialect &dialect)
Creates a disassembler instance for the given dialect.
Definition: fcml_disassembler.hpp:1859
Instruction & getInstructionInternal()
Gets mutable instruction.
Definition: fcml_disassembler.hpp:1639
fcml_uint8_t prefix
Prefix itself as raw byte.
Definition: fcml_disassembler.h:105
OperandDetails()
Creates default operand details with an undefined access mode.
Definition: fcml_disassembler.hpp:1059
fcml_bool fail_if_unknown_instruction
If set to true assembler will return FCML_CEH_GEC_UNKNOWN_INSTRUCTION error code if instruction is no...
Definition: fcml_disassembler.h:71
fcml_bool short_forms
Set to true in order to use short forms.
Definition: fcml_disassembler.h:65
fcml_int64_t fcml_ip
General instruction pointer holder.
Definition: fcml_common.h:95
const fcml_uint8_t * getInstructionCode() const
Gets a pointer to the instruction code.
Definition: fcml_disassembler.hpp:1258
void setAddrMode(fcml_uint16_t addrMode)
Sets instruction form.
Definition: fcml_disassembler.hpp:1228
bool isEnableErrorMessages() const
Definition: fcml_disassembler.hpp:95
OperandDetails & getOperandDetails(fcml_usize index)
Gets the operand details for given index.
Definition: fcml_disassembler.hpp:1425
fcml_en_prefix_types prefix_type
Type of the prefix.
Definition: fcml_disassembler.h:107
PrefixType
Type of the instruction prefix.
Definition: fcml_disassembler.hpp:376
fcml_uint8_t getX() const
Gets X flag.
Definition: fcml_disassembler.hpp:976
fcml_uint8_t vex_xop_bytes[2]
Place for additional bytes of VEX/XOP prefix.
Definition: fcml_disassembler.h:111
Reusable disassembler result holder.
Definition: fcml_disassembler.h:219
C++ wrapper for the base dialect.
DisassemblerConf()
Default constructor.
Definition: fcml_disassembler.hpp:63
Operand is read by instruction.
Definition: fcml_common.h:416
void setDisassemblerConf(DisassemblerConf disassemblerConf)
Sets a new disassembler configuration for the context.
Definition: fcml_disassembler.hpp:271
fcml_st_entry_point entry_point
Instruction entry point configuration.
Definition: fcml_disassembler.h:81
void setAddressSizeAttribute(fcml_usize addressSizeAttribute)
Sets a new address size attribute for the entry point.
Definition: fcml_disassembler.hpp:342
Dialect & getDialect() const
Gets dialect associated with the disassembler.
Definition: fcml_disassembler.hpp:1945
LIB_EXPORT void LIB_CALL fcml_fn_disassembler_result_free(fcml_st_disassembler_result *result)
Cleans result holder.
Describes one decoded prefix.
Definition: fcml_disassembler.h:103
fcml_ceh_error disassemble(DisassemblerContext &ctx, DisassemblerResult &disassemblerResult)
Disassembled the next instruction from the context.
Definition: fcml_disassembler.hpp:1889
OperatingMode
Supported operating modes.
Definition: fcml_common.hpp:506
bool isOpcodeFieldSBit() const
Gets opcode field 'S'.
Definition: fcml_disassembler.hpp:1368
void setNobranch(bool isNobranch)
Sets no-branch prefix availability.
Definition: fcml_disassembler.hpp:616
fcml_bool mandatory_prefix
FCML_TRUE if prefix is treated as mandatory one.
Definition: fcml_disassembler.h:109
LIB_EXPORT void LIB_CALL fcml_fn_disassembler_result_prepare(fcml_st_disassembler_result *result)
Prepares reusable result holder for disassembler.
void setPrefixesDetails(const PrefixesDetails &prefixesDetails)
Sets a new instruction prefixes details.
Definition: fcml_disassembler.hpp:1458
InstructionDetails & getInstructionDetails()
Gets mutable instruction details.
Definition: fcml_disassembler.hpp:1621
fcml_bool is_branch
FCML_TRUE if branch prefix exists.
Definition: fcml_disassembler.h:123
fcml_bool is_rex
FCML_TRUE if REX prefix exists.
Definition: fcml_disassembler.h:141
Prefixes details.
Definition: fcml_disassembler.hpp:481
Disassembler result.
Definition: fcml_disassembler.hpp:1567
fcml_uint16_t addr_mode
Code of the instruction form/addressing mode of the instruction above.
Definition: fcml_disassembler.h:213
fcml_usize getCodeLength() const
Gets length of the buffer in bytes.
Definition: fcml_disassembler.hpp:231
Undefined mode.
Definition: fcml_common.h:414
fcml_uint8_t conditional_group
There are two groups of suffixes for conditional instructions, you can choose which one should be use...
Definition: fcml_disassembler.h:61
fcml_st_prefixes_details prefixes_details
Some additional information about decoded instruction prefixes.
Definition: fcml_disassembler.h:195
Wraps multiple errors into one component.
Definition: fcml_errors.hpp:148
bool isRip() const
Gets true if RIP byte is available.
Definition: fcml_disassembler.hpp:1120
fcml_bool is_shortcut
True if this is a shortcut.
Definition: fcml_disassembler.h:187
fcml_st_disassembler * disassembler
Disassembler used to decode instructions.
Definition: fcml_disassembler.h:77
InstructionPrefixDetails & getPrefixes(fcml_usize index)
Gets a reference to the prefix of the given index.
Definition: fcml_disassembler.hpp:843
void setShortcut(bool isShortcut)
Marks the instruction as a shortcut.
Definition: fcml_disassembler.hpp:1328
void setRex(bool isRex)
Sets REX prefix availability.
Definition: fcml_disassembler.hpp:676
AccessMode
Definition: fcml_disassembler.hpp:1044
bool isShortcut() const
Gets true if it's a shortcut instruction.
Definition: fcml_disassembler.hpp:1318
fcml_uint8_t r
R field of REX,XOP or VEX prefix.
Definition: fcml_disassembler.h:145
void setOpMode(OperatingMode opMode)
Sets a new processor operating mode for the entry point.
Definition: fcml_common.hpp:646
Describes an instruction.
Definition: fcml_common.hpp:6207
void setInstruction(const Instruction &instruction)
Sets a new instruction for the result.
Definition: fcml_disassembler.hpp:1648
fcml_uint8_t getPrefix() const
Gets the prefix byte.
Definition: fcml_disassembler.hpp:413
#define FCML_INSTRUCTION_SIZE
Maximal number of bytes instruction can use.
Definition: fcml_common.h:37
fcml_usize code_length
Size of the code in the buffer above.
Definition: fcml_disassembler.h:85
void setExtendDispToAsa(bool extendDispToAsa)
Definition: fcml_disassembler.hpp:110
#define FCML_DASM_PREFIXES_COUNT
Maximal number of instruction prefixes.
Definition: fcml_disassembler.h:42
void setXop(bool isXop)
Sets Xop prefix availability.
Definition: fcml_disassembler.hpp:736
const EntryPoint & getEntryPoint() const
Gets reference to the constant entry point instance associated with the context.
Definition: fcml_disassembler.hpp:281
fcml_bool opcode_field_w_bit
Opcode field 'w'.
Definition: fcml_disassembler.h:207
bool isLock() const
Gets true if lock prefix is available.
Definition: fcml_disassembler.hpp:586
Operation succeed.
Definition: fcml_errors.h:42
void clean()
Cleans all errors and warnings.
Definition: fcml_errors.hpp:296
void setErrorContainer(const ErrorContainer &errorContainer)
Sets error container.
Definition: fcml_disassembler.hpp:1657
fcml_uint8_t x
X field of REX,XOP or VEX prefix.
Definition: fcml_disassembler.h:147
fcml_uint8_t getR() const
Gets R flag.
Definition: fcml_disassembler.hpp:896
void setPp(fcml_uint8_t pp)
Sets PP field.
Definition: fcml_disassembler.hpp:816
fcml_uint8_t modrm
ModR/M byte if exists.
Definition: fcml_disassembler.h:171
void setSib(const Nullable< fcml_uint8_t > &sib)
Sets SIB nullable byte.
Definition: fcml_disassembler.hpp:1190
fcml_uint8_t getVexXopFirstByte() const
Gets the first byte of the VEX/XOP prefix.
Definition: fcml_disassembler.hpp:916
fcml_st_ceh_error_container errors
All errors and warnings messages going here.
Definition: fcml_disassembler.h:221
Bad arguments.
Definition: fcml_common.hpp:217
Disassembler context.
Definition: fcml_disassembler.hpp:179
bool isCarryFlagConditionalSuffix() const
Definition: fcml_disassembler.hpp:75
const InstructionPrefixDetails & getPrefixes(fcml_usize index) const
Gets a reference to the prefix of the given index.
Definition: fcml_disassembler.hpp:828
void setThrowExceptionOnError(bool throwExceptionOnError)
Sets the way how the error handling is done.
Definition: fcml_disassembler.hpp:160
fcml_nuint8_t sib
SIB byte if exists.
Definition: fcml_disassembler.h:173
OperandDetails(AccessMode accessMode)
Creates operand details for given access mode.
Definition: fcml_disassembler.hpp:1069
fcml_bool carry_flag_conditional_suffix
True if suffixes for carry flag has to be used by disassembler.
Definition: fcml_disassembler.h:59
An abstract dialect.
Definition: fcml_dialect.hpp:41
Renderer wrapper.
Definition: fcml_renderer.hpp:160
void setOpcodeFieldWBit(bool opcodeFieldWBit)
Sets 'W' field of the opcode byte.
Definition: fcml_disassembler.hpp:1398
fcml_uint8_t * getInstructionCode()
Gets a pointer to the instruction code.
Definition: fcml_disassembler.hpp:1268
Undefined mode.
Definition: fcml_disassembler.hpp:1046
void setConditionalGroup(fcml_uint8_t conditionalGroup)
Definition: fcml_disassembler.hpp:90
Operand details.
Definition: fcml_disassembler.hpp:1040
void setVex(bool isVex)
Sets VEX prefix availability.
Definition: fcml_disassembler.hpp:696
fcml_bool is_xrelease
FCML_TRUE if xrelease explicit prefix exists.
Definition: fcml_disassembler.h:133
void setIP(fcml_ip ip)
Sets instruction pointer directly into the entry point.
Definition: fcml_disassembler.hpp:312
const Nullable< fcml_uint8_t > & getSib() const
Gets SIB nullable byte.
Definition: fcml_disassembler.hpp:1170
fcml_usize instruction_size
Instruction size in bytes.
Definition: fcml_disassembler.h:193
fcml_uint8_t * getVexXopBytes()
Gets the second and third bytes of the XOP/VEX prefix.
Definition: fcml_disassembler.hpp:463
fcml_st_dialect * extractDialect(const Dialect &dialect) const
Extracts the native FCML dialect from the dialect object.
Definition: fcml_dialect.hpp:119
fcml_bool is_lock
FCML_TRUE if lock explicit prefix exists.
Definition: fcml_disassembler.h:127
void setInstruction(fcml_en_instruction instruction)
Gets a new instruction code for the instruction.
Definition: fcml_disassembler.hpp:1248
const Instruction & getInstruction() const
Gets errors container with errors related to the failed disassembling process.
Definition: fcml_disassembler.hpp:1587
fcml_uint8_t getB() const
Gets b flag.
Definition: fcml_disassembler.hpp:546
InstructionPrefixDetails & operator[](fcml_usize index)
Gets reference to the instruction prefix at given index.
Definition: fcml_disassembler.hpp:533
void setRep(bool isRep)
Sets Rep prefix availability.
Definition: fcml_disassembler.hpp:636
ErrorContainerAwareException(const fcml_cstring &msg, const ErrorContainer &errorContainer, fcml_ceh_error error=FCML_CEH_GEC_NO_ERROR)
Creates an error container aware exception instance and sets basic information for it...
Definition: fcml_errors.hpp:357
fcml_uint8_t b
B field of REX,XOP or VEX prefix.
Definition: fcml_disassembler.h:149
Component can not be initialized correctly.
Definition: fcml_common.hpp:206
struct fcml_st_disassembler fcml_st_disassembler
This structure and type declaration represents an abstract disassembler.
Definition: fcml_disassembler.h:50
LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_disassembler_init(const fcml_st_dialect *dialect, fcml_st_disassembler **disassembler)
Initializes disassembler instance.
Additional instruction details provided by disassembler.
Definition: fcml_disassembler.h:181
bool isRep() const
Gets true if Rep prefix is available.
Definition: fcml_disassembler.hpp:626
Nullable< fcml_uint8_t > & getSib()
Gets SIB nullable byte.
Definition: fcml_disassembler.hpp:1180
fcml_uint16_t fcml_ceh_error
All error codes should be held in variables of this type.
Definition: fcml_errors.h:139
fcml_int getPrefixesBytesCount() const
Gets number of bytes interpreted to be prefixes.
Definition: fcml_disassembler.hpp:856
bool isExtendDispToAsa() const
Definition: fcml_disassembler.hpp:105
bool isIncrementIp() const
Definition: fcml_disassembler.hpp:125
fcml_uint16_t getAddrMode() const
Gets address mode/instruction form.
Definition: fcml_disassembler.hpp:1218
void setMandatoryPrefix(bool mandatoryPrefix)
Sets mandatory prefix flag for the prefix.
Definition: fcml_disassembler.hpp:403
Object which shouldn't be copied can inherit from this class.
Definition: fcml_common.hpp:263
fcml_en_instruction getInstruction() const
Gets instruction code.
Definition: fcml_disassembler.hpp:1238
fcml_en_pseudo_operations getPseudoOp() const
Gets pseudo operation code.
Definition: fcml_disassembler.hpp:1468
C++ wrapper for the FCML errors handling.
Illegal argument exception.
Definition: fcml_common.hpp:239
void setPrefixesCount(fcml_int prefixesCount)
Sets number of prefixes available for the instruction.
Definition: fcml_disassembler.hpp:886
LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_disassemble(fcml_st_disassembler_context *context, fcml_st_disassembler_result *result)
Disassembles one instruction from provided code buffer.
PrefixesDetails()
Default constructor.
Definition: fcml_disassembler.hpp:488
const Nullable< fcml_uint8_t > & getModRM() const
Gets ModR/M nullable byte.
Definition: fcml_disassembler.hpp:1140
fcml_st_operand_details operand_details[FCML_OPERANDS_COUNT]
All disassembler specific information about operands going there.
Definition: fcml_disassembler.h:197
fcml_uint8_t pp
pp field of XOP or VEX prefix.
Definition: fcml_disassembler.h:159
fcml_st_instruction_prefix prefixes[FCML_DASM_PREFIXES_COUNT]
Array with decoded prefixes.
Definition: fcml_disassembler.h:117