Skip to content

Instantly share code, notes, and snippets.

@sl4v
Created December 14, 2017 00:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sl4v/fcbd03efcc712207e99d2ab1900c6a63 to your computer and use it in GitHub Desktop.
Save sl4v/fcbd03efcc712207e99d2ab1900c6a63 to your computer and use it in GitHub Desktop.
int calc_damaged_instructions(uint8_t *data, size_t len_erased) {
size_t max_len = 50;
size_t decoded_len = 0;
// Initialize decoder context.
ZydisDecoder decoder;
ZydisDecoderInit(
&decoder,
ZYDIS_MACHINE_MODE_LONG_64,
ZYDIS_ADDRESS_WIDTH_64);
ZydisFormatter formatter;
ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL);
uint64_t instructionPointer = 0x007FFFFFFF400000;
uint8_t* readPointer = data;
ZydisDecodedInstruction instruction;
while (ZYDIS_SUCCESS(ZydisDecoderDecodeBuffer(
&decoder, readPointer, max_len, instructionPointer, &instruction)))
{
char buffer[256];
ZydisFormatterFormatInstruction(
&formatter, &instruction, buffer, sizeof(buffer));
puts(buffer);
readPointer += instruction.length;
max_len -= instruction.length;
instructionPointer += instruction.length;
decoded_len += instruction.length;
if (decoded_len >= len_erased) {
break;
}
}
return decoded_len;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment