1
0
mirror of https://github.com/bitdefender/bddisasm.git synced 2024-11-14 03:19:24 +00:00

Fetch the instruction bytes inside the Instrux when first entering NdDecode, and then use that buffer for further decoding.

This commit is contained in:
Andrei Vlad LUTAS 2020-11-12 10:57:16 +02:00
parent 460e544652
commit 67da1892d4

View File

@ -3978,10 +3978,16 @@ NdDecodeWithContext(
Instrux->VendMode = (uint8_t)Context->VendMode;
Instrux->FeatMode = (uint8_t)Context->FeatMode;
// Fetch prefixes. We peek at the first byte, if that's not a prefix, there's no need to call the main decoder.
if (ND_PREF_CODE_NONE != gPrefixesMap[Code[0]])
// Copy the instruction bytes.
for (opIndex = 0; opIndex < ((Size < ND_MAX_INSTRUCTION_LENGTH) ? Size : ND_MAX_INSTRUCTION_LENGTH); opIndex++)
{
status = NdFetchPrefixes(Instrux, Code, 0, Size);
Instrux->InstructionBytes[opIndex] = Code[opIndex];
}
// Fetch prefixes. We peek at the first byte, if that's not a prefix, there's no need to call the main decoder.
if (ND_PREF_CODE_NONE != gPrefixesMap[Instrux->InstructionBytes[0]])
{
status = NdFetchPrefixes(Instrux, Instrux->InstructionBytes, 0, Size);
if (!ND_SUCCESS(status))
{
return status;
@ -3996,7 +4002,7 @@ NdDecodeWithContext(
}
// Start iterating the tables, in order to extract the instruction entry.
status = NdFindInstruction(Instrux, Code, Instrux->Length, Size, &pIns);
status = NdFindInstruction(Instrux, Instrux->InstructionBytes, Instrux->Length, Size, &pIns);
if (!ND_SUCCESS(status))
{
return status;
@ -4086,7 +4092,8 @@ NdDecodeWithContext(
// And now decode each operand.
for (opIndex = 0; opIndex < Instrux->OperandsCount; ++opIndex)
{
status = NdParseOperand(Instrux, Code, Instrux->Length, Size, opIndex, pIns->Operands[opIndex]);
status = NdParseOperand(Instrux, Instrux->InstructionBytes, Instrux->Length, Size,
opIndex, pIns->Operands[opIndex]);
if (!ND_SUCCESS(status))
{
return status;
@ -4124,12 +4131,6 @@ NdDecodeWithContext(
return status;
}
// Copy the instruction bytes.
for (opIndex = 0; opIndex < Instrux->Length; opIndex++)
{
Instrux->InstructionBytes[opIndex] = Code[opIndex];
}
// All done! Instruction successfully decoded!
return ND_STATUS_SUCCESS;
}