Skip to main content

Overview

The emulator class is the base interface for all emulator implementations in Sogen. It combines three core interfaces:
  • cpu_interface - CPU register and execution control
  • memory_interface - Memory read/write operations
  • hook_interface - Event hooks for monitoring and control

Class Definition

This abstract base class defines the contract that all emulator implementations must fulfill. Source: emulator.hpp:9

Constructors and Assignment

The emulator class is non-copyable and non-movable:

Pure Virtual Methods

get_name()

Returns the name of the emulator implementation. Returns: String identifier for the emulator (e.g., “unicorn”, “qemu”) Source: emulator.hpp:21

serialize_state()

Serializes the emulator state to a buffer.
utils::buffer_serializer&
required
Buffer to write the serialized state to
bool
required
Whether this is a snapshot (for quick rollback) or full serialization
Source: emulator.hpp:23

deserialize_state()

Deserializes the emulator state from a buffer.
utils::buffer_deserializer&
required
Buffer to read the serialized state from
bool
required
Whether this is a snapshot (for quick rollback) or full deserialization
Source: emulator.hpp:24

Inherited Interfaces

The emulator class inherits methods from three interfaces:

From cpu_interface

  • start(size_t count) - Start CPU execution
  • stop() - Stop CPU execution
  • read_raw_register() - Read CPU register values
  • write_raw_register() - Write CPU register values
  • save_registers() - Save all registers to a buffer
  • restore_registers() - Restore registers from a buffer
  • read_descriptor_table() - Read descriptor table registers (GDTR, IDTR, etc.)
  • has_violation() - Check if a memory violation occurred
See the CPU interface documentation for details.

From memory_interface

  • read_memory() - Read memory at an address
  • try_read_memory() - Attempt to read memory without throwing
  • write_memory() - Write memory at an address
  • try_write_memory() - Attempt to write memory without throwing
  • move_memory() - Move memory from one location to another
See the memory interface documentation for details.

From hook_interface

  • hook_memory_execution() - Hook memory execution
  • hook_memory_read() - Hook memory read operations
  • hook_memory_write() - Hook memory write operations
  • hook_instruction() - Hook specific instruction types
  • hook_interrupt() - Hook interrupts
  • hook_memory_violation() - Hook memory access violations
  • hook_basic_block() - Hook basic block execution
  • delete_hook() - Remove a hook
See the hook interface documentation for details.

Usage Example

Implementation Notes

  • Implementations must provide thread-safe state serialization
  • The is_snapshot parameter allows optimizations for temporary state saves
  • Snapshots may exclude persistent state like module mappings
  • Full serialization should capture all state needed to resume execution
  • The emulator name should be a unique, stable identifier for the backend
See also: