#include "PanoptesYara.h"
#include <iostream>
#include <fstream>
#include <stdexcept>
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 63 of file yara-scan.cpp.
63 {
64 const uint8_t* ns;
65 size_t ns_len;
66 const uint8_t* ident;
67 size_t ident_len;
68 std::vector<string>* detectedRules = (std::vector<string>*)user_data;
69
70
71 yrx_rule_namespace(rule, &ns, &ns_len);
72 yrx_rule_identifier(rule, &ident, &ident_len);
73
74 detectedRules->push_back(std::string(ns, ns + ns_len) + "::" +
75 std::string(ident, ident + ident_len));
76}
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 9 of file yara-scan.cpp.
9 {
10 std::ifstream file(filename, std::ios::binary | std::ios::ate);
11 std::vector<uint8_t> buffer;
12
13 if (!file.is_open()) {
14 std::cerr << "Error: Could not open file " << filename << " for reading." << std::endl;
15 return buffer;
16 }
17
18
19 std::streamsize size = file.tellg();
20 file.seekg(0, std::ios::beg);
21
22
23 buffer.resize(size);
24
25
26 if (!file.read(reinterpret_cast<char*>(buffer.data()), size)) {
27 std::cerr << "Error: Failed to read data from file " << filename << std::endl;
28 buffer.clear();
29 }
30
31 file.close();
32 return buffer;
33}
Referenced by YaraScanner::YaraScanFile(), and YaraScanner::YaraScanner().