retdec
pattern_extractor.h
Go to the documentation of this file.
1 
7 #ifndef RETDEC_PATTERNGEN_PATTERN_EXTRACTOR_PATTERN_EXTRACTOR_H
8 #define RETDEC_PATTERNGEN_PATTERN_EXTRACTOR_PATTERN_EXTRACTOR_H
9 
10 #include <ostream>
11 #include <string>
12 #include <vector>
13 
15 
16 // Forward declarations.
17 namespace retdec {
18 namespace fileformat {
19  class FileFormat;
20  class Section;
21  class Symbol;
22 } // namespace fileformat
23 } // namespace retdec
24 
25 namespace retdec {
26 namespace patterngen {
27 
32 {
33  private:
34  std::unique_ptr<retdec::fileformat::FileFormat> inputFile;
35 
36  bool stateValid = false;
37  std::string errorMessage;
38  std::vector<std::string> warnings;
39 
40  std::string groupName;
41  std::vector<SymbolPattern> patterns;
42 
48 
51  bool processFile();
52  bool checkPPC64Sections();
53  std::vector<const retdec::fileformat::Symbol*> filterSymbols();
54  void processSymbol(const retdec::fileformat::Symbol *symbol);
55  void processSection(const retdec::fileformat::Section *section);
56  void addSectionPatterns(
57  const retdec::fileformat::Section *section,
58  std::vector<const retdec::fileformat::Symbol *> &symbols);
59  void addPattern(const retdec::fileformat::Section *section,
60  const std::string &name, const unsigned long long offset,
61  const unsigned long long size);
62  std::string getArchAsString();
64 
65  public:
68  PatternExtractor(const std::string &filePath,
69  const std::string &groupName = "unknown_group");
72 
75  bool isValid() const;
76  std::string getErrorMessage() const;
77  std::vector<std::string> getWarnings() const;
79 
82  void printRules(std::ostream &outputStream,
83  const std::string &withNote = "") const;
84  void addRulesToBuilder(yaramod::YaraFileBuilder &builder,
85  const std::string &withNote = "") const;
87 };
88 
89 } // namespace patterngen
90 } // namespace retdec
91 
92 #endif
Definition: section.h:19
Definition: symbol.h:19
Definition: pattern_extractor.h:32
std::string getErrorMessage() const
Definition: pattern_extractor.cpp:551
std::vector< const retdec::fileformat::Symbol * > filterSymbols()
Definition: pattern_extractor.cpp:232
void processSymbol(const retdec::fileformat::Symbol *symbol)
Definition: pattern_extractor.cpp:302
std::string groupName
Name for set of rules.
Definition: pattern_extractor.h:40
PatternExtractor(const std::string &filePath, const std::string &groupName="unknown_group")
Constructors and destructor.
Definition: pattern_extractor.cpp:525
void addPattern(const retdec::fileformat::Section *section, const std::string &name, const unsigned long long offset, const unsigned long long size)
Definition: pattern_extractor.cpp:446
void addSectionPatterns(const retdec::fileformat::Section *section, std::vector< const retdec::fileformat::Symbol * > &symbols)
Definition: pattern_extractor.cpp:402
std::string errorMessage
Error message if invalid state.
Definition: pattern_extractor.h:37
std::unique_ptr< retdec::fileformat::FileFormat > inputFile
Parser.
Definition: pattern_extractor.h:34
bool checkPPC64Sections()
Definition: pattern_extractor.cpp:208
void printRules(std::ostream &outputStream, const std::string &withNote="") const
Output methods.
Definition: pattern_extractor.cpp:572
bool processFile()
Processing methods.
Definition: pattern_extractor.cpp:136
bool isPic32DataObjectOnlyFile()
Strange PIC32 architecture files processing.
Definition: pattern_extractor.cpp:55
void processSection(const retdec::fileformat::Section *section)
Definition: pattern_extractor.cpp:359
std::string getArchAsString()
Definition: pattern_extractor.cpp:494
bool stateValid
Extractor state.
Definition: pattern_extractor.h:36
void addRulesToBuilder(yaramod::YaraFileBuilder &builder, const std::string &withNote="") const
Definition: pattern_extractor.cpp:587
void processPic32DataObjectOnly()
Definition: pattern_extractor.cpp:82
bool isValid() const
Error handling methods.
Definition: pattern_extractor.cpp:541
std::vector< std::string > getWarnings() const
Definition: pattern_extractor.cpp:561
std::vector< SymbolPattern > patterns
Vector of patterns found.
Definition: pattern_extractor.h:41
std::vector< std::string > warnings
Vector with possible warnings.
Definition: pattern_extractor.h:38
Definition: archive_wrapper.h:19
Class representing pattern of one function.