8using namespace sig_finder;
12 for (
size_t i = 0; (i + pattern_size) < buf_size; i++) {
13 if (max_iter != 0 && i > max_iter)
break;
14 if (memcmp(buffer + i, pattern_buf, pattern_size) == 0) {
32 for (
size_t i = 0; i < _countof(
patterns32); i++)
35 std::string name =
"prolog32_" + std::to_string((ULONGLONG)i);
36 Signature sign(name, pattern.
ptr, pattern.
size);
37 if (rootN->addPattern(sign)) {
51 for (
size_t i = 0; i < _countof(
patterns64); i++)
54 std::string name =
"prolog64_" + std::to_string((ULONGLONG)i);
55 Signature sign(name, pattern.
ptr, pattern.
size);
56 if (rootN->addPattern(sign)) {
66 Match m = sig_finder::find_first_match(rootN, loadedData, loadedSize);
77 static sig_finder::Node rootN;
86 static sig_finder::Node rootN;
95 static sig_finder::Node rootN;
96 if (peconv::is_padding(loadedData, loadedSize, 0)) {
111 const bool is_any_exec = (protection & PAGE_EXECUTE_READWRITE)
112 || (protection & PAGE_EXECUTE_READ)
113 || (protection & PAGE_EXECUTE)
114 || (protection & PAGE_EXECUTE_WRITECOPY);
120 const bool is_read = (protection & PAGE_READWRITE)
121 || (protection & PAGE_READONLY);
127 if ((state & MEM_COMMIT) == 0) {
131 if (mapping_type != MEM_IMAGE && (mapping_type != MEM_MAPPED) && mapping_type != MEM_PRIVATE) {
135 if (protection & PAGE_NOACCESS) {
154 static bool isLoaded =
false;
155 if (isLoaded)
return 0;
158 std::vector<Signature*> signatures;
159 Signature::loadFromFile(filename, signatures);
160 const size_t added = mainMatcher.addPatterns(signatures);
162 for (
auto itr = signatures.begin(); itr != signatures.end(); ++itr) {
163 Signature* sign = *itr;
166 std::cout <<
"Added patterns: " << std::dec << added <<
"\n";
173 static bool isLoaded =
false;
174 if (isLoaded)
return false;
187 if (peconv::is_padding(loadedData, loadedSize, 0)) {
190 const size_t matches = sig_finder::find_all_matches(mainMatcher, loadedData, loadedSize, allMatches);
197 size_t customCount = 0;
198 for (
auto itr = allMatches.begin(); itr != allMatches.end(); ++itr) {
199 sig_finder::Match m = *itr;
201 const DWORD checks = m.sign->checksum();
205 customPatternMatches.push_back(m);
#define PATTERN_NOT_FOUND
pesieve::util::Mutex mainMatcherMutex
sig_finder::Node mainMatcher
size_t loadPatternFile(const char *filename)
size_t findAllPatterns(BYTE *loadedData, size_t loadedSize, ::std::vector< sig_finder::Match > &allMatches)
bool initShellcodePatterns()
size_t filterCustom(::std::vector< sig_finder::Match > &allMatches, ::std::vector< sig_finder::Match > &customPatternMatches)
size_t is_32bit_code(BYTE *loadedData, size_t loadedSize)
bool is_readable(DWORD mapping_type, DWORD protection)
BYTE * find_pattern(BYTE *buffer, size_t buf_size, BYTE *pattern_buf, size_t pattern_size, size_t max_iter=0)
bool is_normal_inaccessible(DWORD state, DWORD mapping_type, DWORD protection)
bool is_code(BYTE *loadedData, size_t loadedSize)
bool is_executable(DWORD mapping_type, DWORD protection)
size_t is_64bit_code(BYTE *loadedData, size_t loadedSize)
size_t init_32_patterns(Node *rootN)
size_t search_till_pattern(sig_finder::Node &rootN, const BYTE *loadedData, size_t loadedSize)
pesieve::util::Mutex g_HardcodedPatternsMutex
size_t init_64_patterns(Node *rootN)
std::set< DWORD > HardcodedPatterns