-
Notifications
You must be signed in to change notification settings - Fork 539
/
Main.cpp
126 lines (109 loc) · 3.82 KB
/
Main.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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#include "stdafx.h"
#include "MainDlg.h"
#include "DumpHandler.h"
#include "DriverExtract.h"
#include <shellapi.h>
/// <summary>
/// Crash dump notify callback
/// </summary>
/// <param name="path">Dump file path</param>
/// <param name="context">User context</param>
/// <param name="expt">Exception info</param>
/// <param name="success">if false - crash dump file was not saved</param>
/// <returns>status</returns>
int DumpNotifier( const wchar_t* path, void* context, EXCEPTION_POINTERS* expt, bool success )
{
Message::ShowError( NULL, L"Program has crashed. Dump file saved at '" + std::wstring( path ) + L"'" );
return 0;
}
/// <summary>
/// Associate profile file extension
/// </summary>
void AssociateExtension()
{
wchar_t tmp[255] = { 0 };
GetModuleFileNameW( NULL, tmp, sizeof( tmp ) );
#ifdef USE64
std::wstring ext = L".xpr64";
std::wstring alias = L"XenosProfile64";
std::wstring desc = L"Xenos 64-bit injection profile";
#else
std::wstring ext = L".xpr";
std::wstring alias = L"XenosProfile";
std::wstring desc = L"Xenos injection profile";
#endif
std::wstring editWith = std::wstring( tmp ) + L" --load %1";
std::wstring runWith = std::wstring( tmp ) + L" --run %1";
std::wstring icon = std::wstring( tmp ) + L",-" + std::to_wstring( IDI_ICON1 );
auto AddKey = []( const std::wstring& subkey, const std::wstring& value, const wchar_t* regValue ) {
SHSetValue( HKEY_CLASSES_ROOT, subkey.c_str(), regValue, REG_SZ, value.c_str(), (DWORD)(value.size() * sizeof( wchar_t )) );
};
SHDeleteKeyW( HKEY_CLASSES_ROOT, alias.c_str() );
AddKey( ext, alias, nullptr );
AddKey( ext, L"Application/xml", L"Content Type" );
AddKey( alias, desc, nullptr );
AddKey( alias + L"\\shell", L"Run", nullptr );
AddKey( alias + L"\\shell\\Edit\\command", editWith, nullptr );
AddKey( alias + L"\\shell\\Run\\command", runWith, nullptr );
AddKey( alias + L"\\DefaultIcon", icon, nullptr );
}
/// <summary>
/// Log major OS information
/// </summary>
void LogOSInfo()
{
SYSTEM_INFO info = { 0 };
char* osArch = "x64";
auto pPeb = (blackbone::PEB_T*)NtCurrentTeb()->ProcessEnvironmentBlock;
GetNativeSystemInfo( &info );
if (info.wProcessorArchitecture == PROCESSOR_ARCHITECTURE_INTEL)
osArch = "x86";
xlog::Normal(
"Started on Windows %d.%d.%d.%d %s. Driver status: 0x%X",
pPeb->OSMajorVersion,
pPeb->OSMinorVersion,
(pPeb->OSCSDVersion >> 8) & 0xFF,
pPeb->OSBuildNumber,
osArch,
blackbone::Driver().status()
);
}
/// <summary>
/// Parse command line string
/// </summary>
/// <param name="param">Resulting param</param>
/// <returns>Profile action</returns>
MainDlg::StartAction ParseCmdLine( std::wstring& param )
{
int argc = 0;
auto pCmdLine = GetCommandLineW();
auto argv = CommandLineToArgvW( pCmdLine, &argc );
for (int i = 1; i < argc; i++)
{
if (_wcsicmp( argv[i], L"--load" ) == 0 && i + 1 < argc)
{
param = argv[i + 1];
return MainDlg::LoadProfile;
}
if (_wcsicmp( argv[i], L"--run" ) == 0 && i + 1 < argc)
{
param = argv[i + 1];
return MainDlg::RunProfile;
}
}
return MainDlg::Nothing;
}
int APIENTRY wWinMain( HINSTANCE /*hInstance*/, HINSTANCE /*hPrevInstance*/, LPWSTR /*lpCmdLine*/, int /*nCmdShow*/ )
{
// Setup dump generation
dump::DumpHandler::Instance().CreateWatchdog( blackbone::Utils::GetExeDirectory(), dump::CreateFullDump, &DumpNotifier );
AssociateExtension();
std::wstring param;
auto action = ParseCmdLine( param );
MainDlg mainDlg( action, param );
LogOSInfo();
if (action != MainDlg::RunProfile)
return (int)mainDlg.RunModeless( NULL, IDR_ACCELERATOR1 );
else
return mainDlg.LoadAndInject();
}