mirror of
				https://github.com/hedge-dev/XenonRecomp.git
				synced 2025-11-04 06:47:09 +00:00 
			
		
		
		
	Repository cleanup & README.md. (#5)
This commit is contained in:
		@@ -172,32 +172,25 @@ void* SearchMask(const void* source, const uint32_t* compare, size_t compareCoun
 | 
			
		||||
    return nullptr;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
int main()
 | 
			
		||||
static std::string out;
 | 
			
		||||
 | 
			
		||||
template<class... Args>
 | 
			
		||||
static void println(fmt::format_string<Args...> fmt, Args&&... args)
 | 
			
		||||
{
 | 
			
		||||
    const auto file = LoadFile("private/default.xex");
 | 
			
		||||
    auto image = Image::ParseImage(file.data(), file.size());
 | 
			
		||||
    fmt::vformat_to(std::back_inserter(out), fmt.get(), fmt::make_format_args(args...));
 | 
			
		||||
    out += '\n';
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
    std::string out;
 | 
			
		||||
    auto println = [&]<class... Args>(fmt::format_string<Args...> fmt, Args&&... args)
 | 
			
		||||
int main(int argc, char** argv)
 | 
			
		||||
{
 | 
			
		||||
    if (argc < 3)
 | 
			
		||||
    {
 | 
			
		||||
        fmt::vformat_to(std::back_inserter(out), fmt.get(), fmt::make_format_args(args...));
 | 
			
		||||
        out += '\n';
 | 
			
		||||
    };
 | 
			
		||||
    //for (const auto& section : image.sections)
 | 
			
		||||
    //{
 | 
			
		||||
    //    image.symbols.emplace(section.name, section.base, section.size, Symbol_Section);
 | 
			
		||||
    //}
 | 
			
		||||
        printf("Usage: XenonAnalyse [input XEX file path] [output jump table TOML file path]");
 | 
			
		||||
        return EXIT_SUCCESS;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    // MakeMask((uint32_t*)image.Find(0x82C40D84), 6);
 | 
			
		||||
 | 
			
		||||
    //auto data = "\x4D\x99\x00\x20";
 | 
			
		||||
    //auto data2 = ByteSwap((2129));
 | 
			
		||||
    //ppc_insn insn;
 | 
			
		||||
    //ppc_insn insn2;
 | 
			
		||||
    //ppc::Disassemble(data, 0, insn);
 | 
			
		||||
    //ppc::Disassemble(&data2, 0, insn2);
 | 
			
		||||
    //auto op = PPC_OP(insn.instruction);
 | 
			
		||||
    //auto xop = PPC_XOP(insn.instruction);
 | 
			
		||||
    const auto file = LoadFile(argv[1]);
 | 
			
		||||
    auto image = Image::ParseImage(file.data(), file.size());
 | 
			
		||||
 | 
			
		||||
    auto printTable = [&](const SwitchTable& table)
 | 
			
		||||
        {
 | 
			
		||||
@@ -217,27 +210,7 @@ int main()
 | 
			
		||||
 | 
			
		||||
    std::vector<SwitchTable> switches{};
 | 
			
		||||
 | 
			
		||||
    auto insertTable = [&](size_t base, size_t defaultLabel, size_t r, size_t nLabels, uint32_t type)
 | 
			
		||||
        {
 | 
			
		||||
            auto& sw = switches.emplace_back();
 | 
			
		||||
            sw.base = base;
 | 
			
		||||
            sw.defaultLabel = defaultLabel;
 | 
			
		||||
            sw.r = r;
 | 
			
		||||
            sw.labels.resize(nLabels);
 | 
			
		||||
            sw.type = type;
 | 
			
		||||
        };
 | 
			
		||||
 | 
			
		||||
    println("# Generated by PowerAnalyse");
 | 
			
		||||
    insertTable(0x830ADAD8, 0x830ADB28, 11, 0x1B, SWITCH_COMPUTED);
 | 
			
		||||
    insertTable(0x830AE1B0, 0x830AE21C, 11, 0x1B, SWITCH_BYTEOFFSET);
 | 
			
		||||
    insertTable(0x82CFE120, 0x82CFDE68, 11, 0x10, SWITCH_SHORTOFFSET);
 | 
			
		||||
 | 
			
		||||
    println("# ---- MANUAL JUMPTABLE ----");
 | 
			
		||||
    for (auto& table : switches)
 | 
			
		||||
    {
 | 
			
		||||
        ReadTable(image, table);
 | 
			
		||||
        printTable(table);
 | 
			
		||||
    }
 | 
			
		||||
    println("# Generated by XenonAnalyse");
 | 
			
		||||
 | 
			
		||||
    auto scanPattern = [&](uint32_t* pattern, size_t count, size_t type)
 | 
			
		||||
        {
 | 
			
		||||
@@ -332,122 +305,8 @@ int main()
 | 
			
		||||
    scanPattern(offsetSwitch, std::size(offsetSwitch), SWITCH_BYTEOFFSET);
 | 
			
		||||
    scanPattern(wordOffsetSwitch, std::size(wordOffsetSwitch), SWITCH_SHORTOFFSET);
 | 
			
		||||
 | 
			
		||||
    FILE* f = fopen("out/switches.toml", "w");
 | 
			
		||||
    fwrite(out.data(), 1, out.size(), f);
 | 
			
		||||
    fclose(f);
 | 
			
		||||
    std::ofstream f(argv[2]);
 | 
			
		||||
    f.write(out.data(), out.size());
 | 
			
		||||
 | 
			
		||||
    uint32_t cxxFrameHandler = ByteSwap(0x831B1C90);
 | 
			
		||||
    uint32_t cSpecificFrameHandler = ByteSwap(0x8324B3BC);
 | 
			
		||||
    image.symbols.emplace("__CxxFrameHandler", 0x831B1C90, 0x38, Symbol_Function);
 | 
			
		||||
    image.symbols.emplace("__C_specific_handler", 0x8324B3BC, 0x38, Symbol_Function);
 | 
			
		||||
    image.symbols.emplace("memcpy", 0x831B0ED0, 0x488, Symbol_Function);
 | 
			
		||||
    image.symbols.emplace("memset", 0x831B0BA0, 0xA0, Symbol_Function);
 | 
			
		||||
    image.symbols.emplace("blkmov", 0x831B1358, 0xA8, Symbol_Function);
 | 
			
		||||
 | 
			
		||||
    image.symbols.emplace(fmt::format("sub_{:X}", 0x82EF5D78), 0x82EF5D78, 0x3F8, Symbol_Function);
 | 
			
		||||
 | 
			
		||||
    // auto fnd = Function::Analyze(image.Find(0x82C40D58), image.size, 0x82C40D58);
 | 
			
		||||
 | 
			
		||||
    std::vector<Function> functions;
 | 
			
		||||
    auto& pdata = *image.Find(".pdata");
 | 
			
		||||
    size_t count = pdata.size / sizeof(IMAGE_CE_RUNTIME_FUNCTION);
 | 
			
		||||
    auto* pf = (IMAGE_CE_RUNTIME_FUNCTION*)pdata.data;
 | 
			
		||||
    for (size_t i = 0; i < count; i++)
 | 
			
		||||
    {
 | 
			
		||||
        auto fn = pf[i];
 | 
			
		||||
        fn.BeginAddress = ByteSwap(fn.BeginAddress);
 | 
			
		||||
        fn.Data = ByteSwap(fn.Data);
 | 
			
		||||
 | 
			
		||||
        auto& f = functions.emplace_back();
 | 
			
		||||
        f.base = fn.BeginAddress;
 | 
			
		||||
        f.size = fn.FunctionLength * 4;
 | 
			
		||||
 | 
			
		||||
        if (f.base == 0x82BD7420)
 | 
			
		||||
        {
 | 
			
		||||
            __builtin_debugtrap();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        image.symbols.emplace(fmt::format("sub_{:X}", f.base), f.base, f.size, Symbol_Function);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    auto sym = image.symbols.find(0x82BD7420);
 | 
			
		||||
 | 
			
		||||
    std::vector<Function> missingFunctions;
 | 
			
		||||
    for (const auto& section : image.sections) 
 | 
			
		||||
    {
 | 
			
		||||
        if (!(section.flags & SectionFlags_Code))
 | 
			
		||||
        {
 | 
			
		||||
            continue;
 | 
			
		||||
        }
 | 
			
		||||
        size_t base = section.base;
 | 
			
		||||
        uint8_t* data = section.data;
 | 
			
		||||
        uint8_t* dataEnd = section.data + section.size;
 | 
			
		||||
        const Symbol* prevSymbol = nullptr;
 | 
			
		||||
        while (data < dataEnd)
 | 
			
		||||
        {
 | 
			
		||||
            if (*(uint32_t*)data == 0)
 | 
			
		||||
            {
 | 
			
		||||
                data += 4;
 | 
			
		||||
                base += 4;
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            if (*(uint32_t*)data == cxxFrameHandler || *(uint32_t*)data == cSpecificFrameHandler)
 | 
			
		||||
            {
 | 
			
		||||
                data += 8;
 | 
			
		||||
                base += 8;
 | 
			
		||||
                continue;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            auto fnSymbol = image.symbols.find(base);
 | 
			
		||||
            if (fnSymbol != image.symbols.end() && fnSymbol->type == Symbol_Function)
 | 
			
		||||
            {
 | 
			
		||||
                assert(fnSymbol->address == base);
 | 
			
		||||
 | 
			
		||||
                prevSymbol = &*fnSymbol;
 | 
			
		||||
                base += fnSymbol->size;
 | 
			
		||||
                data += fnSymbol->size;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                auto& missingFn = missingFunctions.emplace_back(Function::Analyze(data, dataEnd - data, base));
 | 
			
		||||
                base += missingFn.size;
 | 
			
		||||
                data += missingFn.size;
 | 
			
		||||
                
 | 
			
		||||
                fmt::println("sub_{:X}", missingFn.base);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //ppc_insn insn;
 | 
			
		||||
    //uint8_t c[4] = { 0x10, 0x00, 0x59, 0xC3 };
 | 
			
		||||
    //ppc::Disassemble(c, 0x831D6C64, insn);
 | 
			
		||||
    //fmt::println("{:20}{}", insn.opcode->name, insn.op_str);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    const auto entrySymbol = image.symbols.find(image.entry_point);
 | 
			
		||||
    assert(entrySymbol != image.symbols.end());
 | 
			
		||||
 | 
			
		||||
    const auto entrySize = entrySymbol->size;
 | 
			
		||||
    image.symbols.erase(entrySymbol);
 | 
			
		||||
 | 
			
		||||
    image.symbols.emplace("_start", image.entry_point, entrySize, Symbol_Function);
 | 
			
		||||
 | 
			
		||||
    fmt::println("FUNCTIONS");
 | 
			
		||||
    for (const auto& fn : functions)
 | 
			
		||||
    {
 | 
			
		||||
        fmt::println("\tsub_{:X}", fn.base);
 | 
			
		||||
    }
 | 
			
		||||
    fmt::println("");
 | 
			
		||||
    
 | 
			
		||||
 | 
			
		||||
    fmt::println("SECTIONS");
 | 
			
		||||
    for (const auto& section : image.sections)
 | 
			
		||||
    {
 | 
			
		||||
        printf("Section %.8s\n", section.name.c_str());
 | 
			
		||||
        printf("\t%X-%X\n", section.base, section.base + section.size);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    fmt::println("");
 | 
			
		||||
    return 0;
 | 
			
		||||
    return EXIT_SUCCESS;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user