-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathImage.hpp
50 lines (49 loc) · 1.56 KB
/
Image.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#pragma once
#define WIN32_LEAN_AND_MEAN
#define STRICT_GS_ENABLED
#define _ATL_NO_AUTOMATIC_NAMESPACE
#include <atlbase.h>
#include <windows.h>
#include <algorithm>
#include <memory>
#include <optional>
#include "miscutil.hpp"
class Image
{
protected:
HANDLE image_file;
UINT32 require_alignment;
Image() = default;
Image(_In_ HANDLE file, _In_ UINT32 cluster_size) : image_file(file), require_alignment(cluster_size)
{
if (!IsPow2(require_alignment))
{
die(L"Require alignment is not power of 2.");
}
}
public:
Image(const Image&) = delete;
Image& operator=(const Image&) = delete;
virtual ~Image() = default;
virtual void Attach(_In_ HANDLE file, _In_ UINT32 cluster_size)
{
if (!IsPow2(cluster_size))
{
die(L"Require alignment is not power of 2.");
}
image_file = file;
require_alignment = cluster_size;
}
virtual void ReadHeader() = 0;
virtual void ConstructHeader(_In_ UINT64 disk_size, _In_ UINT32 block_size, _In_ UINT32 sector_size, _In_ bool is_fixed) = 0;
virtual void WriteHeader() const = 0;
virtual bool CheckConvertible(_When_(return == false, _Outptr_result_z_) PCWSTR* reason) const = 0;
virtual bool IsFixed() const noexcept = 0;
virtual PCSTR GetImageTypeName() const noexcept = 0;
virtual UINT64 GetDiskSize() const noexcept = 0;
virtual UINT32 GetSectorSize() const noexcept = 0;
virtual UINT32 GetBlockSize() const noexcept = 0;
virtual UINT32 GetTableEntriesCount() const noexcept = 0;
virtual std::optional<UINT64> ProbeBlock(_In_ UINT32 index) const noexcept = 0;
virtual UINT64 AllocateBlockForWrite(_In_ UINT32 index) = 0;
};