46 lines
1.3 KiB
C++
Raw Normal View History

2024-09-07 18:00:09 +06:00
#include <file.h>
#include <disasm.h>
2024-09-07 22:56:20 +06:00
#include <image.h>
2024-09-07 18:00:09 +06:00
int main()
{
2024-09-07 18:21:08 +06:00
// TODO: ELFs, symbols, sections, a lot
2024-09-07 22:56:20 +06:00
const auto file = LoadFile("add.elf");
const auto image = Image::ParseImage(file.data(), file.size()).value();
2024-09-07 18:21:08 +06:00
2024-09-07 22:56:20 +06:00
for (const auto& section : image.sections)
2024-09-07 18:21:08 +06:00
{
2024-09-07 22:56:20 +06:00
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;
2024-09-07 18:21:08 +06:00
ppc::SetDetail(true);
2024-09-07 22:56:20 +06:00
if (section.flags & SectionFlags_Code)
2024-09-07 18:21:08 +06:00
{
2024-09-07 22:56:20 +06:00
while(base < end)
2024-09-07 18:21:08 +06:00
{
2024-09-07 22:56:20 +06:00
auto* instruction = ppc::DisassembleSingle(reinterpret_cast<uint8_t*>(data), base);
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);
}
2024-09-07 18:21:08 +06:00
}
}
}
return 0;
2024-09-07 22:56:20 +06:00
}