forked from DarthTon/Xenos
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDriverExtract.h
85 lines (73 loc) · 2.21 KB
/
DriverExtract.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#pragma once
#include "resource.h"
#include <BlackBone/src/3rd_Party/VersionApi.h>
#include <BlackBone/src/BlackBone/DriverControl/DriverControl.h>
class DriverExtract
{
public:
static DriverExtract& Instance()
{
static DriverExtract inst;
return inst;
}
/// <summary>
/// Extracts required driver version form self
/// </summary>
void Extract()
{
int resID = IDR_DRV7;
const wchar_t* filename = L"BlackBoneDrv7.sys";
if (IsWindows10OrGreater())
{
filename = L"BlackBoneDrv10.sys";
resID = IDR_DRV10;
}
else if (IsWindows8Point1OrGreater())
{
filename = L"BlackBoneDrv81.sys";
resID = IDR_DRV81;
}
else if (IsWindows8OrGreater())
{
filename = L"BlackBoneDrv8.sys";
resID = IDR_DRV8;
}
HRSRC resInfo = FindResourceW( NULL, MAKEINTRESOURCEW( resID ), L"Driver" );
if (resInfo)
{
HGLOBAL hRes = LoadResource( NULL, resInfo );
PVOID pDriverData = LockResource( hRes );
HANDLE hFile = CreateFileW(
(blackbone::Utils::GetExeDirectory() + L"\\" + filename).c_str(),
FILE_GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL
);
if (hFile != INVALID_HANDLE_VALUE)
{
DWORD bytes = 0;
WriteFile( hFile, pDriverData, SizeofResource( NULL, resInfo ), &bytes, NULL );
CloseHandle( hFile );
}
}
}
~DriverExtract()
{
Cleanup();
}
/// <summary>
/// Remove unpacked driver, if any
/// </summary>
void Cleanup()
{
const wchar_t* filename = L"BlackBoneDrv7.sys";
if (IsWindows10OrGreater())
filename = L"BlackBoneDrv10.sys";
else if (IsWindows8Point1OrGreater())
filename = L"BlackBoneDrv81.sys";
else if (IsWindows8OrGreater())
filename = L"BlackBoneDrv8.sys";
DeleteFileW( (blackbone::Utils::GetExeDirectory() + L"\\" + filename).c_str() );
}
private:
DriverExtract() = default;
DriverExtract( const DriverExtract& ) = default;
};