DBG: finished plugin menu API (tested&working)
DBG: updated TitanEngine GUI: different DbgInit calling place
This commit is contained in:
parent
98b0d7d858
commit
b7b4fb2969
|
@ -136,10 +136,10 @@
|
|||
#define UE_CH_UNLOADDLL 19
|
||||
#define UE_CH_OUTPUTDEBUGSTRING 20
|
||||
#define UE_CH_AFTEREXCEPTIONPROCESSING 21
|
||||
#define UE_CH_ALLEVENTS 22
|
||||
#define UE_CH_SYSTEMBREAKPOINT 23
|
||||
#define UE_CH_UNHANDLEDEXCEPTION 24
|
||||
#define UE_CH_RIPEVENT 25
|
||||
#define UE_CH_DEBUGEVENT 26
|
||||
|
||||
#define UE_OPTION_HANDLER_RETURN_HANDLECOUNT 1
|
||||
#define UE_OPTION_HANDLER_RETURN_ACCESS 2
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "stackinfo.h"
|
||||
#include "thread.h"
|
||||
#include "disasm_fast.h"
|
||||
#include "plugin_loader.h"
|
||||
|
||||
extern "C" DLL_EXPORT duint _dbg_memfindbaseaddr(duint addr, duint* size)
|
||||
{
|
||||
|
@ -713,6 +714,7 @@ extern "C" DLL_EXPORT uint _dbg_sendmessage(DBGMSG type, void* param1, void* par
|
|||
case DBG_MENU_ENTRY_CLICKED:
|
||||
{
|
||||
int hEntry=(int)(uint)param1;
|
||||
pluginmenucall(hEntry);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,12 @@ struct PLUG_INITSTRUCT
|
|||
int sdkVersion;
|
||||
int pluginVersion;
|
||||
char pluginName[256];
|
||||
};
|
||||
|
||||
struct PLUG_SETUPSTRUCT
|
||||
{
|
||||
//provided by the debugger
|
||||
HWND hwndDlg; //gui window handle
|
||||
int hMenu; //plugin menu handle
|
||||
};
|
||||
|
||||
|
@ -120,6 +125,16 @@ struct PLUG_CB_DETACH
|
|||
PROCESS_INFORMATION* fdProcessInfo;
|
||||
};
|
||||
|
||||
struct PLUG_CB_DEBUGEVENT
|
||||
{
|
||||
DEBUG_EVENT* DebugEvent;
|
||||
};
|
||||
|
||||
struct PLUG_CB_MENUENTRY
|
||||
{
|
||||
int hEntry;
|
||||
};
|
||||
|
||||
//enums
|
||||
enum CBTYPE
|
||||
{
|
||||
|
@ -141,6 +156,7 @@ enum CBTYPE
|
|||
CB_ATTACH, //PLUG_CB_ATTACHED (before attaching, after CB_INITDEBUG)
|
||||
CB_DETACH, //PLUG_CB_DETACH (before detaching, before CB_STOPDEBUG)
|
||||
CB_DEBUGEVENT, //PLUG_CB_DEBUGEVENT (called on any debug event)
|
||||
CB_MENUENTRY //PLUG_CB_MENUENTRY
|
||||
};
|
||||
|
||||
//typedefs
|
||||
|
|
|
@ -522,7 +522,7 @@ static void cbCreateProcess(CREATE_PROCESS_DEBUG_INFO* CreateProcessInfo)
|
|||
dputs("failed to get TLS callback addresses!");
|
||||
else
|
||||
{
|
||||
for(int i=0; i<NumberOfCallBacks; i++)
|
||||
for(unsigned int i=0; i<NumberOfCallBacks; i++)
|
||||
{
|
||||
sprintf(command, "bp "fhex",\"TLS Callback %d\",ss", TLSCallBacks[i], i+1);
|
||||
cmddirectexec(dbggetcommandlist(), command);
|
||||
|
@ -667,7 +667,7 @@ static void cbLoadDll(LOAD_DLL_DEBUG_INFO* LoadDll)
|
|||
if(modnamefromaddr((uint)base, modname, true))
|
||||
bpenumall(cbSetModuleBreakpoints, modname);
|
||||
bool bAlreadySetEntry=false;
|
||||
if(bFileIsDll and !stricmp(DLLDebugFileName, szFileName) and !bIsAttached) //Set entry breakpoint
|
||||
if(bFileIsDll and !_stricmp(DLLDebugFileName, szFileName) and !bIsAttached) //Set entry breakpoint
|
||||
{
|
||||
pDebuggedBase=(uint)base;
|
||||
char command[256]="";
|
||||
|
@ -872,6 +872,13 @@ static void cbException(EXCEPTION_DEBUG_INFO* ExceptionData)
|
|||
wait(WAITID_RUN);
|
||||
}
|
||||
|
||||
static void cbDebugEvent(DEBUG_EVENT* DebugEvent)
|
||||
{
|
||||
PLUG_CB_DEBUGEVENT debugEventInfo;
|
||||
debugEventInfo.DebugEvent=DebugEvent;
|
||||
plugincbcall(CB_DEBUGEVENT, &debugEventInfo);
|
||||
}
|
||||
|
||||
static DWORD WINAPI threadDebugLoop(void* lpParameter)
|
||||
{
|
||||
lock(WAITID_STOP); //we are running
|
||||
|
@ -926,6 +933,7 @@ static DWORD WINAPI threadDebugLoop(void* lpParameter)
|
|||
SetCustomHandler(UE_CH_UNLOADDLL, (void*)cbUnloadDll);
|
||||
SetCustomHandler(UE_CH_OUTPUTDEBUGSTRING, (void*)cbOutputDebugString);
|
||||
SetCustomHandler(UE_CH_UNHANDLEDEXCEPTION, (void*)cbException);
|
||||
SetCustomHandler(UE_CH_DEBUGEVENT, (void*)cbDebugEvent);
|
||||
//inform GUI we started without problems
|
||||
GuiSetDebugState(initialized);
|
||||
//set GUI title
|
||||
|
@ -1718,7 +1726,7 @@ CMDRESULT cbDebugFree(int argc, char* argv[])
|
|||
}
|
||||
if(addr==lastalloc)
|
||||
varset("$lastalloc", (uint)0, true);
|
||||
bool ok=VirtualFreeEx(fdProcessInfo->hProcess, (void*)addr, 0, MEM_RELEASE);
|
||||
bool ok=!!VirtualFreeEx(fdProcessInfo->hProcess, (void*)addr, 0, MEM_RELEASE);
|
||||
if(!ok)
|
||||
dputs("VirtualFreeEx failed");
|
||||
varset("$res", ok, false);
|
||||
|
|
|
@ -32,6 +32,7 @@ void pluginload(const char* pluginDir)
|
|||
PLUG_DATA pluginData;
|
||||
do
|
||||
{
|
||||
//set plugin data
|
||||
pluginData.initStruct.pluginHandle=curPluginHandle;
|
||||
char szPluginPath[MAX_PATH]="";
|
||||
sprintf(szPluginPath, "%s\\%s", pluginDir, foundData.cFileName);
|
||||
|
@ -49,6 +50,8 @@ void pluginload(const char* pluginDir)
|
|||
continue;
|
||||
}
|
||||
pluginData.plugstop=(PLUGSTOP)GetProcAddress(pluginData.hPlugin, "plugstop");
|
||||
pluginData.plugsetup=(PLUGSETUP)GetProcAddress(pluginData.hPlugin, "plugsetup");
|
||||
//init plugin
|
||||
//TODO: handle exceptions
|
||||
if(!pluginData.pluginit(&pluginData.initStruct))
|
||||
{
|
||||
|
@ -58,7 +61,31 @@ void pluginload(const char* pluginDir)
|
|||
}
|
||||
else
|
||||
dprintf("[PLUGIN] %s v%d Loaded!\n", pluginData.initStruct.pluginName, pluginData.initStruct.pluginVersion);
|
||||
//add plugin menu
|
||||
int hNewMenu=GuiMenuAdd(GUI_PLUGIN_MENU, pluginData.initStruct.pluginName);
|
||||
if(hNewMenu==-1)
|
||||
{
|
||||
dprintf("[PLUGIN] GuiMenuAdd failed for plugin: %s\n", pluginData.initStruct.pluginName);
|
||||
pluginData.hMenu=-1;
|
||||
}
|
||||
else
|
||||
{
|
||||
PLUG_MENU newMenu;
|
||||
newMenu.hEntryMenu=hNewMenu;
|
||||
newMenu.hEntryPlugin=-1;
|
||||
newMenu.pluginHandle=pluginData.initStruct.pluginHandle;
|
||||
pluginMenuList.push_back(newMenu);
|
||||
pluginData.hMenu=hNewMenu;
|
||||
}
|
||||
pluginList.push_back(pluginData);
|
||||
//setup plugin
|
||||
if(pluginData.plugsetup)
|
||||
{
|
||||
PLUG_SETUPSTRUCT setupStruct;
|
||||
setupStruct.hwndDlg=GuiGetWindowHandle();
|
||||
setupStruct.hMenu=hNewMenu;
|
||||
pluginData.plugsetup(&setupStruct);
|
||||
}
|
||||
curPluginHandle++;
|
||||
}
|
||||
while(FindNextFileA(hSearch, &foundData));
|
||||
|
@ -208,6 +235,8 @@ bool pluginmenuaddentry(int hMenu, int hEntry, const char* title)
|
|||
if(pluginMenuList.at(i).pluginHandle==pluginHandle && pluginMenuList.at(i).hEntryPlugin==hEntry)
|
||||
return false;
|
||||
int hNewEntry=GuiMenuAddEntry(hMenu, title);
|
||||
if(hNewEntry==-1)
|
||||
return false;
|
||||
PLUG_MENU newMenu;
|
||||
newMenu.hEntryMenu=hNewEntry;
|
||||
newMenu.hEntryPlugin=hEntry;
|
||||
|
@ -249,3 +278,29 @@ bool pluginmenuclear(int hMenu)
|
|||
GuiMenuClear(hMenu);
|
||||
return false;
|
||||
}
|
||||
|
||||
void pluginmenucall(int hEntry)
|
||||
{
|
||||
dprintf("pluginmenucall(%d)\n", hEntry);
|
||||
if(hEntry==-1)
|
||||
return;
|
||||
for(unsigned int i=0; i<pluginMenuList.size(); i++)
|
||||
{
|
||||
if(pluginMenuList.at(i).hEntryMenu==hEntry && pluginMenuList.at(i).hEntryPlugin!=-1)
|
||||
{
|
||||
PLUG_CB_MENUENTRY menuEntryInfo;
|
||||
menuEntryInfo.hEntry=pluginMenuList.at(i).hEntryPlugin;
|
||||
int pluginCallbackCount=pluginCallbackList.size();
|
||||
int pluginHandle=pluginMenuList.at(i).pluginHandle;
|
||||
for(int j=0; j<pluginCallbackCount; j++)
|
||||
{
|
||||
if(pluginCallbackList.at(j).pluginHandle==pluginHandle and pluginCallbackList.at(j).cbType==CB_MENUENTRY)
|
||||
{
|
||||
//TODO: handle exceptions
|
||||
pluginCallbackList.at(j).cbPlugin(CB_MENUENTRY, &menuEntryInfo);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,6 +7,7 @@
|
|||
//typedefs
|
||||
typedef bool (*PLUGINIT)(PLUG_INITSTRUCT* initStruct);
|
||||
typedef bool (*PLUGSTOP)();
|
||||
typedef void (*PLUGSETUP)(PLUG_SETUPSTRUCT* setupStruct);
|
||||
|
||||
//structures
|
||||
struct PLUG_MENU
|
||||
|
@ -21,6 +22,8 @@ struct PLUG_DATA
|
|||
HINSTANCE hPlugin;
|
||||
PLUGINIT pluginit;
|
||||
PLUGSTOP plugstop;
|
||||
PLUGSETUP plugsetup;
|
||||
int hMenu;
|
||||
PLUG_INITSTRUCT initStruct;
|
||||
};
|
||||
|
||||
|
@ -49,5 +52,6 @@ int pluginmenuadd(int hMenu, const char* title);
|
|||
bool pluginmenuaddentry(int hMenu, int hEntry, const char* title);
|
||||
bool pluginmenuaddseparator(int hMenu);
|
||||
bool pluginmenuclear(int hMenu);
|
||||
void pluginmenucall(int hEntry);
|
||||
|
||||
#endif // _PLUGIN_LOADER_H
|
||||
|
|
|
@ -145,17 +145,6 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||
|
||||
//setup menu api
|
||||
initMenuApi();
|
||||
|
||||
const char* errormsg=DbgInit();
|
||||
if(errormsg)
|
||||
{
|
||||
QMessageBox msg(QMessageBox::Critical, "DbgInit Error!", QString(errormsg));
|
||||
msg.setWindowIcon(QIcon(":/icons/images/compile-error.png"));
|
||||
msg.setParent(this, Qt::Dialog);
|
||||
msg.setWindowFlags(msg.windowFlags()&(~Qt::WindowContextHelpButtonHint));
|
||||
msg.exec();
|
||||
ExitProcess(1);
|
||||
}
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
|
|
|
@ -54,8 +54,21 @@ int main(int argc, char *argv[])
|
|||
// Start GUI
|
||||
MainWindow w;
|
||||
w.show();
|
||||
|
||||
// Set some data
|
||||
Bridge::getBridge()->winId=(void*)w.winId();
|
||||
|
||||
// Init debugger
|
||||
const char* errormsg=DbgInit();
|
||||
if(errormsg)
|
||||
{
|
||||
QMessageBox msg(QMessageBox::Critical, "DbgInit Error!", QString(errormsg));
|
||||
msg.setWindowIcon(QIcon(":/icons/images/compile-error.png"));
|
||||
msg.setWindowFlags(msg.windowFlags()&(~Qt::WindowContextHelpButtonHint));
|
||||
msg.exec();
|
||||
ExitProcess(1);
|
||||
}
|
||||
|
||||
return a.exec();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue