fcml  1.2.2
fcml_assembler.hpp
Go to the documentation of this file.
1 /*
2  * FCML - Free Code Manipulation Library.
3  * Copyright (C) 2010-2020 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_ASSEMBLER_HPP_
28 #define FCML_ASSEMBLER_HPP_
29 
30 #include <vector>
31 #include <ostream>
32 
33 #include "fcml_assembler.h"
34 
35 #include "fcml_common.hpp"
36 #include "fcml_errors.hpp"
37 #include "fcml_dialect.hpp"
38 
39 namespace fcml {
40 
46 public:
48  ErrorContainer errorContainer = ErrorContainer(),
50  ErrorContainerAwareException(msg, errorContainer, error) {
51  }
52 };
53 
58 public:
59 
70  AssembledInstruction(const fcml_uint8_t *buffer, fcml_usize len,
71  const ErrorContainer &errorContainer) {
72  set(buffer, len, errorContainer);
73  }
74 
80  set(cpy._code, cpy._codeLength, cpy._warningContainer);
81  }
82 
91  if (&cpy != this) {
92  if (this->_code) {
93  delete[] this->_code;
94  }
95  set(cpy._code, cpy._codeLength, cpy._warningContainer);
96  }
97  return *this;
98  }
99 
104  if (_code) {
105  delete[] _code;
106  _code = NULL;
107  }
108  }
109 
110 public:
111 
118  const fcml_uint8_t* getCode() const {
119  return _code;
120  }
121 
128  fcml_usize getCodeLength() const {
129  return _codeLength;
130  }
131 
139  return _warningContainer;
140  }
141 
142 private:
143 
152  void set(const fcml_uint8_t *buffer, fcml_usize len,
153  const ErrorContainer warnigns) {
154  _warningContainer = warnigns;
155  if (len > 0) {
156  _code = new fcml_uint8_t[len];
157  for (fcml_usize i = 0; i < len; i++) {
158  _code[i] = buffer[i];
159  }
160  } else {
161  _code = NULL;
162  }
163  _codeLength = len;
164  }
165 
166 private:
167 
169  ErrorContainer _warningContainer;
170 
172  fcml_uint8_t *_code;
173 
175  fcml_usize _codeLength;
176 
177 };
178 
179 class Assembler;
180 
183 public:
184 
189  _chosenInstructionIndex(-1) {
190  }
191 
192 public:
193 
201  if (_chosenInstructionIndex == -1) {
202  return NULL;
203  }
204  return &(_assembledInstructions[_chosenInstructionIndex]);
205  }
206 
214  return _errorContainer;
215  }
216 
223  fcml_usize getSize() const {
224  return static_cast<fcml_usize>(_assembledInstructions.size());
225  }
226 
233  operator const AssembledInstruction*() const {
234  if (_chosenInstructionIndex == -1) {
235  return NULL;
236  }
237  return &(_assembledInstructions[_chosenInstructionIndex]);
238  }
239 
247  const AssembledInstruction& operator[](fcml_usize index) const {
248  if (index > _assembledInstructions.size()) {
249  throw BadArgumentException(FCML_TEXT("Array index out of bound."),
251  }
252  return _assembledInstructions[index];
253  }
254 
263  friend std::basic_ostream<fcml_uint8_t>& operator<<(
264  std::basic_ostream<fcml_uint8_t> &out,
265  const AssemblerResult &result) {
266  const AssembledInstruction *assembled = result.getChosenInstruction();
267  if (assembled) {
268  // If chosen instruction is not available, do not
269  // stream anything. It's not so common, because
270  // instructions choosers are obliged to chose something.
271  if (assembled->getCode() && assembled->getCodeLength() > 0) {
272  out.write(assembled->getCode(), assembled->getCodeLength());
273  }
274  }
275  return out;
276  }
277 
283  void clear() {
284  _errorContainer.clean();
285  _assembledInstructions.clear();
286  _chosenInstructionIndex = -1;
287  }
288 
289 protected:
290 
291  friend Assembler;
292 
293  void setErrorContainer(const ErrorContainer &errorContainer) {
294  _errorContainer = errorContainer;
295  }
296 
297  std::vector<AssembledInstruction>& getAssembledInstructions() {
298  return _assembledInstructions;
299  }
300 
301  void setChoosenInstructionIndex(fcml_int index) {
302  _chosenInstructionIndex = index;
303  }
304 
305 private:
306 
308  ErrorContainer _errorContainer;
310  std::vector<AssembledInstruction> _assembledInstructions;
312  fcml_int _chosenInstructionIndex;
313 
314 };
315 
322 public:
323 
328  _throwExceptionOnError(true),
329  _incrementIp(true),
330  _enableErrorMessages(true),
331  _chooseSibEncoding(false),
332  _chooseAbsEncoding(false),
333  _forceRexPrefix(false),
334  _forceThreeByteVEX(false),
335  _noBranchPrediction(false),
336  _optimizer(NULL),
337  _optimizerFlags(0),
338  _chooser(NULL) {
339  }
340 
341 public:
342 
346  bool isChooseAbsEncoding() const {
347  return _chooseAbsEncoding;
348  }
349 
353  void setChooseAbsEncoding(bool chooseAbsEncoding) {
354  _chooseAbsEncoding = chooseAbsEncoding;
355  }
356 
361  return _chooser;
362  }
363 
368  _chooser = chooser;
369  }
370 
374  bool isChooseSibEncoding() const {
375  return _chooseSibEncoding;
376  }
377 
381  void setChooseSibEncoding(bool chooseSibEncoding) {
382  _chooseSibEncoding = chooseSibEncoding;
383  }
384 
388  bool isEnableErrorMessages() const {
389  return _enableErrorMessages;
390  }
391 
395  void setEnableErrorMessages(bool enableErrorMessages) {
396  _enableErrorMessages = enableErrorMessages;
397  }
398 
402  bool isForceRexPrefix() const {
403  return _forceRexPrefix;
404  }
405 
409  void setForceRexPrefix(bool forceRexPrefix) {
410  _forceRexPrefix = forceRexPrefix;
411  }
412 
416  bool isForceThreeByteVex() const {
417  return _forceThreeByteVEX;
418  }
419 
423  void setForceThreeByteVex(bool forceThreeByteVex) {
424  _forceThreeByteVEX = forceThreeByteVex;
425  }
426 
430  bool isIncrementIp() const {
431  return _incrementIp;
432  }
433 
437  void setIncrementIp(bool incrementIp) {
438  _incrementIp = incrementIp;
439  }
440 
445  return _optimizer;
446  }
447 
452  _optimizer = optimizer;
453  }
454 
458  fcml_uint16_t getOptimizerFlags() const {
459  return _optimizerFlags;
460  }
461 
465  void setOptimizerFlags(fcml_uint16_t optimizerFlags) {
466  _optimizerFlags = optimizerFlags;
467  }
468 
476  bool isThrowExceptionOnError() const {
477  return _throwExceptionOnError;
478  }
479 
487  void setThrowExceptionOnError(bool throwExceptionOnError) {
488  _throwExceptionOnError = throwExceptionOnError;
489  }
490 
491 private:
492  bool _throwExceptionOnError;
493  bool _incrementIp;
494  bool _enableErrorMessages;
495  bool _chooseSibEncoding;
496  bool _chooseAbsEncoding;
497  bool _forceRexPrefix;
498  bool _forceThreeByteVEX;
499  bool _noBranchPrediction;
500  fcml_fnp_asm_optimizer _optimizer;
501  fcml_uint16_t _optimizerFlags;
503 };
504 
511 
512 public:
513 
518  }
519 
529  _entryPoint(operatingMode, ip) {
530  }
531 
532 public:
533 
540  const AssemblerConf& getConfig() const {
541  return _config;
542  }
543 
551  return _config;
552  }
553 
562  void setConfig(const AssemblerConf &config) {
563  _config = config;
564  }
565 
573  const EntryPoint& getEntryPoint() const {
574  return _entryPoint;
575  }
576 
584  return _entryPoint;
585  }
594  void setEntryPoint(const EntryPoint &entryPoint) {
595  _entryPoint = entryPoint;
596  }
597 
604  void setIP(fcml_ip ip) {
605  _entryPoint.setIP(ip);
606  }
607 
615  void incrementIP(fcml_ip ip) {
616  _entryPoint.incrementIP(ip);
617  }
618 
626  _entryPoint.setOpMode(operatingMode);
627  }
628 
635  void setAddressSizeAttribute(fcml_usize addressSizeAttribute) {
636  _entryPoint.setAddressSizeAttribute(addressSizeAttribute);
637  }
638 
645  void setOperandSizeAttribute(fcml_usize operandSizeAttribute) {
646  _entryPoint.setOperandSizeAttribute(operandSizeAttribute);
647  }
648 
649 private:
650 
652  EntryPoint _entryPoint;
654  AssemblerConf _config;
655 
656 };
657 
663 public:
664 
665  static void convert(const fcml_st_assembler_context &src,
666  AssemblerContext &dest) {
667  // Converts assembler configuration and entry point.
668  // Both of them have dedicated conversion methods.
669  convert(src.configuration, dest.getConfig());
670  TypeConverter::convert(src.entry_point, dest.getEntryPoint());
671  }
672 
673  static void convert(const AssemblerContext &src,
675  // Converts assembler configuration and entry point. Both of them
676  // have dedicated conversion methods.
677  convert(src.getConfig(), dest.configuration);
678  TypeConverter::convert(src.getEntryPoint(), dest.entry_point);
679  }
680 
681  static void convert(const fcml_st_assembler_conf &src,
682  AssemblerConf &dest) {
683  dest.setChooseAbsEncoding(FCML_TO_CPP_BOOL(src.choose_abs_encoding));
684  dest.setChooseSibEncoding(FCML_TO_CPP_BOOL(src.choose_sib_encoding));
685  dest.setChooser(src.chooser);
687  FCML_TO_CPP_BOOL(src.enable_error_messages));
688  dest.setForceRexPrefix(FCML_TO_CPP_BOOL(src.force_rex_prefix));
689  dest.setForceThreeByteVex(FCML_TO_CPP_BOOL(src.force_three_byte_VEX));
690  dest.setIncrementIp(FCML_TO_CPP_BOOL(src.increment_ip));
691  dest.setOptimizer(src.optimizer);
693  }
694 
695  static void convert(const AssemblerConf &src,
696  fcml_st_assembler_conf &dest) {
699  dest.chooser = src.getChooser();
701  dest.force_rex_prefix = src.isForceRexPrefix();
703  dest.increment_ip = src.isIncrementIp();
704  dest.optimizer = src.getOptimizer();
705  dest.optimizer_flags = src.getOptimizerFlags();
706  }
707 
708 };
709 
717 class Assembler: public NonCopyable, protected DialectAware {
718 public:
719 
727  Assembler(Dialect &dialect) :
728  _dialect(dialect) {
729  fcml_ceh_error error = ::fcml_fn_assembler_init(extractDialect(dialect),
730  &_assembler);
731  if (error) {
732  throw InitException(FCML_TEXT("Cannot initialize the assembler."),
733  error);
734  }
735  }
736 
740  virtual ~Assembler() {
741  if (_assembler) {
742  ::fcml_fn_assembler_free(_assembler);
743  _assembler = NULL;
744  }
745  }
746 
747 public:
748 
761  const Instruction &instruction, AssemblerResult &result) {
762 
763  // Prepare assembler context.
765  AssemblerTypeConverter::convert(ctx, context);
766 
767  context.assembler = _assembler;
768 
769  // Prepare instruction.
770  fcml_st_instruction inst;
771  TypeConverter::convert(instruction, inst);
772 
773  // Prepare assembler result.
776 
778 
779  try {
780 
781  result.clear();
782 
783  error = ::fcml_fn_assemble(&context, &inst, &res);
784 
785  // Free instruction mnemonic.
786  TypeConverter::free(inst);
787 
788  // Failed or not, convert assembler errors.
789  ErrorContainer errorContainer;
790  ErrorTypeConverter::convert(res.errors, errorContainer);
791 
792  // Prepares assembler result.
793  result.setErrorContainer(errorContainer);
794 
795  if (error && ctx.getConfig().isThrowExceptionOnError()) {
797  throw AssemblingFailedException(FCML_TEXT("Assembling failed."),
798  errorContainer, error);
799  }
800 
801  if (!error) {
802 
803  std::vector<AssembledInstruction> &assembledInstructions =
804  result.getAssembledInstructions();
805 
806  assembledInstructions.clear();
807 
808  if (res.number_of_instructions > 0) {
809  ErrorContainer instructionWarnings;
810  fcml_int i = 0;
811  fcml_st_assembled_instruction *next_instruction =
812  res.instructions;
813  while (next_instruction) {
814  fcml_st_ceh_error_container &instruction_warnings =
815  next_instruction->warnings;
816  ErrorTypeConverter::convert(instruction_warnings,
817  instructionWarnings);
818  AssembledInstruction assembledInstruction(
819  next_instruction->code,
820  next_instruction->code_length,
821  instructionWarnings);
822  assembledInstructions.push_back(assembledInstruction);
823  if (next_instruction == res.chosen_instruction) {
824  result.setChoosenInstructionIndex(i);
825  }
826  next_instruction = next_instruction->next;
827  i++;
828  }
829  }
830 
831  // Convert it back to the context because it might have been
832  // modified during assembling process (IP incrementing etc).
833  TypeConverter::convert(context.entry_point,
834  ctx.getEntryPoint());
835 
836  }
837 
839 
840  } catch (std::exception &exc) {
841  // If anything failed, free assembler results.
842  TypeConverter::free(inst);
844  throw exc;
845  }
846 
847  return error;
848  }
849 
855  Dialect& getDialect() const {
856  return _dialect;
857  }
858 
859 private:
860 
861  // A dialect used by the assembler.
862  Dialect &_dialect;
863 
864  // An initialized assembler instance.
865  fcml_st_assembler *_assembler;
866 
867 };
868 
872 class CodeIterator: public Iterator<fcml_uint8_t> {
873 public:
874 
880  CodeIterator(std::vector<AssembledInstruction> &assembledInstructions) :
881  _buffer(NULL), _len(0), _pos(0), _iterator(
882  assembledInstructions.begin()), _assembledInstructions(
883  assembledInstructions) {
884  }
885 
889  virtual ~CodeIterator() {
890  }
891 
898  bool hasNext() {
899  if (_buffer && _pos >= _len) {
900  _buffer = NULL;
901  }
902  if (!_buffer) {
903  if (_iterator == _assembledInstructions.end()) {
904  return false;
905  }
906  AssembledInstruction &current = *_iterator++;
907  _buffer = current.getCode();
908  _len = current.getCodeLength();
909  _pos = 0;
910  }
911  return true;
912  }
913 
921  fcml_uint8_t next() {
922  if ((!_buffer || _pos >= _len) && !hasNext()) {
923  throw IllegalStateException(
924  FCML_TEXT("No more elements in the iterator."));
925  }
926  return _buffer[_pos++];
927  }
928 
929 private:
930 
932  const fcml_uint8_t *_buffer;
934  fcml_usize _len;
936  fcml_usize _pos;
938  std::vector<AssembledInstruction>::iterator _iterator;
940  std::vector<AssembledInstruction> &_assembledInstructions;
941 
942 };
943 
944 }
945 
946 #endif //FCML_ASSEMBLER_HPP_
bool isChooseAbsEncoding() const
Definition: fcml_assembler.hpp:346
AssemblerConf & getConfig()
Gets assembler configuration associated with the context.
Definition: fcml_assembler.hpp:550
AssembledInstruction(const AssembledInstruction &cpy)
Copy constructor.
Definition: fcml_assembler.hpp:79
fcml_usize getCodeLength() const
Gets number of bytes in the buffer.
Definition: fcml_assembler.hpp:128
fcml_ptr(LIB_CALL * fcml_fnp_asm_instruction_chooser)(fcml_st_chooser_context *chooser_context)
Instruction chooser function pointer declaration.
Definition: fcml_choosers.h:68
C++ wrappers common classes.
void setEnableErrorMessages(bool enableErrorMessages)
Definition: fcml_assembler.hpp:395
void setThrowExceptionOnError(bool throwExceptionOnError)
Sets the way how the error handling is done.
Definition: fcml_assembler.hpp:487
fcml_bool choose_abs_encoding
If memory address can be encoded as relative or absolute value choose the absolute addressing...
Definition: fcml_assembler.h:60
Assembler result.
Definition: fcml_assembler.hpp:182
Illegal state exception.
Definition: fcml_common.hpp:253
bool isForceThreeByteVex() const
Definition: fcml_assembler.hpp:416
const AssemblerConf & getConfig() const
Gets constant assembler configuration associated with the context.
Definition: fcml_assembler.hpp:540
Assembling failed.
Definition: fcml_assembler.hpp:45
bool isForceRexPrefix() const
Definition: fcml_assembler.hpp:402
fcml_st_assembler_conf configuration
Assembler behavior can be configured here.
Definition: fcml_assembler.h:116
friend std::basic_ostream< fcml_uint8_t > & operator<<(std::basic_ostream< fcml_uint8_t > &out, const AssemblerResult &result)
Copies machine code of the chosen instruction to the output stream.
Definition: fcml_assembler.hpp:263
std::basic_string< fcml_char > fcml_cstring
By using this type definition here, it will be definitely much easier to support UNICODE in future re...
Definition: fcml_common.hpp:53
virtual ~Assembler()
Definition: fcml_assembler.hpp:740
void setChooseSibEncoding(bool chooseSibEncoding)
Definition: fcml_assembler.hpp:381
AssembledInstruction & operator=(const AssembledInstruction &cpy)
Copies one instruction into another.
Definition: fcml_assembler.hpp:90
void setIP(fcml_ip ip)
Sets instruction pointer directly into the entry point.
Definition: fcml_assembler.hpp:604
void setAddressSizeAttribute(fcml_usize addressSizeAttribute)
Sets a new address size attribute for the entry point.
Definition: fcml_assembler.hpp:635
Converts objects to their structures counterparts.
Definition: fcml_assembler.hpp:662
fcml_uint16_t getOptimizerFlags() const
Definition: fcml_assembler.hpp:458
Assembler result.
Definition: fcml_assembler.h:100
Assembler context.
Definition: fcml_assembler.hpp:510
fcml_st_assembled_instruction * instructions
Chain of assembled instructions.
Definition: fcml_assembler.h:104
EntryPoint & getEntryPoint()
Gets reference to the entry point instance associated with the context.
Definition: fcml_assembler.hpp:583
Assembler runtime configuration.
Definition: fcml_assembler.h:48
bool isIncrementIp() const
Definition: fcml_assembler.hpp:430
Container for all collected errors and warnings.
Definition: fcml_errors.h:180
const AssembledInstruction & operator[](fcml_usize index) const
Gets an assembled instruction reference by its index.
Definition: fcml_assembler.hpp:247
void setOptimizerFlags(fcml_uint16_t optimizerFlags)
Definition: fcml_assembler.hpp:465
AssembledInstruction(const fcml_uint8_t *buffer, fcml_usize len, const ErrorContainer &errorContainer)
Creates an assembled instruction basing on given code buffer and errors.
Definition: fcml_assembler.hpp:70
#define FCML_TEXT(x)
Used to code literal strings.
Definition: fcml_types.h:61
fcml_st_assembler * assembler
Assembler instance that should be used to assemble instructions.
Definition: fcml_assembler.h:114
struct fcml_st_assembled_instruction * next
Next assembled instruction in the chain.
Definition: fcml_assembler.h:87
const fcml_uint8_t * getCode() const
Gets pointer to machine code buffer.
Definition: fcml_assembler.hpp:118
Holds instruction pointer, processor operating mode and memory segment flags.
Definition: fcml_common.hpp:524
Base class for all exceptions that are aware of ErrorContainer.
Definition: fcml_errors.hpp:347
Generic instruction model.
Definition: fcml_common.h:783
const AssembledInstruction * getChosenInstruction() const
Gets instruction chosen by the assembler as the preferred one.
Definition: fcml_assembler.hpp:200
LIB_EXPORT void LIB_CALL fcml_fn_assembler_result_prepare(fcml_st_assembler_result *result)
Prepares reusable result holder for assembler.
fcml_uint16_t optimizer_flags
This field is passed to the chosen optimizer.
Definition: fcml_assembler.h:73
fcml_st_ceh_error_container warnings
Warning messages related to assembled instruction.
Definition: fcml_assembler.h:89
Definition: fcml_assembler.hpp:39
void setChooseAbsEncoding(bool chooseAbsEncoding)
Definition: fcml_assembler.hpp:353
fcml_ceh_error assemble(AssemblerContext &ctx, const Instruction &instruction, AssemblerResult &result)
Assembles given generic instruction model.
Definition: fcml_assembler.hpp:760
fcml_fnp_asm_optimizer getOptimizer() const
Definition: fcml_assembler.hpp:444
fcml_st_entry_point entry_point
Instruction entry point configuration.
Definition: fcml_assembler.h:118
void setForceThreeByteVex(bool forceThreeByteVex)
Definition: fcml_assembler.hpp:423
Inherit from this class in order to get access to the native FCML dialect structure.
Definition: fcml_dialect.hpp:98
fcml_st_assembled_instruction * chosen_instruction
Instruction chosen by used instruction chooser; otherwise NULL.
Definition: fcml_assembler.h:106
Used mainly in case of integers and offsets.
Definition: fcml_errors.h:55
void setChooser(fcml_fnp_asm_instruction_chooser chooser)
Definition: fcml_assembler.hpp:367
const ErrorContainer & getWarningContainer() const
Gets reference to the errors container.
Definition: fcml_assembler.hpp:138
void setIncrementIp(bool incrementIp)
Definition: fcml_assembler.hpp:437
LIB_EXPORT void LIB_CALL fcml_fn_assembler_result_free(fcml_st_assembler_result *result)
Cleans result holder.
void clear()
Clears assembler result by removing all assembled instructions, errors and reseting the chosen instru...
Definition: fcml_assembler.hpp:283
An assembler wrapper.
Definition: fcml_assembler.hpp:717
fcml_bool enable_error_messages
True if optional error and warning messages should be collected during processing.
Definition: fcml_assembler.h:54
bool isChooseSibEncoding() const
Definition: fcml_assembler.hpp:374
AssemblerResult()
Definition: fcml_assembler.hpp:188
const ErrorContainer & getErrorContainer() const
Gets errors container.
Definition: fcml_assembler.hpp:213
fcml_fnp_asm_instruction_chooser getChooser() const
Definition: fcml_assembler.hpp:360
fcml_int64_t fcml_ip
General instruction pointer holder.
Definition: fcml_common.h:96
Describes an assembled instruction.
Definition: fcml_assembler.hpp:57
void setConfig(const AssemblerConf &config)
Copies given configuration to the instance associated with the context.
Definition: fcml_assembler.hpp:562
C++ wrapper for the base dialect.
bool hasNext()
Gets true if there is an another element in the iterator.
Definition: fcml_assembler.hpp:898
void setErrorContainer(const ErrorContainer &errorContainer)
Sets a new error container for the exception.
Definition: fcml_errors.hpp:375
Assembler runtime context.
Definition: fcml_assembler.h:112
OperatingMode
Supported operating modes.
Definition: fcml_common.hpp:531
void setOperatingMode(EntryPoint::OperatingMode operatingMode)
Sets processor operating mode directly into the entry point.
Definition: fcml_assembler.hpp:625
void setForceRexPrefix(bool forceRexPrefix)
Definition: fcml_assembler.hpp:409
fcml_uint8_t next()
Gets the next element from the iterator.
Definition: fcml_assembler.hpp:921
fcml_fnp_asm_instruction_chooser chooser
instruction chooser implementation that should be used by assembler to choose most appropriate instru...
Definition: fcml_assembler.h:77
A base iterator interface.
Definition: fcml_common.hpp:98
const EntryPoint & getEntryPoint() const
Gets reference to the constant entry point instance associated with the context.
Definition: fcml_assembler.hpp:573
fcml_fnp_asm_optimizer optimizer
Optimizer implementation that should be used by assembler.
Definition: fcml_assembler.h:70
void setOptimizer(fcml_fnp_asm_optimizer optimizer)
Definition: fcml_assembler.hpp:451
void incrementIP(fcml_ip ip)
Increments entry point by given number of bytes.
Definition: fcml_assembler.hpp:615
Wraps multiple errors into one component.
Definition: fcml_errors.hpp:148
fcml_bool force_rex_prefix
Sometimes REX prefix is useless so it is just omitted in the final machine code.
Definition: fcml_assembler.h:64
bool isEnableErrorMessages() const
Definition: fcml_assembler.hpp:388
fcml_bool force_three_byte_VEX
Every 2 byte VEX/XOP prefix can be encoded using three byte form.
Definition: fcml_assembler.h:67
bool isThrowExceptionOnError() const
Returns true if exception should be thrown when assembling fails.
Definition: fcml_assembler.hpp:476
fcml_uint8_t * code
Instruction machine code.
Definition: fcml_assembler.h:91
Describes an instruction.
Definition: fcml_common.hpp:7185
virtual ~CodeIterator()
Definition: fcml_assembler.hpp:889
Operation succeed.
Definition: fcml_errors.h:42
AssemblerContext()
Definition: fcml_assembler.hpp:517
Assembler configuration.
Definition: fcml_assembler.hpp:321
void setOperandSizeAttribute(fcml_usize operandSizeAttribute)
Sets a new operand size attribute for the entry point.
Definition: fcml_assembler.hpp:645
Bad arguments.
Definition: fcml_common.hpp:242
LIB_EXPORT void LIB_CALL fcml_fn_assembler_free(fcml_st_assembler *assembler)
Frees assembler instance.
Encoded instruction.
Definition: fcml_assembler.h:85
An abstract dialect.
Definition: fcml_dialect.hpp:41
virtual ~AssembledInstruction()
Definition: fcml_assembler.hpp:103
void setEntryPoint(const EntryPoint &entryPoint)
Copies given entry point to the instance associated with the context.
Definition: fcml_assembler.hpp:594
LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_assembler_init(const fcml_st_dialect *dialect, fcml_st_assembler **assembler)
Initializes assembler for given dialect.
fcml_bool choose_sib_encoding
If there are SIB and "ModR/M only" encodings available, choose the SIB based one. ...
Definition: fcml_assembler.h:57
AssemblerContext(EntryPoint::OperatingMode operatingMode, fcml_ip ip=0)
Creates an entry point instance for given operating mode and optional instruction pointer...
Definition: fcml_assembler.hpp:528
Dialect & getDialect() const
Gets dialect associated with the assembler.
Definition: fcml_assembler.hpp:855
fcml_usize number_of_instructions
Number of encoded instruction forms.
Definition: fcml_assembler.h:108
Structures and functions declarations related to one-line FCML assembler.
struct fcml_st_assembler fcml_st_assembler
Abstract assembler representation.
Definition: fcml_assembler.h:43
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
Component can not be initialized correctly.
Definition: fcml_common.hpp:231
fcml_st_ceh_error_container errors
Error and warning messages from assembler.
Definition: fcml_assembler.h:102
fcml_uint16_t fcml_ceh_error
All error codes should be held in variables of this type.
Definition: fcml_errors.h:156
fcml_usize code_length
Instruction code length in bytes.
Definition: fcml_assembler.h:93
LIB_EXPORT fcml_ceh_error LIB_CALL fcml_fn_assemble(fcml_st_assembler_context *context, const fcml_st_instruction *instruction, fcml_st_assembler_result *result)
Assembles one instruction encoded in the generic instruction model.
Iterates over machine code bytes from assembled instructions.
Definition: fcml_assembler.hpp:872
Object which shouldn&#39;t be copied can inherit from this class.
Definition: fcml_common.hpp:288
Assembler(Dialect &dialect)
Creates an assembler instance for given dialect.
Definition: fcml_assembler.hpp:727
C++ wrapper for the FCML errors handling.
CodeIterator(std::vector< AssembledInstruction > &assembledInstructions)
Creates a code iterator instance.
Definition: fcml_assembler.hpp:880
fcml_bool increment_ip
Set to true in order to force assembler to increment IP address by length of the assembled instructio...
Definition: fcml_assembler.h:51
fcml_usize getSize() const
Gets number of instructions alternatives available in the result.
Definition: fcml_assembler.hpp:223
fcml_ceh_error(LIB_CALL * fcml_fnp_asm_optimizer)(fcml_st_asm_optimizer_context *context, fcml_st_asm_optimizer_processing_details *ds_flags, fcml_fnp_asm_optimizer_callback callback, fcml_ptr args)
Function pointer declaration for optimizers.
Definition: fcml_optimizers.h:102
AssemblerConf()
Definition: fcml_assembler.hpp:327