]> git.siccegge.de Git - frida/frida.git/blob - src/disassembler.old/InstructionReader.cxx
Some more notes
[frida/frida.git] / src / disassembler.old / InstructionReader.cxx
1 #include "InstructionReader.hxx"
2
3 InstructionReader::InstructionReader(const Target& target)
4 : _logger(log4cxx::Logger::getLogger("disassembler.Target"))
5 , _target(target)
6 {
7 DisAsm.reset(_target.getTarget().createMCDisassembler(_target.getSubTargetInfo()));
8 if (!DisAsm) {
9 LOG4CXX_ERROR(_logger, "error: no disassembler for target " << _target.getTripleName())
10 return;
11 }
12 }
13
14 void InstructionReader::readInstruction(std::string& data, size_t& offset, Instruction& inst) {
15 llvm::MCInst instr;
16 llvm::StringRefMemoryObject memoryObject(data);
17 uint64_t size;
18
19 if (DisAsm->getInstruction(instr, size, memoryObject, offset,
20 llvm::nulls(), llvm::nulls())) {
21
22 } else {
23 LOG4CXX_WARN(_logger, "warning: invalid instruction encoding");
24 if (size == 0)
25 size = 1; // skip illegible bytes
26 }
27 }