Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 15 additions & 40 deletions smda/intel/IntelInstructionEscaper.py
Original file line number Diff line number Diff line change
Expand Up @@ -2014,6 +2014,8 @@ class IntelInstructionEscaper:
"tr7",
]

_PREFIXES = {"26", "2e", "36", "3e", "64", "65", "66", "67", "f2", "f3"}

@staticmethod
def escapeMnemonic(mnemonic):
mnemonic = mnemonic.split(" ")[-1]
Expand Down Expand Up @@ -2151,29 +2153,21 @@ def escapeOperands(ins, offsets_only=False):
)
return ", ".join(escaped_fields)

@classmethod
def _getPrefixLen(cls, ins_bytes):
prefixes = cls._PREFIXES
return next(
(i for i in range(0, len(ins_bytes), 2) if ins_bytes[i : i + 2] not in prefixes),
len(ins_bytes),
)

@staticmethod
def escapeToOpcodeOnly(ins):
escaped_sequence = ""
ins_bytes = ins.bytes
cleaned = ""
is_cleaning = True
for target_byte in [ins_bytes[i : i + 2] for i in range(0, len(ins_bytes), 2)]:
if is_cleaning and target_byte in [
"26",
"2e",
"36",
"3e",
"64",
"65",
"66",
"67",
"f2",
"f3",
]:
escaped_sequence += target_byte
else:
is_cleaning = False
cleaned += target_byte
prefix_len = IntelInstructionEscaper._getPrefixLen(ins_bytes)

escaped_sequence = ins_bytes[:prefix_len]
cleaned = ins_bytes[prefix_len:]
cap_ins = ins.getDetailed()
opcode_length = 0
if cap_ins.rex:
Expand Down Expand Up @@ -2332,23 +2326,4 @@ def escapeBinaryValue(ins, escaped_sequence, value):
@staticmethod
def getByteWithoutPrefixes(ins):
ins_bytes = ins.bytes
cleaned = ""
is_cleaning = True
for prefix_byte in [ins_bytes[i : i + 2] for i in range(0, len(ins_bytes), 2)]:
if is_cleaning and prefix_byte in [
"26",
"2e",
"36",
"3e",
"64",
"65",
"66",
"67",
"f2",
"f3",
]:
continue
else:
is_cleaning = False
cleaned += prefix_byte
return cleaned
return ins_bytes[IntelInstructionEscaper._getPrefixLen(ins_bytes) :]
Loading