int
main(
int
argc,char
*
argv[])
{
uint8_t dump[]
=
{
0x55
,
0x8B
,
0xEC
,
0x51
,
0x8B
,
0x45
,
0x08
,
0x50
,
0xE8
,
0xC6
,
0x05
,
0xFE
,
0xFF
,
0x83
,
0xC4
,
0x04
,
0x85
,
0xC0
,
0x74
,
0x09
,
0xC7
,
0x45
,
0xFC
,
0x00
,
0x00
,
0x00
,
0x00
,
0xEB
,
0x07
,
0xC7
,
0x45
,
0xFC
,
0xFF
,
0xFF
,
0xFF
,
0xFF
,
0x8B
,
0x45
,
0xFC
,
0x8B
,
0xE5
,
0x5D
,
0xC3
};
/
/
Initialize decoder context
ZydisDecoder decoder;
ZydisDecoderInit(&decoder, ZYDIS_MACHINE_MODE_LONG_COMPAT_32, ZYDIS_ADDRESS_WIDTH_32);
/
/
Initialize formatter. Only required when you actually plan to do instruction
/
/
formatting (
"disassembling"
), like we do here
ZydisFormatter formatter;
ZydisFormatterInit(&formatter, ZYDIS_FORMATTER_STYLE_INTEL);
ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_SEGMENT, ZYAN_TRUE);
ZydisFormatterSetProperty(&formatter, ZYDIS_FORMATTER_PROP_FORCE_SIZE, ZYAN_TRUE);
/
/
Loop over the instructions
in
our
buffer
.
/
/
The runtime
-
address (instruction pointer)
is
chosen arbitrary here
in
order to better
/
/
visualize relative addressing
ZyanU32 runtime_address
=
0x00401000
;
ZyanUSize offset
=
0
;
const ZyanUSize length
=
sizeof(dump);
ZydisDecodedInstruction instruction;
while
(ZYAN_SUCCESS(ZydisDecoderDecodeBuffer(&decoder, dump
+
offset, length
-
offset,
&instruction)))
{
/
/
Print
current instruction pointer.
printf(
"%08"
PRIX32
">> "
, runtime_address);
/
/
Format
&
print
the binary instruction structure to human readable
format
char
buffer
[
256
];
ZydisFormatterFormatInstruction(&formatter, &instruction,
buffer
, sizeof(
buffer
),
runtime_address);
puts(
buffer
);
offset
+
=
instruction.length;
runtime_address
+
=
instruction.length;
}
}