mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 11:54:57 +00:00
disasm: Port to LibMain
This commit is contained in:
parent
1716105e73
commit
affef5d1a9
3 changed files with 9 additions and 13 deletions
|
@ -478,7 +478,7 @@ if (BUILD_LAGOM)
|
||||||
|
|
||||||
add_executable(disasm_lagom ../../Userland/Utilities/disasm.cpp)
|
add_executable(disasm_lagom ../../Userland/Utilities/disasm.cpp)
|
||||||
set_target_properties(disasm_lagom PROPERTIES OUTPUT_NAME disasm)
|
set_target_properties(disasm_lagom PROPERTIES OUTPUT_NAME disasm)
|
||||||
target_link_libraries(disasm_lagom LagomCore LagomELF LagomX86)
|
target_link_libraries(disasm_lagom LagomCore LagomELF LagomX86 LagomMain)
|
||||||
|
|
||||||
add_executable(gml-format_lagom ../../Userland/Utilities/gml-format.cpp)
|
add_executable(gml-format_lagom ../../Userland/Utilities/gml-format.cpp)
|
||||||
set_target_properties(gml-format_lagom PROPERTIES OUTPUT_NAME gml-format)
|
set_target_properties(gml-format_lagom PROPERTIES OUTPUT_NAME gml-format)
|
||||||
|
|
|
@ -84,7 +84,7 @@ target_link_libraries(ddate LibMain)
|
||||||
target_link_libraries(df LibMain)
|
target_link_libraries(df LibMain)
|
||||||
target_link_libraries(diff LibDiff LibMain)
|
target_link_libraries(diff LibDiff LibMain)
|
||||||
target_link_libraries(dirname LibMain)
|
target_link_libraries(dirname LibMain)
|
||||||
target_link_libraries(disasm LibX86)
|
target_link_libraries(disasm LibX86 LibMain)
|
||||||
target_link_libraries(dmesg LibMain)
|
target_link_libraries(dmesg LibMain)
|
||||||
target_link_libraries(du LibMain)
|
target_link_libraries(du LibMain)
|
||||||
target_link_libraries(echo LibMain)
|
target_link_libraries(echo LibMain)
|
||||||
|
|
|
@ -11,11 +11,12 @@
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
#include <LibCore/MappedFile.h>
|
#include <LibCore/MappedFile.h>
|
||||||
#include <LibELF/Image.h>
|
#include <LibELF/Image.h>
|
||||||
|
#include <LibMain/Main.h>
|
||||||
#include <LibX86/Disassembler.h>
|
#include <LibX86/Disassembler.h>
|
||||||
#include <LibX86/ELFSymbolProvider.h>
|
#include <LibX86/ELFSymbolProvider.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
int main(int argc, char** argv)
|
ErrorOr<int> serenity_main(Main::Arguments args)
|
||||||
{
|
{
|
||||||
const char* path = nullptr;
|
const char* path = nullptr;
|
||||||
|
|
||||||
|
@ -24,15 +25,9 @@ int main(int argc, char** argv)
|
||||||
"Disassemble an executable, and show human-readable "
|
"Disassemble an executable, and show human-readable "
|
||||||
"assembly code for each function.");
|
"assembly code for each function.");
|
||||||
args_parser.add_positional_argument(path, "Path to i386 binary file", "path");
|
args_parser.add_positional_argument(path, "Path to i386 binary file", "path");
|
||||||
args_parser.parse(argc, argv);
|
args_parser.parse(args);
|
||||||
|
|
||||||
auto file_or_error = Core::MappedFile::map(path);
|
auto file = TRY(Core::MappedFile::map(path));
|
||||||
if (file_or_error.is_error()) {
|
|
||||||
warnln("Could not map file: {}", file_or_error.error());
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto& file = *file_or_error.value();
|
|
||||||
|
|
||||||
struct Symbol {
|
struct Symbol {
|
||||||
size_t value;
|
size_t value;
|
||||||
|
@ -46,8 +41,8 @@ int main(int argc, char** argv)
|
||||||
};
|
};
|
||||||
Vector<Symbol> symbols;
|
Vector<Symbol> symbols;
|
||||||
|
|
||||||
const u8* asm_data = (const u8*)file.data();
|
const u8* asm_data = (const u8*)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.
|
||||||
|
@ -131,4 +126,5 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
outln("{:p} {}", virtual_offset, insn.value().to_string(virtual_offset, symbol_provider));
|
outln("{:p} {}", virtual_offset, insn.value().to_string(virtual_offset, symbol_provider));
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue