From 2a1eaa4baafc1487a3131b022f28149df9505e73 Mon Sep 17 00:00:00 2001 From: DC3-TSD <12175126+DC3-DCCI@users.noreply.github.com> Date: Tue, 21 Feb 2023 13:21:24 -0500 Subject: [PATCH] General updates and bugfixes --- CHANGELOG.md | 5 +++++ rugosa/emulation/variables.py | 5 +++-- rugosa/emulation/x86_64/fpu_opcodes.py | 10 +++++----- rugosa/ghidra_plugin/install.py | 17 ++++++++--------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d5d0af..e1f8a84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ All notable changes to this project will be documented in this file. +## [Unreleased] +- Fixed emulation of floating point opcodes. +- Fixed bug in Ghidra plugin setup handling. + + ## [0.7.0] - 2023-01-26 - Add `movsq` opcode support (@ddash-ct) - Added utility functions for analyzing strings: diff --git a/rugosa/emulation/variables.py b/rugosa/emulation/variables.py index 978f911..e2bf8a9 100644 --- a/rugosa/emulation/variables.py +++ b/rugosa/emulation/variables.py @@ -48,7 +48,7 @@ def __getitem__(self, addr_or_name) -> "Variable": elif isinstance(addr_or_name, int): return self._variables[addr_or_name] else: - raise ValueError("Invalid variable name or address: {!r}".format(addr_or_name)) + raise KeyError(f"Invalid variable name or address: {addr_or_name!r}") def __len__(self): return len(self._variables) @@ -91,7 +91,8 @@ def __contains__(self, addr_or_name) -> bool: addr = addr_or_name return addr in self._variables else: - raise ValueError("Invalid variable name or address: {!r}".format(addr_or_name)) + # We could have floats or None checked if dealing with a FPU register. + return False def __iter__(self) -> Iterable["Variable"]: return iter(self._variables.values()) diff --git a/rugosa/emulation/x86_64/fpu_opcodes.py b/rugosa/emulation/x86_64/fpu_opcodes.py index c3972f1..13c60a9 100644 --- a/rugosa/emulation/x86_64/fpu_opcodes.py +++ b/rugosa/emulation/x86_64/fpu_opcodes.py @@ -244,7 +244,7 @@ def FLD(cpu_context: ProcessorContext, instruction: Instruction): mnem = instruction.mnem operands = instruction.operands - value = orig_value = operands[0].value if operands else None + value = orig_value = operands[-1].value if operands else None if mnem == "fld": value = utils.int_to_float(value) elif mnem == "fild": @@ -300,8 +300,8 @@ def FST(cpu_context: ProcessorContext, instruction: Instruction): value = int(value) else: value = utils.float_to_int(value) - operands[0].value = value - logger.debug("Storing: %f -> %d -> %s", orig_value, value, operands[0].text) + operands[-1].value = value + logger.debug("Storing: %f -> %d -> %s", orig_value, value, operands[-1].text) if mnem.endswith("p"): cpu_context.registers.fpu.pop() @@ -363,8 +363,8 @@ def FXCH(cpu_context: ProcessorContext, instruction: Instruction): st0 = 0.0 if operands: - opvalue = operands[0].value - cpu_context.registers.st0, operands[0].value = opvalue, st0 + opvalue = operands[-1].value + cpu_context.registers.st0, operands[-1].value = opvalue, st0 logger.debug("exchange %f <-> %f", st0, opvalue) else: st1 = cpu_context.registers.st1 diff --git a/rugosa/ghidra_plugin/install.py b/rugosa/ghidra_plugin/install.py index 96e33a7..b81e1a2 100644 --- a/rugosa/ghidra_plugin/install.py +++ b/rugosa/ghidra_plugin/install.py @@ -11,15 +11,14 @@ def setup(launcher): """ Run by pyhidra launcher to install our plugin. """ - if isinstance(launcher, pyhidra.GuiPyhidraLauncher): - source_path = Path(__file__).parent / "java" / "plugin" - details = pyhidra.ExtensionDetails( - name="rugosa", - description="Rugosa Emulator Plugin", - author="Department of Defence Cyber Crime Center (DC3)", - plugin_version=__version__, - ) - launcher.install_plugin(source_path, details) + source_path = Path(__file__).parent / "java" / "plugin" + details = pyhidra.ExtensionDetails( + name="rugosa", + description="Rugosa Emulator Plugin", + author="Department of Defence Cyber Crime Center (DC3)", + plugin_version=__version__, + ) + launcher.install_plugin(source_path, details) def pre_launch():