NAME
AED_x86_serialize —
aed x86 serializer functions
SYNOPSIS
/* -laed */
#include <aed/x86.h>
int
AED_x86_serialize(const
AED_x86_instruction *inst, char *buf,
size_t buflen, uint32_t
flags);
DESCRIPTION
The aed x86 serializer provides functions used to serialize decoded instructions targeting the x86 instruction set architecture.
The
AED_x86_serialize()
function serializes the decoded instruction inst by
writing at most buflen number of bytes to
buf. The flags may be any
combination of the following:
- AED_X86_FORMAT_INTEL
- Serialize using the Intel® syntax. (default)
- AED_X86_FORMAT_SDM
- Serialize using the Intel® Software Development Manual (SDM) syntax.
Its return value is interpreted as follows:
- > 0
- Instruction successfully serialized. Returns the number of written bytes including the NUL-terminator.
- < 0
- The buf is too small.
The required buflen can be determined by
passing NULL as buf and 0 as
buflen in which the return value reflects the required
buffer capacity including the NUL-terminator.
EXAMPLES
#include <aed/x86.h>
int
main(void)
{
AED_x86_decoder_init();
const uint8_t raw[] = { 0x90, 0x00, 0x00 };
const uint8_t *buf = raw;
size_t buflen = sizeof(raw);
while (buflen > 0) {
AED_x86_instruction inst;
int error = AED_x86_decoder_decode(buf, buflen, &inst, 1, 0, 0);
if (error)
errx(1, "%s", AED_x86_decoder_get_error(error));
char serialized[128];
if (AED_x86_serialize(&inst, serialized, sizeof(serialized), 0) > 0)
printf("%s\n", serialized);
uint8_t len = AED_x86_instruction_get_length(&inst);
buf += len;
buflen -= len;
}
return 0;
}
SEE ALSO
AUTHORS
Anton Lindqvist <anton@basename.se>