[LLVMdev] Disassembly arbitrary machine-code byte arrays
James.Molloy at arm.com
Mon Dec 19 01:23:37 PST 2011
The easiest thing I can do is to point you to the source of the "llvm-mc" tool, which does exactly what you ask in its "-disassemble" mode. The code is rather small, so it should be easy to work out.
From: llvmdev-bounces at cs.uiuc.edu [mailto:llvmdev-bounces at cs.uiuc.edu] On Behalf Of Aidan Steele
Sent: 19 December 2011 04:30
To: llvmdev at cs.uiuc.edu
Subject: [LLVMdev] Disassembly arbitrary machine-code byte arrays
My apologies if this appears to be a very trivial question -- I have
tried to solve this on my own and I am stuck. Any assistance that
could be provided would be immensely appreciated.
What is the absolute bare minimum that I need to do to disassemble an
array of, say, ARM machine code bytes? Or an array of Thumb machine
code bytes? For example, I might have an array of unsigned chars --
how could I go about decoding these into MCInst objects? Does such a
decoding process take place in one fell swoop or do I parse the stream
one instruction at a time? Can I ask it to "decode the next 10 bytes"?
What follows is my (feeble) attempt at getting started. It probably
doesn't help that I am only familiar with C and Objective-C and find
C++ syntax absolutely bewildering.
int main (int argc, const char *argv)
const llvm::Target Target;
STI(Target.createMCSubtargetInfo("", "", ""));
uint64_t Size = 0;
disassembler->getInstruction(Inst, Size, *Buffer.take(), 0,
// llvm::StringRef TheArchString("arm-apple-darwin");
// std::string normalized = llvm::Triple::normalize(TheArchString);
// llvm::Triple TheTriple;
// llvm::Target *TheTarget = NULL;
LLVM Developers mailing list
LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
-- IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
More information about the llvm-dev