ROSE  0.9.11.42
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>&);
39 std::vector<SgAsmElfSection*> findSectionsByName(SgAsmInterpretation*, const std::string&);
40 
45 bool isImport(const Partitioner&, const Function::Ptr&);
46 
51 bool isLinkedImport(const Partitioner&, const Function::Ptr&);
52 
56 bool isUnlinkedImport(const Partitioner&, const Function::Ptr&);
57 
62 bool isObjectFile(const boost::filesystem::path&);
63 
68 bool isStaticArchive(const boost::filesystem::path&);
69 
71 namespace FixUndefinedSymbols {
73 enum Boolean {
74  NO,
75  YES
76 };
77 } // namespace
78 
83 bool tryLink(const std::string &command, const boost::filesystem::path &outputName,
84  std::vector<boost::filesystem::path> inputNames, Sawyer::Message::Stream &errors,
86 
92 std::vector<boost::filesystem::path>
93 extractStaticArchive(const boost::filesystem::path &directory, const boost::filesystem::path &archive);
94 
98  rose_addr_t baseVa_; // base address for computing memAddress_
99  rose_addr_t gotEntryVa_; // address through which an indirect branch branches
100  size_t gotEntryNBytes_; // size of the global offset table entry in bytes
101  rose_addr_t gotEntry_; // address read from the GOT if the address is mapped (or zero)
102  size_t nBytesMatched_; // number of bytes matched for PLT entry
103 
104 public:
105  PltEntryMatcher(rose_addr_t base)
106  : baseVa_(base), gotEntryVa_(0), gotEntryNBytes_(0), gotEntry_(0), nBytesMatched_(0) {}
107  static Ptr instance(rose_addr_t base) { return Ptr(new PltEntryMatcher(base)); }
108  virtual bool match(const Partitioner&, rose_addr_t anchor);
109 
111  size_t nBytesMatched() const { return nBytesMatched_; }
112 
114  rose_addr_t gotEntryVa() const { return gotEntryVa_; }
115 
117  size_t gotEntryNBytes() const { return gotEntryNBytes_; }
118 
120  rose_addr_t gotEntry() const { return gotEntry_; }
121 
122  // [Robb Matzke 2018-04-06]: deprecated: use gotEntryVa
123  rose_addr_t memAddress() const { return gotEntryVa_; }
124 };
125 
127 void buildMayReturnLists(Partitioner&);
128 
129 } // namespace
130 } // namespace
131 } // namespace
132 } // namespace
133 
134 #endif
std::vector< Function::Ptr > findPltFunctions(const Partitioner &, SgAsmElfFileHeader *)
Reads ELF PLT sections and returns a list of functions.
std::vector< SgAsmElfSection * > findSectionsByName(SgAsmInterpretation *, const std::string &)
Get a list of all ELF sections by name.
bool tryLink(const std::string &command, const boost::filesystem::path &outputName, std::vector< boost::filesystem::path > inputNames, Sawyer::Message::Stream &errors, FixUndefinedSymbols::Boolean fixUndefinedSymbols=FixUndefinedSymbols::YES)
Try to run a link command.
rose_addr_t gotEntry() const
Value stored in the GOT entry.
Definition: ModulesElf.h:120
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:114
std::vector< boost::filesystem::path > extractStaticArchive(const boost::filesystem::path &directory, const boost::filesystem::path &archive)
Extract object files from a static archive.
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:78
Reference-counting smart pointer.
Definition: SharedPointer.h:67
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.
size_t nBytesMatched() const
Size of the PLT entry in bytes.
Definition: ModulesElf.h:111
Sawyer::SharedPointer< InstructionMatcher > Ptr
Shared-ownership pointer to an InstructionMatcher.
Definition: Modules.h:81
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:117
bool isUnlinkedImport(const Partitioner &, const Function::Ptr &)
True if function is a non-linked import.