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

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

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