retdec
fileimage.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_BIN2LLVMIR_PROVIDERS_FILEIMAGE_H
8 #define RETDEC_BIN2LLVMIR_PROVIDERS_FILEIMAGE_H
9 
10 #include <llvm/IR/Constants.h>
11 #include <llvm/IR/Module.h>
12 #include <llvm/IR/Value.h>
13 
14 #include "retdec/common/address.h"
20 
21 namespace retdec {
22 namespace bin2llvmir {
23 
24 class DebugFormat;
25 
26 class FileImage
27 {
28  // Ctors.
29  //
30  public:
31  FileImage(
32  llvm::Module* m,
33  const std::string& path,
34  Config* config);
35  FileImage(
36  llvm::Module* m,
37  const std::shared_ptr<retdec::fileformat::FileFormat>& ff,
38  Config* config);
39  FileImage(
40  llvm::Module* m,
41  std::unique_ptr<retdec::loader::Image> img,
42  Config* config);
43 
44  void initRtti(Config* config);
45 
46  // Constant getters - get LLVM constant from the given address.
47  //
48  public:
49  llvm::ConstantInt* getConstantInt(
50  llvm::IntegerType* t,
52  llvm::ConstantInt* getConstantDefault(retdec::common::Address addr);
53  llvm::Constant* getConstantHalf(retdec::common::Address addr);
54  llvm::Constant* getConstantFloat(retdec::common::Address addr);
55  llvm::Constant* getConstantDouble(retdec::common::Address addr);
56  llvm::Constant* getConstantLongDouble(retdec::common::Address addr);
57  llvm::Constant* getConstantCharPointer(retdec::common::Address addr);
59  llvm::Constant* getConstantPointer(
60  llvm::PointerType* type,
62  llvm::Constant* getConstantStruct(
63  llvm::StructType* type,
65  llvm::Constant* getConstantArray(
66  llvm::ArrayType* type,
68  llvm::Constant* getConstant(
69  llvm::Type* type,
71  bool wideString = false);
72  llvm::Constant* getConstant(
73  Config* config,
74  DebugFormat* dbgf = nullptr,
76 
77  // Miscellaneous
78  //
79  public:
81  const fileformat::ImportTable* impTbl,
82  const fileformat::Import* imp) const;
83 
84  // Image getters.
85  //
86  public:
88  auto& getSegments() const { return _image->getSegments(); }
89 
90  // FileFormat getters.
91  //
92  public:
94 
95  // Other getters.
96  //
97  public:
99 
100  // Private data.
101  //
102  private:
103  llvm::Module* _module = nullptr;
104  std::unique_ptr<retdec::loader::Image> _image;
106 };
107 
119 {
120  public:
121  static FileImage* addFileImage(
122  llvm::Module* m,
123  const std::string& path,
124  Config* config);
125  static FileImage* addFileImage(
126  llvm::Module* m,
127  const std::shared_ptr<retdec::fileformat::FileFormat>& ff,
128  Config* config);
129 
130  static FileImage* getFileImage(
131  llvm::Module* m);
132  static bool getFileImage(
133  llvm::Module* m,
134  FileImage*& img);
135 
136  static void clear();
137 
138  private:
139  static FileImage* addFileImage(
140  llvm::Module* m,
141  FileImage img);
142 
143  private:
145  static std::map<llvm::Module*, FileImage> _module2image;
146 };
147 
148 } // namespace bin2llvmir
149 } // namespace retdec
150 
151 #endif
ABI information.
Config DB provider for bin2llvmirl.
Debug format provider for bin2llvmirl.
Definition: config.h:24
Definition: debugformat.h:20
Definition: fileimage.h:119
static FileImage * addFileImage(llvm::Module *m, const std::string &path, Config *config)
Definition: fileimage.cpp:636
static std::map< llvm::Module *, FileImage > _module2image
Mapping of modules to file images associated with them.
Definition: fileimage.h:145
static FileImage * getFileImage(llvm::Module *m)
Definition: fileimage.cpp:670
static void clear()
Definition: fileimage.cpp:696
Definition: fileimage.h:27
void initRtti(Config *config)
Definition: fileimage.cpp:103
llvm::Constant * getConstantArray(llvm::ArrayType *type, retdec::common::Address addr)
Definition: fileimage.cpp:292
llvm::Constant * getConstantFloat(retdec::common::Address addr)
Definition: fileimage.cpp:154
const retdec::rtti_finder::RttiFinder & getRtti() const
Definition: fileimage.cpp:125
FileImage(llvm::Module *m, const std::string &path, Config *config)
Definition: fileimage.cpp:24
llvm::Module * _module
Definition: fileimage.h:103
retdec::fileformat::FileFormat * getFileFormat() const
Definition: fileimage.cpp:120
llvm::Constant * getConstantCharPointer(retdec::common::Address addr)
Definition: fileimage.cpp:193
llvm::Constant * getConstantStruct(llvm::StructType *type, retdec::common::Address addr)
Definition: fileimage.cpp:270
llvm::Constant * getConstantDouble(retdec::common::Address addr)
Definition: fileimage.cpp:166
std::unique_ptr< retdec::loader::Image > _image
Definition: fileimage.h:104
auto & getSegments() const
Definition: fileimage.h:88
llvm::Constant * getConstantLongDouble(retdec::common::Address addr)
Definition: fileimage.cpp:178
llvm::Constant * getConstant(llvm::Type *type, retdec::common::Address addr=retdec::common::Address::Undefined, bool wideString=false)
Definition: fileimage.cpp:337
llvm::ConstantInt * getConstantInt(llvm::IntegerType *t, retdec::common::Address addr)
Definition: fileimage.cpp:130
llvm::ConstantInt * getConstantDefault(retdec::common::Address addr)
Definition: fileimage.cpp:144
llvm::Constant * getConstantHalf(retdec::common::Address addr)
Definition: fileimage.cpp:149
retdec::rtti_finder::RttiFinder _rtti
Definition: fileimage.h:105
bool isImportTerminating(const fileformat::ImportTable *impTbl, const fileformat::Import *imp) const
Definition: fileimage.cpp:572
retdec::loader::Image * getImage() const
Definition: fileimage.cpp:115
llvm::Constant * getConstantCharArrayNice(retdec::common::Address addr)
Definition: fileimage.cpp:229
llvm::Constant * getConstantPointer(llvm::PointerType *type, retdec::common::Address addr)
Definition: fileimage.cpp:248
Definition: address.h:21
static const uint64_t Undefined
Definition: address.h:47
Definition: file_format.h:45
Definition: import_table.h:22
Definition: import.h:19
Definition: image.h:22
Definition: rtti_finder.h:24
Address, address pair and other derived class representation.
Declaration of loadable image class.
The frontend-end part of the decompiler.
Definition: archive_wrapper.h:19
Find C++ RTTI structures in Image.