|
| 1 | +// BSCP.cpp : Defines the entry point for the console application. |
| 2 | +// |
| 3 | + |
| 4 | +#include "stdafx.h" |
| 5 | +#include <iostream> |
| 6 | +#include <string> |
| 7 | +#include "Strsafe.h" |
| 8 | +#include "Shellapi.h" |
| 9 | +#include "../../BSCP/RegProvider/RegProvider.h" |
| 10 | + |
| 11 | + |
| 12 | +int main() |
| 13 | +{ |
| 14 | + /* |
| 15 | + CONSOLE_READCONSOLE_CONTROL tControl; |
| 16 | + tControl.nInitialChars = 0; |
| 17 | + tControl.dwCtrlWakeupMask = L'\n'; |
| 18 | + WCHAR* first_message = TEXT("Enter reg key to open \r\n"); |
| 19 | + WCHAR* second_message = TEXT("Enter value to open \r\n"); |
| 20 | + HANDLE hwnd_console_out = GetStdHandle(STD_OUTPUT_HANDLE); |
| 21 | + HANDLE hwnd_console_in = GetStdHandle(STD_INPUT_HANDLE); |
| 22 | + WCHAR key_name[100]; //reg key in HKLM to read |
| 23 | + WCHAR prop_name[100]; //reg key property to read |
| 24 | + DWORD len_key = 100; |
| 25 | + DWORD len_prop = 100; |
| 26 | + DWORD len_output = 0; |
| 27 | + //WCHAR* output; |
| 28 | + */ |
| 29 | + CRegProvider prov = CRegProvider(); |
| 30 | + int index = 0; |
| 31 | + while (true) { |
| 32 | + //get values |
| 33 | + /*WriteConsole(hwnd_console_out, first_message, _tcslen(first_message), NULL, NULL); |
| 34 | + ReadConsole(hwnd_console_in, &key_name, len_key, &len_key, &tControl); |
| 35 | + WCHAR* key_rightsized = new WCHAR[len_key + 1]; |
| 36 | + StringCchCopy(key_rightsized, len_key -1, key_name); |
| 37 | +
|
| 38 | + WriteConsole(hwnd_console_out, second_message, _tcslen(second_message), NULL, NULL); |
| 39 | + ReadConsole(hwnd_console_in, &prop_name, len_key, &len_prop, &tControl); |
| 40 | + WCHAR* prop_rightsized = new WCHAR[len_prop - 1]; |
| 41 | + StringCchCopy(prop_rightsized, len_prop - 1, prop_name); |
| 42 | +
|
| 43 | + //print entered values |
| 44 | + WriteConsole(hwnd_console_out, key_name, len_key, NULL, NULL); |
| 45 | + WriteConsole(hwnd_console_out, prop_name, len_prop, NULL, NULL); |
| 46 | +
|
| 47 | + prov.GetSizeAt_sz(key_rightsized, prop_rightsized, &len_output); |
| 48 | + output = new WCHAR[len_output/2]; |
| 49 | + prov.GetValueAt_sz(key_rightsized, prop_rightsized, output, &len_output); |
| 50 | + */ |
| 51 | + /* |
| 52 | + CRegProvider prov = CRegProvider(); |
| 53 | + WCHAR* prop_value = TEXT("Windows Explorer"); |
| 54 | + WCHAR* prop_value_2 = TEXT("/C explorer.exe"); |
| 55 | + WCHAR* prop_name_1 = TEXT("command"); |
| 56 | + WCHAR* key_name = TEXT("SOFTWARE\\Castle\\BootShellCredentialProvider\\Shells\\Default"); |
| 57 | + DWORD prop_val_length = (_tcslen(prop_value) + 1) *2; //extra bytes for terminating char |
| 58 | + DWORD prop_val_length_2 = (_tcslen(prop_value) + 1) * 2; |
| 59 | + //LONG res = prov.EnsureKeyValueSet_sz(key_name, TEXT("name"), prop_value, &prop_val_length); |
| 60 | + LONG res2 = prov.EnsureKeyValueSet_sz(key_name, TEXT("command"), prop_value_2, &prop_val_length_2); |
| 61 | + DWORD length = 0; |
| 62 | + prov.GetSizeAt_sz(key_name, prop_name_1, &length); |
| 63 | + WCHAR* output = new WCHAR[length / 2]; |
| 64 | + prov.GetValueAt_sz(key_name, prop_name_1, output, &length); |
| 65 | + WriteConsole(hwnd_console_out, output, length/2, NULL, NULL); |
| 66 | + ShellExecute(NULL, TEXT("Open"), TEXT("cmd.exe"), output, NULL, SW_HIDE); |
| 67 | + system("pause"); |
| 68 | + delete output; |
| 69 | + //delete prop_rightsized; |
| 70 | + //delete key_rightsized; |
| 71 | + */ |
| 72 | + /*WCHAR* key_name = TEXT("SOFTWARE\\Castle\\BootShellCredentialProvider\\Shells"); |
| 73 | + DWORD count_subkeys = 0; |
| 74 | + DWORD max_length = 0; |
| 75 | + prov.CountSubkeys(key_name, &count_subkeys, &max_length); |
| 76 | + |
| 77 | + int index = 0; |
| 78 | + while (index < count_subkeys) { |
| 79 | + WCHAR* subkey_name = new WCHAR[max_length]; |
| 80 | + DWORD length_subkey = max_length * 2; //need bytes |
| 81 | + LONG r_result = prov.GetSubKey(key_name, index, subkey_name, &length_subkey); |
| 82 | + WCHAR* final_answer = new WCHAR[length_subkey + 1]; |
| 83 | + StringCchCopy(final_answer, length_subkey + 1, subkey_name); |
| 84 | + WriteConsole(hwnd_console_out, final_answer, length_subkey + 1, NULL, NULL); |
| 85 | + index++; |
| 86 | + }*/ |
| 87 | + /*DWORD dwSelectedItem = 0; |
| 88 | + HRESULT hr; |
| 89 | + //load up correct subkey |
| 90 | + DWORD max_length = 150; |
| 91 | + WCHAR* subkey_name = new WCHAR[max_length]; |
| 92 | + DWORD length_subkey = max_length; //need bytes |
| 93 | + LONG r_result = prov.GetSubKey(TEXT("SOFTWARE\\Castle\\BootShellCredentialProvider\\Shells"), dwSelectedItem, subkey_name, &length_subkey); |
| 94 | + //get command for selected option |
| 95 | + WCHAR* command_base = TEXT("SOFTWARE\\Castle\\BootShellCredentialProvider\\Shells\\"); |
| 96 | + DWORD command_length = _tcslen(command_base) + length_subkey + 2; |
| 97 | + WCHAR* command_key = new WCHAR[command_length]; |
| 98 | + StringCchCopy(command_key, _tcslen(command_base) + 2, command_base); |
| 99 | + WCHAR* command_pre = new WCHAR[600]; |
| 100 | + StringCchCat(command_key, command_length, subkey_name); |
| 101 | + LONG res = prov.GetValueAt_sz(command_key, TEXT("command"), command_pre, &command_length); //get length |
| 102 | +
|
| 103 | + WCHAR* control_key_name = TEXT("SOFTWARE\\Castle\\BootShellCredentialProvider\\Shell"); |
| 104 | + res = prov.EnsureKeyValueSet_sz(control_key_name, TEXT("name"), subkey_name, &length_subkey); |
| 105 | + res += prov.EnsureKeyValueSet_sz(control_key_name, TEXT("command"), command_pre, &command_length); |
| 106 | +
|
| 107 | + delete subkey_name; |
| 108 | + delete command_pre; |
| 109 | + delete command_key;*/ |
| 110 | + PWSTR s_RegistryKey_Shells = L"SOFTWARE\\Castle\\BootShellCredentialProvider\\Shells"; |
| 111 | + PWSTR s_RegistryKey_Shells_s = L"SOFTWARE\\Castle\\BootShellCredentialProvider\\Shells\\"; |
| 112 | + PWSTR s_RegistryKey_Shell = L"SOFTWARE\\Castle\\BootShellCredentialProvider\\Shell"; |
| 113 | + DWORD _dwComboIndex = index; |
| 114 | + //get subkey for selected option |
| 115 | + DWORD ccSubkeyLength = 0; |
| 116 | + DWORD cbSubkeyLength = 0; |
| 117 | + WCHAR* subkey_name = prov.pwszGetSubKey(s_RegistryKey_Shells, _dwComboIndex, &cbSubkeyLength, &ccSubkeyLength); |
| 118 | + //get command subkey for selected option |
| 119 | + DWORD command_length = wcslen(s_RegistryKey_Shells) + ccSubkeyLength + 2; |
| 120 | + WCHAR* command_key = new WCHAR[command_length]; |
| 121 | + StringCchCopy(command_key, wcslen(s_RegistryKey_Shells_s) + 2, s_RegistryKey_Shells_s); |
| 122 | + StringCchCat(command_key, command_length, subkey_name); |
| 123 | + //get command for selected option |
| 124 | + DWORD ccCommLength = 0; |
| 125 | + DWORD cbCommLength = 0; |
| 126 | + WCHAR* command_pre = prov.pwszGetValueAt_sz(command_key, TEXT("command"), &cbCommLength, &ccCommLength); |
| 127 | + //get console for selected option |
| 128 | + DWORD ccConsoleLength = 0; |
| 129 | + DWORD cbConsoleLength = 0; |
| 130 | + WCHAR* console_name = prov.pwszGetValueAt_sz(command_key, TEXT("console"), &cbConsoleLength, &ccConsoleLength); |
| 131 | + //get xming for selected option |
| 132 | + DWORD ccXmingLength = 0; |
| 133 | + DWORD cbXmingLength = 0; |
| 134 | + WCHAR* xming_value = prov.pwszGetValueAt_sz(command_key, TEXT("xming"), &cbXmingLength, &ccXmingLength); |
| 135 | + //set values |
| 136 | + prov.EnsureKeyValueSet_sz(s_RegistryKey_Shell, TEXT("name"), subkey_name, &cbSubkeyLength); |
| 137 | + prov.EnsureKeyValueSet_sz(s_RegistryKey_Shell, TEXT("command"), command_pre, &cbCommLength); |
| 138 | + prov.EnsureKeyValueSet_sz(s_RegistryKey_Shell, TEXT("console"), console_name, &cbConsoleLength); |
| 139 | + prov.EnsureKeyValueSet_sz(s_RegistryKey_Shell, TEXT("xming"), xming_value, &cbXmingLength); |
| 140 | + //ShellExecute(NULL, TEXT("Open"), TEXT("bash.exe"), TEXT("/K \"bash.exe\" "), NULL, SW_SHOW); |
| 141 | + //system("pause"); |
| 142 | + index += 1; |
| 143 | + } |
| 144 | + return 0; |
| 145 | +} |
| 146 | + |
0 commit comments