1. Overview
The encryption_support.cpp file implements higher-level detection and unlock workflows for encrypted recovery targets.
This is an implementation file. It contains executable logic for the subsystem, including parsing, I/O, validation, recovery flow, or graphical behavior declared by the corresponding interface.
Its paired source or interface file is encryption_support.hpp.
Primary responsibilities:
- Detect encrypted candidates among scan results
- Invoke required helper tools
- Track temporary mappings and mounts
- Clean up privileged resources reliably
2. File Identity and Scope
- Source path:
src/encryption_support.cpp - Language: C++
- File role: implementation file
- Physical lines: 557
- Non-empty lines: 505
- SHA-256:
e8cb266d019d91b33197d3c0eb80d216ea153a5ef2779f43ad8c476484499b93
The declarations in this file use the global namespace.
3. Dependencies
3.1 Project Headers
encryption_support.hppi18n.hppunistd.h
3.2 Standard and External Headers
algorithmarraycstdiocstdlibfilesystemfstreamsetsstreamstringvector
These dependencies define the file’s compile-time integration with the recovery engine, GTK interface, on-disk format decoders, operating-system services, or C++ standard library.
4. Declared Types
No class, structure, or enumeration definition is declared directly in this file.
5. Constants and Configuration Values
No preprocessor or compile-time constants were detected as top-level declarations in this file.
5.1 Operational Strings, Paths, Formats, or Commands
The following code literals are operationally relevant and may identify filesystem paths, helper commands, formats, signatures, or subsystem labels:
>/dev/null 2>&1cryptsetupcryptsetup not availablecryptsetup open --readonly --type luks --key-filecryptsetup open failed/dev/mapper/Unlocked LUKS container through cryptsetup:Unlocked LUKS container through cryptsetup key file:dislockerdislocker or losetup not available_dislockerdislocker -r -Vdislocker faileddislocker-filedislocker-file not producedUnlocked BitLocker container through dislocker:cryptsetup closeThe engine will attempt external read-only unlock through cryptsetup/dislocker when available.
6. Data Members and Persistent State
No class data members are declared directly in this file, or the file primarily implements methods declared elsewhere.
7. API and Function Inventory
The following callable interfaces or definitions were detected:
uint16_t be16(const unsigned char*p)– Implements the operation identified by this API and updates or returns the associated state.uint32_t le32(const unsigned char*p)– Implements the operation identified by this API and updates or returns the associated state.uint64_t le64(const unsigned char*p)– Implements the operation identified by this API and updates or returns the associated state.std::string sanitize_name(const std::string&in)– Implements the operation identified by this API and updates or returns the associated state.bool write_bytes(DiskReader&reader,uint64_t offset,uint64_t length,const fs::path&out_path,std::string&error)– Persists or exports the supplied state to the relevant destination.bool command_exists(const std::string&name)– Implements the operation identified by this API and updates or returns the associated state.std::string shell_quote(const std::string&s)– Implements the operation identified by this API and updates or returns the associated state.bool run_command_capture(const std::string&cmd,std::string&output,int&rc)– Implements the operation identified by this API and updates or returns the associated state.std::string trim_copy(std::string s)– Implements the operation identified by this API and updates or returns the associated state.std::string getenv_str(const char*name)– Implements the operation identified by this API and updates or returns the associated state.std::string getenv_existing_file(const char*name)– Implements the operation identified by this API and updates or returns the associated state.bool is_partition_like_seed(const ScanResult&seed)– Evaluates the stated condition and returns the corresponding Boolean result.std::vector<uint64_t> candidate_offsets(const std::vector<ScanResult>&seed_results)– Implements the operation identified by this API and updates or returns the associated state.ScanResult probe_luks(DiskReader&reader,uint64_t offset)– Inspects the source and reports matching candidates or detected metadata.ScanResult probe_bitlocker(DiskReader&reader,uint64_t offset)– Inspects the source and reports matching candidates or detected metadata.bool ensure_parent_created(const fs::path&p,std::string&error)– Implements the operation identified by this API and updates or returns the associated state.bool create_loop_for_offset(const std::string&source_path,uint64_t offset,std::string&loop_path,std::vector<std::string>&logs,std::string&error)– Constructs the requested object, data structure or user-interface component.bool cryptsetup_open(const std::string&source_path,uint64_t offset,const std::string&passphrase,UnlockSession&session,std::vector<std::string>&logs,std::string&error)– Implements the operation identified by this API and updates or returns the associated state.bool cryptsetup_open_with_keyfile(const std::string&source_path,uint64_t offset,const std::string&keyfile,UnlockSession&session,std::vector<std::string>&logs,std::string&error)– Implements the operation identified by this API and updates or returns the associated state.bool dislocker_open(const std::string&source_path,uint64_t offset,const std::string&credential,bool use_recovery_key,UnlockSession&session,std::vector<std::string>&logs,std::string&error)– Implements the operation identified by this API and updates or returns the associated state.void UnlockSession::cleanup(std::vector<std::string>&logs)– Manages the corresponding resource lifecycle or resets internal state.std::vector<ScanResult> EncryptionSupport::detect_encrypted_volumes(DiskReader&reader,const std::vector<ScanResult>&seed_results,std::vector<std::string>&logs)– Inspects the source and reports matching candidates or detected metadata.bool EncryptionSupport::export_encrypted_metadata(DiskReader&reader,const ScanResult&result,const std::string&output_dir,std::vector<std::string>&logs,std::string&error)– Persists or exports the supplied state to the relevant destination.} catch(const std::exception&ex)– Implements the operation identified by this API and updates or returns the associated state.bool EncryptionSupport::try_unlock_volume(const std::string&source_path,const ScanResult&result,UnlockSession&session,std::vector<std::string>&logs,std::string&error)– Implements the operation identified by this API and updates or returns the associated state.
8. Operational Flow
The subsystem represented by this file normally participates in the following flow:
- Detect encrypted candidates among scan results.
- Invoke required helper tools.
- Track temporary mappings and mounts.
- Clean up privileged resources reliably.
- Expose or execute the detected APIs:
be16, le32, le64, sanitize_name, write_bytes, command_exists, shell_quote, run_command_capture, trim_copy, getenv_str, getenv_existing_file, is_partition_like_seed, candidate_offsets, probe_luks, probe_bitlocker, ensure_parent_created, create_loop_for_offset, cryptsetup_openand additional helpers. - Return explicit results, progress data, recovered records, or diagnostics to the calling layer.
9. Validation and Error Handling
- Errors are propagated through Boolean results, error strings, logs, exceptions, or status records depending on the API.
- Byte offsets, sizes and lengths must be validated before arithmetic and before every read to avoid overflow and out-of-bounds access.
- Input and output paths require existence checks, permission handling and safe destination construction.
- The implementation contains explicit failure-catching paths and should retain the original diagnostic context.
10. Runtime, Concurrency, and Resource Management
- I/O: filesystem and raw-source operations can fail partially and must preserve exact byte counts and diagnostic context.
- Privileges: some paths involve raw devices, mappings or mounts and therefore require carefully bounded elevated execution.
- Error handling: explicit error, exception or optional-result paths are present and form part of the file contract.
- File descriptors and streams must be closed on success, cancellation and error paths.
- Temporary loop devices, mappings and mounts require deterministic reverse-order cleanup.
11. Security and Data-Recovery Considerations
- Recovery code should prefer read-only source access and avoid writing to the original damaged medium.
- Raw devices and image files are treated as untrusted binary input; every offset and length must remain bounded by the source size.
- Recovered names and destination paths must be sanitized to prevent directory traversal and accidental overwrite outside the selected export directory.
- Operations that open block devices, create mappings or mount filesystems require elevated privileges and should expose the smallest possible privileged surface.
- Passphrases, keys and unlock parameters must not be written to logs or retained longer than required.
12. Implementation Considerations
- The implementation should remain aligned with declarations in the paired header and preserve documented return-value semantics.
- Binary decoding uses low-level memory operations or casts; alignment, endianness and packed-structure assumptions require careful review.
- Large-device arithmetic uses 64-bit values; additions and multiplications should be checked before use as offsets or allocation sizes.
- Filesystem operations can cross trust boundaries and should use normalized, contained destination paths.
13. Integration with the Recovery Pipeline
- The file belongs to the source-discovery, parsing or support layer.
- Its results feed scanner, recovery or reporting modules through shared models.
- The API should remain deterministic so higher layers can combine results safely.
14. Licensing and Provenance
No explicit copyright or software-license statement was detected in the opening section of this individual file. Distribution terms should therefore be verified against the project-level license and repository metadata.
The SHA-256 value in this document can be used to associate the generated documentation with the exact source version analyzed.
