Skip to content

refactor Emu/Config god objects: add OperatingSystem enum, persist ELF/Mach-O, remove dead fields#167

Merged
sha0coder merged 1 commit intosha0coder:mainfrom
brandonros:refactor
Apr 6, 2026
Merged

refactor Emu/Config god objects: add OperatingSystem enum, persist ELF/Mach-O, remove dead fields#167
sha0coder merged 1 commit intosha0coder:mainfrom
brandonros:refactor

Conversation

@brandonros
Copy link
Copy Markdown
Contributor

Structural cleanup of the two largest structs (Emu, Config, SerializableEmu):

OperatingSystem enum replaces linux/macos bools

  • Add OperatingSystem { Windows, Linux, MacOS } enum to arch/mod.rs
  • Replace emu.linux: bool + emu.macos: bool with emu.os: OperatingSystem
  • Windows is now an explicit variant instead of implicit !linux && !macos
  • Update all 27 conditional sites across instruction_pointer, operands, syscall, svc, int handlers, and tests

Persist ELF/Mach-O structs on Emu (parity with PE)

  • Add elf32: Option<Elf32>, elf64: Option<Elf64>, macho64: Option<Macho64> to Emu, matching the existing pe32/pe64 pattern
  • Loaders now store parsed binary structs instead of dropping them after load
  • Add addr_to_symbol: HashMap<u64, String> to Macho64 struct, populated during dylib loading — replaces the standalone emu.macho_addr_to_symbol

Remove dead fields

  • Remove mnemonic: String — never written, actual mnemonic comes from ins.mnemonic(). Fix emu_context.rs to use instruction.mnemonic() instead
  • Remove aarch64_instruction: Option<Instruction> — was set but never read

Organize structs with section comments

  • Group Emu fields into: Configuration, Memory, Instruction decoding, Core execution, Platform & binary, Threads, API interception, Debugging, Tracing, Resource management
  • Group Config fields into: Binary & arch, Memory layout, Heap behavior, Tracing, Verbosity, Console, Execution limits, API emulation, Threading, Inspection, Dump, Environment constants, Testing
  • Group SerializableEmu to match Emu layout, with a dedicated "Flattened thread context" section for fields extracted at serialize time
  • Add NOTE comments documenting fields intentionally not serialized
  • Simplify SerializableEmu::Default to delegate to From<&Emu>

Nix flake

  • Add flake.nix/flake.lock for reproducible Rust dev shell
  • Per-system target lists (Linux vs macOS)
  • Document nix develop in AGENTS.md

…F/Mach-O, remove dead fields

Structural cleanup of the two largest structs (Emu, Config, SerializableEmu):

**OperatingSystem enum replaces linux/macos bools**
- Add `OperatingSystem { Windows, Linux, MacOS }` enum to arch/mod.rs
- Replace `emu.linux: bool` + `emu.macos: bool` with `emu.os: OperatingSystem`
- Windows is now an explicit variant instead of implicit `!linux && !macos`
- Update all 27 conditional sites across instruction_pointer, operands,
  syscall, svc, int handlers, and tests

**Persist ELF/Mach-O structs on Emu (parity with PE)**
- Add `elf32: Option<Elf32>`, `elf64: Option<Elf64>`, `macho64: Option<Macho64>`
  to Emu, matching the existing pe32/pe64 pattern
- Loaders now store parsed binary structs instead of dropping them after load
- Add `addr_to_symbol: HashMap<u64, String>` to Macho64 struct, populated
  during dylib loading — replaces the standalone `emu.macho_addr_to_symbol`

**Remove dead fields**
- Remove `mnemonic: String` — never written, actual mnemonic comes from
  `ins.mnemonic()`. Fix emu_context.rs to use instruction.mnemonic() instead
- Remove `aarch64_instruction: Option<Instruction>` — was set but never read

**Organize structs with section comments**
- Group Emu fields into: Configuration, Memory, Instruction decoding,
  Core execution, Platform & binary, Threads, API interception,
  Debugging, Tracing, Resource management
- Group Config fields into: Binary & arch, Memory layout, Heap behavior,
  Tracing, Verbosity, Console, Execution limits, API emulation,
  Threading, Inspection, Dump, Environment constants, Testing
- Group SerializableEmu to match Emu layout, with a dedicated
  "Flattened thread context" section for fields extracted at serialize time
- Add NOTE comments documenting fields intentionally not serialized
- Simplify SerializableEmu::Default to delegate to From<&Emu>

**Nix flake**
- Add flake.nix/flake.lock for reproducible Rust dev shell
- Per-system target lists (Linux vs macOS)
- Document nix develop in AGENTS.md

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@sha0coder sha0coder merged commit cca18be into sha0coder:main Apr 6, 2026
0 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants