/src/sleuthkit/tsk/pool/pool_compat.hpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * The Sleuth Kit |
3 | | * |
4 | | * Brian Carrier [carrier <at> sleuthkit [dot] org] |
5 | | * Copyright (c) 2019-2020 Brian Carrier. All Rights reserved |
6 | | * Copyright (c) 2018-2019 BlackBag Technologies. All Rights reserved |
7 | | * |
8 | | * This software is distributed under the Common Public License 1.0 |
9 | | */ |
10 | | /** \@file C -> C++ compatability layer */ |
11 | | #pragma once |
12 | | |
13 | | #include "tsk_pool.hpp" |
14 | | |
15 | | #include <type_traits> |
16 | | |
17 | | template <typename T, |
18 | | typename = std::enable_if_t<std::is_base_of<TSKPool, T>::value>> |
19 | | |
20 | | class TSKPoolCompat : public T { |
21 | | protected: |
22 | | TSK_POOL_INFO _info{}; |
23 | | |
24 | | // disable copying so we don't mess with the C API |
25 | | TSKPoolCompat(const TSKPoolCompat &) = delete; |
26 | | TSKPoolCompat &operator=(const TSKPoolCompat &) = delete; |
27 | | |
28 | | // disable moving so we don't mess with the C API |
29 | | TSKPoolCompat(TSKPoolCompat &&) noexcept = delete; |
30 | | TSKPoolCompat &operator=(TSKPoolCompat &&) noexcept = delete; |
31 | | |
32 | | public: |
33 | | template <typename... Args> |
34 | | |
35 | | |
36 | | TSKPoolCompat(TSK_POOL_TYPE_ENUM type, Args &&... args) noexcept( |
37 | | std::is_nothrow_constructible<T, Args...>::value) |
38 | 48 | : T(std::forward<Args>(args)...) { |
39 | | ///< \internal the C info structure |
40 | 48 | _info.tag = TSK_POOL_INFO_TAG; |
41 | 48 | _info.ctype = type; |
42 | 48 | _info.block_size = this->block_size(); |
43 | 48 | _info.num_blocks = this->num_blocks(); |
44 | 48 | _info.img_offset = this->first_img_offset(); |
45 | 48 | _info.num_vols = this->num_vols(); |
46 | 48 | _info.vol_list = nullptr; |
47 | 48 | _info.close = [](const TSK_POOL_INFO *pool) { |
48 | 2 | delete static_cast<TSKPoolCompat *>(pool->impl); |
49 | 2 | }; |
50 | 48 | _info.poolstat = [](const TSK_POOL_INFO *pool, FILE *hFile) { |
51 | 0 | return static_cast<TSKPoolCompat *>(pool->impl)->poolstat(hFile); |
52 | 0 | }; |
53 | 48 | _info.get_img_info = [](const TSK_POOL_INFO *pool, TSK_DADDR_T pvol_block) { |
54 | 2 | return static_cast<TSKPoolCompat *>(pool->impl)->getImageInfo(pool, pvol_block); |
55 | 2 | }; |
56 | 48 | _info.impl = this; |
57 | 48 | } |
58 | | |
59 | 2 | inline const TSK_POOL_INFO &pool_info() const noexcept { return _info; } |
60 | | |
61 | 2 | virtual ~TSKPoolCompat() { |
62 | 2 | if (_info.vol_list != nullptr) { |
63 | 0 | for (auto vol = _info.vol_list; vol != nullptr; vol = vol->next) { |
64 | 0 | delete[] vol->desc; |
65 | 0 | } |
66 | |
|
67 | 0 | delete[] _info.vol_list; |
68 | 0 | _info.vol_list = nullptr; |
69 | 0 | } |
70 | 2 | } |
71 | | |
72 | | virtual uint8_t poolstat(FILE *) const noexcept = 0; |
73 | | virtual TSK_IMG_INFO * getImageInfo(const TSK_POOL_INFO *pool_info, TSK_DADDR_T pvol_block) = 0; |
74 | | }; |