Skip to content

Commit 787876e

Browse files
committed
Allow setting the driver name for GUI and x64dbg plugin
1 parent 826c47c commit 787876e

7 files changed

Lines changed: 105 additions & 54 deletions

File tree

TitanHideGUI/main.cpp

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,44 @@
11
#include <windows.h>
22
#include <commctrl.h>
33
#include <stdio.h>
4+
#include <utility>
45
#include "resource.h"
56
#include "..\TitanHide\TitanHide.h"
67

7-
HINSTANCE hInst;
8+
static HINSTANCE hInst;
9+
static char iniPath[MAX_PATH];
10+
11+
static std::pair<int, HIDE_TYPE> gOptions[] =
12+
{
13+
{ IDC_CHK_PROCESSDEBUGFLAGS, HideProcessDebugFlags },
14+
{ IDC_CHK_PROCESSDEBUGPORT, HideProcessDebugPort },
15+
{ IDC_CHK_PROCESSDEBUGOBJECTHANDLE, HideProcessDebugObjectHandle },
16+
{ IDC_CHK_DEBUGOBJECT, HideDebugObject },
17+
{ IDC_CHK_SYSTEMDEBUGGERINFORMATION, HideSystemDebuggerInformation },
18+
{ IDC_CHK_NTCLOSE, HideNtClose },
19+
{ IDC_CHK_THREADHIDEFROMDEBUGGER, HideThreadHideFromDebugger },
20+
{ IDC_CHK_NTGETCONTEXTTHREAD, HideNtGetContextThread },
21+
{ IDC_CHK_NTSETCONTEXTTHREAD, HideNtSetContextThread },
22+
{ IDC_CHK_NTSYSTEMDEBUGCONTROL, HideNtSystemDebugControl },
23+
};
824

925
static ULONG GetTypeDword(HWND hwndDlg)
1026
{
1127
ULONG Option = 0;
12-
if(IsDlgButtonChecked(hwndDlg, IDC_CHK_PROCESSDEBUGFLAGS))
13-
Option |= (ULONG)HideProcessDebugFlags;
14-
if(IsDlgButtonChecked(hwndDlg, IDC_CHK_PROCESSDEBUGPORT))
15-
Option |= (ULONG)HideProcessDebugPort;
16-
if(IsDlgButtonChecked(hwndDlg, IDC_CHK_PROCESSDEBUGOBJECTHANDLE))
17-
Option |= (ULONG)HideProcessDebugObjectHandle;
18-
if(IsDlgButtonChecked(hwndDlg, IDC_CHK_DEBUGOBJECT))
19-
Option |= (ULONG)HideDebugObject;
20-
if(IsDlgButtonChecked(hwndDlg, IDC_CHK_SYSTEMDEBUGGERINFORMATION))
21-
Option |= (ULONG)HideSystemDebuggerInformation;
22-
if(IsDlgButtonChecked(hwndDlg, IDC_CHK_NTCLOSE))
23-
Option |= (ULONG)HideNtClose;
24-
if(IsDlgButtonChecked(hwndDlg, IDC_CHK_THREADHIDEFROMDEBUGGER))
25-
Option |= (ULONG)HideThreadHideFromDebugger;
26-
if(IsDlgButtonChecked(hwndDlg, IDC_CHK_NTGETCONTEXTTHREAD))
27-
Option |= (ULONG)HideNtGetContextThread;
28-
if(IsDlgButtonChecked(hwndDlg, IDC_CHK_NTSETCONTEXTTHREAD))
29-
Option |= (ULONG)HideNtSetContextThread;
30-
if(IsDlgButtonChecked(hwndDlg, IDC_CHK_NTSYSTEMDEBUGCONTROL))
31-
Option |= (ULONG)HideNtSystemDebugControl;
28+
for (const auto& option : gOptions)
29+
{
30+
if (IsDlgButtonChecked(hwndDlg, option.first))
31+
Option |= (ULONG)option.second;
32+
}
3233
return Option;
3334
}
3435

3536
static void TitanHideCall(HWND hwndDlg, HIDE_COMMAND Command)
3637
{
37-
HANDLE hDevice = CreateFileA("\\\\.\\TitanHide", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
38+
char driverName[256] = "\\\\.\\";
39+
GetWindowTextA(GetDlgItem(hwndDlg, IDC_EDT_DRIVER), driverName + 4, sizeof(driverName) - 4);
40+
WritePrivateProfileStringA("TitanHide", "DriverName", driverName + 4, iniPath);
41+
HANDLE hDevice = CreateFileA(driverName, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
3842
if(hDevice == INVALID_HANDLE_VALUE)
3943
{
4044
MessageBoxA(hwndDlg, "Could not open TitanHide handle...", "Driver loaded?", MB_ICONERROR);
@@ -58,6 +62,14 @@ static BOOL CALLBACK DlgMain(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lPar
5862
{
5963
case WM_INITDIALOG:
6064
{
65+
SetWindowTextA(GetDlgItem(hwndDlg, IDC_EDT_DRIVER), "TitanHide");
66+
for (const auto& option : gOptions)
67+
{
68+
CheckDlgButton(hwndDlg, option.first, BST_CHECKED);
69+
}
70+
char driverName[256] = "";
71+
GetPrivateProfileStringA("TitanHide", "DriverName", "TitanHide", driverName, sizeof(driverName), iniPath);
72+
SetWindowTextA(GetDlgItem(hwndDlg, IDC_EDT_DRIVER), driverName);
6173
}
6274
return TRUE;
6375

@@ -100,5 +112,12 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
100112
{
101113
hInst = hInstance;
102114
InitCommonControls();
115+
GetModuleFileNameA(hInstance, iniPath, sizeof(iniPath));
116+
auto ext = strrchr(iniPath, '.');
117+
if (ext != nullptr)
118+
{
119+
*ext = '\0'; // remove the extension
120+
}
121+
strncat_s(iniPath, ".ini", _TRUNCATE); // append .ini
103122
return (int)DialogBox(hInst, MAKEINTRESOURCE(DLG_MAIN), NULL, (DLGPROC)DlgMain);
104123
}

TitanHideGUI/resource.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@
1717
#define IDC_CHK_SYSTEMDEBUGGERINFORMATION 1011
1818
#define IDC_CHK_NTSYSTEMDEBUGCONTROL 1012
1919
#define IDC_CHK_NTGETCONTEXTTHREAD 1013
20+
#define IDC_EDT_DRIVER 40000

TitanHideGUI/resource.rc

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// Generated by ResEdit 1.5.11
2-
// Copyright (C) 2006-2012
1+
// Generated by ResEdit 1.6.6
2+
// Copyright (C) 2006-2015
33
// http://www.resedit.net
44

55
#include <windows.h>
@@ -14,25 +14,27 @@
1414
// Dialog resources
1515
//
1616
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
17-
DLG_MAIN DIALOG 0, 0, 182, 134
17+
DLG_MAIN DIALOG 0, 0, 182, 133
1818
STYLE DS_3DLOOK | DS_CENTER | DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_VISIBLE | WS_POPUP | WS_SYSMENU
1919
CAPTION "TitanHide"
2020
FONT 8, "Courier New"
2121
{
22-
RTEXT "PID:", IDC_STATIC, 3, 4, 17, 8, SS_RIGHT
23-
EDITTEXT IDC_EDT_PID, 22, 3, 36, 12, ES_NUMBER
24-
PUSHBUTTON "&Hide", IDC_BTN_HIDE, 125, 10, 50, 14
25-
PUSHBUTTON "&Unhide", IDC_BTN_UNHIDE, 125, 26, 50, 14
26-
PUSHBUTTON "Unhide &All", IDC_BTN_UNHIDEALL, 125, 42, 50, 14
27-
GROUPBOX "Options", IDC_STATIC, 2, 18, 117, 112
28-
AUTOCHECKBOX "ProcessDebugFlags", IDC_CHK_PROCESSDEBUGFLAGS, 7, 28, 80, 8
29-
AUTOCHECKBOX "ProcessDebugPort", IDC_CHK_PROCESSDEBUGPORT, 7, 38, 74, 8
30-
AUTOCHECKBOX "ProcessDebugObjectHandle", IDC_CHK_PROCESSDEBUGOBJECTHANDLE, 7, 48, 108, 8
31-
AUTOCHECKBOX "DebugObject", IDC_CHK_DEBUGOBJECT, 7, 58, 55, 8
32-
AUTOCHECKBOX "SystemDebuggerInformation", IDC_CHK_SYSTEMDEBUGGERINFORMATION, 7, 68, 110, 8
33-
AUTOCHECKBOX "NtClose", IDC_CHK_NTCLOSE, 7, 78, 38, 8
34-
AUTOCHECKBOX "ThreadHideFromDebugger", IDC_CHK_THREADHIDEFROMDEBUGGER, 7, 88, 99, 8
35-
AUTOCHECKBOX "GetContextThread", IDC_CHK_NTGETCONTEXTTHREAD, 7, 98, 96, 8
36-
AUTOCHECKBOX "SetContextThread", IDC_CHK_NTSETCONTEXTTHREAD, 7, 108, 96, 8
37-
AUTOCHECKBOX "SystemDebugControl", IDC_CHK_NTSYSTEMDEBUGCONTROL, 7, 118, 96, 8
22+
RTEXT "PID:", IDC_STATIC, 3, 4, 17, 8, SS_RIGHT, WS_EX_LEFT
23+
EDITTEXT IDC_EDT_PID, 22, 3, 36, 12, ES_NUMBER, WS_EX_LEFT
24+
RTEXT "Driver:", IDC_STATIC, 62, 4, 29, 9, SS_RIGHT, WS_EX_LEFT
25+
EDITTEXT IDC_EDT_DRIVER, 93, 3, 81, 12, 0, WS_EX_LEFT
26+
PUSHBUTTON "&Hide", IDC_BTN_HIDE, 125, 26, 50, 14, 0, WS_EX_LEFT
27+
PUSHBUTTON "&Unhide", IDC_BTN_UNHIDE, 125, 42, 50, 14, 0, WS_EX_LEFT
28+
PUSHBUTTON "Unhide &All", IDC_BTN_UNHIDEALL, 125, 58, 50, 14, 0, WS_EX_LEFT
29+
GROUPBOX "Options", IDC_STATIC, 2, 18, 117, 112, 0, WS_EX_LEFT
30+
AUTOCHECKBOX "ProcessDebugFlags", IDC_CHK_PROCESSDEBUGFLAGS, 7, 28, 80, 8, 0, WS_EX_LEFT
31+
AUTOCHECKBOX "ProcessDebugPort", IDC_CHK_PROCESSDEBUGPORT, 7, 38, 74, 8, 0, WS_EX_LEFT
32+
AUTOCHECKBOX "ProcessDebugObjectHandle", IDC_CHK_PROCESSDEBUGOBJECTHANDLE, 7, 48, 108, 8, 0, WS_EX_LEFT
33+
AUTOCHECKBOX "DebugObject", IDC_CHK_DEBUGOBJECT, 7, 58, 55, 8, 0, WS_EX_LEFT
34+
AUTOCHECKBOX "SystemDebuggerInformation", IDC_CHK_SYSTEMDEBUGGERINFORMATION, 7, 68, 110, 8, 0, WS_EX_LEFT
35+
AUTOCHECKBOX "NtClose", IDC_CHK_NTCLOSE, 7, 78, 38, 8, 0, WS_EX_LEFT
36+
AUTOCHECKBOX "ThreadHideFromDebugger", IDC_CHK_THREADHIDEFROMDEBUGGER, 7, 88, 99, 8, 0, WS_EX_LEFT
37+
AUTOCHECKBOX "GetContextThread", IDC_CHK_NTGETCONTEXTTHREAD, 7, 98, 96, 8, 0, WS_EX_LEFT
38+
AUTOCHECKBOX "SetContextThread", IDC_CHK_NTSETCONTEXTTHREAD, 7, 108, 96, 8, 0, WS_EX_LEFT
39+
AUTOCHECKBOX "SystemDebugControl", IDC_CHK_NTSYSTEMDEBUGCONTROL, 7, 118, 96, 8, 0, WS_EX_LEFT
3840
}

TitanHide_OllyDbg/TitanHide_OllyDbg.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
<SDLCheck>true</SDLCheck>
6666
<AdditionalOptions>/Zc:threadSafeInit- %(AdditionalOptions)</AdditionalOptions>
6767
<PreprocessorDefinitions>WINVER=0x0501;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010000;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
68+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
6869
</ClCompile>
6970
<Link>
7071
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>

TitanHide_TitanEngine/TitanHide_TitanEngine.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<SDLCheck>true</SDLCheck>
9494
<AdditionalOptions>/Zc:threadSafeInit- %(AdditionalOptions)</AdditionalOptions>
9595
<PreprocessorDefinitions>WINVER=0x0502;_WIN32_WINNT=0x0502;NTDDI_VERSION=0x05020000;WINVER=0x0501;_WIN32_WINNT=0x0501;NTDDI_VERSION=0x05010000;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
96+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
9697
</ClCompile>
9798
<Link>
9899
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>
@@ -106,6 +107,7 @@
106107
<Optimization>Disabled</Optimization>
107108
<SDLCheck>true</SDLCheck>
108109
<PreprocessorDefinitions>WINVER=0x0502;_WIN32_WINNT=0x0502;NTDDI_VERSION=0x05020000;_WINDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
110+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
109111
</ClCompile>
110112
<Link>
111113
<GenerateDebugInformation>DebugFull</GenerateDebugInformation>

TitanHide_x64dbg/TitanHide_x64dbg.vcxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@
118118
<FunctionLevelLinking>true</FunctionLevelLinking>
119119
<IntrinsicFunctions>true</IntrinsicFunctions>
120120
<SDLCheck>true</SDLCheck>
121-
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
121+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
122122
<InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
123123
<WholeProgramOptimization>false</WholeProgramOptimization>
124124
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
@@ -159,7 +159,7 @@
159159
<FunctionLevelLinking>true</FunctionLevelLinking>
160160
<IntrinsicFunctions>true</IntrinsicFunctions>
161161
<SDLCheck>true</SDLCheck>
162-
<RuntimeLibrary>MultiThreadedDebugDLL</RuntimeLibrary>
162+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
163163
<InlineFunctionExpansion>Disabled</InlineFunctionExpansion>
164164
<WholeProgramOptimization>false</WholeProgramOptimization>
165165
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>

TitanHide_x64dbg/plugin.cpp

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,28 @@
11
#include "plugin.h"
22
#include <windows.h>
33
#include <stdio.h>
4+
#include <string>
45
#include "../TitanHide/TitanHide.h"
56

67
static DWORD pid = 0;
78
static bool hidden = false;
9+
static std::string driverName = "TitanHide";
810

911
static ULONG GetTitanHideOptions()
1012
{
1113
duint options = 0;
12-
if(!BridgeSettingGetUint("TitanHide", "Options", &options))
14+
if (!BridgeSettingGetUint("TitanHide", "Options", &options))
1315
options = 0xffffffff;
1416
return (ULONG)options;
1517
}
1618

1719
static bool TitanHideCall(HIDE_COMMAND Command)
1820
{
19-
HANDLE hDevice = CreateFileA("\\\\.\\TitanHide", GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
20-
if(hDevice == INVALID_HANDLE_VALUE)
21+
auto path = "\\\\.\\" + driverName;
22+
HANDLE hDevice = CreateFileA(path.c_str(), GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING, 0, 0);
23+
if (hDevice == INVALID_HANDLE_VALUE)
2124
{
22-
_plugin_logputs("[" PLUGIN_NAME "] Could not open TitanHide handle...");
25+
_plugin_logputs("[" PLUGIN_NAME "] Could not open TitanHide handle (wrong driver name?)");
2326
return false;
2427
}
2528
HIDE_INFO HideInfo;
@@ -28,7 +31,7 @@ static bool TitanHideCall(HIDE_COMMAND Command)
2831
HideInfo.Type = GetTitanHideOptions();
2932
DWORD written = 0;
3033
auto result = false;
31-
if(WriteFile(hDevice, &HideInfo, sizeof(HIDE_INFO), &written, 0))
34+
if (WriteFile(hDevice, &HideInfo, sizeof(HIDE_INFO), &written, 0))
3235
{
3336
_plugin_logprintf("[" PLUGIN_NAME "] Process %shidden!\n", Command == UnhidePid ? "un" : "");
3437
result = true;
@@ -43,10 +46,10 @@ static bool TitanHideCall(HIDE_COMMAND Command)
4346

4447
static bool cbTitanHide(int argc, char* argv[])
4548
{
46-
if(!hidden)
49+
if (!hidden)
4750
{
4851
_plugin_logprintf("[" PLUGIN_NAME "] Hiding PID %X (%ud)\n", pid, pid);
49-
if(TitanHideCall(HidePid))
52+
if (TitanHideCall(HidePid))
5053
{
5154
DbgCmdExecDirect("hide");
5255
hidden = true;
@@ -57,32 +60,47 @@ static bool cbTitanHide(int argc, char* argv[])
5760

5861
static bool cbTitanUnhide(int argc, char* argv[])
5962
{
60-
if(hidden)
63+
if (hidden)
6164
{
6265
_plugin_logprintf("[" PLUGIN_NAME "] Unhiding PID %X (%ud)\n", pid, pid);
63-
if(TitanHideCall(UnhidePid))
66+
if (TitanHideCall(UnhidePid))
6467
hidden = false;
6568
}
6669
return !hidden;
6770
}
6871

6972
static bool cbTitanHideOptions(int argc, char* argv[])
7073
{
71-
if(argc < 2)
74+
if (argc < 2)
7275
{
7376
_plugin_logprintf("[" PLUGIN_NAME "] Options: 0x%08X\n", GetTitanHideOptions());
7477
}
7578
else
7679
{
7780
duint options = DbgValFromString(argv[1]);
7881
BridgeSettingSetUint("TitanHide", "Options", options & 0xffffffff);
79-
if(hidden)
82+
if (hidden)
8083
TitanHideCall(HidePid);
8184
_plugin_logprintf("[" PLUGIN_NAME "] New options: 0x%08X\n", GetTitanHideOptions());
8285
}
8386
return true;
8487
}
8588

89+
static bool cbTitanHideName(int argc, char* argv[])
90+
{
91+
if (argc < 2)
92+
{
93+
_plugin_logprintf("[" PLUGIN_NAME "] Current driver name: '%s'\n", argv[0]);
94+
}
95+
else
96+
{
97+
driverName = argv[1];
98+
BridgeSettingSet("TitanHide", "DriverName", driverName.c_str());
99+
_plugin_logprintf("[" PLUGIN_NAME "] New driver name: '%s'\n", driverName.c_str());
100+
}
101+
return true;
102+
}
103+
86104
PLUG_EXPORT void CBCREATEPROCESS(CBTYPE cbType, PLUG_CB_CREATEPROCESS* info)
87105
{
88106
pid = info->fdProcessInfo->dwProcessId;
@@ -107,9 +125,17 @@ PLUG_EXPORT void CBSTOPDEBUG(CBTYPE cbType, PLUG_CB_STOPDEBUG* info)
107125

108126
void TitanHideInit(PLUG_INITSTRUCT* initStruct)
109127
{
128+
char setting[MAX_SETTING_SIZE] = "";
129+
BridgeSettingGet("TitanHide", "DriverName", setting);
130+
if (setting[0] != '\0')
131+
{
132+
driverName = setting;
133+
}
134+
110135
_plugin_registercommand(pluginHandle, "TitanHide", cbTitanHide, true);
111136
_plugin_registercommand(pluginHandle, "TitanUnhide", cbTitanUnhide, true);
112137
_plugin_registercommand(pluginHandle, "TitanHideOptions", cbTitanHideOptions, false);
138+
_plugin_registercommand(pluginHandle, "TitanHideName", cbTitanHideName, false);
113139
}
114140

115141
void TitanHideStop()

0 commit comments

Comments
 (0)