Skip to content
API Documentation
BastionGuard™
anonymous_namespace{encrypted_volume_support.cpp} Namespace Reference

Functions

uint16_t be16 (const unsigned char *p)
uint16_t le16 (const unsigned char *p)
uint32_t le32 (const unsigned char *p)
uint64_t le64 (const unsigned char *p)
bool read_bytes (DiskReader &reader, uint64_t offset, void *buffer, size_t len)
ScanResult luks_probe (DiskReader &reader, uint64_t offset)
ScanResult bitlocker_probe (DiskReader &reader, uint64_t offset)

Function Documentation

◆ be16()

uint16_t anonymous_namespace{encrypted_volume_support.cpp}::be16 ( const unsigned char * p)

Definition at line 11 of file encrypted_volume_support.cpp.

11 {
12 return (static_cast<uint16_t>(p[0]) << 8) | static_cast<uint16_t>(p[1]);
13}

References be16().

Referenced by be16(), and luks_probe().

◆ bitlocker_probe()

ScanResult anonymous_namespace{encrypted_volume_support.cpp}::bitlocker_probe ( DiskReader & reader,
uint64_t offset )

Definition at line 74 of file encrypted_volume_support.cpp.

74 {
75 std::array<unsigned char, 512> sector{};
76 if (!read_bytes(reader, offset, sector.data(), sector.size())) return {};
77
78 const std::string oem(reinterpret_cast<const char*>(sector.data() + 3), 8);
79 const std::string fve(reinterpret_cast<const char*>(sector.data() + 0x03), 11);
80 const bool has_fvefs = oem == "-FVE-FS-" || fve.find("FVE-FS") != std::string::npos;
81 if (!has_fvefs) return {};
82
83 std::ostringstream detail;
84 detail << "BitLocker/FVE metadata detected";
85 const uint16_t bps = le16(sector.data() + 11);
86 const uint8_t spc = sector[13];
87 if (bps != 0 && spc != 0) {
88 detail << ", bytes/sector: " << bps << ", sectors/cluster: " << static_cast<unsigned>(spc);
89 }
90 detail << ", encrypted container detected (data recovery requires recovery key/password or an already unlocked device)";
91
93 offset,
94 reader.size() > offset ? (reader.size() - offset) : 0,
95 "BitLocker volume",
96 "Encrypted volume probe",
97 detail.str(),
98 0.97};
99}
uint64_t size() const
@ FilesystemVolume
Definition models.hpp:11
bool read_bytes(DiskReader &reader, uint64_t offset, void *buffer, size_t len)

References bitlocker_probe(), FilesystemVolume, le16(), read_bytes(), and DiskReader::size().

Referenced by bitlocker_probe().

◆ le16()

uint16_t anonymous_namespace{encrypted_volume_support.cpp}::le16 ( const unsigned char * p)

Definition at line 15 of file encrypted_volume_support.cpp.

15 {
16 return static_cast<uint16_t>(p[0]) | (static_cast<uint16_t>(p[1]) << 8);
17}

References le16().

Referenced by bitlocker_probe(), and le16().

◆ le32()

uint32_t anonymous_namespace{encrypted_volume_support.cpp}::le32 ( const unsigned char * p)

Definition at line 19 of file encrypted_volume_support.cpp.

19 {
20 return static_cast<uint32_t>(p[0]) |
21 (static_cast<uint32_t>(p[1]) << 8) |
22 (static_cast<uint32_t>(p[2]) << 16) |
23 (static_cast<uint32_t>(p[3]) << 24);
24}

References le32().

Referenced by le32(), and luks_probe().

◆ le64()

uint64_t anonymous_namespace{encrypted_volume_support.cpp}::le64 ( const unsigned char * p)

Definition at line 26 of file encrypted_volume_support.cpp.

26 {
27 return static_cast<uint64_t>(p[0]) |
28 (static_cast<uint64_t>(p[1]) << 8) |
29 (static_cast<uint64_t>(p[2]) << 16) |
30 (static_cast<uint64_t>(p[3]) << 24) |
31 (static_cast<uint64_t>(p[4]) << 32) |
32 (static_cast<uint64_t>(p[5]) << 40) |
33 (static_cast<uint64_t>(p[6]) << 48) |
34 (static_cast<uint64_t>(p[7]) << 56);
35}

References le64().

Referenced by le64(), and luks_probe().

◆ luks_probe()

ScanResult anonymous_namespace{encrypted_volume_support.cpp}::luks_probe ( DiskReader & reader,
uint64_t offset )

Definition at line 41 of file encrypted_volume_support.cpp.

41 {
42 std::array<unsigned char, 4096> hdr{};
43 if (!read_bytes(reader, offset, hdr.data(), hdr.size())) return {};
44 if (!(hdr[0] == 'L' && hdr[1] == 'U' && hdr[2] == 'K' && hdr[3] == 'S' && hdr[4] == 0xBA && hdr[5] == 0xBE)) {
45 return {};
46 }
47
48 const uint16_t version = be16(hdr.data() + 6);
49 std::ostringstream detail;
50 uint64_t payload_offset = 0;
51 if (version == 1) {
52 const uint32_t payload_sectors = le32(hdr.data() + 104);
53 payload_offset = static_cast<uint64_t>(payload_sectors) * 512ull;
54 detail << "LUKS1, payload offset: " << payload_offset << " bytes";
55 } else if (version == 2) {
56 // We intentionally avoid a full JSON parser here; this is enough to identify container geometry safely.
57 const uint64_t hdr_size = le64(hdr.data() + 8);
58 payload_offset = hdr_size >= 4096 ? hdr_size * 2ull : (16ull * 1024 * 1024);
59 detail << "LUKS2, metadata area: " << hdr_size << " bytes, estimated payload offset: " << payload_offset << " bytes";
60 } else {
61 detail << "LUKS version " << version;
62 }
63 detail << ", encrypted container detected (data recovery requires passphrase/key material or an already unlocked mapper device)";
64
66 offset,
67 reader.size() > offset ? (reader.size() - offset) : 0,
68 version == 2 ? "LUKS2 container" : "LUKS1 container",
69 "Encrypted volume probe",
70 detail.str(),
71 0.98};
72}

References be16(), FilesystemVolume, le32(), le64(), luks_probe(), read_bytes(), and DiskReader::size().

Referenced by luks_probe().

◆ read_bytes()

bool anonymous_namespace{encrypted_volume_support.cpp}::read_bytes ( DiskReader & reader,
uint64_t offset,
void * buffer,
size_t len )

Definition at line 37 of file encrypted_volume_support.cpp.

37 {
38 return reader.read_at(offset, buffer, len);
39}
bool read_at(uint64_t offset, void *buffer, size_t len)

References DiskReader::read_at(), and read_bytes().

Referenced by bitlocker_probe(), luks_probe(), and read_bytes().