mirror of
https://github.com/hedge-dev/XenonRecomp.git
synced 2025-07-22 21:17:14 +00:00
Implement ELF support
This commit is contained in:
@@ -1,41 +1,45 @@
|
||||
#include <windows.h>
|
||||
#include <xex.h>
|
||||
#include <file.h>
|
||||
#include <disasm.h>
|
||||
#include <image.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
// TODO: ELFs, symbols, sections, a lot
|
||||
const auto file = LoadFile("default.xex");
|
||||
const auto image = Xex2LoadImage(file.data());
|
||||
const auto file = LoadFile("add.elf");
|
||||
const auto image = Image::ParseImage(file.data(), file.size()).value();
|
||||
|
||||
auto* headers = (IMAGE_NT_HEADERS32*)(image.get() + ((IMAGE_DOS_HEADER*)image.get())->e_lfanew);
|
||||
auto numSections = headers->FileHeader.NumberOfSections;
|
||||
auto* sections = (IMAGE_SECTION_HEADER*)(headers + 1);
|
||||
auto base = headers->OptionalHeader.ImageBase;
|
||||
|
||||
for (size_t i = 0; i < numSections; i++)
|
||||
for (const auto& section : image.sections)
|
||||
{
|
||||
const auto& section = sections[i];
|
||||
std::printf("Section %.8s\n", reinterpret_cast<const char*>(section.Name));
|
||||
std::printf("\t%X-%X\n", base + section.VirtualAddress, base + section.VirtualAddress + section.Misc.VirtualSize);
|
||||
std::printf("Section %.8s\n", section.name.c_str());
|
||||
std::printf("\t%X-%X\n", section.base, section.base + section.size);
|
||||
|
||||
auto* data = (uint32_t*)section.data;
|
||||
auto base = section.base;
|
||||
const auto end = section.base + section.size;
|
||||
|
||||
auto* data = image.get() + section.VirtualAddress; // XEX is weird
|
||||
ppc::SetDetail(true);
|
||||
|
||||
if (section.Characteristics & IMAGE_SCN_CNT_CODE)
|
||||
if (section.flags & SectionFlags_Code)
|
||||
{
|
||||
cs_insn* instructions;
|
||||
size_t n = ppc::Disassemble(data, section.SizeOfRawData, base + section.VirtualAddress, 0, &instructions);
|
||||
|
||||
for(size_t i = 0; i < n; i++)
|
||||
while(base < end)
|
||||
{
|
||||
printf("\t%s\n", instructions[i].mnemonic);
|
||||
}
|
||||
auto* instruction = ppc::DisassembleSingle(reinterpret_cast<uint8_t*>(data), base);
|
||||
|
||||
cs_free(instructions, n);
|
||||
base += 4;
|
||||
++data;
|
||||
|
||||
if (instruction == nullptr)
|
||||
{
|
||||
printf("\t%X\t.long %Xh\n", static_cast<uint32_t>(base - 4), *(data - 1));
|
||||
}
|
||||
else
|
||||
{
|
||||
std::printf("\t%X\t%s %s\n", static_cast<uint32_t>(base - 4), instruction->mnemonic, instruction->op_str);
|
||||
cs_free(instruction, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user