From c7735c0ddc30c0d5de1890e17e915f4f947132cb Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Fri, 16 Aug 2024 06:26:37 +0300 Subject: [PATCH] begin working on prefixes --- include/rtdisasm.h | 2 ++ src/rtdisasm.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/include/rtdisasm.h b/include/rtdisasm.h index 6ca34b3..56dfe0b 100644 --- a/include/rtdisasm.h +++ b/include/rtdisasm.h @@ -1,4 +1,6 @@ #ifndef __RTDISASM_H #define __RTDISASM_H +#include + #endif \ No newline at end of file diff --git a/src/rtdisasm.c b/src/rtdisasm.c index 1fd96c4..e9f5e91 100644 --- a/src/rtdisasm.c +++ b/src/rtdisasm.c @@ -1 +1,44 @@ -#include "rtdisasm.h" \ No newline at end of file +#include "rtdisasm.h" + +// prefix definitions. must be declared with macro in order +// to be readable later in prefix table + +#define PREFIX_LOCK 0xF0 +#define PREFIX_REPNZ 0xF2 // also BND prefix +#define PREFIX_REPZ 0xF3 + +#define PREFIX_CS_OVERRIDE 0x2E // also branch-not-taken hint +#define PREFIX_SS_OVERRIDE 0x36 +#define PREFIX_DS_OVERRIDE 0x3E // also branch-taken hint +#define PREFIX_ES_OVERRIDE 0x26 +#define PREFIX_FS_OVERRIDE 0x64 +#define PREFIX_GS_OVERRIDE 0x65 + +#define PREFIX_OPERAND_OVERRIDE 0x66 +#define PREFIX_ADDRESS_OVERRIDE 0x67 + +static const uint8_t std_prefixes[] = { + PREFIX_LOCK, + PREFIX_REPNZ, + PREFIX_REPZ, + + PREFIX_CS_OVERRIDE, + PREFIX_SS_OVERRIDE, + PREFIX_DS_OVERRIDE, + PREFIX_ES_OVERRIDE, + PREFIX_FS_OVERRIDE, + PREFIX_GS_OVERRIDE, + + PREFIX_OPERAND_OVERRIDE, + PREFIX_ADDRESS_OVERRIDE +}; + +static const unsigned std_prefixes_len = sizeof(std_prefixes); + +static int is_std_prefix(const uint8_t prefix) +{ + for (unsigned i = 0; i < std_prefixes_len; i++) + if (prefix == std_prefixes[i]) return 1; + + return 0; +} \ No newline at end of file