1
0
mirror of https://github.com/momo5502/hypervisor.git synced 2025-12-18 16:37:51 +00:00

Extract into library

This commit is contained in:
Maurice Heumann
2022-12-27 16:27:33 +01:00
parent f8f636a829
commit 28dd94f2ef
31 changed files with 279 additions and 237 deletions

46
src/library/driver.cpp Normal file
View File

@@ -0,0 +1,46 @@
#include "std_include.hpp"
#include "driver.hpp"
driver::driver(const std::filesystem::path& driver_file, const std::string& service_name)
{
this->manager_ = OpenSCManagerA(nullptr, nullptr, SC_MANAGER_ALL_ACCESS);
if (!this->manager_)
{
throw std::runtime_error("Unable to open SC manager");
}
this->service_ = OpenServiceA(this->manager_, service_name.data(), SERVICE_ALL_ACCESS);
if (!this->service_)
{
this->service_ = CreateServiceA(this->manager_, service_name.data(),
service_name.data(), SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER,
SERVICE_DEMAND_START, SERVICE_ERROR_NORMAL,
driver_file.generic_string().data(), nullptr, nullptr,
nullptr, nullptr, nullptr);
}
if (!this->service_)
{
this->service_ = OpenServiceA(this->manager_, service_name.data(), SERVICE_ALL_ACCESS);
}
if (!this->service_)
{
this->manager_ = {};
throw std::runtime_error("Unable to create service");
}
StartServiceA(this->service_, 0, nullptr);
}
driver::~driver()
{
if (this->service_)
{
SERVICE_STATUS status{};
ControlService(this->service_, SERVICE_CONTROL_STOP, &status);
DeleteService(this->service_);
}
}