-
Notifications
You must be signed in to change notification settings - Fork 1
/
driver.cpp
44 lines (38 loc) · 1.44 KB
/
driver.cpp
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
#include "driver.h"
#include <string.hpp>
#include <fmt/xchar.h>
using namespace ktl;
EXTERN_C NTSTATUS DriverEntry([[maybe_unused]] PDRIVER_OBJECT DriverObject,
[[maybe_unused]] PUNICODE_STRING RegistryPath) {
try {
const auto time{GetCurrentTime()};
auto str{format(L"[{:02}-{:02}-{:04} {:02}:{:02}:{:02}.{:03}][{}]",
time.Day, time.Month, time.Year, time.Hour, time.Minute,
time.Second, time.Milliseconds, L"CoroDriverSample")};
DbgPrint("%wZ\n", str.raw_str());
system_thread thread;
resuming_on_new_thread(thread);
thread.join();
} catch (const exception& exc) {
DbgPrint("Unhandled exception caught: %wS with code %x\n", exc.what(),
exc.code());
return exc.code();
}
return STATUS_INSUFFICIENT_RESOURCES;
}
task resuming_on_new_thread(system_thread& out) {
DbgPrint("Coroutine started on thread: %u\n",
HandleToUlong(PsGetCurrentThreadId()));
co_await switch_to_new_thread(out);
DbgPrint("Coroutine resumed on thread: %u\n",
HandleToUlong(PsGetCurrentThreadId()));
}
TIME_FIELDS GetCurrentTime() noexcept {
const auto current_time{
chrono::system_clock::now().time_since_epoch().count()};
LARGE_INTEGER native_time;
native_time.QuadPart = static_cast<long long>(current_time);
TIME_FIELDS time_fields;
RtlTimeToTimeFields(addressof(native_time), addressof(time_fields));
return time_fields;
}