From 9c6c3dbaa60f922947bd9e5477d19e841323ae3b Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 13 Mar 2025 10:17:10 -0400 Subject: [PATCH 1/3] Search for and print out register save/load locations Signed-off-by: Isaac Marovitz --- XenonAnalyse/main.cpp | 63 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 59 insertions(+), 4 deletions(-) diff --git a/XenonAnalyse/main.cpp b/XenonAnalyse/main.cpp index d08371e..fc424fd 100644 --- a/XenonAnalyse/main.cpp +++ b/XenonAnalyse/main.cpp @@ -1,11 +1,11 @@ +#include "fmt/xchar.h" +#include "function.h" +#include #include -#include -#include #include +#include #include #include -#include -#include "function.h" #define SWITCH_ABSOLUTE 0 #define SWITCH_COMPUTED 1 @@ -21,6 +21,59 @@ struct SwitchTable uint32_t type{}; }; +static const std::vector RESTGPRLR_14 = { 0xe9, 0xc1, 0xff, 0x68 }; +static const std::vector SAVEGPRLR_14 = { 0xf9, 0xc1, 0xff, 0x68 }; +static const std::vector RESTFPR_14 = { 0xc9, 0xcc, 0xff, 0x70 }; +static const std::vector SAVEFPR_14 = { 0xd9, 0xcc, 0xff, 0x70 }; +static const std::vector RESTVMX_14 = { 0x39, 0x60, 0xfe, 0xe0, 0x7d, 0xcb, 0x60, 0xce }; +static const std::vector SAVEVMX_14 = { 0x39, 0x60, 0xfe, 0xe0, 0x7d, 0xcb, 0x61, 0xce }; +static const std::vector RESTVMX_64 = { 0x39, 0x60, 0xfc, 0x00, 0x10, 0x0b, 0x60, 0xcb }; +static const std::vector SAVEVMX_64 = { 0x39, 0x60, 0xfc, 0x00, 0x10, 0x0b, 0x61, 0xcb }; + +uint32_t BytePatternSearch(uint8_t* data, uint32_t size, uint32_t baseAddress, const std::vector& pattern) +{ + auto result = std::search(data, data + size, pattern.begin(), pattern.end()); + if (result != data + size) { + return baseAddress + std::distance(data, result); + } + + return UINT32_MAX; +} + +void RegisterFunctionsSearch(Image& image) +{ + uint32_t baseAddress = UINT32_MAX; + + for (const auto& section : image.sections) { + if (section.name == ".text") { + baseAddress = section.base; + + if (baseAddress == UINT32_MAX) { + fmt::println("Could not find \".text\" section."); + return; + } + + uint32_t restgprlr_14 = BytePatternSearch(section.data, section.size, baseAddress, RESTGPRLR_14); + uint32_t savegprlr_14 = BytePatternSearch(section.data, section.size, baseAddress, SAVEGPRLR_14); + uint32_t restfpr_14 = BytePatternSearch(section.data, section.size, baseAddress, RESTFPR_14); + uint32_t savefpr_14 = BytePatternSearch(section.data, section.size, baseAddress, SAVEFPR_14); + uint32_t restvmx_14 = BytePatternSearch(section.data, section.size, baseAddress, RESTVMX_14); + uint32_t savevmx_14 = BytePatternSearch(section.data, section.size, baseAddress, SAVEVMX_14); + uint32_t restvmx_64 = BytePatternSearch(section.data, section.size, baseAddress, RESTVMX_64); + uint32_t savevmx_64 = BytePatternSearch(section.data, section.size, baseAddress, SAVEVMX_64); + + fmt::println("restgprlr_14_address = 0x{:X}", restgprlr_14); + fmt::println("savegprlr_14_address = 0x{:X}", savegprlr_14); + fmt::println("restfpr_14_address = 0x{:X}", restfpr_14); + fmt::println("savefpr_14_address = 0x{:X}", savefpr_14); + fmt::println("restvmx_14_address = 0x{:X}", restvmx_14); + fmt::println("savevmx_14_address = 0x{:X}", savevmx_14); + fmt::println("restvmx_64_address = 0x{:X}", restvmx_64); + fmt::println("savevmx_64_address = 0x{:X}", savevmx_64); + } + } +} + void ReadTable(Image& image, SwitchTable& table) { uint32_t pOffset; @@ -192,6 +245,8 @@ int main(int argc, char** argv) const auto file = LoadFile(argv[1]); auto image = Image::ParseImage(file.data(), file.size()); + RegisterFunctionsSearch(image); + auto printTable = [&](const SwitchTable& table) { println("[[switch]]"); From 6783869c8aa0e3144165eebf21337c979d813146 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 13 Mar 2025 10:42:15 -0400 Subject: [PATCH 2/3] This langauge sucks Signed-off-by: Isaac Marovitz --- XenonAnalyse/main.cpp | 39 ++++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/XenonAnalyse/main.cpp b/XenonAnalyse/main.cpp index fc424fd..db36785 100644 --- a/XenonAnalyse/main.cpp +++ b/XenonAnalyse/main.cpp @@ -21,19 +21,20 @@ struct SwitchTable uint32_t type{}; }; -static const std::vector RESTGPRLR_14 = { 0xe9, 0xc1, 0xff, 0x68 }; -static const std::vector SAVEGPRLR_14 = { 0xf9, 0xc1, 0xff, 0x68 }; -static const std::vector RESTFPR_14 = { 0xc9, 0xcc, 0xff, 0x70 }; -static const std::vector SAVEFPR_14 = { 0xd9, 0xcc, 0xff, 0x70 }; -static const std::vector RESTVMX_14 = { 0x39, 0x60, 0xfe, 0xe0, 0x7d, 0xcb, 0x60, 0xce }; -static const std::vector SAVEVMX_14 = { 0x39, 0x60, 0xfe, 0xe0, 0x7d, 0xcb, 0x61, 0xce }; -static const std::vector RESTVMX_64 = { 0x39, 0x60, 0xfc, 0x00, 0x10, 0x0b, 0x60, 0xcb }; -static const std::vector SAVEVMX_64 = { 0x39, 0x60, 0xfc, 0x00, 0x10, 0x0b, 0x61, 0xcb }; +static const uint8_t RESTGPRLR_14[] = { 0xe9, 0xc1, 0xff, 0x68 }; +static const uint8_t SAVEGPRLR_14[] = { 0xf9, 0xc1, 0xff, 0x68 }; +static const uint8_t RESTFPR_14[] = { 0xc9, 0xcc, 0xff, 0x70 }; +static const uint8_t SAVEFPR_14[] = { 0xd9, 0xcc, 0xff, 0x70 }; +static const uint8_t RESTVMX_14[] = { 0x39, 0x60, 0xfe, 0xe0, 0x7d, 0xcb, 0x60, 0xce }; +static const uint8_t SAVEVMX_14[] = { 0x39, 0x60, 0xfe, 0xe0, 0x7d, 0xcb, 0x61, 0xce }; +static const uint8_t RESTVMX_64[] = { 0x39, 0x60, 0xfc, 0x00, 0x10, 0x0b, 0x60, 0xcb }; +static const uint8_t SAVEVMX_64[] = { 0x39, 0x60, 0xfc, 0x00, 0x10, 0x0b, 0x61, 0xcb }; -uint32_t BytePatternSearch(uint8_t* data, uint32_t size, uint32_t baseAddress, const std::vector& pattern) + +uint32_t BytePatternSearch(uint8_t* data, const uint32_t dataSize, const uint32_t baseAddress, const uint8_t pattern[], const size_t patternSize) { - auto result = std::search(data, data + size, pattern.begin(), pattern.end()); - if (result != data + size) { + auto result = std::search(data, data + dataSize, pattern, pattern + patternSize); + if (result != data + dataSize) { return baseAddress + std::distance(data, result); } @@ -53,14 +54,14 @@ void RegisterFunctionsSearch(Image& image) return; } - uint32_t restgprlr_14 = BytePatternSearch(section.data, section.size, baseAddress, RESTGPRLR_14); - uint32_t savegprlr_14 = BytePatternSearch(section.data, section.size, baseAddress, SAVEGPRLR_14); - uint32_t restfpr_14 = BytePatternSearch(section.data, section.size, baseAddress, RESTFPR_14); - uint32_t savefpr_14 = BytePatternSearch(section.data, section.size, baseAddress, SAVEFPR_14); - uint32_t restvmx_14 = BytePatternSearch(section.data, section.size, baseAddress, RESTVMX_14); - uint32_t savevmx_14 = BytePatternSearch(section.data, section.size, baseAddress, SAVEVMX_14); - uint32_t restvmx_64 = BytePatternSearch(section.data, section.size, baseAddress, RESTVMX_64); - uint32_t savevmx_64 = BytePatternSearch(section.data, section.size, baseAddress, SAVEVMX_64); + uint32_t restgprlr_14 = BytePatternSearch(section.data, section.size, baseAddress, RESTGPRLR_14, sizeof(RESTGPRLR_14)); + uint32_t savegprlr_14 = BytePatternSearch(section.data, section.size, baseAddress, SAVEGPRLR_14, sizeof(SAVEGPRLR_14)); + uint32_t restfpr_14 = BytePatternSearch(section.data, section.size, baseAddress, RESTFPR_14, sizeof(RESTFPR_14)); + uint32_t savefpr_14 = BytePatternSearch(section.data, section.size, baseAddress, SAVEFPR_14, sizeof(SAVEFPR_14)); + uint32_t restvmx_14 = BytePatternSearch(section.data, section.size, baseAddress, RESTVMX_14, sizeof(RESTVMX_14)); + uint32_t savevmx_14 = BytePatternSearch(section.data, section.size, baseAddress, SAVEVMX_14, sizeof(SAVEVMX_14)); + uint32_t restvmx_64 = BytePatternSearch(section.data, section.size, baseAddress, RESTVMX_64, sizeof(RESTVMX_64)); + uint32_t savevmx_64 = BytePatternSearch(section.data, section.size, baseAddress, SAVEVMX_64, sizeof(SAVEVMX_64)); fmt::println("restgprlr_14_address = 0x{:X}", restgprlr_14); fmt::println("savegprlr_14_address = 0x{:X}", savegprlr_14); From c122571951b3ea6660f7872f832e93f474a481b7 Mon Sep 17 00:00:00 2001 From: Isaac Marovitz Date: Thu, 13 Mar 2025 11:01:32 -0400 Subject: [PATCH 3/3] Whitespace Signed-off-by: Isaac Marovitz --- XenonAnalyse/main.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/XenonAnalyse/main.cpp b/XenonAnalyse/main.cpp index db36785..9b3ef89 100644 --- a/XenonAnalyse/main.cpp +++ b/XenonAnalyse/main.cpp @@ -30,7 +30,6 @@ static const uint8_t SAVEVMX_14[] = { 0x39, 0x60, 0xfe, 0xe0, 0x7d, 0xcb, 0x61, static const uint8_t RESTVMX_64[] = { 0x39, 0x60, 0xfc, 0x00, 0x10, 0x0b, 0x60, 0xcb }; static const uint8_t SAVEVMX_64[] = { 0x39, 0x60, 0xfc, 0x00, 0x10, 0x0b, 0x61, 0xcb }; - uint32_t BytePatternSearch(uint8_t* data, const uint32_t dataSize, const uint32_t baseAddress, const uint8_t pattern[], const size_t patternSize) { auto result = std::search(data, data + dataSize, pattern, pattern + patternSize);