From a681a53ff38f6f6f4a4702c10391f67b06122145 Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Thu, 1 Aug 2024 02:37:08 +0300 Subject: [PATCH] now I can definitely tell if instruction has ModRM byte or no --- genc.py | 31 +++++++++++++++++++++++-------- plan.txt | 1 + 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/genc.py b/genc.py index d9dcdf6..51f9ca7 100644 --- a/genc.py +++ b/genc.py @@ -25,14 +25,29 @@ class Instruction: value = Instruction.VALUE_REGEX.search(opc) opreg = Instruction.OPREG_REGEX.search(opc) - print(ins.find("mnem").text) - if rex: print("rex\t", rex.group(1)) - print(bytes) - if digit: print("digit\t", digit.group(1)) - if modrm: print("modrm\t", modrm.group(0)) - if imm: print("imm\t", imm.group(1)) - if value: print("value\t", value.group(1)) - if opreg: print("opreg\t", opreg.group(1)) + self.mnemonic = ins.find("mnem").text + self.bytes = bytes + + self.rex = None + self.digit = None + self.modrm = False + self.imm = None + self.value = None + self.opreg = None + + if rex: self.rex = rex.group(1) + if digit: self.digit = int(digit.group(1)) + if modrm: self.modrm = True + if imm: self.imm = imm.group(1) + if value: self.value = value.group(1) + if opreg: self.opreg = opreg.group(1) + + self.has_modrm = self.modrm or self.digit is not None + + print(self) + + def __str__(self): + return f"{self.mnemonic} rex {self.rex} bytes {self.bytes} has_modrm {self.has_modrm} digit {self.digit} modrm {self.modrm} imm {self.imm} value {self.value} opreg {self.opreg}" class InstructionGroup: def __init__(self, common): diff --git a/plan.txt b/plan.txt index f37f7c0..631a68d 100644 --- a/plan.txt +++ b/plan.txt @@ -1,4 +1,5 @@ The Intel OpCode Syntax can tell if there is ModRM byte, as well as if registers are encoded directly in opcode (rb for example), and can tell size of immediate (ib iw id for example). The /digit can also indiciate presense of ModRM. The size of displacement is also dictated by cw/cd. +ModRM also can tell if there is SIB byte or no. VEX prefixes. 0xC5 for 3-byte VEX and 0xC4 for 2-byte prefix \ No newline at end of file