From 60ded0d85bc25b007c7ac4c94e6e177d1fdfda68 Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Mon, 19 Aug 2024 07:11:45 +0300 Subject: [PATCH] encorporate rt_target - unique identifier for instructions we will be looking for --- genc.py | 15 ++++++++++++++- include/rtdisasm_table.h | 12 ++++++++++++ src/rtdisasm_test_data.s | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/genc.py b/genc.py index 1a6deb3..b5cab11 100644 --- a/genc.py +++ b/genc.py @@ -19,6 +19,16 @@ class InstructionType(Enum): elif self == InstructionType.EVEX: return 2 class Instruction: + RT_TARGETS = { + "90" : 1, + "C3" : 2, + "C2 iw" : 3, + "CC" : 4, + "CD ib" : 5, + "0F 34" : 6, + "0F 05" : 7, + } + def __init__(self, ins): self._opc = ins.find("opc").text self.x32m = ins.attrib["x32m"] @@ -48,6 +58,9 @@ class Instruction: def has_opreg(self): return False + def encode_rt_target(self): + return Instruction.RT_TARGETS.get(self._opc, 0) + def __str__(self): return f"<{self.get_type()}> {self.mnemonic} bytes {self.bytes} rex {self.has_rex()} digit {self.has_digit()} modrm {self.has_modrm()} imm {self.has_imm()} value {self.has_value()} opreg {self.has_opreg()}" @@ -283,7 +296,7 @@ def generate_table(groups): int(i.w) ), end = '') - print(" .opcode_len = {}, .opcode = {{ {} }} }},".format(opcode_len, opcode)) + print(" .rt_target = {}, .opcode_len = {}, .opcode = {{ {} }} }},".format(i.encode_rt_target(), opcode_len, opcode)) table_len += 1 # footer print("}};\n\nconst unsigned rtdisasm_table_len = {};".format(table_len)) diff --git a/include/rtdisasm_table.h b/include/rtdisasm_table.h index c454645..ba15802 100644 --- a/include/rtdisasm_table.h +++ b/include/rtdisasm_table.h @@ -24,6 +24,16 @@ #define VALUE_O 4 #define VALUE_T 5 +// these are target instructions that rtdisasm will look for +#define RT_TARGET_NO_MEANING 0 +#define RT_TARGET_NOP 1 // 90 +#define RT_TARGET_RET 2 // C3 +#define RT_TARGET_RET_N 3 // C2 iw +#define RT_TARGET_INT3 4 // CC +#define RT_TARGET_INT_N 5 // CD ib +#define RT_TARGET_SYSENTER 6 // 0F 34 +#define RT_TARGET_SYSCALL 7 // 0F 05 + #define MAX_OPCODE_LEN 4 typedef struct { @@ -61,6 +71,8 @@ typedef struct { uint16_t imm : 3; } evex; }; + + uint16_t rt_target; uint16_t opcode_len; uint8_t opcode[MAX_OPCODE_LEN]; diff --git a/src/rtdisasm_test_data.s b/src/rtdisasm_test_data.s index b535e40..46d8fd2 100644 --- a/src/rtdisasm_test_data.s +++ b/src/rtdisasm_test_data.s @@ -3,7 +3,7 @@ .globl test_1_end test_1: - push %rbp + push (%rbp) nop # target that rtdisasm must reach test_1_end: