DBG: updated TitanEngine (hardware breakpoints for x64 now work)

PROJECT: updated help
DBG: you can now set & delete hardware breakpoints (x32+x64)
GUI: added hardware breakpoint delete in context menu
GUI: changed command bar shortcut to CTRL+ENTER
This commit is contained in:
mr.exodia 2013-11-18 22:12:42 +01:00
parent aa6c48743a
commit 0f7e547f74
17 changed files with 272 additions and 199 deletions

Binary file not shown.

Binary file not shown.

View File

@ -96,7 +96,7 @@ Font=
DefaultTopic=Introduction.htm
[TOPICS]
TitleList=41
TitleList=40
TitleList.Title.0=Introduction
TitleList.Level.0=0
TitleList.Url.0=Introduction.htm
@ -287,224 +287,214 @@ TitleList.ContextNumber.18=1016
TitleList.ApplyTemp.18=0
TitleList.Expanded.18=0
TitleList.Kind.18=0
TitleList.Title.19=ToggleBPX/bpt/bt
TitleList.Title.19=bplist
TitleList.Level.19=1
TitleList.Url.19=ToggleBPX_bpt_bt.htm
TitleList.Url.19=bplist.htm
TitleList.Icon.19=0
TitleList.Status.19=0
TitleList.Keywords.19=
TitleList.ContextNumber.19=1019
TitleList.ContextNumber.19=1015
TitleList.ApplyTemp.19=0
TitleList.Expanded.19=0
TitleList.Kind.19=0
TitleList.Title.20=bplist
TitleList.Title.20=StepInto/sti
TitleList.Level.20=1
TitleList.Url.20=bplist.htm
TitleList.Url.20=StepInto.htm
TitleList.Icon.20=0
TitleList.Status.20=0
TitleList.Keywords.20=
TitleList.ContextNumber.20=1015
TitleList.ContextNumber.20=1021
TitleList.ApplyTemp.20=0
TitleList.Expanded.20=0
TitleList.Kind.20=0
TitleList.Title.21=StepInto/sti
TitleList.Title.21=StepOver/step/sto/st
TitleList.Level.21=1
TitleList.Url.21=StepInto.htm
TitleList.Url.21=StepOver.htm
TitleList.Icon.21=0
TitleList.Status.21=0
TitleList.Keywords.21=
TitleList.ContextNumber.21=1021
TitleList.ContextNumber.21=1022
TitleList.ApplyTemp.21=0
TitleList.Expanded.21=0
TitleList.Kind.21=0
TitleList.Title.22=StepOver/step/sto/st
TitleList.Title.22=SingleStep/sstep/sst
TitleList.Level.22=1
TitleList.Url.22=StepOver.htm
TitleList.Url.22=SingleStep.htm
TitleList.Icon.22=0
TitleList.Status.22=0
TitleList.Keywords.22=
TitleList.ContextNumber.22=1022
TitleList.ContextNumber.22=1023
TitleList.ApplyTemp.22=0
TitleList.Expanded.22=0
TitleList.Kind.22=0
TitleList.Title.23=SingleStep/sstep/sst
TitleList.Title.23=HideDebugger/dbh/hide
TitleList.Level.23=1
TitleList.Url.23=SingleStep.htm
TitleList.Url.23=HideDebugger_dbh_hide.htm
TitleList.Icon.23=0
TitleList.Status.23=0
TitleList.Keywords.23=
TitleList.ContextNumber.23=1023
TitleList.ContextNumber.23=1025
TitleList.ApplyTemp.23=0
TitleList.Expanded.23=0
TitleList.Kind.23=0
TitleList.Title.24=HideDebugger/dbh/hide
TitleList.Title.24=disasm/dis/d
TitleList.Level.24=1
TitleList.Url.24=HideDebugger_dbh_hide.htm
TitleList.Url.24=disasm_dis_d.htm
TitleList.Icon.24=0
TitleList.Status.24=0
TitleList.Keywords.24=
TitleList.ContextNumber.24=1025
TitleList.ContextNumber.24=1026
TitleList.ApplyTemp.24=0
TitleList.Expanded.24=0
TitleList.Kind.24=0
TitleList.Title.25=disasm/dis/d
TitleList.Title.25=SetMemoryBPX/membp/bpm
TitleList.Level.25=1
TitleList.Url.25=disasm_dis_d.htm
TitleList.Url.25=SetMemoryBPX_membp_bpm.htm
TitleList.Icon.25=0
TitleList.Status.25=0
TitleList.Keywords.25=
TitleList.ContextNumber.25=1026
TitleList.ContextNumber.25=1027
TitleList.ApplyTemp.25=0
TitleList.Expanded.25=0
TitleList.Kind.25=0
TitleList.Title.26=SetMemoryBPX/membp/bpm
TitleList.Title.26=chd
TitleList.Level.26=1
TitleList.Url.26=SetMemoryBPX_membp_bpm.htm
TitleList.Url.26=chd.htm
TitleList.Icon.26=0
TitleList.Status.26=0
TitleList.Keywords.26=
TitleList.ContextNumber.26=1027
TitleList.ContextNumber.26=1029
TitleList.ApplyTemp.26=0
TitleList.Expanded.26=0
TitleList.Kind.26=0
TitleList.Title.27=chd
TitleList.Title.27=rtr
TitleList.Level.27=1
TitleList.Url.27=chd.htm
TitleList.Url.27=rtr.htm
TitleList.Icon.27=0
TitleList.Status.27=0
TitleList.Keywords.27=
TitleList.ContextNumber.27=1029
TitleList.ContextNumber.27=1028
TitleList.ApplyTemp.27=0
TitleList.Expanded.27=0
TitleList.Kind.27=0
TitleList.Title.28=rtr
TitleList.Title.28=SetHardwareBreakpoint/bph/bphws
TitleList.Level.28=1
TitleList.Url.28=rtr.htm
TitleList.Url.28=SetHardwareBreakpoint_bph_bphws.htm
TitleList.Icon.28=0
TitleList.Status.28=0
TitleList.Keywords.28=
TitleList.ContextNumber.28=1028
TitleList.ContextNumber.28=1030
TitleList.ApplyTemp.28=0
TitleList.Expanded.28=0
TitleList.Kind.28=0
TitleList.Title.29=SetHardwareBreakpoint/bph/bphws
TitleList.Title.29=alloc
TitleList.Level.29=1
TitleList.Url.29=SetHardwareBreakpoint_bph_bphws.htm
TitleList.Url.29=alloc.htm
TitleList.Icon.29=0
TitleList.Status.29=0
TitleList.Keywords.29=
TitleList.ContextNumber.29=1030
TitleList.ContextNumber.29=1032
TitleList.ApplyTemp.29=0
TitleList.Expanded.29=0
TitleList.Kind.29=0
TitleList.Title.30=alloc
TitleList.Title.30=free
TitleList.Level.30=1
TitleList.Url.30=alloc.htm
TitleList.Url.30=free.htm
TitleList.Icon.30=0
TitleList.Status.30=0
TitleList.Keywords.30=
TitleList.ContextNumber.30=1032
TitleList.ContextNumber.30=1031
TitleList.ApplyTemp.30=0
TitleList.Expanded.30=0
TitleList.Kind.30=0
TitleList.Title.31=free
TitleList.Title.31=Fill/memset
TitleList.Level.31=1
TitleList.Url.31=free.htm
TitleList.Url.31=Fill_memset.htm
TitleList.Icon.31=0
TitleList.Status.31=0
TitleList.Keywords.31=
TitleList.ContextNumber.31=1031
TitleList.ContextNumber.31=1033
TitleList.ApplyTemp.31=0
TitleList.Expanded.31=0
TitleList.Kind.31=0
TitleList.Title.32=Fill/memset
TitleList.Title.32=cmt/cmtset/commentset
TitleList.Level.32=1
TitleList.Url.32=Fill_memset.htm
TitleList.Url.32=cmt_cmtset_commentset.htm
TitleList.Icon.32=0
TitleList.Status.32=0
TitleList.Keywords.32=
TitleList.ContextNumber.32=1033
TitleList.ContextNumber.32=1035
TitleList.ApplyTemp.32=0
TitleList.Expanded.32=0
TitleList.Kind.32=0
TitleList.Title.33=cmt/cmtset/commentset
TitleList.Title.33=cmtc/cmtdel/commentdel
TitleList.Level.33=1
TitleList.Url.33=cmt_cmtset_commentset.htm
TitleList.Url.33=cmtc_cmtdel_commentdel.htm
TitleList.Icon.33=0
TitleList.Status.33=0
TitleList.Keywords.33=
TitleList.ContextNumber.33=1035
TitleList.ContextNumber.33=1036
TitleList.ApplyTemp.33=0
TitleList.Expanded.33=0
TitleList.Kind.33=0
TitleList.Title.34=cmtc/cmtdel/commentdel
TitleList.Title.34=lbl/lblset/labelset
TitleList.Level.34=1
TitleList.Url.34=cmtc_cmtdel_commentdel.htm
TitleList.Url.34=lbl_lblset_labelset.htm
TitleList.Icon.34=0
TitleList.Status.34=0
TitleList.Keywords.34=
TitleList.ContextNumber.34=1036
TitleList.ContextNumber.34=1037
TitleList.ApplyTemp.34=0
TitleList.Expanded.34=0
TitleList.Kind.34=0
TitleList.Title.35=lbl/lblset/labelset
TitleList.Title.35=lblc/lbldel/labeldel
TitleList.Level.35=1
TitleList.Url.35=lbl_lblset_labelset.htm
TitleList.Url.35=lblc_lbldel_labeldel.htm
TitleList.Icon.35=0
TitleList.Status.35=0
TitleList.Keywords.35=
TitleList.ContextNumber.35=1037
TitleList.ContextNumber.35=1038
TitleList.ApplyTemp.35=0
TitleList.Expanded.35=0
TitleList.Kind.35=0
TitleList.Title.36=lblc/lbldel/labeldel
TitleList.Title.36=savedb/dbsave
TitleList.Level.36=1
TitleList.Url.36=lblc_lbldel_labeldel.htm
TitleList.Url.36=savedb_dbsave.htm
TitleList.Icon.36=0
TitleList.Status.36=0
TitleList.Keywords.36=
TitleList.ContextNumber.36=1038
TitleList.ContextNumber.36=1034
TitleList.ApplyTemp.36=0
TitleList.Expanded.36=0
TitleList.Kind.36=0
TitleList.Title.37=savedb/dbsave
TitleList.Title.37=loaddb/dbload
TitleList.Level.37=1
TitleList.Url.37=savedb_dbsave.htm
TitleList.Url.37=loaddb_dbload.htm
TitleList.Icon.37=0
TitleList.Status.37=0
TitleList.Keywords.37=
TitleList.ContextNumber.37=1034
TitleList.ContextNumber.37=1039
TitleList.ApplyTemp.37=0
TitleList.Expanded.37=0
TitleList.Kind.37=0
TitleList.Title.38=loaddb/dbload
TitleList.Level.38=1
TitleList.Url.38=loaddb_dbload.htm
TitleList.Title.38=Special Thanks
TitleList.Level.38=0
TitleList.Url.38=Special_Thanks.htm
TitleList.Icon.38=0
TitleList.Status.38=0
TitleList.Keywords.38=
TitleList.ContextNumber.38=1039
TitleList.ContextNumber.38=1024
TitleList.ApplyTemp.38=0
TitleList.Expanded.38=0
TitleList.Kind.38=0
TitleList.Title.39=Special Thanks
TitleList.Title.39=Fixed Top Style
TitleList.Level.39=0
TitleList.Url.39=Special_Thanks.htm
TitleList.Url.39=template\fixedtop.htm
TitleList.Icon.39=0
TitleList.Status.39=0
TitleList.Keywords.39=
TitleList.ContextNumber.39=1024
TitleList.ContextNumber.39=
TitleList.ApplyTemp.39=0
TitleList.Expanded.39=0
TitleList.Kind.39=0
TitleList.Title.40=Fixed Top Style
TitleList.Level.40=0
TitleList.Url.40=template\fixedtop.htm
TitleList.Icon.40=0
TitleList.Status.40=0
TitleList.Keywords.40=
TitleList.ContextNumber.40=
TitleList.ApplyTemp.40=0
TitleList.Expanded.40=0
TitleList.Kind.40=2
TitleList.Kind.39=2

View File

@ -192,7 +192,6 @@ extern "C" DLL_EXPORT int _dbg_bpgettypeat(duint addr)
if(bp.enabled)
result|=bpmemory;
return result;
return 0;
}
extern "C" DLL_EXPORT bool _dbg_getregdump(REGDUMP* regdump)

View File

@ -15,6 +15,7 @@
#include <stdarg.h>
#include <psapi.h>
#include <vector>
#include <tlhelp32.h>
#include "..\x64_dbg_bridge\bridgemain.h"
#include "sqlite\sqlite3.h"

View File

@ -16,7 +16,7 @@ void dbinit()
dputs("failed to open database!");
return;
}
sqlloadorsavedb(userdb, dbpath, false);
sqlloadsavedb(userdb, dbpath, false);
if(!sqlexec(userdb, "CREATE TABLE IF NOT EXISTS comments (id INTEGER PRIMARY KEY AUTOINCREMENT, mod TEXT, addr INT64 NOT NULL, text TEXT NOT NULL)"))
dprintf("SQL Error: %s\n", sqllasterror());
if(!sqlexec(userdb, "CREATE TABLE IF NOT EXISTS labels (id INTEGER PRIMARY KEY AUTOINCREMENT, mod TEXT, addr INT64 NOT NULL, text TEXT NOT NULL)"))
@ -34,13 +34,13 @@ bool dbload()
dbinit();
return true;
}
return sqlloadorsavedb(userdb, dbpath, false);
return sqlloadsavedb(userdb, dbpath, false);
}
bool dbsave()
{
CreateDirectoryA(sqlitedb_basedir, 0); //create database directory
return sqlloadorsavedb(userdb, dbpath, true);
return sqlloadsavedb(userdb, dbpath, true);
}
void dbclose()

View File

@ -55,7 +55,6 @@ bool bpget(uint addr, BP_TYPE type, const char* name, BREAKPOINT* bp)
{
sqlstringescape(name, bpname);
sprintf(sql, "SELECT addr,enabled,singleshoot,oldbytes,type,titantype,mod,name FROM breakpoints WHERE (addr=%"fext"d AND type=%d AND mod IS NULL) OR name='%s'", addr, type, bpname);
puts(sql);
}
else
sprintf(sql, "SELECT addr,enabled,singleshoot,oldbytes,type,titantype,mod,name FROM breakpoints WHERE (addr=%"fext"d AND type=%d AND mod IS NULL)", addr, type);
@ -160,7 +159,7 @@ bool bpenable(uint addr, BP_TYPE type, bool enable)
sprintf(sql, "UPDATE breakpoints SET enabled=%d WHERE addr=%"fext"d AND mod IS NULL AND type=%d", enable, addr, type);
else
sprintf(sql, "UPDATE breakpoints SET enabled=%d WHERE addr=%"fext"d AND mod='%s' AND type=%d", enable, addr-modbasefromaddr(addr), modname, type);
if(sqlexec(userdb, sql))
if(!sqlexec(userdb, sql))
{
dprintf("SQL Error: %s\n", sqllasterror());
return false;
@ -237,17 +236,16 @@ bool bpenumall(BPENUMCALLBACK cbEnum, const char* module)
strcpy(curbp.name, bpname);
else
*curbp.name=0;
//TODO: fix breakpoints without module
uint modbase=modbasefromname(modname);
if(!modbase) //module not loaded //TODO: fix this
continue;
if(!modbase) //module not loaded
*curbp.mod=0;
curbp.addr=modbase+rva;
if(cbEnum)
{
if(!cbEnum(&curbp))
retval=false;
}
else if(bpcount<1000 and curbp.type==BPNORMAL)
else if(bpcount<1000)
{
memcpy(&bpall[bpcount], &curbp, sizeof(BREAKPOINT));
bpcount++;
@ -262,3 +260,10 @@ bool bpenumall(BPENUMCALLBACK cbEnum)
{
return bpenumall(cbEnum, 0);
}
int bpgetcount(BP_TYPE type)
{
char sql[deflen]="";
sprintf(sql, "SELECT * FROM breakpoints WHERE type=%d", type);
return sqlrowcount(userdb, sql);
}

View File

@ -41,5 +41,6 @@ bool bpenable(uint addr, BP_TYPE type, bool enable);
bool bpsetname(uint addr, BP_TYPE type, const char* name);
bool bpenumall(BPENUMCALLBACK cbEnum);
bool bpenumall(BPENUMCALLBACK cbEnum, const char* module);
int bpgetcount(BP_TYPE type);
#endif // _BREAKPOINT_H

View File

@ -14,7 +14,6 @@ PROCESS_INFORMATION* fdProcessInfo=&g_pi;
static char szFileName[deflen]="";
bool bFileIsDll=false;
uint pDebuggedDllBase=0;
BREAKPOINT* bplist=0;
static bool isStepping=false;
static bool isPausedByUser=false;
static bool bScyllaLoaded=false;
@ -34,7 +33,7 @@ void dbgdisablebpx()
int bpcount=bpgetlist(&list);
for(int i=0; i<bpcount; i++)
{
if(IsBPXEnabled(list[i].addr))
if(list[i].type==BPNORMAL and IsBPXEnabled(list[i].addr))
DeleteBPX(list[i].addr);
}
}
@ -45,7 +44,7 @@ void dbgenablebpx()
int bpcount=bpgetlist(&list);
for(int i=0; i<bpcount; i++)
{
if(!IsBPXEnabled(list[i].addr) and list[i].enabled)
if(list[i].type==BPNORMAL and !IsBPXEnabled(list[i].addr) and list[i].enabled)
SetBPX(list[i].addr, list[i].titantype, (void*)cbUserBreakpoint);
}
}
@ -110,21 +109,20 @@ static void cbUserBreakpoint()
static void cbHardwareBreakpoint(void* ExceptionAddress)
{
//TODO: restore bp
uint cip=GetContextData(UE_CIP);
/*BREAKPOINT* cur=bpfind(bplist, 0, (uint)ExceptionAddress, 0, BPHARDWARE);
if(!cur)
BREAKPOINT found;
if(!bpget((uint)ExceptionAddress, BPHARDWARE, 0, &found))
dputs("hardware breakpoint reached not in list!");
else
{
//TODO: type
char log[50]="";
if(cur->name)
sprintf(log, "hardware breakpoint \"%s\" "fhex"!", cur->name, cur->addr);
char log[deflen]="";
if(*found.name)
sprintf(log, "hardware breakpoint \"%s\" "fhex"!", found.name, found.addr);
else
sprintf(log, "hardware breakpoint "fhex"!", cur->addr);
sprintf(log, "hardware breakpoint "fhex"!", found.addr);
dputs(log);
}*/
}
DebugUpdateGui(cip);
GuiSetDebugState(paused);
//lock
@ -254,12 +252,17 @@ static bool cbSetModuleBreakpoints(const BREAKPOINT* bp)
if(bp->enabled)
{
if(!SetBPX(bp->addr, bp->titantype, (void*)cbUserBreakpoint))
dprintf("could not set breakpoint "fhex"\n!", bp->addr);
dprintf("could not set breakpoint "fhex"!\n", bp->addr);
}
break;
case BPMEMORY:
break;
case BPHARDWARE:
if(bp->enabled)
{
if(!SetHardwareBreakPoint(bp->addr, (bp->titantype>>8)&0xF, (bp->titantype>>4)&0xF, bp->titantype&0xF, (void*)cbHardwareBreakpoint))
dprintf("could not set hardware breakpoint "fhex"!\n", bp->addr);
}
break;
default:
break;
@ -276,6 +279,7 @@ static void cbLoadDll(LOAD_DLL_DEBUG_INFO* LoadDll)
else
DevicePathToPath(DLLDebugFileName, DLLDebugFileName, deflen);
dprintf("DLL Loaded: "fhex" %s\n", base, DLLDebugFileName);
SymLoadModuleEx(fdProcessInfo->hProcess, LoadDll->hFile, DLLDebugFileName, 0, (DWORD64)base, 0, 0, 0);
IMAGEHLP_MODULE64 modInfo;
memset(&modInfo, 0, sizeof(modInfo));
@ -300,6 +304,8 @@ static bool cbRemoveModuleBreakpoints(const BREAKPOINT* bp)
case BPMEMORY:
break;
case BPHARDWARE:
if(bp->enabled)
DeleteHardwareBreakPoint((bp->titantype>>8)&0xF);
break;
default:
break;
@ -310,16 +316,11 @@ static bool cbRemoveModuleBreakpoints(const BREAKPOINT* bp)
static void cbUnloadDll(UNLOAD_DLL_DEBUG_INFO* UnloadDll)
{
void* base=UnloadDll->lpBaseOfDll;
char DLLDebugFileName[deflen]="";
if(!GetMappedFileNameA(fdProcessInfo->hProcess, base, DLLDebugFileName, deflen))
strcpy(DLLDebugFileName, "??? (GetMappedFileName failed)");
else
DevicePathToPath(DLLDebugFileName, DLLDebugFileName, deflen);
dprintf("DLL Unloaded: "fhex" %s\n", base, DLLDebugFileName);
char modname[256]="";
char modname[256]="???";
if(modnamefromaddr((uint)base, modname))
bpenumall(cbRemoveModuleBreakpoints, modname);
SymUnloadModule64(fdProcessInfo->hProcess, (DWORD64)base);
dprintf("DLL Unloaded: "fhex" %s\n", base, modname);
}
static void cbCreateProcess(CREATE_PROCESS_DEBUG_INFO* CreateProcessInfo)
@ -452,6 +453,7 @@ static DWORD WINAPI threadDebugLoop(void* lpParameter)
//message the user/do final stuff
SymCleanup(fdProcessInfo->hProcess);
dbclose();
modclear();
GuiSetDebugState(stopped);
dputs("debugging stopped!");
varset("$hp", 0, true);
@ -633,7 +635,7 @@ CMDRESULT cbDebugDeleteBPX(const char* cmd)
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, true)) //delete all breakpoints
{
if(!bpgetlist(0)) //get number of breakpoints
if(!bpgetcount(BPNORMAL))
{
dputs("no breakpoints to delete!");
return STATUS_CONTINUE;
@ -682,10 +684,11 @@ static bool cbEnableAllBreakpoints(const BREAKPOINT* bp)
CMDRESULT cbDebugEnableBPX(const char* cmd)
{
puts("cbDebugEnableBPX");
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, true)) //delete all breakpoints
{
if(!bpgetlist(0)) //get number of breakpoints
if(!bpgetcount(BPNORMAL))
{
dputs("no breakpoints to enable!");
return STATUS_CONTINUE;
@ -744,7 +747,7 @@ CMDRESULT cbDebugDisableBPX(const char* cmd)
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, true)) //delete all breakpoints
{
if(!bpgetlist(0)) //get number of breakpoints
if(!bpgetcount(BPNORMAL))
{
dputs("no breakpoints to disable!");
return STATUS_CONTINUE;
@ -787,43 +790,28 @@ CMDRESULT cbDebugDisableBPX(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbDebugToggleBPX(const char* cmd)
static bool cbBreakpointList(const BREAKPOINT* bp)
{
//TODO: restore bp
return STATUS_CONTINUE;
const char* type=0;
if(bp->singleshoot)
type="SS";
else if(bp->type==BPNORMAL)
type="BP";
else if(bp->type==BPHARDWARE)
type="HW";
else if(bp->type==BPMEMORY)
type="GP";
bool enabled=bp->enabled;
if(*bp->name)
dprintf("%d:%s:"fhex":\"%s\"\n", enabled, type, bp->addr, bp->name);
else
dprintf("%d:%s:"fhex"\n", enabled, type, bp->addr);
return true;
}
CMDRESULT cbDebugBplist(const char* cmd)
{
//TODO: restore bp
/*
BREAKPOINT* cur=bplist;
if(!cur or !cur->addr)
{
dputs("no breakpoints!");
return STATUS_CONTINUE;
}
bool bNext=true;
while(bNext)
{
const char* type=0;
if(cur->type==BPNORMAL)
type="BP";
if(cur->type==BPSINGLESHOOT)
type="SS";
if(cur->type==BPHARDWARE)
type="HW";
if(cur->type==BPMEMORY)
type="GP";
bool enabled=cur->enabled;
if(cur->name)
dprintf("%d:%s:"fhex":\"%s\"\n", enabled, type, cur->addr, cur->name);
else
dprintf("%d:%s:"fhex"\n", enabled, type, cur->addr);
cur=cur->next;
if(!cur)
bNext=false;
}*/
bpenumall(cbBreakpointList);
return STATUS_CONTINUE;
}
@ -941,10 +929,39 @@ CMDRESULT cbDebugRtr(const char* cmd)
return STATUS_CONTINUE;
}
static bool SetGlobalHardwareBreakpoint(ULONG_PTR bpxAddress, DWORD IndexOfRegister, DWORD bpxType, DWORD bpxSize, LPVOID bpxCallback)
{
HANDLE hProcessSnap=CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD, fdProcessInfo->dwProcessId);
if(hProcessSnap==INVALID_HANDLE_VALUE)
return SetHardwareBreakPoint(bpxAddress, IndexOfRegister, bpxType, bpxSize, bpxCallback);
THREADENTRY32 threadEntry32;
threadEntry32.dwSize=sizeof(THREADENTRY32);
if(!Thread32First(hProcessSnap, &threadEntry32))
{
CloseHandle(hProcessSnap);
return SetHardwareBreakPoint(bpxAddress, IndexOfRegister, bpxType, bpxSize, bpxCallback);
}
HANDLE hThread=INVALID_HANDLE_VALUE;
do
{
if(fdProcessInfo->dwProcessId==threadEntry32.th32OwnerProcessID)
{
hThread=OpenThread(THREAD_ALL_ACCESS,false,threadEntry32.th32ThreadID);
if(hThread==INVALID_HANDLE_VALUE)
return SetHardwareBreakPoint(bpxAddress, IndexOfRegister, bpxType, bpxSize, bpxCallback);
if(!SetHardwareBreakPointEx(hThread, bpxAddress, IndexOfRegister, bpxType, bpxSize, bpxCallback, 0))
return false;
CloseHandle(hThread);
hThread=INVALID_HANDLE_VALUE;
}
}
while(Thread32Next(hProcessSnap, &threadEntry32));
CloseHandle(hProcessSnap);
return false;
}
CMDRESULT cbDebugSetHardwareBreakpoint(const char* cmd)
{
//TODO: restore bp
/*
char arg1[deflen]=""; //addr
if(!argget(cmd, arg1, 0, false))
return STATUS_ERROR;
@ -966,7 +983,7 @@ CMDRESULT cbDebugSetHardwareBreakpoint(const char* cmd)
case 'x':
break;
default:
dputs("invlalid type, assuming 'x'");
dputs("invalid type, assuming 'x'");
break;
}
}
@ -993,7 +1010,7 @@ CMDRESULT cbDebugSetHardwareBreakpoint(const char* cmd)
dputs("invalid size, using 1");
break;
}
if(addr%size)
if((addr%size)!=0)
{
dprintf("address not aligned to %d\n", size);
return STATUS_ERROR;
@ -1005,17 +1022,69 @@ CMDRESULT cbDebugSetHardwareBreakpoint(const char* cmd)
dputs("no free debug register");
return STATUS_ERROR;
}
BREAKPOINT* found=bpfind(bplist, 0, addr, 0, BPHARDWARE);
if(found or !SetHardwareBreakPoint(addr, drx, type, size, (void*)cbHardwareBreakpoint))
int titantype=(drx<<8)|(type<<4)|size;
//TODO: hwbp in multiple threads TEST
if(bpget(addr, BPHARDWARE, 0, 0) or !SetHardwareBreakPoint(addr, drx, type, size, (void*)cbHardwareBreakpoint) or !bpnew(addr, true, false, 0, BPHARDWARE, titantype, 0))
{
dputs("error setting hardware breakpoint!");
return STATUS_ERROR;
}
if(bpnew(bplist, 0, addr, (drx<<8)|(type<<4)|size, BPHARDWARE))
dprintf("hardware breakpoint at "fhex" set!\n", addr);
else
dputs("problem setting breakpoint (report please)!");
GuiUpdateAllViews();*/
GuiUpdateAllViews();
return STATUS_CONTINUE;
}
static bool cbDeleteAllHardwareBreakpoints(const BREAKPOINT* bp)
{
if(!bp->enabled)
return true;
if(!DeleteHardwareBreakPoint((bp->titantype>>8)&0xF) or !bpdel(bp->addr, BPHARDWARE))
{
dprintf("delete hardware breakpoint failed: "fhex"\n", bp->addr);
return STATUS_ERROR;
}
return true;
}
CMDRESULT cbDebugDeleteHardwareBreakpoint(const char* cmd)
{
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, true)) //delete all breakpoints
{
if(!bpgetcount(BPHARDWARE))
{
dputs("no hardware breakpoints to delete!");
return STATUS_CONTINUE;
}
if(!bpenumall(cbDeleteAllHardwareBreakpoints)) //at least one deletion failed
return STATUS_ERROR;
dputs("all hardware breakpoints deleted!");
GuiUpdateAllViews();
return STATUS_CONTINUE;
}
BREAKPOINT found;
if(bpget(0, BPHARDWARE, arg1, &found)) //found a breakpoint with name
{
if(!DeleteHardwareBreakPoint((found.titantype>>8)&0xF) or !bpdel(found.addr, BPHARDWARE))
{
dprintf("delete hardware breakpoint failed: "fhex"\n", found.addr);
return STATUS_ERROR;
}
return STATUS_CONTINUE;
}
uint addr=0;
if(!valfromstring(arg1, &addr, 0, 0, true, 0) or !bpget(addr, BPHARDWARE, 0, &found)) //invalid breakpoint
{
dprintf("no such breakpoint \"%s\"\n", arg1);
return STATUS_ERROR;
}
if(!DeleteHardwareBreakPoint((found.titantype>>8)&0xF) or !bpdel(found.addr, BPHARDWARE))
{
dprintf("delete hardware breakpoint failed: "fhex"\n", found.addr);
return STATUS_ERROR;
}
dputs("hardware breakpoint deleted!");
GuiUpdateAllViews();
return STATUS_CONTINUE;
}

View File

@ -25,10 +25,9 @@ CMDRESULT cbStopDebug(const char* cmd);
CMDRESULT cbDebugRun(const char* cmd);
CMDRESULT cbDebugSetBPXOptions(const char* cmd);
CMDRESULT cbDebugSetBPX(const char* cmd);
CMDRESULT cbDebugDeleteBPX(const char* cmd);
CMDRESULT cbDebugEnableBPX(const char* cmd);
CMDRESULT cbDebugDisableBPX(const char* cmd);
CMDRESULT cbDebugToggleBPX(const char* cmd);
CMDRESULT cbDebugDeleteBPX(const char* cmd);
CMDRESULT cbDebugBplist(const char* cmd);
CMDRESULT cbDebugStepInto(const char* cmd);
CMDRESULT cbDebugStepOver(const char* cmd);
@ -45,6 +44,7 @@ CMDRESULT cbBenchmark(const char* cmd);
CMDRESULT cbDebugPause(const char* cmd);
CMDRESULT cbMemWrite(const char* cmd);
CMDRESULT cbStartScylla(const char* cmd);
CMDRESULT cbDebugDeleteHardwareBreakpoint(const char* cmd);
//variables
extern PROCESS_INFORMATION* fdProcessInfo;

View File

@ -346,7 +346,10 @@ bool mathhandlebrackets(char* expression)
for(int i=deepest; i>0; i--)
if(!printlayer(expression, &expstruct, i))
{
efree(expstruct.pairs, "mathhandlebrackets:expstruct.pairs");
return false;
}
efree(expstruct.pairs, "mathhandlebrackets:expstruct.pairs");
return true;

View File

@ -117,7 +117,7 @@ void sqlstringescape(const char* string, char* escaped_string)
}
}
bool sqlloadorsavedb(sqlite3* memory, const char* file, bool save)
bool sqlloadsavedb(sqlite3* memory, const char* file, bool save)
{
//CREDIT: http://www.sqlite.org/backup.html
int rc;
@ -141,3 +141,17 @@ bool sqlloadorsavedb(sqlite3* memory, const char* file, bool save)
sqlite3_close(pFile);
return (rc==SQLITE_OK);
}
int sqlrowcount(sqlite3* db, const char* query)
{
int rowcount=0;
sqlite3_stmt* stmt;
if(sqlite3_prepare_v2(db, query, -1, &stmt, 0)!=SQLITE_OK)
{
sqlite3_finalize(stmt);
return false;
}
while(sqlite3_step(stmt)==SQLITE_ROW)
rowcount++;
return rowcount;
}

View File

@ -9,6 +9,7 @@ bool sqlgettext(sqlite3* db, const char* query, char* result);
bool sqlgetuint(sqlite3* db, const char* query, uint* result);
bool sqlgetint(sqlite3* db, const char* query, int* result);
void sqlstringescape(const char* string, char* escaped_string);
bool sqlloadorsavedb(sqlite3* memory, const char* file, bool save);
bool sqlloadsavedb(sqlite3* memory, const char* file, bool save);
int sqlrowcount(sqlite3* db, const char* query);
#endif // _SQLHELPER_H

View File

@ -50,10 +50,9 @@ static void registercommands()
cmdnew(cmd, "run\1go\1r\1g", cbDebugRun, true); //unlock WAITID_RUN
cmdnew(cmd, "SetBPXOptions\1bptype", cbDebugSetBPXOptions, false); //breakpoint type
cmdnew(cmd, "SetBPX\1bp\1bpx", cbDebugSetBPX, true); //breakpoint
cmdnew(cmd, "DeleteBPX\1bpc\1bc", cbDebugDeleteBPX, true); //breakpoint delete
cmdnew(cmd, "EnableBPX\1bpe\1be", cbDebugEnableBPX, true); //breakpoint enable
cmdnew(cmd, "DisableBPX\1bpd\1bd", cbDebugDisableBPX, true); //breakpoint disable
cmdnew(cmd, "ToggleBPX\1bpt\1bt", cbDebugToggleBPX, true); //breakpoint toggle
cmdnew(cmd, "DeleteBPX\1bpc\1bc", cbDebugDeleteBPX, true); //breakpoint delete
cmdnew(cmd, "bplist", cbDebugBplist, true); //breakpoint list
cmdnew(cmd, "StepInto\1sti", cbDebugStepInto, true); //StepInto
cmdnew(cmd, "StepOver\1step\1sto\1st", cbDebugStepOver, true); //StepOver
@ -78,6 +77,7 @@ static void registercommands()
cmdnew(cmd, "lblc\1lbldel\1labeldel", cbInstrLbldel, true); //delete label
cmdnew(cmd, "savedb\1dbsave", cbSavedb, true); //save program database
cmdnew(cmd, "loaddb\1dbload", cbLoaddb, true); //load program database
cmdnew(cmd, "DeleteHardwareBreakpoint\1bphwc", cbDebugDeleteHardwareBreakpoint, true); //delete hardware breakpoint
}
static bool cbCommandProvider(char* cmd, int maxlen)

View File

@ -25,11 +25,11 @@ void CPUDisassembly::contextMenuEvent(QContextMenuEvent* event)
if((wBpType & bphardware) == bphardware)
{
mToogleHwBpAction->setText("Remove Hardware");
mToggleHwBpAction->setText("Remove Hardware");
}
else
{
mToogleHwBpAction->setText("Set Hardware on Execution");
mToggleHwBpAction->setText("Set Hardware on Execution");
}
QAction* wAction = mRigthClickContextMenu->exec(event->globalPos());
@ -47,17 +47,17 @@ void CPUDisassembly::setupRightClickContextMenu()
QMenu* wBPMenu = new QMenu("Breakpoints", this);
// INT3 BP
mToogleInt3BpAction = new QAction("Toogle INT3", this);
mToogleInt3BpAction->setShortcutContext(Qt::WidgetShortcut);
mToogleInt3BpAction->setShortcut(QKeySequence(Qt::Key_F2));
this->addAction(mToogleInt3BpAction);
connect(mToogleInt3BpAction, SIGNAL(triggered()), this, SLOT(toogleInt3BPAction()));
wBPMenu->addAction(mToogleInt3BpAction);
mToggleInt3BpAction = new QAction("Toggle INT3", this);
mToggleInt3BpAction->setShortcutContext(Qt::WidgetShortcut);
mToggleInt3BpAction->setShortcut(QKeySequence(Qt::Key_F2));
this->addAction(mToggleInt3BpAction);
connect(mToggleInt3BpAction, SIGNAL(triggered()), this, SLOT(toggleInt3BPAction()));
wBPMenu->addAction(mToggleInt3BpAction);
// HW BP
mToogleHwBpAction = new QAction("Set Hardware on Execution", this);
connect(mToogleHwBpAction, SIGNAL(triggered()), this, SLOT(toogleHwBpActionSlot()));
wBPMenu->addAction(mToogleHwBpAction);
mToggleHwBpAction = new QAction("Set Hardware on Execution", this);
connect(mToggleHwBpAction, SIGNAL(triggered()), this, SLOT(toggleHwBpActionSlot()));
wBPMenu->addAction(mToggleHwBpAction);
mRigthClickContextMenu->addMenu(wBPMenu);
@ -75,7 +75,7 @@ void CPUDisassembly::setupRightClickContextMenu()
}
void CPUDisassembly::toogleInt3BPAction()
void CPUDisassembly::toggleInt3BPAction()
{
int_t wVA = rvaToVa(getInitialSelection());
BPXTYPE wBpType = DbgGetBpxTypeAt(wVA);
@ -90,11 +90,11 @@ void CPUDisassembly::toogleInt3BPAction()
wCmd = "bp " + QString("%1").arg(wVA, sizeof(int_t) * 2, 16, QChar('0')).toUpper();
}
Bridge::getBridge()->execCmd(wCmd.toAscii().data());
Bridge::getBridge()->execCmd(wCmd.toUtf8().constData());
}
void CPUDisassembly::toogleHwBpActionSlot()
void CPUDisassembly::toggleHwBpActionSlot()
{
int_t wVA = rvaToVa(getInitialSelection());
BPXTYPE wBpType = DbgGetBpxTypeAt(wVA);
@ -102,30 +102,20 @@ void CPUDisassembly::toogleHwBpActionSlot()
if((wBpType & bphardware) == bphardware)
{
// Todo
QMessageBox::information(this, "Remove Hardware Breakpoint", "Not yet implemented!");
return;
wCmd = "bphwc " + QString("%1").arg(wVA, sizeof(int_t) * 2, 16, QChar('0')).toUpper();
}
else
{
wCmd = "bph " + QString("%1").arg(wVA, sizeof(int_t) * 2, 16, QChar('0')).toUpper();
wCmd = "bphws " + QString("%1").arg(wVA, sizeof(int_t) * 2, 16, QChar('0')).toUpper();
}
Bridge::getBridge()->execCmd(wCmd.toAscii().data());
Bridge::getBridge()->execCmd(wCmd.toUtf8().constData());
}
void CPUDisassembly::setNewOriginHereActionSlot()
{
int_t wVA = rvaToVa(getInitialSelection());
QString wCmd = "";
#ifdef _WIN64
wCmd = "rip=";
#else
wCmd = "eip=";
#endif
wCmd += QString("%1").arg(wVA, sizeof(int_t) * 2, 16, QChar('0')).toUpper();
Bridge::getBridge()->execCmd(wCmd.toAscii().data());
QString wCmd = "cip=" + QString("%1").arg(wVA, sizeof(int_t) * 2, 16, QChar('0')).toUpper();
Bridge::getBridge()->execCmd(wCmd.toUtf8().constData());
}

View File

@ -23,16 +23,16 @@ public:
signals:
public slots:
void toogleInt3BPAction();
void toogleHwBpActionSlot();
void toggleInt3BPAction();
void toggleHwBpActionSlot();
void setNewOriginHereActionSlot();
private:
// Rigth Click Context Menu
QMenu* mRigthClickContextMenu;
QAction* mToogleInt3BpAction;
QAction* mToogleHwBpAction;
QAction* mToggleInt3BpAction;
QAction* mToggleHwBpAction;
QAction* mSetNewOriginHere;
};

View File

@ -228,7 +228,7 @@
<string>Command</string>
</property>
<property name="shortcut">
<string>Ctrl+Alt+Return</string>
<string>Ctrl+Return</string>
</property>
</action>
<action name="actionRtr">