Index: src/processor/disassembler_x86.h |
diff --git a/src/processor/disassembler_x86.h b/src/processor/disassembler_x86.h |
index 71069410721740b610b65b1a762ae73384249155..09aa359e2e224596f3049dd2eadc6959ed961340 100644 |
--- a/src/processor/disassembler_x86.h |
+++ b/src/processor/disassembler_x86.h |
@@ -28,7 +28,7 @@ |
// disassembler_x86.h: Basic x86 bytecode disassembler |
// |
-// Provides a simple disassembler which wraps libdisasm. This allows simple |
+// Provides a simple disassembler which wraps capstone. This allows simple |
// tests to be run against bytecode to test for various properties. |
// |
// Author: Cris Neckar |
@@ -41,12 +41,12 @@ |
#include "google_breakpad/common/breakpad_types.h" |
-namespace libdis { |
-#include "third_party/libdisasm/libdis.h" |
-} |
+#include "capstone.h" |
+ |
namespace google_breakpad { |
+// Flags for current disassembler state. |
enum { |
DISX86_NONE = 0x0, |
DISX86_BAD_BRANCH_TARGET = 0x1, |
@@ -71,26 +71,35 @@ class DisassemblerX86 { |
// including any registers marked as bad through setBadRead() |
// or setBadWrite(). This method can be called in a loop to |
// disassemble until the end of a region. |
- uint32_t NextInstruction(); |
+ // |
+ // Returns the size of the instruction in bytes, or zero if |
+ // disassembly failed. |
+ size_t NextInstruction(); |
// Indicates whether the current disassembled instruction was valid. |
bool currentInstructionValid() { return instr_valid_; } |
- // Returns the current instruction as defined in libdis.h, |
+ // Returns the current instruction as defined in capstone.h, |
// or NULL if the current instruction is not valid. |
- const libdis::x86_insn_t* currentInstruction() { |
- return instr_valid_ ? ¤t_instr_ : NULL; |
+ const cs_insn* currentInstruction() { |
+ return instr_valid_ ? current_instr_ : nullptr; |
} |
- // Returns the type of the current instruction as defined in libdis.h. |
- libdis::x86_insn_group currentInstructionGroup() { |
- return current_instr_.group; |
+ // Returns true if the current instruction is in group. |
+ bool currentInstructionIsGroup(x86_insn_group group) { |
+ return instr_valid_ ? |
+ cs_insn_group(handle_, current_instr_, group) : false; |
} |
+ // Returns true if the current instruction is a block data instruction. |
+ bool currentInstructionIsBlockData(); |
+ |
+ |
// Indicates whether a return instruction has been encountered. |
bool endOfBlock() { return end_of_block_; } |
- // The flags set so far for the disassembly. |
+ // The flags set so far for the disassembly, from the set defined in |
+ // the anonymous enum above. |
uint16_t flags() { return flags_; } |
// This sets an indicator that the register used to determine |
@@ -102,19 +111,24 @@ class DisassemblerX86 { |
bool setBadWrite(); |
protected: |
- const uint8_t *bytecode_; |
- uint32_t size_; |
- uint32_t virtual_address_; |
- uint32_t current_byte_offset_; |
- uint32_t current_inst_offset_; |
+ // Memory containing instructions to disassemble. |
+ // Owned by caller. |
+ const uint8_t* bytecode_; |
+ // Size of remaining bytecode. |
+ size_t size_; |
+ // Virtual address of current instruction. |
+ uint64_t virtual_address_; |
+ |
+ // capstone library handle |
+ csh handle_; |
bool instr_valid_; |
- libdis::x86_insn_t current_instr_; |
+ cs_insn* current_instr_; |
// TODO(cdn): Maybe also track an expression's index register. |
// ex: mov eax, [ebx + ecx]; ebx is base, ecx is index. |
bool register_valid_; |
- libdis::x86_reg_t bad_register_; |
+ x86_reg bad_register_; |
bool pushed_bad_value_; |
bool end_of_block_; |