ROSE  0.9.10.95
ModulesElf.h
1 #ifndef ROSE_Partitioner2_ModulesElf_H
2 #define ROSE_Partitioner2_ModulesElf_H
3 
4 #include <Partitioner2/BasicTypes.h>
5 #include <Partitioner2/Function.h>
6 #include <Partitioner2/Modules.h>
7 
8 #include <boost/filesystem.hpp>
9 
10 namespace Rose {
11 namespace BinaryAnalysis {
12 namespace Partitioner2 {
13 
15 namespace ModulesElf {
16 
23 std::vector<Function::Ptr> findErrorHandlingFunctions(SgAsmElfFileHeader*);
24 std::vector<Function::Ptr> findErrorHandlingFunctions(SgAsmInterpretation*);
25 size_t findErrorHandlingFunctions(SgAsmElfFileHeader*, std::vector<Function::Ptr>&);
31 std::vector<Function::Ptr> findPltFunctions(const Partitioner&, SgAsmElfFileHeader*);
32 std::vector<Function::Ptr> findPltFunctions(const Partitioner&, SgAsmInterpretation*);
33 size_t findPltFunctions(const Partitioner&, SgAsmElfFileHeader*, std::vector<Function::Ptr>&);
40 bool isImport(const Partitioner&, const Function::Ptr&);
41 
46 bool isLinkedImport(const Partitioner&, const Function::Ptr&);
47 
51 bool isUnlinkedImport(const Partitioner&, const Function::Ptr&);
52 
57 bool isObjectFile(const boost::filesystem::path&);
58 
63 bool isStaticArchive(const boost::filesystem::path&);
64 
66 namespace FixUndefinedSymbols {
68 enum Boolean {
69  NO,
70  YES
71 };
72 } // namespace
73 
78 bool tryLink(const std::string &command, std::string outputName, std::vector<std::string> inputNames,
80 
84  rose_addr_t baseVa_; // base address for computing memAddress_
85  rose_addr_t gotEntryVa_; // address through which an indirect branch branches
86  size_t gotEntryNBytes_; // size of the global offset table entry in bytes
87  rose_addr_t gotEntry_; // address read from the GOT if the address is mapped (or zero)
88  size_t nBytesMatched_; // number of bytes matched for PLT entry
89 
90 public:
91  PltEntryMatcher(rose_addr_t base)
92  : baseVa_(base), gotEntryVa_(0), gotEntryNBytes_(0), gotEntry_(0), nBytesMatched_(0) {}
93  static Ptr instance(rose_addr_t base) { return Ptr(new PltEntryMatcher(base)); }
94  virtual bool match(const Partitioner&, rose_addr_t anchor);
95 
97  size_t nBytesMatched() const { return nBytesMatched_; }
98 
100  rose_addr_t gotEntryVa() const { return gotEntryVa_; }
101 
103  size_t gotEntryNBytes() const { return gotEntryNBytes_; }
104 
106  rose_addr_t gotEntry() const { return gotEntry_; }
107 
108  // [Robb Matzke 2018-04-06]: deprecated: use gotEntryVa
109  rose_addr_t memAddress() const { return gotEntryVa_; }
110 };
111 
113 void buildMayReturnLists(Partitioner&);
114 
115 } // namespace
116 } // namespace
117 } // namespace
118 } // namespace
119 
120 #endif
std::vector< Function::Ptr > findPltFunctions(const Partitioner &, SgAsmElfFileHeader *)
Reads ELF PLT sections and returns a list of functions.
rose_addr_t gotEntry() const
Value stored in the GOT entry.
Definition: ModulesElf.h:106
bool isObjectFile(const boost::filesystem::path &)
True if named file is an ELF object file.
Represents the file header of an ELF binary container.
bool isStaticArchive(const boost::filesystem::path &)
True if named file is a static library archive.
rose_addr_t gotEntryVa() const
Address of the corresponding GOT entry.
Definition: ModulesElf.h:100
void buildMayReturnLists(Partitioner &)
Build may-return white and black lists.
Main namespace for the ROSE library.
Base class for matching an instruction pattern.
Definition: Modules.h:77
std::vector< Function::Ptr > findErrorHandlingFunctions(SgAsmElfFileHeader *)
Reads ELF .eh_frames to find function entry addresses.
virtual bool match(const Partitioner &, rose_addr_t anchor)
Attempt to match an instruction pattern.
bool isLinkedImport(const Partitioner &, const Function::Ptr &)
True if function is a linked import.
bool isImport(const Partitioner &, const Function::Ptr &)
True if the function is an import.
bool tryLink(const std::string &command, std::string outputName, std::vector< std::string > inputNames, Sawyer::Message::Stream &errors, FixUndefinedSymbols::Boolean fixUndefinedSymbols=FixUndefinedSymbols::YES)
Try to run a link command.
size_t nBytesMatched() const
Size of the PLT entry in bytes.
Definition: ModulesElf.h:97
Sawyer::SharedPointer< InstructionMatcher > Ptr
Shared-ownership pointer to an InstructionMatcher.
Definition: Modules.h:80
Converts text to messages.
Definition: Message.h:1394
Partitions instructions into basic blocks and functions.
Definition: Partitioner.h:293
Represents an interpretation of a binary container.
size_t gotEntryNBytes() const
Size of the GOT entry in bytes.
Definition: ModulesElf.h:103
bool isUnlinkedImport(const Partitioner &, const Function::Ptr &)
True if function is a non-linked import.