DBG+BRIDGE+GUI: added various features to restart as admin
This commit is contained in:
parent
f356ea5b2f
commit
72eae713db
|
@ -1559,6 +1559,11 @@ BRIDGE_IMPEXP void GuiUpdateTypeWidget()
|
|||
_gui_sendmessage(GUI_UPDATE_TYPE_WIDGET, nullptr, nullptr);
|
||||
}
|
||||
|
||||
BRIDGE_IMPEXP void GuiCloseApplication()
|
||||
{
|
||||
_gui_sendmessage(GUI_CLOSE_APPLICATION, nullptr, nullptr);
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
|
||||
{
|
||||
hInst = hinstDLL;
|
||||
|
|
|
@ -986,6 +986,7 @@ typedef enum
|
|||
GUI_TYPE_ADDNODE, // param1=void* parent, param2=TYPEDESCRIPTOR* type
|
||||
GUI_TYPE_CLEAR, // param1=unused, param2=unused
|
||||
GUI_UPDATE_TYPE_WIDGET, // param1=unused, param2=unused
|
||||
GUI_CLOSE_APPLICATION, // param1=unused, param2=unused
|
||||
} GUIMSG;
|
||||
|
||||
//GUI Typedefs
|
||||
|
@ -1148,6 +1149,7 @@ BRIDGE_IMPEXP void GuiProcessEvents();
|
|||
BRIDGE_IMPEXP void* GuiTypeAddNode(void* parent, const TYPEDESCRIPTOR* type);
|
||||
BRIDGE_IMPEXP bool GuiTypeClear();
|
||||
BRIDGE_IMPEXP void GuiUpdateTypeWidget();
|
||||
BRIDGE_IMPEXP void GuiCloseApplication();
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -622,4 +622,11 @@ bool cbInstrConfig(int argc, char* argv[])
|
|||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool cbInstrRestartadmin(int argc, char* argv[])
|
||||
{
|
||||
if(dbgrestartadmin())
|
||||
GuiCloseApplication();
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -21,4 +21,5 @@ bool cbDebugSetCmdline(int argc, char* argv[]);
|
|||
bool cbInstrMnemonichelp(int argc, char* argv[]);
|
||||
bool cbInstrMnemonicbrief(int argc, char* argv[]);
|
||||
|
||||
bool cbInstrConfig(int argc, char* argv[]);
|
||||
bool cbInstrConfig(int argc, char* argv[]);
|
||||
bool cbInstrRestartadmin(int argc, char* argv[]);
|
|
@ -180,6 +180,7 @@ static String lastDebugText;
|
|||
static duint timeWastedDebugging = 0;
|
||||
static EXCEPTION_DEBUG_INFO lastExceptionInfo = { 0 };
|
||||
static char szDebuggeeInitializationScript[MAX_PATH] = "";
|
||||
static WString gInitExe, gInitCmd, gInitDir;
|
||||
char szProgramDir[MAX_PATH] = "";
|
||||
char szFileName[MAX_PATH] = "";
|
||||
char szSymbolCachePath[MAX_PATH] = "";
|
||||
|
@ -2437,6 +2438,7 @@ static void debugLoopFunction(void* lpParameter, bool attach)
|
|||
INIT_STRUCT* init;
|
||||
if(attach)
|
||||
{
|
||||
gInitExe = StringUtils::Utf8ToUtf16(szFileName);
|
||||
pid = DWORD(lpParameter);
|
||||
static PROCESS_INFORMATION pi_attached;
|
||||
memset(&pi_attached, 0, sizeof(pi_attached));
|
||||
|
@ -2445,7 +2447,8 @@ static void debugLoopFunction(void* lpParameter, bool attach)
|
|||
else
|
||||
{
|
||||
init = (INIT_STRUCT*)lpParameter;
|
||||
pDebuggedEntry = GetPE32DataW(StringUtils::Utf8ToUtf16(init->exe).c_str(), 0, UE_OEP);
|
||||
gInitExe = StringUtils::Utf8ToUtf16(init->exe);
|
||||
pDebuggedEntry = GetPE32DataW(gInitExe.c_str(), 0, UE_OEP);
|
||||
strcpy_s(szFileName, init->exe);
|
||||
}
|
||||
|
||||
|
@ -2465,16 +2468,34 @@ static void debugLoopFunction(void* lpParameter, bool attach)
|
|||
init->commandline = commandLineArguments;
|
||||
}
|
||||
|
||||
gInitCmd = StringUtils::Utf8ToUtf16(init->commandline);
|
||||
gInitDir = StringUtils::Utf8ToUtf16(init->currentfolder);
|
||||
|
||||
//start the process
|
||||
if(bFileIsDll)
|
||||
fdProcessInfo = (PROCESS_INFORMATION*)InitDLLDebugW(StringUtils::Utf8ToUtf16(init->exe).c_str(), false, StringUtils::Utf8ToUtf16(init->commandline).c_str(), StringUtils::Utf8ToUtf16(init->currentfolder).c_str(), 0);
|
||||
fdProcessInfo = (PROCESS_INFORMATION*)InitDLLDebugW(gInitExe.c_str(), false, gInitCmd.c_str(), gInitDir.c_str(), 0);
|
||||
else
|
||||
fdProcessInfo = (PROCESS_INFORMATION*)InitDebugW(StringUtils::Utf8ToUtf16(init->exe).c_str(), StringUtils::Utf8ToUtf16(init->commandline).c_str(), StringUtils::Utf8ToUtf16(init->currentfolder).c_str());
|
||||
fdProcessInfo = (PROCESS_INFORMATION*)InitDebugW(gInitExe.c_str(), gInitCmd.c_str(), gInitDir.c_str());
|
||||
if(!fdProcessInfo)
|
||||
{
|
||||
auto lastError = GetLastError();
|
||||
if(lastError == ERROR_ELEVATION_REQUIRED)
|
||||
{
|
||||
auto msg = StringUtils::Utf8ToUtf16(GuiTranslateText(QT_TRANSLATE_NOOP("DBG", "The executable you are trying to debug requires elevation. Restart as admin?")));
|
||||
auto title = StringUtils::Utf8ToUtf16(GuiTranslateText(QT_TRANSLATE_NOOP("DBG", "Elevation")));
|
||||
auto answer = MessageBoxW(GuiGetWindowHandle(), msg.c_str(), title.c_str(), MB_ICONQUESTION | MB_YESNO);
|
||||
wchar_t wszProgramPath[MAX_PATH] = L"";
|
||||
if(answer == IDYES && dbgrestartadmin())
|
||||
{
|
||||
fdProcessInfo = &g_pi;
|
||||
unlock(WAITID_STOP);
|
||||
GuiCloseApplication();
|
||||
return;
|
||||
}
|
||||
}
|
||||
fdProcessInfo = &g_pi;
|
||||
dprintf(QT_TRANSLATE_NOOP("DBG", "Error starting process (CreateProcess, %s)!\n"), ErrorCodeToName(GetLastError()).c_str());
|
||||
unlock(WAITID_STOP);
|
||||
dprintf(QT_TRANSLATE_NOOP("DBG", "Error starting process (CreateProcess, %s)!\n"), ErrorCodeToName(lastError).c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -2505,6 +2526,11 @@ static void debugLoopFunction(void* lpParameter, bool attach)
|
|||
if(!OpenProcessToken(fdProcessInfo->hProcess, TOKEN_ALL_ACCESS, &hProcessToken))
|
||||
hProcessToken = 0;
|
||||
}
|
||||
else //attach
|
||||
{
|
||||
gInitCmd.clear();
|
||||
gInitDir.clear();
|
||||
}
|
||||
|
||||
//set custom handlers
|
||||
SetCustomHandler(UE_CH_CREATEPROCESS, (void*)cbCreateProcess);
|
||||
|
@ -2623,3 +2649,19 @@ DWORD WINAPI threadAttachLoop(void* lpParameter)
|
|||
debugLoopFunction(lpParameter, true);
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool dbgrestartadmin()
|
||||
{
|
||||
wchar_t wszProgramPath[MAX_PATH] = L"";
|
||||
if(GetModuleFileNameW(GetModuleHandleW(nullptr), wszProgramPath, _countof(wszProgramPath)))
|
||||
{
|
||||
std::wstring file = wszProgramPath;
|
||||
auto last = wcsrchr(wszProgramPath, L'\\');
|
||||
if(last)
|
||||
*last = L'\0';
|
||||
std::wstring params = gInitExe + L" " + gInitCmd + L" " + gInitDir;
|
||||
auto result = ShellExecuteW(NULL, L"runas", file.c_str(), params.c_str(), wszProgramPath, SW_SHOWDEFAULT);
|
||||
return int(result) > 32 && GetLastError() == ERROR_SUCCESS;
|
||||
}
|
||||
return false;
|
||||
}
|
|
@ -133,6 +133,7 @@ DWORD WINAPI threadAttachLoop(void* lpParameter);
|
|||
void cbDetach();
|
||||
bool cbSetModuleBreakpoints(const BREAKPOINT* bp);
|
||||
EXCEPTION_DEBUG_INFO getLastExceptionInfo();
|
||||
bool dbgrestartadmin();
|
||||
|
||||
//variables
|
||||
extern PROCESS_INFORMATION* fdProcessInfo;
|
||||
|
|
|
@ -413,6 +413,7 @@ static void registercommands()
|
|||
dbgcmdnew("mnemonicbrief", cbInstrMnemonicbrief, false); //mnemonic brief
|
||||
|
||||
dbgcmdnew("config", cbInstrConfig, false); //get or set config uint
|
||||
dbgcmdnew("restartadmin\1runas\1adminrestart", cbInstrRestartadmin, false); //restart x64dbg as administrator
|
||||
|
||||
//undocumented
|
||||
dbgcmdnew("bench", cbDebugBenchmark, true); //benchmark test (readmem etc)
|
||||
|
|
|
@ -696,10 +696,8 @@ void* Bridge::processMessage(GUIMSG type, void* param1, void* param2)
|
|||
break;
|
||||
|
||||
case GUI_PROCESS_EVENTS:
|
||||
{
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case GUI_TYPE_ADDNODE:
|
||||
{
|
||||
|
@ -718,10 +716,12 @@ void* Bridge::processMessage(GUIMSG type, void* param1, void* param2)
|
|||
break;
|
||||
|
||||
case GUI_UPDATE_TYPE_WIDGET:
|
||||
{
|
||||
emit typeUpdateWidget();
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
case GUI_CLOSE_APPLICATION:
|
||||
emit closeApplication();
|
||||
break;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
|
|
|
@ -144,6 +144,7 @@ signals:
|
|||
void typeAddNode(void* parent, const TYPEDESCRIPTOR* type);
|
||||
void typeClear();
|
||||
void typeUpdateWidget();
|
||||
void closeApplication();
|
||||
|
||||
private:
|
||||
QMutex* mBridgeMutex;
|
||||
|
|
|
@ -87,6 +87,7 @@ MainWindow::MainWindow(QWidget* parent)
|
|||
connect(Bridge::getBridge(), SIGNAL(addFavouriteItem(int, QString, QString)), this, SLOT(addFavouriteItem(int, QString, QString)));
|
||||
connect(Bridge::getBridge(), SIGNAL(setFavouriteItemShortcut(int, QString, QString)), this, SLOT(setFavouriteItemShortcut(int, QString, QString)));
|
||||
connect(Bridge::getBridge(), SIGNAL(selectInMemoryMap(duint)), this, SLOT(displayMemMapWidget()));
|
||||
connect(Bridge::getBridge(), SIGNAL(closeApplication()), this, SLOT(close()));
|
||||
|
||||
// Setup menu API
|
||||
initMenuApi();
|
||||
|
@ -560,6 +561,7 @@ void MainWindow::refreshShortcuts()
|
|||
setGlobalShortcut(ui->actionDetach, ConfigShortcut("FileDetach"));
|
||||
setGlobalShortcut(ui->actionImportdatabase, ConfigShortcut("FileImportDatabase"));
|
||||
setGlobalShortcut(ui->actionExportdatabase, ConfigShortcut("FileExportDatabase"));
|
||||
setGlobalShortcut(ui->actionRestartAdmin, ConfigShortcut("FileRestartAdmin"));
|
||||
setGlobalShortcut(ui->actionExit, ConfigShortcut("FileExit"));
|
||||
|
||||
setGlobalShortcut(ui->actionCpu, ConfigShortcut("ViewCpu"));
|
||||
|
@ -1949,3 +1951,8 @@ void MainWindow::onMenuCustomized()
|
|||
delete moreCommands;
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::on_actionRestartAdmin_triggered()
|
||||
{
|
||||
DbgCmdExec("restartadmin");
|
||||
}
|
||||
|
|
|
@ -272,6 +272,7 @@ private slots:
|
|||
void on_actionImportSettings_triggered();
|
||||
void on_actionImportdatabase_triggered();
|
||||
void on_actionExportdatabase_triggered();
|
||||
void on_actionRestartAdmin_triggered();
|
||||
};
|
||||
|
||||
#endif // MAINWINDOW_H
|
||||
|
|
|
@ -47,6 +47,7 @@
|
|||
<addaction name="actionImportdatabase"/>
|
||||
<addaction name="actionExportdatabase"/>
|
||||
<addaction name="actionPatches"/>
|
||||
<addaction name="actionRestartAdmin"/>
|
||||
<addaction name="separator"/>
|
||||
<addaction name="actionExit"/>
|
||||
</widget>
|
||||
|
@ -1118,15 +1119,32 @@
|
|||
</property>
|
||||
</action>
|
||||
<action name="actionHideTab">
|
||||
<property name="icon">
|
||||
<iconset resource="../../resource.qrc">
|
||||
<normaloff>:/icons/images/hidetab.png</normaloff>:/icons/images/hidetab.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Hide Tab</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionVariables">
|
||||
<property name="icon">
|
||||
<iconset resource="../../resource.qrc">
|
||||
<normaloff>:/icons/images/variables.png</normaloff>:/icons/images/variables.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>&Variables</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionRestartAdmin">
|
||||
<property name="icon">
|
||||
<iconset resource="../../resource.qrc">
|
||||
<normaloff>:/icons/images/uac.png</normaloff>:/icons/images/uac.png</iconset>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Restart as Admin</string>
|
||||
</property>
|
||||
</action>
|
||||
</widget>
|
||||
<layoutdefault spacing="6" margin="11"/>
|
||||
<resources>
|
||||
|
|
|
@ -302,6 +302,7 @@ Configuration::Configuration() : QObject(), noMoreMsgbox(false)
|
|||
defaultShortcuts.insert("FileDetach", Shortcut(tr("File -> Detach"), "Ctrl+Alt+F2", true));
|
||||
defaultShortcuts.insert("FileImportDatabase", Shortcut(tr("File -> Import database"), "", true));
|
||||
defaultShortcuts.insert("FileExportDatabase", Shortcut(tr("File -> Export database"), "", true));
|
||||
defaultShortcuts.insert("FileRestartAdmin", Shortcut(tr("File -> Restart as Admin"), "", true));
|
||||
defaultShortcuts.insert("FileExit", Shortcut(tr("File -> Exit"), "Alt+X", true));
|
||||
|
||||
defaultShortcuts.insert("ViewCpu", Shortcut(tr("View -> CPU"), "Alt+C", true));
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 412 B |
Binary file not shown.
After Width: | Height: | Size: 839 B |
Binary file not shown.
After Width: | Height: | Size: 276 B |
|
@ -275,5 +275,8 @@
|
|||
<file>images/visitstruct.png</file>
|
||||
<file>images/structaddr.png</file>
|
||||
<file>images/virtual.png</file>
|
||||
<file>images/uac.png</file>
|
||||
<file>images/hidetab.png</file>
|
||||
<file>images/variables.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
Loading…
Reference in New Issue