mirror of
https://github.com/hedge-dev/XenonRecomp.git
synced 2025-06-06 01:02:08 +00:00
Pseudocode decompilation attempts for the test.
This commit is contained in:
parent
606463ac09
commit
25ede377a1
@ -1,12 +1,16 @@
|
||||
#include <file.h>
|
||||
#include <disasm.h>
|
||||
#include <image.h>
|
||||
#include <format>
|
||||
#include <print>
|
||||
#include <ppc.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
const auto file = LoadFile("add.elf");
|
||||
auto image = Image::ParseImage(file.data(), file.size()).value();
|
||||
|
||||
FILE* f = fopen("add.elf.cpp", "w");
|
||||
|
||||
for (const auto& section : image.sections)
|
||||
{
|
||||
image.symbols.emplace(section.name, section.base, section.size, Symbol_Section);
|
||||
@ -29,21 +33,61 @@ int main()
|
||||
while(base < end)
|
||||
{
|
||||
ppc::Disassemble(data, 4, base, insn);
|
||||
|
||||
|
||||
base += 4;
|
||||
++data;
|
||||
|
||||
if (insn.opcode == nullptr)
|
||||
{
|
||||
printf("\t%X\t%s\n", static_cast<uint32_t>(base - 4), insn.op_str);
|
||||
std::println(f, "// {:x} {}", base - 4, insn.op_str);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::printf("\t%X\t%s %s\n", static_cast<uint32_t>(base - 4), insn.opcode->name, insn.op_str);
|
||||
std::println(f, "// {:x} {} {}", base - 4, insn.opcode->name, insn.op_str);
|
||||
switch (insn.opcode->id)
|
||||
{
|
||||
case PPC_INST_ADD:
|
||||
std::println(f, "r{} = r{} + r{};", insn.operands[0], insn.operands[1], insn.operands[2]);
|
||||
break;
|
||||
case PPC_INST_ADDI:
|
||||
std::println(f, "r{} = r{} + {};", insn.operands[0], insn.operands[1], insn.operands[2]);
|
||||
break;
|
||||
case PPC_INST_STWU:
|
||||
std::println(f, "ea = r{} + {};", insn.operands[2], static_cast<int32_t>(insn.operands[1]));
|
||||
std::println(f, "*ea = byteswap(r{});", insn.operands[0]);
|
||||
std::println(f, "r{} = ea;", insn.operands[2]);
|
||||
break;
|
||||
case PPC_INST_STW:
|
||||
std::println(f, "*(r{} + {}) = byteswap(r{});", insn.operands[2], static_cast<int32_t>(insn.operands[1]), insn.operands[0]);
|
||||
break;
|
||||
case PPC_INST_MR:
|
||||
std::println(f, "r{} = r{};", insn.operands[0], insn.operands[1]);
|
||||
break;
|
||||
case PPC_INST_LWZ:
|
||||
std::println(f, "r{} = *(r{} + {});", insn.operands[0], insn.operands[2], insn.operands[1]);
|
||||
break;
|
||||
case PPC_INST_LI:
|
||||
std::println(f, "r{} = {};", insn.operands[0], insn.operands[1]);
|
||||
break;
|
||||
case PPC_INST_MFLR:
|
||||
std::println(f, "r{} = lr;", insn.operands[0]);
|
||||
break;
|
||||
case PPC_INST_MTLR:
|
||||
std::println(f, "lr = r{};", insn.operands[0]);
|
||||
break;
|
||||
case PPC_INST_BLR:
|
||||
std::println(f, "return;");
|
||||
break;
|
||||
case PPC_INST_BL:
|
||||
std::println(f, "lr = 0x{:x};", insn.operands[0]);
|
||||
std::println(f, "sub_{:x}();", insn.operands[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user