decode: Return partial error on incomplete opcode

This commit is contained in:
Alexis Engelke
2020-06-14 14:01:39 +02:00
parent 8716bd1991
commit 545ec30ad0
4 changed files with 23 additions and 10 deletions

View File

@@ -416,7 +416,7 @@ fd_decode(const uint8_t* buffer, size_t len_sz, int mode_int, uintptr_t address,
}
if (UNLIKELY(kind != ENTRY_INSTR))
return FD_ERR_UD;
return kind == 0 ? FD_ERR_UD : FD_ERR_PARTIAL;
struct InstrDesc* desc = (struct InstrDesc*) table;

View File

@@ -2,3 +2,5 @@ decode32 e900000000 [JMP off4:eip+0x0]
decode32 66e90100 [JMP off2:ip+0x1]
decode64 e900000000 [JMP off8:rip+0x0]
decode64 66e900000000 [JMP off8:rip+0x0]
decode 66e9000000 PARTIAL
decode 66e9 PARTIAL

View File

@@ -49,6 +49,7 @@ main(int argc, char** argv)
struct timespec time_end;
FdInstr instr;
int retval = 0;
__asm__ volatile("" : : : "memory");
clock_gettime(CLOCK_MONOTONIC, &time_start);
@@ -58,18 +59,29 @@ main(int argc, char** argv)
while (current_off != length)
{
size_t remaining = length - current_off;
int retval = fd_decode(code + current_off, remaining, mode, 0, &instr);
retval = fd_decode(code + current_off, remaining, mode, 0, &instr);
if (retval < 0)
goto fail;
break;
current_off += retval;
}
}
clock_gettime(CLOCK_MONOTONIC, &time_end);
__asm__ volatile("" : : : "memory");
if (retval >= 0)
{
char format_buffer[128];
fd_format(&instr, format_buffer, sizeof(format_buffer));
printf("%s\n", format_buffer);
}
else if (retval == FD_ERR_UD)
{
printf("UD\n");
}
else if (retval == FD_ERR_PARTIAL)
{
printf("PARTIAL\n");
}
if (repetitions > 1)
{
@@ -80,8 +92,4 @@ main(int argc, char** argv)
}
return 0;
fail:
puts("Decoding failed.");
return 1;
}

View File

@@ -14,3 +14,6 @@ decode f266f3660f10c1 [SSE_MOVSS reg4:r0 reg4:r1]
decode64 4890 [NOP]
decode64 4990 [XCHG reg8:r8 reg8:r0]
decode64 6690 [NOP]
decode 66 PARTIAL
decode 0f PARTIAL
decode 80 PARTIAL