Merge branch 'master' into develop

This commit is contained in:
flobernd 2017-08-15 14:33:07 +02:00
commit f89398877d
4 changed files with 41 additions and 19 deletions

View File

@ -56,7 +56,7 @@ int main()
ZydisDecodedInstruction instruction;
char buffer[256];
while (ZYDIS_SUCCESS(
ZydisDecoderDecodeBuffer(decoder, data, length, instructionPointer, &instruction)))
ZydisDecoderDecodeBuffer(&decoder, &data[0], length, instructionPointer, &instruction)))
{
data += instruction.length;
length -= instruction.length;

View File

@ -156,7 +156,7 @@ void testPerformance(const char* buffer, size_t length, ZydisDecodeGranularity g
{
count += processBuffer(buffer, length, granularity, format);
}
printf("Granularity %d, Formatting %d, Instructions: ~%6.2fM, Time: %8.2f msec\n",
printf("Granularity %d, Formatting %d, Instructions: %6.2fM, Time: %8.2f msec\n",
granularity, format, (double)count / 1000000, GetCounter());
}
@ -171,9 +171,9 @@ void generateTestData(FILE* file, uint8_t encoding)
}
uint8_t last = 0;
double size = 0;
uint32_t count = 0;
ZydisDecodedInstruction instruction;
while (size < 1024 * 1024)
while (count < 100000)
{
uint8_t data[ZYDIS_MAX_INSTRUCTION_LENGTH];
for (int i = 0; i < ZYDIS_MAX_INSTRUCTION_LENGTH; ++i)
@ -235,13 +235,13 @@ void generateTestData(FILE* file, uint8_t encoding)
if (b)
{
fwrite(&instruction.data[0], 1, instruction.length, file);
size += instruction.length;
++count;
double p = (size / (1024 * 1024) * 100);
if (last < (uint8_t)p)
uint8_t p = (uint8_t)((double)count / 100000 * 100);
if (last < p)
{
last = (uint8_t)p;
printf("%3.0f%%\n", p);
last = p;
printf("%3.0d%%\n", p);
}
}

View File

@ -920,9 +920,21 @@ static uint8_t ZydisCalcRegisterId(ZydisDecoderContext* context,
{
ZYDIS_ASSERT(instruction->raw.modrm.isDecoded);
uint8_t value = instruction->raw.modrm.reg;
if (registerClass != ZYDIS_REGCLASS_MASK)
switch (registerClass)
{
value |= (context->cache.R << 3);
case ZYDIS_REGCLASS_GPR8:
case ZYDIS_REGCLASS_GPR16:
case ZYDIS_REGCLASS_GPR32:
case ZYDIS_REGCLASS_GPR64:
case ZYDIS_REGCLASS_XMM:
case ZYDIS_REGCLASS_YMM:
case ZYDIS_REGCLASS_ZMM:
case ZYDIS_REGCLASS_CONTROL:
case ZYDIS_REGCLASS_DEBUG:
value |= (context->cache.R << 3);
break;
default:
break;
}
// R' only exists for EVEX and MVEX. No encoding check needed
switch (registerClass)
@ -954,9 +966,21 @@ static uint8_t ZydisCalcRegisterId(ZydisDecoderContext* context,
{
ZYDIS_ASSERT(instruction->raw.modrm.isDecoded);
uint8_t value = instruction->raw.modrm.rm;
if (registerClass != ZYDIS_REGCLASS_MASK)
switch (registerClass)
{
value |= (context->cache.B << 3);
case ZYDIS_REGCLASS_GPR8:
case ZYDIS_REGCLASS_GPR16:
case ZYDIS_REGCLASS_GPR32:
case ZYDIS_REGCLASS_GPR64:
case ZYDIS_REGCLASS_XMM:
case ZYDIS_REGCLASS_YMM:
case ZYDIS_REGCLASS_ZMM:
case ZYDIS_REGCLASS_CONTROL:
case ZYDIS_REGCLASS_DEBUG:
value |= (context->cache.B << 3);
break;
default:
break;
}
// We have to check the instruction-encoding, because the extension by X is only valid
// for EVEX and MVEX instructions

View File

@ -880,11 +880,6 @@ static ZydisStatus ZydisFormatterFormatInstrIntel(const ZydisFormatter* formatte
ZYDIS_CHECK(formatter->funcPrintMnemonic(formatter, buffer, bufEnd - *buffer, instruction));
char* bufRestore = *buffer;
if (instruction->operandCount > 0)
{
ZYDIS_CHECK(ZydisStringBufferAppend(buffer, bufEnd - *buffer, 0, " "));
}
for (uint8_t i = 0; i < instruction->operandCount; ++i)
{
if (instruction->operands[i].visibility == ZYDIS_OPERAND_VISIBILITY_HIDDEN)
@ -892,7 +887,10 @@ static ZydisStatus ZydisFormatterFormatInstrIntel(const ZydisFormatter* formatte
break;
}
if (i != 0)
if (i == 0)
{
ZYDIS_CHECK(ZydisStringBufferAppend(buffer, bufEnd - *buffer, 0, " "));
} else
{
bufRestore = *buffer;
ZYDIS_CHECK(ZydisStringBufferAppend(buffer, bufEnd - *buffer, 0, ", "));