mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 15:57:45 +00:00
LibX86: Add an X86 instruction decoder library + basic disassembler
This will be very useful for developer tools like ProfileView, and also for future tools like debuggers and such. :^)
This commit is contained in:
parent
7cc7d303e3
commit
32d83fdee4
7 changed files with 2367 additions and 2 deletions
27
Userland/disasm.cpp
Normal file
27
Userland/disasm.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include <AK/LogStream.h>
|
||||
#include <AK/MappedFile.h>
|
||||
#include <LibX86/Disassembler.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
if (argc == 1) {
|
||||
fprintf(stderr, "usage: %s <binary>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
MappedFile file(argv[1]);
|
||||
|
||||
X86::SimpleInstructionStream stream((const u8*)file.data(), file.size());
|
||||
X86::Disassembler disassembler(stream);
|
||||
|
||||
for (;;) {
|
||||
auto offset = stream.offset();
|
||||
auto insn = disassembler.next();
|
||||
if (!insn.has_value())
|
||||
break;
|
||||
out() << String::format("%08x", offset) << " " << insn.value().to_string(offset, true);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue