Skip to content

Commit

Permalink
General updates and bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dc3-tsd committed Feb 27, 2023
1 parent 2b5f0a1 commit 2a1eaa4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 3 additions & 2 deletions rugosa/emulation/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down
10 changes: 5 additions & 5 deletions rugosa/emulation/x86_64/fpu_opcodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions rugosa/ghidra_plugin/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down

0 comments on commit 2a1eaa4

Please sign in to comment.