Skip to content

Commit 1fc7e91

Browse files
NtQueryNtQuery
authored andcommitted
distorm update
1 parent adea6cf commit 1fc7e91

11 files changed

Lines changed: 1706 additions & 1568 deletions

File tree

diStorm/include/distorm.h

Lines changed: 44 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,10 @@ typedef unsigned __int8 uint8_t;
9191

9292
/*
9393
* Operand Size or Adderss size are stored inside the flags:
94-
* 0 - 16 bits
95-
* 1 - 32 bits
96-
* 2 - 64 bits
97-
* 3 - reserved
94+
* 00 - 16 bits
95+
* 01 - 32 bits
96+
* 10 - 64 bits
97+
* 11 - reserved
9898
*
9999
* If you call these set-macros more than once, you will have to clean the bits before doing so.
100100
*/
@@ -104,6 +104,8 @@ typedef unsigned __int8 uint8_t;
104104
#define FLAG_GET_ADDRSIZE(flags) (((flags) >> 10) & 3)
105105
/* To get the LOCK/REPNZ/REP prefixes. */
106106
#define FLAG_GET_PREFIX(flags) ((flags) & 7)
107+
/* Indicates whether the instruction is privileged. */
108+
#define FLAG_GET_PRIVILEGED(flags) (((flags) & FLAG_PRIVILEGED_INSTRUCTION) != 0)
107109

108110
/*
109111
* Macros to extract segment registers from 'segment':
@@ -179,7 +181,7 @@ typedef struct {
179181
*/
180182
uint8_t index;
181183

182-
/* Size of:
184+
/* Size in bits of:
183185
O_REG: register
184186
O_IMM: instruction.imm
185187
O_IMM1: instruction.imm.ex.i1
@@ -206,13 +208,18 @@ typedef struct {
206208
#define FLAG_HINT_TAKEN (1 << 3)
207209
/* Indicates there is a hint non-taken for Jcc instructions only. */
208210
#define FLAG_HINT_NOT_TAKEN (1 << 4)
209-
/* The Imm value is signed extended. */
211+
/* The Imm value is signed extended (E.G in 64 bit decoding mode, a 32 bit imm is usually sign extended into 64 bit imm). */
210212
#define FLAG_IMM_SIGNED (1 << 5)
211213
/* The destination operand is writable. */
212214
#define FLAG_DST_WR (1 << 6)
213215
/* The instruction uses RIP-relative indirection. */
214216
#define FLAG_RIP_RELATIVE (1 << 7)
215217

218+
/* See flag FLAG_GET_XXX macros above. */
219+
220+
/* The instruction is privileged and can only be used from Ring0. */
221+
#define FLAG_PRIVILEGED_INSTRUCTION (1 << 15)
222+
216223
/* No register was defined. */
217224
#define R_NONE ((uint8_t)-1)
218225

@@ -243,12 +250,12 @@ typedef struct {
243250
/* Unused prefixes mask, for each bit that is set that prefix is not used (LSB is byte [addr + 0]). */
244251
uint16_t unusedPrefixesMask;
245252
/* Mask of registers that were used in the operands, only used for quick look up, in order to know *some* operand uses that register class. */
246-
uint16_t usedRegistersMask;
253+
uint32_t usedRegistersMask;
247254
/* ID of opcode in the global opcode table. Use for mnemonic look up. */
248255
uint16_t opcode;
249256
/* Up to four operands per instruction, ignored if ops[n].type == O_NONE. */
250257
_Operand ops[OPERANDS_NO];
251-
/* Size of the whole instruction. */
258+
/* Size of the whole instruction in bytes. */
252259
uint8_t size;
253260
/* Segment information of memory indirection, default segment, or overriden one, can be -1. Use SEGMENT macros. */
254261
uint8_t segment;
@@ -258,7 +265,7 @@ typedef struct {
258265
/* Meta defines the instruction set class, and the flow control flags. Use META macros. */
259266
uint8_t meta;
260267
/* The CPU flags that the instruction operates upon. */
261-
uint8_t modifiedFlagsMask, testedFlagsMask, undefinedFlagsMask;
268+
uint16_t modifiedFlagsMask, testedFlagsMask, undefinedFlagsMask;
262269
} _DInst;
263270

264271
#ifndef DISTORM_LIGHT
@@ -279,7 +286,7 @@ typedef struct {
279286
_WString mnemonic; /* Mnemonic of decoded instruction, prefixed if required by REP, LOCK etc. */
280287
_WString operands; /* Operands of the decoded instruction, up to 3 operands, comma-seperated. */
281288
_WString instructionHex; /* Hex dump - little endian, including prefixes. */
282-
unsigned int size; /* Size of decoded instruction. */
289+
unsigned int size; /* Size of decoded instruction in bytes. */
283290
_OffsetType offset; /* Start offset of the decoded instruction. */
284291
} _DecodedInst;
285292

@@ -300,20 +307,29 @@ typedef struct {
300307
#define RM_AVX 0x800 /* YMM0 - YMM15 */
301308
#define RM_CR 0x1000 /* CR0, CR2, CR3, CR4, CR8 */
302309
#define RM_DR 0x2000 /* DR0, DR1, DR2, DR3, DR6, DR7 */
310+
#define RM_R8 0x4000 /* R8B, R8W, R8D, R8 */
311+
#define RM_R9 0x8000 /* R9B, R9W, R9D, R9 */
312+
#define RM_R10 0x10000 /* R10B, R10W, R10D, R10 */
313+
#define RM_R11 0x20000 /* R11B, R11W, R11D, R11 */
314+
#define RM_R12 0x40000 /* R12B, R12W, R12D, R12 */
315+
#define RM_R13 0x80000 /* R13B, R13W, R13D, R13 */
316+
#define RM_R14 0x100000 /* R14B, R14W, R14D, R14 */
317+
#define RM_R15 0x200000 /* R15B, R15W, R15D, R15 */
318+
303319
/* RIP should be checked using the 'flags' field and FLAG_RIP_RELATIVE.
304320
* Segments should be checked using the segment macros.
305321
* For now R8 - R15 are not supported and non general purpose registers map into same RM.
306322
*/
307323

308-
/* CPU Flags that instructions modify, test or undefine. */
309-
#define D_ZF 1 /* Zero */
310-
#define D_SF 2 /* Sign */
311-
#define D_CF 4 /* Carry */
312-
#define D_OF 8 /* Overflow */
313-
#define D_PF 0x10 /* Parity */
314-
#define D_AF 0x20 /* Auxilary */
315-
#define D_DF 0x40 /* Direction */
316-
#define D_IF 0x80 /* Interrupt */
324+
/* CPU flags that instructions modify, test or undefine (are EFLAGS compatible!). */
325+
#define D_CF 1 /* Carry */
326+
#define D_PF 4 /* Parity */
327+
#define D_AF 0x10 /* Auxiliary */
328+
#define D_ZF 0x40 /* Zero */
329+
#define D_SF 0x80 /* Sign */
330+
#define D_IF 0x200 /* Interrupt */
331+
#define D_DF 0x400 /* Direction */
332+
#define D_OF 0x800 /* Overflow */
317333

318334
/*
319335
* Instructions Set classes:
@@ -427,6 +443,15 @@ typedef enum { DECRES_NONE, DECRES_SUCCESS, DECRES_MEMORYERR, DECRES_INPUTERR, D
427443
* Notes: 1)The minimal size of maxInstructions is 15.
428444
* 2)You will have to synchronize the offset,code and length by yourself if you pass code fragments and not a complete code block!
429445
*/
446+
447+
/* distorm_decompose
448+
* There is lots of documentation about diStorm at https://code.google.com/p/distorm/wiki
449+
*
450+
* Please read https://code.google.com/p/distorm/wiki/DecomposeInterface
451+
*
452+
* And also see https://code.google.com/p/distorm/wiki/TipsnTricks
453+
*
454+
*/
430455
#ifdef SUPPORT_64BIT_OFFSET
431456

432457
_DecodeResult distorm_decompose64(_CodeInfo* ci, _DInst result[], unsigned int maxInstructions, unsigned int* usedInstructionsCount);

diStorm/include/mnemonics.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,14 @@ typedef enum {
124124
I_MOVNTDQA = 7895, I_MOVNTI = 952, I_MOVNTPD = 2556, I_MOVNTPS = 2547, I_MOVNTQ = 6841,
125125
I_MOVNTSD = 2574, I_MOVNTSS = 2565, I_MOVQ = 3926, I_MOVQ2DQ = 6513, I_MOVS = 295,
126126
I_MOVSD = 2110, I_MOVSHDUP = 2353, I_MOVSLDUP = 2176, I_MOVSS = 2103, I_MOVSX = 939,
127-
I_MOVSXD = 10013, I_MOVUPD = 2095, I_MOVUPS = 2087, I_MOVZX = 927, I_MPSADBW = 9628,
127+
I_MOVSXD = 10005, I_MOVUPD = 2095, I_MOVUPS = 2087, I_MOVZX = 927, I_MPSADBW = 9628,
128128
I_MUL = 1625, I_MULPD = 3170, I_MULPS = 3163, I_MULSD = 3184, I_MULSS = 3177,
129129
I_MWAIT = 1764, I_NEG = 1620, I_NOP = 581, I_NOT = 1615, I_OR = 27, I_ORPD = 3053,
130130
I_ORPS = 3047, I_OUT = 451, I_OUTS = 128, I_PABSB = 7688, I_PABSD = 7718, I_PABSW = 7703,
131131
I_PACKSSDW = 3849, I_PACKSSWB = 3681, I_PACKUSDW = 7916, I_PACKUSWB = 3759,
132132
I_PADDB = 7204, I_PADDD = 7234, I_PADDQ = 6481, I_PADDSB = 6930, I_PADDSW = 6947,
133133
I_PADDUSB = 6620, I_PADDUSW = 6639, I_PADDW = 7219, I_PALIGNR = 9410, I_PAND = 6607,
134-
I_PANDN = 6665, I_PAUSE = 10021, I_PAVGB = 6680, I_PAVGUSB = 2078, I_PAVGW = 6725,
134+
I_PANDN = 6665, I_PAUSE = 10013, I_PAVGB = 6680, I_PAVGUSB = 2078, I_PAVGW = 6725,
135135
I_PBLENDVB = 7599, I_PBLENDW = 9391, I_PCLMULQDQ = 9647, I_PCMPEQB = 4043,
136136
I_PCMPEQD = 4081, I_PCMPEQQ = 7876, I_PCMPEQW = 4062, I_PCMPESTRI = 9726,
137137
I_PCMPESTRM = 9703, I_PCMPGTB = 3702, I_PCMPGTD = 3740, I_PCMPGTQ = 8087,
@@ -163,7 +163,7 @@ typedef enum {
163163
I_PUNPCKLDQ = 3658, I_PUNPCKLQDQ = 3870, I_PUNPCKLWD = 3635, I_PUSH = 16,
164164
I_PUSHA = 91, I_PUSHF = 270, I_PXOR = 6981, I_RCL = 977, I_RCPPS = 2953, I_RCPSS = 2960,
165165
I_RCR = 982, I_RDFSBASE = 9882, I_RDGSBASE = 9912, I_RDMSR = 600, I_RDPMC = 607,
166-
I_RDRAND = 9980, I_RDTSC = 593, I_RDTSCP = 1864, I_RET = 325, I_RETF = 354,
166+
I_RDRAND = 10026, I_RDTSC = 593, I_RDTSCP = 1864, I_RET = 325, I_RETF = 354,
167167
I_ROL = 967, I_ROR = 972, I_ROUNDPD = 9296, I_ROUNDPS = 9277, I_ROUNDSD = 9334,
168168
I_ROUNDSS = 9315, I_RSM = 882, I_RSQRTPS = 2915, I_RSQRTSS = 2924, I_SAHF = 283,
169169
I_SAL = 997, I_SALC = 394, I_SAR = 1002, I_SBB = 36, I_SCAS = 319, I_SETA = 807,
@@ -241,17 +241,17 @@ typedef enum {
241241
I_VHADDPD = 4197, I_VHADDPS = 4206, I_VHSUBPD = 4231, I_VHSUBPS = 4240, I_VINSERTF128 = 9503,
242242
I_VINSERTPS = 9557, I_VLDDQU = 7001, I_VLDMXCSR = 9941, I_VMASKMOVDQU = 7131,
243243
I_VMASKMOVPD = 7949, I_VMASKMOVPS = 7937, I_VMAXPD = 3588, I_VMAXPS = 3580,
244-
I_VMAXSD = 3604, I_VMAXSS = 3596, I_VMCALL = 1719, I_VMCLEAR = 9997, I_VMFUNC = 1787,
244+
I_VMAXSD = 3604, I_VMAXSS = 3596, I_VMCALL = 1719, I_VMCLEAR = 9989, I_VMFUNC = 1787,
245245
I_VMINPD = 3468, I_VMINPS = 3460, I_VMINSD = 3484, I_VMINSS = 3476, I_VMLAUNCH = 1727,
246246
I_VMLOAD = 1811, I_VMMCALL = 1802, I_VMOVAPD = 2476, I_VMOVAPS = 2467, I_VMOVD = 3932,
247247
I_VMOVDDUP = 2234, I_VMOVDQA = 3962, I_VMOVDQU = 3971, I_VMOVHLPS = 2195,
248248
I_VMOVHPD = 2382, I_VMOVHPS = 2373, I_VMOVLHPS = 2363, I_VMOVLPD = 2214, I_VMOVLPS = 2205,
249249
I_VMOVMSKPD = 2836, I_VMOVMSKPS = 2825, I_VMOVNTDQ = 6858, I_VMOVNTDQA = 7905,
250250
I_VMOVNTPD = 2593, I_VMOVNTPS = 2583, I_VMOVQ = 3939, I_VMOVSD = 2143, I_VMOVSHDUP = 2391,
251251
I_VMOVSLDUP = 2223, I_VMOVSS = 2135, I_VMOVUPD = 2126, I_VMOVUPS = 2117, I_VMPSADBW = 9637,
252-
I_VMPTRLD = 9988, I_VMPTRST = 6385, I_VMREAD = 4128, I_VMRESUME = 1737, I_VMRUN = 1795,
252+
I_VMPTRLD = 9980, I_VMPTRST = 6385, I_VMREAD = 4128, I_VMRESUME = 1737, I_VMRUN = 1795,
253253
I_VMSAVE = 1819, I_VMULPD = 3199, I_VMULPS = 3191, I_VMULSD = 3215, I_VMULSS = 3207,
254-
I_VMWRITE = 4152, I_VMXOFF = 1747, I_VMXON = 10006, I_VORPD = 3066, I_VORPS = 3059,
254+
I_VMWRITE = 4152, I_VMXOFF = 1747, I_VMXON = 9998, I_VORPD = 3066, I_VORPS = 3059,
255255
I_VPABSB = 7695, I_VPABSD = 7725, I_VPABSW = 7710, I_VPACKSSDW = 3859, I_VPACKSSWB = 3691,
256256
I_VPACKUSDW = 7926, I_VPACKUSWB = 3769, I_VPADDB = 7211, I_VPADDD = 7241,
257257
I_VPADDQ = 6488, I_VPADDSB = 6938, I_VPADDSW = 6955, I_VPADDUSW = 6629, I_VPADDW = 7226,
@@ -287,7 +287,7 @@ typedef enum {
287287
I_VTESTPD = 7590, I_VTESTPS = 7581, I_VUCOMISD = 2761, I_VUCOMISS = 2751,
288288
I_VUNPCKHPD = 2317, I_VUNPCKHPS = 2306, I_VUNPCKLPD = 2275, I_VUNPCKLPS = 2264,
289289
I_VXORPD = 3095, I_VXORPS = 3087, I_VZEROALL = 4118, I_VZEROUPPER = 4106,
290-
I_WAIT = 10028, I_WBINVD = 561, I_WRFSBASE = 9931, I_WRGSBASE = 9960, I_WRMSR = 586,
290+
I_WAIT = 10020, I_WBINVD = 561, I_WRFSBASE = 9931, I_WRGSBASE = 9960, I_WRMSR = 586,
291291
I_XADD = 946, I_XCHG = 212, I_XGETBV = 1771, I_XLAT = 400, I_XOR = 61, I_XORPD = 3080,
292292
I_XORPS = 3073, I_XRSTOR = 4273, I_XRSTOR64 = 4281, I_XSAVE = 4249, I_XSAVE64 = 4256,
293293
I_XSAVEOPT = 4299, I_XSAVEOPT64 = 4309, I_XSETBV = 1779, I__3DNOW = 10034

diStorm/src/decoder.c

Lines changed: 62 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,17 @@ static _DecodeType decode_get_effective_op_size(_DecodeType dt, _iflags decodedP
7878
return dt;
7979
}
8080

81+
/* A helper macro to convert from diStorm's CPU flags to EFLAGS. */
82+
#define CONVERT_FLAGS_TO_EFLAGS(dst, src, field) dst->field = ((src->field & D_COMPACT_SAME_FLAGS) | \
83+
((src->field & D_COMPACT_IF) ? D_IF : 0) | \
84+
((src->field & D_COMPACT_DF) ? D_DF : 0) | \
85+
((src->field & D_COMPACT_OF) ? D_OF : 0));
86+
8187
static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di)
8288
{
89+
/* Remember whether the instruction is privileged. */
90+
uint16_t privilegedFlag = 0;
91+
8392
/* The ModR/M byte of the current instruction. */
8493
unsigned int modrm = 0;
8594

@@ -106,7 +115,7 @@ static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di)
106115
*/
107116
int lockable = FALSE;
108117

109-
/* Calcualte (and cache) effective-operand-size and effective-address-size only once. */
118+
/* Calculate (and cache) effective-operand-size and effective-address-size only once. */
110119
_DecodeType effOpSz, effAdrSz;
111120
_iflags instFlags;
112121

@@ -115,6 +124,10 @@ static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di)
115124
isi = &InstSharedInfoTable[ii->sharedIndex];
116125
instFlags = FlagsTable[isi->flagsIndex];
117126

127+
/* Copy the privileged bit and remove it from the opcodeId field ASAP. */
128+
privilegedFlag = ii->opcodeId & OPCODE_ID_PRIVILEGED;
129+
ii->opcodeId &= ~OPCODE_ID_PRIVILEGED;
130+
118131
/*
119132
* If both REX and OpSize are available we will have to disable the OpSize, because REX has precedence.
120133
* However, only if REX.W is set !
@@ -135,8 +148,8 @@ static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di)
135148
* Which practically means, don't allow 32 bits instructions in 16 bits decoding mode, but do allow
136149
* 16 bits instructions in 32 bits decoding mode, of course...
137150
138-
* NOTE: Make sure the instruction set for 32 bits has explicitly this specfic flag set.
139-
* NOTE2: Make sure the instruction set for 64 bits has explicitly this specfic flag set.
151+
* NOTE: Make sure the instruction set for 32 bits has explicitly this specific flag set.
152+
* NOTE2: Make sure the instruction set for 64 bits has explicitly this specific flag set.
140153
141154
* If this is the case, drop what we've got and restart all over after DB'ing that byte.
142155
@@ -263,7 +276,7 @@ static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di)
263276
else if ((instFlags & (INST_PRE_ADDR_SIZE | INST_NATIVE)) == (INST_PRE_ADDR_SIZE | INST_NATIVE)) {
264277
di->opcode = ii->opcodeId;
265278

266-
/* If LOOPxx gets here from 64bits, it must be Decode32Bits because Address Size perfix is set. */
279+
/* If LOOPxx gets here from 64bits, it must be Decode32Bits because Address Size prefix is set. */
267280
ps->usedPrefixes |= INST_PRE_ADDR_SIZE;
268281
}
269282
/*
@@ -336,10 +349,10 @@ static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di)
336349
* Therefore, we use another table to fix the offset.
337350
*/
338351
if (instFlags & INST_PRE_VEX) {
339-
/* Use the AVX pesudo compare mnemonics table. */
352+
/* Use the AVX pseudo compare mnemonics table. */
340353
di->opcode = ii->opcodeId + VCmpMnemonicOffsets[cmpType];
341354
} else {
342-
/* Use the SSE psuedo compare mnemonics table. */
355+
/* Use the SSE pseudo compare mnemonics table. */
343356
di->opcode = ii->opcodeId + CmpMnemonicOffsets[cmpType];
344357
}
345358
}
@@ -356,6 +369,9 @@ static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di)
356369
/* Set the unused prefixes mask. */
357370
di->unusedPrefixesMask = prefixes_set_unused_mask(ps);
358371

372+
/* Fix privileged. Assumes the privilegedFlag is 0x8000 only. */
373+
di->flags |= privilegedFlag;
374+
359375
/* Copy instruction meta. */
360376
di->meta = isi->meta;
361377
if (di->segment == 0) di->segment = R_NONE;
@@ -364,9 +380,9 @@ static _DecodeResult decode_inst(_CodeInfo* ci, _PrefixState* ps, _DInst* di)
364380
if (di->base != R_NONE) di->usedRegistersMask |= _REGISTERTORCLASS[di->base];
365381

366382
/* Copy CPU affected flags. */
367-
di->modifiedFlagsMask = isi->modifiedFlags;
368-
di->testedFlagsMask = isi->testedFlags;
369-
di->undefinedFlagsMask = isi->undefinedFlags;
383+
CONVERT_FLAGS_TO_EFLAGS(di, isi, modifiedFlagsMask);
384+
CONVERT_FLAGS_TO_EFLAGS(di, isi, testedFlagsMask);
385+
CONVERT_FLAGS_TO_EFLAGS(di, isi, undefinedFlagsMask);
370386

371387
/* Calculate the size of the instruction we've just decoded. */
372388
di->size = (uint8_t)((ci->code - startCode) & 0xff);
@@ -404,6 +420,8 @@ _DecodeResult decode_internal(_CodeInfo* _ci, int supportOldIntr, _DInst result[
404420
_PrefixState ps;
405421
unsigned int prefixSize;
406422
_CodeInfo ci;
423+
unsigned int features;
424+
unsigned int mfc;
407425

408426
_OffsetType codeOffset = _ci->codeOffset;
409427
const uint8_t* code = _ci->code;
@@ -428,10 +446,15 @@ _DecodeResult decode_internal(_CodeInfo* _ci, int supportOldIntr, _DInst result[
428446

429447
#ifdef DISTORM_LIGHT
430448
supportOldIntr; /* Unreferenced. */
431-
#endif
432449

450+
/*
451+
* Only truncate address if we are using the decompose interface.
452+
* Otherwise, we use the textual interface which needs full addresses for formatting bytes output.
453+
* So distorm_format will truncate later.
454+
*/
433455
if (_ci->features & DF_MAXIMUM_ADDR32) addrMask = 0xffffffff;
434456
else if (_ci->features & DF_MAXIMUM_ADDR16) addrMask = 0xffff;
457+
#endif
435458

436459
/* No entries are used yet. */
437460
*usedInstructionsCount = 0;
@@ -557,13 +580,26 @@ _DecodeResult decode_internal(_CodeInfo* _ci, int supportOldIntr, _DInst result[
557580
pdi->addr = startInstOffset & addrMask;
558581
/* pdi->disp &= addrMask; */
559582

560-
/* Advance to next instruction. */
561-
codeLen -= pdi->size;
562-
codeOffset += pdi->size;
563-
code += pdi->size;
583+
if ((decodeResult == DECRES_INPUTERR) && (ps.decodedPrefixes & INST_PRE_VEX)) {
584+
if (ps.prefixExtType == PET_VEX3BYTES) {
585+
prefixSize -= 2;
586+
codeLen += 2;
587+
} else if (ps.prefixExtType == PET_VEX2BYTES) {
588+
prefixSize -= 1;
589+
codeLen += 1;
590+
}
591+
ps.last = ps.start + prefixSize - 1;
592+
code = ps.last + 1;
593+
codeOffset = startInstOffset + prefixSize;
594+
} else {
595+
/* Advance to next instruction. */
596+
codeLen -= pdi->size;
597+
codeOffset += pdi->size;
598+
code += pdi->size;
564599

565-
/* Instruction's size should include prefixes. */
566-
pdi->size += (uint8_t)prefixSize;
600+
/* Instruction's size should include prefixes. */
601+
pdi->size += (uint8_t)prefixSize;
602+
}
567603

568604
/* Drop all prefixes and the instruction itself, because the instruction wasn't successfully decoded. */
569605
if ((decodeResult == DECRES_INPUTERR) && (~_ci->features & DF_RETURN_FC_ONLY)) {
@@ -599,14 +635,16 @@ _DecodeResult decode_internal(_CodeInfo* _ci, int supportOldIntr, _DInst result[
599635
_ci->nextOffset = codeOffset;
600636

601637
/* Check whether we need to stop on any flow control instruction. */
602-
if ((decodeResult == DECRES_SUCCESS) && (_ci->features & DF_STOP_ON_FLOW_CONTROL)) {
603-
if (((_ci->features & DF_STOP_ON_CALL) && (META_GET_FC(pdi->meta) == FC_CALL)) ||
604-
((_ci->features & DF_STOP_ON_RET) && (META_GET_FC(pdi->meta) == FC_RET)) ||
605-
((_ci->features & DF_STOP_ON_SYS) && (META_GET_FC(pdi->meta) == FC_SYS)) ||
606-
((_ci->features & DF_STOP_ON_UNC_BRANCH) && (META_GET_FC(pdi->meta) == FC_UNC_BRANCH)) ||
607-
((_ci->features & DF_STOP_ON_CND_BRANCH) && (META_GET_FC(pdi->meta) == FC_CND_BRANCH)) ||
608-
((_ci->features & DF_STOP_ON_INT) && (META_GET_FC(pdi->meta) == FC_INT)) ||
609-
((_ci->features & DF_STOP_ON_CMOV) && (META_GET_FC(pdi->meta) == FC_CMOV)))
638+
features = _ci->features;
639+
mfc = META_GET_FC(pdi->meta);
640+
if ((decodeResult == DECRES_SUCCESS) && (features & DF_STOP_ON_FLOW_CONTROL)) {
641+
if (((features & DF_STOP_ON_CALL) && (mfc == FC_CALL)) ||
642+
((features & DF_STOP_ON_RET) && (mfc == FC_RET)) ||
643+
((features & DF_STOP_ON_SYS) && (mfc == FC_SYS)) ||
644+
((features & DF_STOP_ON_UNC_BRANCH) && (mfc == FC_UNC_BRANCH)) ||
645+
((features & DF_STOP_ON_CND_BRANCH) && (mfc == FC_CND_BRANCH)) ||
646+
((features & DF_STOP_ON_INT) && (mfc == FC_INT)) ||
647+
((features & DF_STOP_ON_CMOV) && (mfc == FC_CMOV)))
610648
return DECRES_SUCCESS;
611649
}
612650
}

0 commit comments

Comments
 (0)