ROSE 0.11.145.276
JumpTable.h
1#ifndef ROSE_BinaryAnalysis_Partitioner2_JumpTable_H
2#define ROSE_BinaryAnalysis_Partitioner2_JumpTable_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5#include <Rose/BinaryAnalysis/Partitioner2/MemoryTable.h>
6
7namespace Rose {
8namespace BinaryAnalysis {
9namespace Partitioner2 {
10
15class JumpTable: public MemoryTable {
16public:
25 enum class EntryType {
26 ABSOLUTE,
28 };
29
38 public:
39 using Ptr = std::shared_ptr<Entries>;
40
41 private:
42 std::vector<Address> targets_;
43
44 protected:
45 Entries();
46 public:
47 static Ptr instance();
48
49 public:
51 const std::vector<Address>& targets() const;
52
53 public:
54 size_t size() const override;
55 bool maybeAppend(const MemoryTable*, Address entryAddr, const std::vector<uint8_t> &bytes) override;
56 bool maybePrepend(const MemoryTable*, Address entryAddr, const std::vector<uint8_t> &bytes) override;
57
58 private:
59 // Parse a jump table entry and return the potential target address
60 Address parseEntry(const JumpTable*, const std::vector<uint8_t> &bytes) const;
61
62 // Test whether a potential target address is valid
63 bool isValidTarget(const JumpTable*, Address target) const;
64 };
65
66private:
67 PartitionerConstPtr partitioner_;
68 Address perEntryOffset_ = 0;
69 EntryType entryType_ = EntryType::ABSOLUTE;
70 AddressInterval targetLimits_;
71
72protected:
75public:
77 static Ptr
80
81public:
86
91
98
108public:
110 const std::vector<Address>& targets() const;
111
113 std::set<Address> uniqueTargets() const;
114
115public:
117 void refineLocationLimits(const BasicBlockPtr&, Address probableTableAddr);
118
123
128
133
139};
140
141} // namespace
142} // namespace
143} // namespace
144
145#endif
146#endif
bool maybeAppend(const MemoryTable *, Address entryAddr, const std::vector< uint8_t > &bytes) override
Parse a table entry and append to this list if the entry is valid.
bool maybePrepend(const MemoryTable *, Address entryAddr, const std::vector< uint8_t > &bytes) override
Parse a table entry and prepend to this list if the entry is valid.
size_t size() const override
Number of entries stored.
const std::vector< Address > & targets() const
Return the targets.
Utilities for working with jump tables.
Definition JumpTable.h:15
std::set< Address > uniqueTargets() const
Result: Unique target addresses parsed from the table.
JumpTablePtr Ptr
Shared ownership pointer.
Definition JumpTable.h:20
EntryType
How target addresses are computed from entries.
Definition JumpTable.h:25
@ ABSOLUTE
Target is entry plus (nominally zero) constant offset.
@ TABLE_RELATIVE
Like ABSOLUTE but add the table address.
PartitionerConstPtr partitioner() const
Property: Partitioner supplied to the constructor.
void attachTableToBasicBlock(const BasicBlockPtr &) const
Create a data block and attach it to the specified basic block.
Address perEntryOffset() const
Property: Offset added to each table entry when calculating the target address.
JumpTableConstPtr ConstPtr
Shared ownership pointer.
Definition JumpTable.h:21
void replaceBasicBlockSuccessors(const PartitionerConstPtr &, const BasicBlockPtr &) const
Change basic block successors to be the table's targets.
AddressInterval targetLimits() const
Property: Predicate to determine whether a target is valid.
static Ptr instance(const PartitionerConstPtr &, const AddressInterval &tableLimits, size_t bytesPerEntry, Address perEntryOffset, EntryType)
Allocating constructor.
void refineTargetLimits(const BasicBlockPtr &)
Refine target limits based on a particular basic block.
const std::vector< Address > & targets() const
Result: Target addresses parsed from the table.
DataBlockPtr createDataBlock() const
Build a data block to represent the table.
void refineLocationLimits(const BasicBlockPtr &, Address probableTableAddr)
Refine the table limits based on a particular basic block.
void targetLimits(const AddressInterval &)
Property: Predicate to determine whether a target is valid.
EntryType entryType() const
Property: Entry type.
Utilities for working with tables.
Definition MemoryTable.h:18
size_t bytesPerEntry() const
Property: Bytes per entry.
AddressInterval tableLimits() const
Property: Limits for table location.
std::shared_ptr< const JumpTable > JumpTableConstPtr
Shared-ownership pointer for JumpTable.
std::shared_ptr< JumpTable > JumpTablePtr
Shared-ownership pointer for JumpTable.
std::uint64_t Address
Address.
Definition Address.h:11
The ROSE library.