Zydis  v2.0.0-alpha1
Encoder.h
Go to the documentation of this file.
1 /***************************************************************************************************
2 
3  Zyan Disassembler Library (Zydis)
4 
5  Original Author : Joel H´┐Żner
6 
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in all
15  * copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE.
24 
25 ***************************************************************************************************/
26 
27 #ifndef ZYDIS_ENCODER_H
28 #define ZYDIS_ENCODER_H
29 
30 #include <Zydis/Defines.h>
31 #include <Zydis/Status.h>
32 #include <Zydis/SharedTypes.h>
33 #ifdef ZYDIS_ENABLE_FEATURE_DECODER
34 # include <Zydis/DecoderTypes.h>
35 #endif
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 /* ============================================================================================== */
42 /* Constants */
43 /* ============================================================================================== */
44 
48 #define ZYDIS_USER_ENCODABLE_ATTRIB_MASK ( \
49  ZYDIS_ATTRIB_HAS_LOCK | \
50  ZYDIS_ATTRIB_HAS_REP | \
51  ZYDIS_ATTRIB_HAS_REPE | \
52  ZYDIS_ATTRIB_HAS_REPNE | \
53  ZYDIS_ATTRIB_HAS_BOUND | \
54  ZYDIS_ATTRIB_HAS_XACQUIRE | \
55  ZYDIS_ATTRIB_HAS_XRELEASE | \
56  ZYDIS_ATTRIB_HAS_BRANCH_TAKEN | \
57  ZYDIS_ATTRIB_HAS_BRANCH_NOT_TAKEN \
58 )
59 
60 /* ============================================================================================== */
61 /* Structs */
62 /* ============================================================================================== */
63 
64 #define ZYDIS_ENCODER_MAX_OPERANDS (5)
65 
66 typedef struct ZydisEncoderOperand_
67 {
70  struct
71  {
75  uint8_t scale;
76  uint8_t dispSize;
77  int64_t disp;
78  } mem;
79  struct
80  {
81  uint16_t segment;
82  uint32_t offset;
83  } ptr;
84  uint8_t immSize;
85  union
86  {
87  uint64_t u;
88  int64_t s;
89  } imm;
91 
92 typedef struct ZydisEncoderRequest_
93 {
98  uint8_t operandCount;
100 
101  // TODO: AVX stuff
102  // TODO: MVEX stuff
104 
105 /* ============================================================================================== */
106 /* Exported functions */
107 /* ============================================================================================== */
108 
109 #ifdef ZYDIS_ENABLE_FEATURE_DECODER
110 ZYDIS_EXPORT ZydisStatus ZydisEncoderDecodedInstructionToRequest(
112 #endif
113 
123 ZYDIS_EXPORT ZydisStatus ZydisEncoderEncodeInstruction(void* buffer, size_t* bufferLen,
124  const ZydisEncoderRequest* request);
125 
126 /* ============================================================================================== */
127 
128 #ifdef __cplusplus
129 }
130 #endif
131 
132 #endif /* ZYDIS_ENCODER_H */
Defines the basic ZydisDecodedInstruction and ZydisDecodedOperand structs.
uint64_t ZydisInstructionAttributes
Defines the ZydisInstructionAttributes datatype.
Definition: DecoderTypes.h:177
ZYDIS_EXPORT ZydisStatus ZydisEncoderEncodeInstruction(void *buffer, size_t *bufferLen, const ZydisEncoderRequest *request)
Encodes the given instruction info to byte-code.
#define ZYDIS_ENCODER_MAX_OPERANDS
Definition: Encoder.h:64
struct ZydisEncoderOperand_ ZydisEncoderOperand
struct ZydisEncoderRequest_ ZydisEncoderRequest
uint16_t ZydisMnemonic
Defines the ZydisMnemonic datatype.
Definition: Mnemonic.h:44
uint8_t ZydisRegister
Defines the ZydisRegister datatype.
Definition: Register.h:49
Defines decoder/encoder-shared macros and types.
uint8_t ZydisMachineMode
Defines the ZydisMachineMode datatype.
Definition: SharedTypes.h:65
uint8_t ZydisInstructionEncoding
Defines the ZydisInstructionEncoding datatype.
Definition: SharedTypes.h:317
uint8_t ZydisOperandType
Defines the ZydisOperandType datatype.
Definition: SharedTypes.h:156
uint32_t ZydisStatus
Defines the ZydisStatus datatype.
Definition: Status.h:43
Defines the ZydisDecodedInstruction struct.
Definition: DecoderTypes.h:676
Definition: Encoder.h:67
int64_t s
Definition: Encoder.h:88
ZydisRegister reg
Definition: Encoder.h:69
union ZydisEncoderOperand_::@23 imm
ZydisRegister segment
Definition: Encoder.h:72
ZydisRegister base
Definition: Encoder.h:73
uint8_t scale
Definition: Encoder.h:75
uint8_t dispSize
Definition: Encoder.h:76
uint8_t immSize
Definition: Encoder.h:84
struct ZydisEncoderOperand_::@21 mem
struct ZydisEncoderOperand_::@22 ptr
uint32_t offset
Definition: Encoder.h:82
uint16_t segment
Definition: Encoder.h:81
int64_t disp
Definition: Encoder.h:77
uint64_t u
Definition: Encoder.h:87
ZydisRegister index
Definition: Encoder.h:74
ZydisOperandType type
Definition: Encoder.h:68
Definition: Encoder.h:93
ZydisMnemonic mnemonic
Definition: Encoder.h:95
uint8_t operandCount
Definition: Encoder.h:98
ZydisInstructionEncoding encoding
Definition: Encoder.h:97
ZydisInstructionAttributes attributes
Definition: Encoder.h:96
ZydisEncoderOperand operands[ZYDIS_ENCODER_MAX_OPERANDS]
Definition: Encoder.h:99
ZydisMachineMode machineMode
Definition: Encoder.h:94