1
0
Fork 0

EXE+DBG: improved launcher (closes issue #1591)

pull/1612/head
mrexodia 2017-05-31 15:47:08 +02:00
parent 9ddfa87789
commit 32be2538dc
No known key found for this signature in database
GPG Key ID: FC89E0AAA0C1AAD8
11 changed files with 213 additions and 62 deletions

View File

@ -2894,7 +2894,12 @@ bool dbgrestartadmin()
*last = L'\0';
//TODO: possibly escape characters in gInitCmd
std::wstring params = L"\"" + gInitExe + L"\" \"" + gInitCmd + L"\" \"" + gInitDir + L"\"";
auto result = ShellExecuteW(NULL, L"runas", file.c_str(), params.c_str(), wszProgramPath, SW_SHOWDEFAULT);
OSVERSIONINFOW osvi;
memset(&osvi, 0, sizeof(osvi));
osvi.dwOSVersionInfoSize = sizeof(osvi);
GetVersionExW(&osvi);
auto operation = osvi.dwMajorVersion >= 6 ? L"runas" : L"open";
auto result = ShellExecuteW(NULL, operation, file.c_str(), params.c_str(), wszProgramPath, SW_SHOWDEFAULT);
return int(result) > 32 && GetLastError() == ERROR_SUCCESS;
}
return false;

View File

@ -1,6 +1,6 @@
#include <string>
#include "resource1.h" // String resources
#include "strings.h" // String resources
inline std::wstring _LoadResString(UINT uID)
{

View File

@ -2,14 +2,19 @@
// Microsoft Visual C++ generated include file.
// Used by resource.rc
//
#define IDD_DIALOGLAUNCHER 105
#define IDC_BUTTON32 1001
#define IDC_BUTTON64 1002
#define IDC_BUTTON3 1003
#define IDC_BUTTONINSTALL 1003
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 105
#define _APS_NEXT_RESOURCE_VALUE 107
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_CONTROL_VALUE 1002
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -7,16 +7,16 @@
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include <windows.h>
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (United States) resources
// Neutral resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEU)
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
#pragma code_page(1252)
#ifdef APSTUDIO_INVOKED
@ -52,6 +52,7 @@ END
1 RT_MANIFEST ".\\manifest.xml"
/////////////////////////////////////////////////////////////////////////////
//
// Version
@ -87,7 +88,53 @@ BEGIN
END
END
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOGLAUNCHER DIALOGEX 0, 0, 177, 28
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Launcher"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
PUSHBUTTON "x32dbg",IDC_BUTTON32,7,7,50,14
PUSHBUTTON "x64dbg",IDC_BUTTON64,63,7,50,14
PUSHBUTTON "Setup",IDC_BUTTONINSTALL,120,7,50,14
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO
BEGIN
IDD_DIALOGLAUNCHER, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 170
TOPMARGIN, 7
BOTTOMMARGIN, 21
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// AFX_DIALOG_LAYOUT
//
IDD_DIALOGLAUNCHER AFX_DIALOG_LAYOUT
BEGIN
0
END
#endif // Neutral resources
/////////////////////////////////////////////////////////////////////////////

View File

@ -1,7 +1,8 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Strings.rc
//
//
//
#define IDS_SETUP 101
#define IDS_ERROR 105
#define IDS_ERRORGETTINGMODULEPATH 106
#define IDS_QUESTION 107
@ -20,13 +21,14 @@
#define IDS_REGOPENKEYFAIL 120
#define IDS_BRIDGEINITERR 121
#define IDS_SHELLEXTDBG 122
#define IDS_ASKICON 123
#define IDS_BRIDGESTARTERR 126
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_RESOURCE_VALUE 102
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101

View File

@ -27,7 +27,7 @@
<ClInclude Include="icon.h" />
<ClInclude Include="LoadResourceString.h" />
<ClInclude Include="resource.h" />
<ClInclude Include="resource1.h" />
<ClInclude Include="strings.h" />
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="icon32.rc">

View File

@ -32,7 +32,7 @@
<ClInclude Include="icon.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="resource1.h">
<ClInclude Include="strings.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="LoadResourceString.h">

View File

@ -7,14 +7,17 @@
#include <shlobj.h>
#include <atlcomcli.h>
#include "../exe/resource.h"
#include "../exe/LoadResourceString.h"
#include "../exe/icon.h"
typedef BOOL(WINAPI* LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
typedef BOOL(WINAPI* LPFN_Wow64DisableWow64FsRedirection)(PVOID);
typedef BOOL(WINAPI* LPFN_Wow64RevertWow64FsRedirection)(PVOID);
#pragma comment(lib, "comctl32.lib")
LPFN_Wow64DisableWow64FsRedirection _Wow64DisableRedirection = NULL;
LPFN_Wow64RevertWow64FsRedirection _Wow64RevertRedirection = NULL;
static bool FileExists(const TCHAR* file)
{
auto attrib = GetFileAttributes(file);
return (attrib != INVALID_FILE_ATTRIBUTES && !(attrib & FILE_ATTRIBUTE_DIRECTORY));
}
enum arch
{
@ -25,12 +28,6 @@ enum arch
dotnet
};
static bool FileExists(const TCHAR* file)
{
auto attrib = GetFileAttributes(file);
return (attrib != INVALID_FILE_ATTRIBUTES && !(attrib & FILE_ATTRIBUTE_DIRECTORY));
}
static arch GetFileArchitecture(const TCHAR* szFileName)
{
arch retval = notfound;
@ -85,12 +82,18 @@ static bool BrowseFileOpen(HWND owner, const TCHAR* filter, const TCHAR* defext,
return !!GetOpenFileName(&ofstruct);
}
typedef BOOL(WINAPI* LPFN_ISWOW64PROCESS)(HANDLE, PBOOL);
typedef BOOL(WINAPI* LPFN_Wow64DisableWow64FsRedirection)(PVOID);
typedef BOOL(WINAPI* LPFN_Wow64RevertWow64FsRedirection)(PVOID);
LPFN_Wow64DisableWow64FsRedirection _Wow64DisableRedirection = NULL;
LPFN_Wow64RevertWow64FsRedirection _Wow64RevertRedirection = NULL;
static BOOL isWoW64()
{
LPFN_ISWOW64PROCESS fnIsWow64Process;
BOOL isWoW64 = FALSE;
fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
static auto fnIsWow64Process = (LPFN_ISWOW64PROCESS)GetProcAddress(GetModuleHandle(TEXT("kernel32")), "IsWow64Process");
if(NULL != fnIsWow64Process)
{
@ -113,9 +116,28 @@ static BOOL isWowRedirectionSupported()
return bRedirectSupported;
else
return !bRedirectSupported;
}
struct RedirectWow
{
PVOID oldValue = NULL;
bool DisableRedirect()
{
return !!_Wow64DisableRedirection(&oldValue);
}
~RedirectWow()
{
if(oldValue != NULL)
{
if(!_Wow64RevertRedirection(oldValue))
//Error occured here. Ignore or reset? (does it matter at this point?)
MessageBox(nullptr, TEXT("Error in Reverting Redirection"), TEXT("Error"), MB_OK | MB_ICONERROR);
}
}
};
static TCHAR* GetDesktopPath()
{
static TCHAR path[MAX_PATH + 1];
@ -124,11 +146,6 @@ static TCHAR* GetDesktopPath()
return nullptr;
}
const wchar_t* SHELLEXT_EXE_KEY = L"exefile\\shell\\Debug with x64dbg\\Command";
const wchar_t* SHELLEXT_ICON_EXE_KEY = L"exefile\\shell\\Debug with x64dbg";
const wchar_t* SHELLEXT_DLL_KEY = L"dllfile\\shell\\Debug with x64dbg\\Command";
const wchar_t* SHELLEXT_ICON_DLL_KEY = L"dllfile\\shell\\Debug with x64dbg";
static HRESULT AddDesktopShortcut(TCHAR* szPathOfFile, const TCHAR* szNameOfLink)
{
HRESULT hRes = NULL;
@ -249,26 +266,6 @@ static bool ResolveShortcut(HWND hwnd, const TCHAR* szShortcutPath, TCHAR* szRes
return SUCCEEDED(hres);
}
struct RedirectWow
{
PVOID oldValue = NULL;
bool DisableRedirect()
{
return !!_Wow64DisableRedirection(&oldValue);
}
~RedirectWow()
{
if(oldValue != NULL)
{
if(!_Wow64RevertRedirection(oldValue))
//Error occured here. Ignore or reset? (does it matter at this point?)
MessageBox(nullptr, TEXT("Error in Reverting Redirection"), TEXT("Error"), MB_OK | MB_ICONERROR);
}
}
};
static void AddDBFileTypeIcon(TCHAR* sz32Path, TCHAR* sz64Path)
{
HKEY hKeyCreatedx32;
@ -337,13 +334,83 @@ static void AddDBFileTypeIcon(TCHAR* sz32Path, TCHAR* sz64Path)
return;
}
static TCHAR szModulePath[MAX_PATH] = TEXT("");
static TCHAR szCurrentDir[MAX_PATH] = TEXT("");
static TCHAR sz32Path[MAX_PATH] = TEXT("");
static TCHAR sz32Dir[MAX_PATH] = TEXT("");
static TCHAR sz64Path[MAX_PATH] = TEXT("");
static TCHAR sz64Dir[MAX_PATH] = TEXT("");
static BOOL CALLBACK DlgLauncher(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
case WM_INITDIALOG:
{
HANDLE hIcon;
hIcon = LoadIconW(GetModuleHandle(0), MAKEINTRESOURCE(IDI_ICON1));
SendMessageW(hwndDlg, WM_SETICON, ICON_BIG, (LPARAM)hIcon);
SetDlgItemText(hwndDlg, IDC_BUTTONINSTALL, LoadResString(IDS_SETUP));
EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON32), *sz32Dir != TEXT('\0'));
EnableWindow(GetDlgItem(hwndDlg, IDC_BUTTON64), *sz64Dir != TEXT('\0') && isWoW64());
}
return TRUE;
case WM_CLOSE:
{
EndDialog(hwndDlg, 0);
}
return TRUE;
case WM_COMMAND:
{
switch(LOWORD(wParam))
{
case IDC_BUTTON32:
{
EndDialog(hwndDlg, 0);
ShellExecute(nullptr, TEXT("open"), sz32Path, TEXT(""), sz32Dir, SW_SHOWNORMAL);
}
return TRUE;
case IDC_BUTTON64:
{
EndDialog(hwndDlg, 0);
ShellExecute(nullptr, TEXT("open"), sz64Path, TEXT(""), sz64Dir, SW_SHOWNORMAL);
}
return TRUE;
case IDC_BUTTONINSTALL:
{
EndDialog(hwndDlg, 0);
OSVERSIONINFO osvi;
memset(&osvi, 0, sizeof(osvi));
osvi.dwOSVersionInfoSize = sizeof(osvi);
GetVersionEx(&osvi);
auto operation = osvi.dwMajorVersion >= 6 ? TEXT("runas") : TEXT("open");
ShellExecute(nullptr, operation, szModulePath, TEXT("::install"), szCurrentDir, SW_SHOWNORMAL);
}
return TRUE;
}
}
break;
}
return FALSE;
}
const wchar_t* SHELLEXT_EXE_KEY = L"exefile\\shell\\Debug with x64dbg\\Command";
const wchar_t* SHELLEXT_ICON_EXE_KEY = L"exefile\\shell\\Debug with x64dbg";
const wchar_t* SHELLEXT_DLL_KEY = L"dllfile\\shell\\Debug with x64dbg\\Command";
const wchar_t* SHELLEXT_ICON_DLL_KEY = L"dllfile\\shell\\Debug with x64dbg";
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
{
InitCommonControls();
//Initialize COM
CoInitialize(nullptr);
//Get INI file path
TCHAR szModulePath[MAX_PATH] = TEXT("");
if(!GetModuleFileName(nullptr, szModulePath, MAX_PATH))
{
MessageBox(nullptr, LoadResString(IDS_ERRORGETTINGMODULEPATH), LoadResString(IDS_ERROR), MB_ICONERROR | MB_SYSTEMMODAL);
@ -351,7 +418,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
}
TCHAR szIniPath[MAX_PATH] = TEXT("");
_tcscpy_s(szIniPath, szModulePath);
TCHAR szCurrentDir[MAX_PATH] = TEXT("");
_tcscpy_s(szCurrentDir, szModulePath);
auto len = int(_tcslen(szCurrentDir));
while(szCurrentDir[len] != TEXT('\\') && len)
@ -369,7 +435,6 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
//Load settings
auto bDoneSomething = false;
TCHAR sz32Path[MAX_PATH] = TEXT("");
if(!GetPrivateProfileString(TEXT("Launcher"), TEXT("x32dbg"), TEXT(""), sz32Path, MAX_PATH, szIniPath))
{
_tcscpy_s(sz32Path, szCurrentDir);
@ -381,11 +446,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
}
}
TCHAR sz32Dir[MAX_PATH] = TEXT("");
_tcscpy_s(sz32Dir, sz32Path);
PathRemoveFileSpec(sz32Dir);
TCHAR sz64Path[MAX_PATH] = TEXT("");
if(!GetPrivateProfileString(TEXT("Launcher"), TEXT("x64dbg"), TEXT(""), sz64Path, MAX_PATH, szIniPath))
{
_tcscpy_s(sz64Path, szCurrentDir);
@ -397,14 +460,27 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
}
}
TCHAR sz64Dir[MAX_PATH] = TEXT("");
_tcscpy_s(sz64Dir, sz64Path);
PathRemoveFileSpec(sz64Dir);
//Handle command line
auto argc = 0;
auto argv = CommandLineToArgvW(GetCommandLineW(), &argc);
if(argc <= 1) //no arguments -> set configuration
if(argc <= 1) //no arguments -> launcher dialog
{
if(!FileExists(sz32Path) && BrowseFileOpen(nullptr, TEXT("x32dbg.exe\0x32dbg.exe\0\0"), nullptr, sz32Path, MAX_PATH, szCurrentDir))
{
WritePrivateProfileString(TEXT("Launcher"), TEXT("x32dbg"), sz32Path, szIniPath);
bDoneSomething = true;
}
if(!FileExists(sz64Path) && BrowseFileOpen(nullptr, TEXT("x64dbg.exe\0x64dbg.exe\0\0"), nullptr, sz64Path, MAX_PATH, szCurrentDir))
{
WritePrivateProfileString(TEXT("Launcher"), TEXT("x64dbg"), sz64Path, szIniPath);
bDoneSomething = true;
}
DialogBox(GetModuleHandle(0), MAKEINTRESOURCE(IDD_DIALOGLAUNCHER), 0, DlgLauncher);
}
else if(argc >= 2 && !wcscmp(argv[1], L"::install")) //set configuration
{
if(!FileExists(sz32Path) && BrowseFileOpen(nullptr, TEXT("x32dbg.exe\0x32dbg.exe\0\0"), nullptr, sz32Path, MAX_PATH, szCurrentDir))
{
@ -426,15 +502,21 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLi
AddShellIcon(SHELLEXT_ICON_EXE_KEY, szIconCommand, LoadResString(IDS_SHELLEXTDBG));
if(RegisterShellExtension(SHELLEXT_DLL_KEY, szLauncherCommand))
AddShellIcon(SHELLEXT_ICON_DLL_KEY, szIconCommand, LoadResString(IDS_SHELLEXTDBG));
bDoneSomething = true;
}
if(MessageBox(nullptr, LoadResString(IDS_ASKDESKTOPSHORTCUT), LoadResString(IDS_QUESTION), MB_YESNO | MB_ICONQUESTION) == IDYES)
{
AddDesktopShortcut(sz32Path, TEXT("x32dbg"));
if(isWoW64())
AddDesktopShortcut(sz64Path, TEXT("x64dbg"));
bDoneSomething = true;
}
AddDBFileTypeIcon(sz32Path, sz64Path);
if(MessageBox(nullptr, LoadResString(IDS_ASKICON), LoadResString(IDS_QUESTION), MB_YESNO | MB_ICONQUESTION) == IDYES)
{
AddDBFileTypeIcon(sz32Path, sz64Path);
bDoneSomething = true;
}
if(bDoneSomething)
MessageBox(nullptr, LoadResString(IDS_NEWCFGWRITTEN), LoadResString(IDS_DONE), MB_ICONINFORMATION);

View File

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
@ -21,6 +21,10 @@
<ItemGroup>
<ClInclude Include="..\exe\resource.h" />
<ClInclude Include="..\exe\icon.h" />
<ClInclude Include="..\exe\strings.h" />
</ItemGroup>
<ItemGroup>
<Xml Include="..\exe\manifest.xml" />
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{AC3F927A-4079-4C97-B8BE-8D04546802E7}</ProjectGuid>

View File

@ -32,10 +32,16 @@
<ClInclude Include="..\exe\icon.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\exe\strings.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="x64dbg_launcher.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<Xml Include="..\exe\manifest.xml" />
</ItemGroup>
</Project>