mirror of
https://github.com/hedge-dev/XenonRecomp.git
synced 2025-10-30 07:11:38 +00:00
Merge c122571951 into 5a945705de
This commit is contained in:
commit
516dfc75ab
1 changed files with 59 additions and 4 deletions
|
|
@ -1,11 +1,11 @@
|
||||||
|
#include "fmt/xchar.h"
|
||||||
|
#include "function.h"
|
||||||
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <iterator>
|
|
||||||
#include <file.h>
|
|
||||||
#include <disasm.h>
|
#include <disasm.h>
|
||||||
|
#include <file.h>
|
||||||
#include <image.h>
|
#include <image.h>
|
||||||
#include <xbox.h>
|
#include <xbox.h>
|
||||||
#include <fmt/core.h>
|
|
||||||
#include "function.h"
|
|
||||||
|
|
||||||
#define SWITCH_ABSOLUTE 0
|
#define SWITCH_ABSOLUTE 0
|
||||||
#define SWITCH_COMPUTED 1
|
#define SWITCH_COMPUTED 1
|
||||||
|
|
@ -21,6 +21,59 @@ struct SwitchTable
|
||||||
uint32_t type{};
|
uint32_t type{};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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, 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);
|
||||||
|
if (result != data + dataSize) {
|
||||||
|
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, 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);
|
||||||
|
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)
|
void ReadTable(Image& image, SwitchTable& table)
|
||||||
{
|
{
|
||||||
uint32_t pOffset;
|
uint32_t pOffset;
|
||||||
|
|
@ -192,6 +245,8 @@ int main(int argc, char** argv)
|
||||||
const auto file = LoadFile(argv[1]);
|
const auto file = LoadFile(argv[1]);
|
||||||
auto image = Image::ParseImage(file.data(), file.size());
|
auto image = Image::ParseImage(file.data(), file.size());
|
||||||
|
|
||||||
|
RegisterFunctionsSearch(image);
|
||||||
|
|
||||||
auto printTable = [&](const SwitchTable& table)
|
auto printTable = [&](const SwitchTable& table)
|
||||||
{
|
{
|
||||||
println("[[switch]]");
|
println("[[switch]]");
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue