retdec
resource.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_FILEFORMAT_TYPES_RESOURCE_TABLE_RESOURCE_H
8 #define RETDEC_FILEFORMAT_TYPES_RESOURCE_TABLE_RESOURCE_H
9 
10 #include <string>
11 #include <vector>
12 
13 #include <llvm/ADT/StringRef.h>
14 
15 namespace retdec {
16 namespace fileformat {
17 
18 class FileFormat;
19 
23 class Resource
24 {
25  private:
26  std::string crc32;
27  std::string md5;
28  std::string sha256;
29  std::string name;
30  std::string type;
31  std::string language;
32  llvm::StringRef bytes;
33  std::size_t offset = 0;
34  std::size_t size = 0;
35  std::size_t nameId = 0;
36  std::size_t typeId = 0;
37  std::size_t languageId = 0;
38  std::size_t sublanguageId = 0;
39  bool nameIdIsValid = false;
40  bool typeIdIsValid = false;
41  bool languageIdIsValid = false;
42  bool sublanguageIdIsValid = false;
43  bool loaded = false;
44  public:
47  std::string getCrc32() const;
48  std::string getMd5() const;
49  std::string getSha256() const;
50  std::string getName() const;
51  std::string getType() const;
52  std::string getLanguage() const;
53  const llvm::StringRef getBytes(std::size_t sOffset = 0, std::size_t sSize = 0) const;
54  std::size_t getOffset() const;
55  std::size_t getSizeInFile() const;
56  std::size_t getLoadedSize() const;
57  bool getNameId(std::size_t &rId) const;
58  bool getTypeId(std::size_t &rId) const;
59  bool getLanguageId(std::size_t &rId) const;
60  bool getSublanguageId(std::size_t &rId) const;
62 
65  bool getBits(std::string &sResult) const;
66  bool getBytes(std::vector<unsigned char> &sResult, std::size_t sOffset = 0, std::size_t sSize = 0) const;
67  bool getString(std::string &sResult, std::size_t sOffset = 0, std::size_t sSize = 0) const;
68  bool getHexBytes(std::string &sResult) const;
70 
73  void setName(std::string rName);
74  void setType(std::string rType);
75  void setLanguage(std::string rLan);
76  void setOffset(std::size_t rOffset);
77  void setSizeInFile(std::size_t rSize);
78  void setNameId(std::size_t rId);
79  void setTypeId(std::size_t rId);
80  void setLanguageId(std::size_t rId);
81  void setSublanguageId(std::size_t rId);
83 
86  bool isLoaded() const;
87  bool hasValidName() const;
88  bool hasValidId() const;
89  void invalidateNameId();
90  void invalidateTypeId();
91  void invalidateLanguageId();
93  void load(const FileFormat *rOwner);
94  bool hasCrc32() const;
95  bool hasMd5() const;
96  bool hasSha256() const;
97  bool hasEmptyName() const;
98  bool hasEmptyType() const;
99  bool hasEmptyLanguage() const;
101 };
102 
103 } // namespace fileformat
104 } // namespace retdec
105 
106 #endif
Definition: file_format.h:45
Definition: resource.h:24
void load(const FileFormat *rOwner)
Definition: resource.cpp:416
void invalidateLanguageId()
Definition: resource.cpp:394
std::string name
resource name
Definition: resource.h:29
void setSizeInFile(std::size_t rSize)
Definition: resource.cpp:294
std::size_t sublanguageId
resource sublanguage identifier
Definition: resource.h:38
bool getNameId(std::size_t &rId) const
Definition: resource.cpp:129
void setTypeId(std::size_t rId)
Definition: resource.cpp:313
std::size_t offset
offset in file
Definition: resource.h:33
llvm::StringRef bytes
reference to resource data
Definition: resource.h:32
bool loaded
true if content of resource was successfully loaded from input file
Definition: resource.h:43
bool hasValidName() const
Definition: resource.cpp:352
bool hasValidId() const
Definition: resource.cpp:361
bool getString(std::string &sResult, std::size_t sOffset=0, std::size_t sSize=0) const
Definition: resource.cpp:232
bool hasEmptyName() const
Definition: resource.cpp:467
std::string getName() const
Definition: resource.cpp:54
void invalidateTypeId()
Definition: resource.cpp:383
std::string sha256
SHA256 of resource content.
Definition: resource.h:28
std::string getCrc32() const
Definition: resource.cpp:27
std::string crc32
CRC32 of resource content.
Definition: resource.h:26
std::size_t size
size in file
Definition: resource.h:34
bool hasEmptyType() const
Definition: resource.cpp:475
std::string getType() const
Definition: resource.cpp:63
void setSublanguageId(std::size_t rId)
Definition: resource.cpp:333
bool getHexBytes(std::string &sResult) const
Definition: resource.cpp:248
bool typeIdIsValid
true if type ID is valid
Definition: resource.h:40
void setLanguageId(std::size_t rId)
Definition: resource.cpp:323
void invalidateNameId()
Definition: resource.cpp:372
bool hasEmptyLanguage() const
Definition: resource.cpp:483
std::string language
resource language
Definition: resource.h:31
bool getSublanguageId(std::size_t &rId) const
Definition: resource.cpp:180
std::string getMd5() const
Definition: resource.cpp:36
std::size_t languageId
resource language identifier
Definition: resource.h:37
bool getBits(std::string &sResult) const
Definition: resource.cpp:195
bool sublanguageIdIsValid
true if sublanguage ID is valid
Definition: resource.h:42
void setName(std::string rName)
Definition: resource.cpp:258
void setOffset(std::size_t rOffset)
Definition: resource.cpp:285
bool getLanguageId(std::size_t &rId) const
Definition: resource.cpp:163
bool nameIdIsValid
true if name ID is valid
Definition: resource.h:39
std::string type
resource type
Definition: resource.h:30
bool isLoaded() const
Definition: resource.cpp:343
std::string getSha256() const
Definition: resource.cpp:45
std::string getLanguage() const
Definition: resource.cpp:72
void setType(std::string rType)
Definition: resource.cpp:267
void setLanguage(std::string rLan)
Definition: resource.cpp:276
std::size_t getOffset() const
Definition: resource.cpp:99
bool hasSha256() const
Definition: resource.cpp:459
std::size_t typeId
resource type identifier
Definition: resource.h:36
void invalidateSublanguageId()
Definition: resource.cpp:405
void setNameId(std::size_t rId)
Definition: resource.cpp:303
const llvm::StringRef getBytes(std::size_t sOffset=0, std::size_t sSize=0) const
Definition: resource.cpp:85
bool languageIdIsValid
true if language ID is valid
Definition: resource.h:41
std::size_t nameId
resource name identifier
Definition: resource.h:35
bool hasCrc32() const
Definition: resource.cpp:441
std::string md5
MD5 of resource content.
Definition: resource.h:27
bool getTypeId(std::size_t &rId) const
Definition: resource.cpp:146
bool hasMd5() const
Definition: resource.cpp:450
std::size_t getSizeInFile() const
Definition: resource.cpp:108
std::size_t getLoadedSize() const
Definition: resource.cpp:117
Definition: archive_wrapper.h:19