summaryrefslogtreecommitdiffstats
path: root/courgette/disassembler_elf_32.h
diff options
context:
space:
mode:
authorpaulgazz@chromium.org <paulgazz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-23 21:18:19 +0000
committerpaulgazz@chromium.org <paulgazz@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-23 21:18:19 +0000
commit144c8e950add26b44467784568d0ca5387a1047d (patch)
tree74c55e162f2128d67552a654d1cc57fb21b91afe /courgette/disassembler_elf_32.h
parent63d353f9d7a70dc827bad25e0932967711d595f3 (diff)
downloadchromium_src-144c8e950add26b44467784568d0ca5387a1047d.zip
chromium_src-144c8e950add26b44467784568d0ca5387a1047d.tar.gz
chromium_src-144c8e950add26b44467784568d0ca5387a1047d.tar.bz2
Added a TypedRVA to track what kind of branch instruction is used for
the jump and compute the target RVA accordingly. Also updated the unit test to use TypedRVA and check that only X86 RVAs are found by the X86 "disassembler". BUG=258645 Review URL: https://chromiumcodereview.appspot.com/18055007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213220 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'courgette/disassembler_elf_32.h')
-rw-r--r--courgette/disassembler_elf_32.h55
1 files changed, 51 insertions, 4 deletions
diff --git a/courgette/disassembler_elf_32.h b/courgette/disassembler_elf_32.h
index 3f63c43..b3f6e59 100644
--- a/courgette/disassembler_elf_32.h
+++ b/courgette/disassembler_elf_32.h
@@ -6,6 +6,7 @@
#define COURGETTE_DISASSEMBLER_ELF_32_H_
#include "base/basictypes.h"
+#include "base/memory/scoped_vector.h"
#include "courgette/disassembler.h"
#include "courgette/memory_allocator.h"
#include "courgette/types_elf.h"
@@ -24,8 +25,52 @@ class AssemblyProgram;
// architecture's machine code.
class DisassemblerElf32 : public Disassembler {
public:
+ // Different instructions encode the target rva differently. This
+ // class encapsulates this behavior. public for use in unit tests.
+ class TypedRVA {
+ public:
+ explicit TypedRVA(RVA rva) : rva_(rva), offset_(-1) {
+ }
+
+ virtual ~TypedRVA() { };
+
+ RVA rva() {
+ return rva_;
+ }
+
+ RVA relative_target() {
+ return relative_target_;
+ }
+
+ void set_relative_target(RVA relative_target) {
+ relative_target_ = relative_target;
+ }
+
+ size_t get_offset() {
+ return offset_;
+ }
+
+ void set_offset(size_t offset) {
+ offset_ = offset;
+ }
+
+ virtual CheckBool ComputeRelativeTarget(const uint8* op_pointer) = 0;
+
+ static bool IsLessThan(TypedRVA *a, TypedRVA *b) {
+ return a->rva() < b->rva();
+ }
+
+ private:
+ const RVA rva_;
+ RVA relative_target_;
+ size_t offset_;
+ };
+
+ public:
explicit DisassemblerElf32(const void* start, size_t length);
+ virtual ~DisassemblerElf32() { };
+
virtual ExecutableType kind() = 0;
virtual e_machine_values ElfEM() = 0;
@@ -39,7 +84,7 @@ class DisassemblerElf32 : public Disassembler {
// Public for unittests only
std::vector<RVA> &Abs32Locations() { return abs32_locations_; }
- std::vector<RVA> &Rel32Locations() { return rel32_locations_; }
+ ScopedVector<TypedRVA> &Rel32Locations() { return rel32_locations_; }
protected:
@@ -111,6 +156,8 @@ class DisassemblerElf32 : public Disassembler {
CheckBool RVAsToOffsets(std::vector<RVA>* rvas /*in*/,
std::vector<size_t>* offsets /*out*/);
+ CheckBool RVAsToOffsets(ScopedVector<TypedRVA>* rvas /*in and out*/);
+
// Parsing Code used to really implement Disassemble
CheckBool ParseFile(AssemblyProgram* target) WARN_UNUSED_RESULT;
@@ -121,8 +168,8 @@ class DisassemblerElf32 : public Disassembler {
const Elf32_Shdr *section_header,
std::vector<size_t>::iterator* current_abs_offset,
std::vector<size_t>::iterator end_abs_offset,
- std::vector<size_t>::iterator* current_rel_offset,
- std::vector<size_t>::iterator end_rel_offset,
+ ScopedVector<TypedRVA>::iterator* current_rel,
+ ScopedVector<TypedRVA>::iterator end_rel,
AssemblyProgram* program) WARN_UNUSED_RESULT;
CheckBool ParseSimpleRegion(size_t start_file_offset,
size_t end_file_offset,
@@ -145,7 +192,7 @@ class DisassemblerElf32 : public Disassembler {
const char *default_string_section_;
std::vector<RVA> abs32_locations_;
- std::vector<RVA> rel32_locations_;
+ ScopedVector<TypedRVA> rel32_locations_;
DISALLOW_COPY_AND_ASSIGN(DisassemblerElf32);
};