1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:07:34 +00:00

disasm: Convert to east-const and C++-style casts

This commit is contained in:
Rummskartoffel 2022-01-16 14:16:09 +01:00 committed by Andreas Kling
parent 28a2a01dc3
commit 0aa5725f72

View file

@ -18,7 +18,7 @@
ErrorOr<int> serenity_main(Main::Arguments args) ErrorOr<int> serenity_main(Main::Arguments args)
{ {
const char* path = nullptr; char const* path = nullptr;
Core::ArgsParser args_parser; Core::ArgsParser args_parser;
args_parser.set_general_help( args_parser.set_general_help(
@ -41,28 +41,28 @@ ErrorOr<int> serenity_main(Main::Arguments args)
}; };
Vector<Symbol> symbols; Vector<Symbol> symbols;
const u8* asm_data = (const u8*)file->data(); u8 const* asm_data = static_cast<u8 const*>(file->data());
size_t asm_size = file->size(); size_t asm_size = file->size();
size_t file_offset = 0; size_t file_offset = 0;
Vector<Symbol>::Iterator current_symbol = symbols.begin(); Vector<Symbol>::Iterator current_symbol = symbols.begin();
OwnPtr<X86::ELFSymbolProvider> symbol_provider; // nullptr for non-ELF disassembly. OwnPtr<X86::ELFSymbolProvider> symbol_provider; // nullptr for non-ELF disassembly.
OwnPtr<ELF::Image> elf; OwnPtr<ELF::Image> elf;
if (asm_size >= 4 && strncmp((const char*)asm_data, "\u007fELF", 4) == 0) { if (asm_size >= 4 && strncmp(reinterpret_cast<char const*>(asm_data), "\u007fELF", 4) == 0) {
elf = make<ELF::Image>(asm_data, asm_size); elf = make<ELF::Image>(asm_data, asm_size);
if (elf->is_valid()) { if (elf->is_valid()) {
symbol_provider = make<X86::ELFSymbolProvider>(*elf); symbol_provider = make<X86::ELFSymbolProvider>(*elf);
elf->for_each_section_of_type(SHT_PROGBITS, [&](const ELF::Image::Section& section) { elf->for_each_section_of_type(SHT_PROGBITS, [&](ELF::Image::Section const& section) {
// FIXME: Disassemble all SHT_PROGBITS sections, not just .text. // FIXME: Disassemble all SHT_PROGBITS sections, not just .text.
if (section.name() != ".text") if (section.name() != ".text")
return IterationDecision::Continue; return IterationDecision::Continue;
asm_data = (const u8*)section.raw_data(); asm_data = reinterpret_cast<u8 const*>(section.raw_data());
asm_size = section.size(); asm_size = section.size();
file_offset = section.address(); file_offset = section.address();
return IterationDecision::Break; return IterationDecision::Break;
}); });
symbols.ensure_capacity(elf->symbol_count() + 1); symbols.ensure_capacity(elf->symbol_count() + 1);
symbols.append({ 0, 0, StringView() }); // Sentinel. symbols.append({ 0, 0, StringView() }); // Sentinel.
elf->for_each_symbol([&](const ELF::Image::Symbol& symbol) { elf->for_each_symbol([&](ELF::Image::Symbol const& symbol) {
symbols.append({ symbol.value(), symbol.size(), symbol.name() }); symbols.append({ symbol.value(), symbol.size(), symbol.name() });
return IterationDecision::Continue; return IterationDecision::Continue;
}); });