diff options
| author | NotRexed <therealnothingfn@gmail.com> | 2026-11-20 15:22:16 -0500 |
|---|---|---|
| committer | NotRexed <therealnothingfn@gmail.com> | 2026-11-20 15:22:16 -0500 |
| commit | db0dc8bd5ebce6e2bc27d47085f7f104eb3037d3 (patch) | |
| tree | 4fb3edca45f8b4dd3368c6ac2a0e4fdc8ed7065c /runtime/src/pe_loader.h | |
Initial commit: Leonida, build-it-yourself PC port groundwork
Shader pipeline (carve, FSSM unpack, gfx1013 disassembly, RDNA2 to SPIR-V),
asset export via rpf9-explorer's Core (submodule), PE loader and shim
skeleton, and make_game.py, which builds from the user's own copy of the game.
No game data, keys or executables are included.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'runtime/src/pe_loader.h')
| -rw-r--r-- | runtime/src/pe_loader.h | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/runtime/src/pe_loader.h b/runtime/src/pe_loader.h new file mode 100644 index 000000000..5d3218f81 --- /dev/null +++ b/runtime/src/pe_loader.h | |||
| @@ -0,0 +1,57 @@ | |||
| 1 | // Native PE mapper for Xbox Series (x86-64) images. | ||
| 2 | // Maps an image, applies relocations and binds every import through the shim registry. | ||
| 3 | // It never runs code from the image: DllMain, TLS callbacks and the entry point are left to the caller. | ||
| 4 | #pragma once | ||
| 5 | #include <cstdint> | ||
| 6 | #include <filesystem> | ||
| 7 | #include <map> | ||
| 8 | #include <string> | ||
| 9 | #include <vector> | ||
| 10 | |||
| 11 | namespace rt { | ||
| 12 | |||
| 13 | enum class Binding { Shim, Host, Module, Unimplemented }; | ||
| 14 | |||
| 15 | struct ImportRecord { | ||
| 16 | std::string dll; | ||
| 17 | std::string name; // "#123" for ordinals | ||
| 18 | Binding binding; | ||
| 19 | }; | ||
| 20 | |||
| 21 | struct Module { | ||
| 22 | std::string name; | ||
| 23 | std::filesystem::path path; | ||
| 24 | uint8_t* base = nullptr; | ||
| 25 | uint64_t preferred_base = 0; | ||
| 26 | uint32_t size = 0; | ||
| 27 | uint32_t entry_rva = 0; | ||
| 28 | bool relocated = false; | ||
| 29 | std::vector<ImportRecord> imports; | ||
| 30 | std::map<std::string, void*> exports; // by name, plus "#ordinal" | ||
| 31 | }; | ||
| 32 | |||
| 33 | class Loader { | ||
| 34 | public: | ||
| 35 | explicit Loader(std::filesystem::path game_dir) : game_dir_(std::move(game_dir)) {} | ||
| 36 | ~Loader(); | ||
| 37 | |||
| 38 | // Loads an image and (recursively) the bundled modules it imports. Throws std::runtime_error on failure. | ||
| 39 | Module& load(const std::filesystem::path& image); | ||
| 40 | |||
| 41 | const std::vector<Module*>& modules() const { return order_; } | ||
| 42 | |||
| 43 | private: | ||
| 44 | Module& map_image(const std::filesystem::path& path); | ||
| 45 | void bind_imports(Module& m); | ||
| 46 | void* resolve(Module& m, const std::string& dll, const std::string& name, uint16_t ordinal, bool by_ordinal); | ||
| 47 | void parse_exports(Module& m); | ||
| 48 | void protect_sections(Module& m); | ||
| 49 | |||
| 50 | std::filesystem::path game_dir_; | ||
| 51 | std::map<std::string, Module*> by_name_; // lower-case file name | ||
| 52 | std::vector<Module*> order_; | ||
| 53 | }; | ||
| 54 | |||
| 55 | std::string lower(std::string s); | ||
| 56 | |||
| 57 | } // namespace rt | ||