mirror of
				https://github.com/hedge-dev/XenonRecomp.git
				synced 2025-11-04 06:47:09 +00:00 
			
		
		
		
	Scan all of swa functions
This commit is contained in:
		@@ -4,33 +4,60 @@
 | 
				
			|||||||
#include <image.h>
 | 
					#include <image.h>
 | 
				
			||||||
#include "function.h"
 | 
					#include "function.h"
 | 
				
			||||||
#include <print>
 | 
					#include <print>
 | 
				
			||||||
 | 
					#include <xbox.h>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int main()
 | 
					int main()
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    const auto file = LoadFile("cond-fall.elf").value();
 | 
					    const auto file = LoadFile("private/default.xex").value();
 | 
				
			||||||
    auto image = Image::ParseImage(file.data(), file.size()).value();
 | 
					    auto image = Image::ParseImage(file.data(), file.size()).value();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    for (const auto& section : image.sections)
 | 
					    //for (const auto& section : image.sections)
 | 
				
			||||||
    {
 | 
					    //{
 | 
				
			||||||
        image.symbols.emplace(section.name, section.base, section.size, Symbol_Section);
 | 
					    //    image.symbols.emplace(section.name, section.base, section.size, Symbol_Section);
 | 
				
			||||||
    }
 | 
					    //}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    //ppc_insn insn;
 | 
					    uint32_t cxxFrameHandler = std::byteswap(0x831B1C90);
 | 
				
			||||||
    //uint8_t c[4] = { 0x10, 0x00, 0x59, 0xC3 };
 | 
					    uint32_t cSpecificFrameHandler = std::byteswap(0x8324B3BC);
 | 
				
			||||||
    //ppc::Disassemble(c, 0x831D6C64, insn);
 | 
					    image.symbols.emplace("__CxxFrameHandler", 0x831B1C90, 0x38, Symbol_Function);
 | 
				
			||||||
    //std::println("{:20}{}", insn.opcode->name, insn.op_str);
 | 
					    image.symbols.emplace("__C_specific_handler", 0x82BD7780, 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(std::format("sub_{:X}", 0x82EF5D78), 0x82EF5D78, 0x3F8, Symbol_Function);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    auto fnd = Function::Analyze(image.Find(0x831B1358), image.size, 0x831B1358);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    std::vector<Function> functions;
 | 
					    std::vector<Function> functions;
 | 
				
			||||||
    for (const auto& section : image.sections)
 | 
					    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 = std::byteswap(fn.BeginAddress);
 | 
				
			||||||
 | 
					        fn.Data = std::byteswap(fn.Data);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        auto& f = functions.emplace_back();
 | 
				
			||||||
 | 
					        f.base = fn.BeginAddress;
 | 
				
			||||||
 | 
					        f.size = fn.FunctionLength * 4;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        image.symbols.emplace(std::format("sub_{:X}", f.base), f.base, f.size, Symbol_Function);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    // auto sym = image.symbols.find(0x822C0000);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    std::vector<Function> missingFunctions;
 | 
				
			||||||
 | 
					    for (const auto& section : image.sections) 
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        if (!(section.flags & SectionFlags_Code))
 | 
					        if (!(section.flags & SectionFlags_Code))
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            continue;
 | 
					            continue;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					 | 
				
			||||||
        size_t base = section.base;
 | 
					        size_t base = section.base;
 | 
				
			||||||
        uint8_t* data = section.data;
 | 
					        uint8_t* data = section.data;
 | 
				
			||||||
        uint8_t* dataEnd = section.data + section.size;
 | 
					        uint8_t* dataEnd = section.data + section.size;
 | 
				
			||||||
 | 
					        const Symbol* prevSymbol = nullptr;
 | 
				
			||||||
        while (data < dataEnd)
 | 
					        while (data < dataEnd)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            if (*(uint32_t*)data == 0)
 | 
					            if (*(uint32_t*)data == 0)
 | 
				
			||||||
@@ -40,14 +67,64 @@ int main()
 | 
				
			|||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            const auto& fn = functions.emplace_back(Function::Analyze(data, dataEnd - data, base));
 | 
					            if (*(uint32_t*)data == cxxFrameHandler || *(uint32_t*)data == cSpecificFrameHandler)
 | 
				
			||||||
            data += fn.size;
 | 
					            {
 | 
				
			||||||
            base += fn.size;
 | 
					                data += 8;
 | 
				
			||||||
 | 
					                base += 8;
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            image.symbols.emplace(std::format("sub_{:X}", fn.base), fn.base, fn.size, Symbol_Function);
 | 
					            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;
 | 
				
			||||||
 | 
					                
 | 
				
			||||||
 | 
					                std::println("sub_{:X}", missingFn.base);
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //ppc_insn insn;
 | 
				
			||||||
 | 
					    //uint8_t c[4] = { 0x10, 0x00, 0x59, 0xC3 };
 | 
				
			||||||
 | 
					    //ppc::Disassemble(c, 0x831D6C64, insn);
 | 
				
			||||||
 | 
					    //std::println("{:20}{}", insn.opcode->name, insn.op_str);
 | 
				
			||||||
 | 
					    //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;
 | 
				
			||||||
 | 
					    //    while (data < dataEnd)
 | 
				
			||||||
 | 
					    //    {
 | 
				
			||||||
 | 
					    //        if (*(uint32_t*)data == 0)
 | 
				
			||||||
 | 
					    //        {
 | 
				
			||||||
 | 
					    //            data += 4;
 | 
				
			||||||
 | 
					    //            base += 4;
 | 
				
			||||||
 | 
					    //            continue;
 | 
				
			||||||
 | 
					    //        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //        const auto& fn = functions.emplace_back(Function::Analyze(data, dataEnd - data, base));
 | 
				
			||||||
 | 
					    //        data += fn.size;
 | 
				
			||||||
 | 
					    //        base += fn.size;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    //        image.symbols.emplace(std::format("sub_{:X}", fn.base), fn.base, fn.size, Symbol_Function);
 | 
				
			||||||
 | 
					    //    }
 | 
				
			||||||
 | 
					    //}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const auto entrySymbol = image.symbols.find(image.entry_point);
 | 
					    const auto entrySymbol = image.symbols.find(image.entry_point);
 | 
				
			||||||
    assert(entrySymbol != image.symbols.end());
 | 
					    assert(entrySymbol != image.symbols.end());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user