#include "PanoptesYara.h"
#include <iostream>
#include <fstream>
#include <stdexcept>
#include <memory>
Go to the source code of this file.
|
| std::vector< uint8_t > | readFileToBuffer (const std::string &filename) |
| | Read a file to a buffer.
|
| void | matchingRule (const struct YRX_RULE *rule, void *user_data) |
| | Callback function for the YARA rules.
|
◆ matchingRule()
| void matchingRule |
( |
const struct YRX_RULE * | rule, |
|
|
void * | user_data ) |
Callback function for the YARA rules.
- Parameters
-
| rule | The rule that was matched |
| user_data | The user data that was passed to the callback containing the detected rules |
Definition at line 64 of file yara-scan.cpp.
64 {
65 const uint8_t* ns;
66 size_t ns_len;
67 const uint8_t* ident;
68 size_t ident_len;
69 std::vector<string>* detectedRules = (std::vector<string>*)user_data;
70
71
72 yrx_rule_namespace(rule, &ns, &ns_len);
73 yrx_rule_identifier(rule, &ident, &ident_len);
74
75 detectedRules->push_back(std::string(ns, ns + ns_len) + "::" +
76 std::string(ident, ident + ident_len));
77}
Referenced by YaraScanner::YaraScanFile().
◆ readFileToBuffer()
| std::vector< uint8_t > readFileToBuffer |
( |
const std::string & | filename | ) |
|
Read a file to a buffer.
- Parameters
-
| filename | The path to the file to read |
- Returns
- A vector of uint8_t containing the file data
Definition at line 10 of file yara-scan.cpp.
10 {
11 std::ifstream file(filename, std::ios::binary | std::ios::ate);
12 std::vector<uint8_t> buffer;
13
14 if (!file.is_open()) {
15 std::cerr << "Error: Could not open file " << filename << " for reading." << std::endl;
16 return buffer;
17 }
18
19
20 std::streamsize size = file.tellg();
21 file.seekg(0, std::ios::beg);
22
23
24 buffer.resize(size);
25
26
27 if (!file.read(reinterpret_cast<char*>(buffer.data()), size)) {
28 std::cerr << "Error: Failed to read data from file " << filename << std::endl;
29 buffer.clear();
30 }
31
32 file.close();
33 return buffer;
34}
Referenced by YaraScanner::YaraScanFile(), and YaraScanner::YaraScanner().