file_carver

1. Overview

The file_carver.cpp file coordinates signature scanning and extraction of files that cannot be recovered through filesystem metadata.

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 file_carver.hpp.

Primary responsibilities:

  • Select carving signatures
  • Scan raw ranges
  • Validate and export candidate files
  • Report carved-file records and errors

2. File Identity and Scope

  • Source path: src/file_carver.cpp
  • Language: C++
  • File role: implementation file
  • Physical lines: 195
  • Non-empty lines: 172
  • SHA-256: 4e1eb70c6ddc302fb0efbbd2e0e74d916532c66eb696db62f8bbb9440da8079f

The declarations in this file use the global namespace.


3. Dependencies

3.1 Project Headers

  • file_carver.hpp
  • i18n.hpp

3.2 Standard and External Headers

  • algorithm
  • array
  • filesystem
  • fstream
  • iomanip
  • sstream
  • utility
  • vector

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

  • struct Pattern.

5. Constants and Configuration Values

  • constexpr uint64_t MiB=1024ull*1024ull
  • constexpr size_t WINDOW=2*1024*1024
  • constexpr uint64_t MAX_FILE_SIZE=128ull*1024ull*1024ull

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:

  • std::vector<Pattern> patterns() – Implements the operation identified by this API and updates or returns the associated state.
  • bool starts_with_at(const std::vector<unsigned char>&buf,size_t pos,const std::vector<unsigned char>&pat) – Implements the operation identified by this API and updates or returns the associated state.
  • bool looks_like_mp4(const std::vector<unsigned char>&buf,size_t pos) – Implements the operation identified by this API and updates or returns the associated state.
  • bool copy_range(DiskReader&reader,uint64_t offset,uint64_t size,const fs::path&out_path,std::string&error) – Implements the operation identified by this API and updates or returns the associated state.
  • bool carve_one_range(DiskReader&reader,uint64_t range_offset,uint64_t range_size,const std::vector<Pattern>&pats,const std::string&output_dir,std::vector<CarvedFile>&carved,std::vector<std::string>&logs,std::string&error) – Performs the associated recovery or extraction operation.
  • bool FileCarver::carve_to_directory(DiskReader&reader,const std::string&output_dir,std::vector<CarvedFile>&carved,std::vector<std::string>&logs,std::string&error) – Performs the associated recovery or extraction operation.
  • bool FileCarver::carve_ranges_to_directory(DiskReader&reader,const std::vector<std::pair<uint64_t,uint64_t>>&ranges,const std::string&output_dir,std::vector<CarvedFile>&carved,std::vector<std::string>&logs,std::string&error) – Performs the associated recovery or extraction operation.
  • } catch(const std::exception&ex) – 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:

  1. Select carving signatures.
  2. Scan raw ranges.
  3. Validate and export candidate files.
  4. Report carved-file records and errors.
  5. Expose or execute the detected APIs: patterns, starts_with_at, looks_like_mp4, copy_range, carve_one_range, carve_to_directory, carve_ranges_to_directory, catch.
  6. 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.
  • 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.

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.

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 extraction layer and consumes scan candidates or validated filesystem metadata.
  • Recovered output is represented through shared models and returned to the exporter or UI.
  • Partial recovery must be reported explicitly rather than silently treated as complete.

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.