-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
kur.h
69 lines (61 loc) · 1.54 KB
/
kur.h
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#pragma once
#include "vul_driver.h"
class kur_t
{
vul_driver vul_driver;
public:
auto query_device_handle() const -> HANDLE;
auto get_process_handle(DWORD pid, ACCESS_MASK access_mask) -> std::optional<HANDLE>;
auto read(void* address, void* buffer, size_t buffer_size, HANDLE h_target_process) -> BOOL;
auto write(void* to_address, void* from_address, size_t size, HANDLE h_target_process) -> BOOL;
kur_t(std::wstring name, std::wstring device_name)
: vul_driver(std::move(name), std::move(device_name))
{
try
{
vul_driver.install();
vul_driver.setup_reg_key();
vul_driver.load();
vul_driver.get_device_handle();
vul_driver.ioctl_initialize_driver();
}
catch (...)
{
try { vul_driver.uninstall(); }
catch (...)
{
}
try { vul_driver.delete_reg_key(); }
catch (...)
{
}
try { vul_driver.unload(); }
catch (...)
{
}
// Rethrow the original exception
throw;
}
}
~kur_t()
{
// Suppress all exceptions to prevent std::terminate() from being called.
try
{
const auto status = utils::open_reg_key(HKEY_LOCAL_MACHINE, SERVICE_PATH_COMMON.c_str());
if (status == ERROR_SUCCESS || status == ERROR_FILE_NOT_FOUND)
{
vul_driver.unload();
vul_driver.delete_reg_key();
vul_driver.uninstall();
}
else
{
std::cerr << "cleanup: key cannot be opened correctly, status: " << status << std::endl;
}
}
catch (...)
{
}
}
};