Panoptes 1.0.0
Endpoint Detection and Response
Loading...
Searching...
No Matches
Functions
yara-scan.cpp File Reference
#include "PanoptesYara.h"
#include <iostream>
#include <fstream>
#include <stdexcept>

Go to the source code of this file.

Functions

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.
 

Function Documentation

◆ matchingRule()

void matchingRule ( const struct YRX_RULE *  rule,
void *  user_data 
)

Callback function for the YARA rules.

Parameters
ruleThe rule that was matched
user_dataThe 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 //yrx_rule_iter_metadata(rule, metaCallback, user_data);
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
filenameThe 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; // Return empty buffer
16 }
17
18 // Get the file size
19 std::streamsize size = file.tellg();
20 file.seekg(0, std::ios::beg);
21
22 // Reserve space in the buffer
23 buffer.resize(size);
24
25 // Read the file
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(); // Clear the buffer on error
29 }
30
31 file.close();
32 return buffer;
33}

Referenced by YaraScanner::YaraScanFile(), and YaraScanner::YaraScanner().