Skip to content
API Documentation
BastionGuard™
SignatureScanner Class Reference

#include <signature_scanner.hpp>

Static Public Member Functions

static std::vector< ScanResult > scan (DiskReader &reader, std::vector< std::string > &logs)

Detailed Description

Definition at line 7 of file signature_scanner.hpp.

Member Function Documentation

◆ scan()

std::vector< ScanResult > SignatureScanner::scan ( DiskReader & reader,
std::vector< std::string > & logs )
static

Definition at line 41 of file signature_scanner.cpp.

41 {
42 std::vector<ScanResult> out;
43 const uint64_t max_scan = reader.size() > 8 * GiB ? 8 * GiB : reader.size();
44 const uint64_t stride = adaptive_stride(reader.size());
45 logs.push_back(trs("Signature scan: starting filesystem signature scan."));
46 logs.push_back(trs("Signature scan stride:") + std::string(" ") + std::to_string(stride / MiB) + " MiB");
47
48 for (uint64_t offset = 0; offset + 4096 < max_scan; offset += stride) {
49 std::array<unsigned char, 512> sector{};
50 if (!reader.read_at(offset, sector.data(), sector.size())) {
51 continue;
52 }
53 if (is_ntfs(sector)) {
54 out.push_back({ResultKind::FilesystemCandidate, offset, 0, "NTFS candidate", "Signature scan", trs("NTFS boot sector detected"), 0.80});
55 }
56 if (is_fat32(sector)) {
57 out.push_back({ResultKind::FilesystemCandidate, offset, 0, "FAT32 candidate", "Signature scan", trs("FAT32 boot sector detected"), 0.78});
58 }
59 if (is_exfat(sector)) {
60 out.push_back({ResultKind::FilesystemCandidate, offset, 0, "exFAT candidate", "Signature scan", trs("exFAT boot sector detected"), 0.82});
61 }
62 if (looks_ext4(reader, offset)) {
63 out.push_back({ResultKind::FilesystemCandidate, offset, 0, "ext4 candidate", "Signature scan", trs("ext4 superblock detected"), 0.76});
64 }
65 if (looks_btrfs(reader, offset)) {
66 out.push_back({ResultKind::FilesystemCandidate, offset, 0, "Btrfs candidate", "Signature scan", trs("Btrfs superblock detected"), 0.79});
67 }
68 }
69
70 logs.push_back(trs("Signature scan: completed."));
71 return out;
72}
bool read_at(uint64_t offset, void *buffer, size_t len)
uint64_t size() const
std::string trs(const char *msgid)
Definition i18n.cpp:22
@ FilesystemCandidate
Definition models.hpp:10
bool is_exfat(const std::array< unsigned char, 512 > &sector)
bool is_fat32(const std::array< unsigned char, 512 > &sector)
bool looks_btrfs(DiskReader &reader, uint64_t offset)
bool is_ntfs(const std::array< unsigned char, 512 > &b)
bool looks_ext4(DiskReader &reader, uint64_t offset)

References FilesystemCandidate, DiskReader::read_at(), DiskReader::size(), and trs().

Referenced by ScannerEngine::run_scan().


The documentation for this class was generated from the following files: