DBG: updated TitanEngine
BRIDGE: added LOOP_ENTRY definition DBG: fixed a bug with strings DBG: added an alloctrace feature (for debugging only) DBG: added plugin callbacks: CB_ATTACH and CB_DETACH GUI: added LOOP_ENTRY drawing
This commit is contained in:
parent
1a8fcdcd65
commit
be36241a69
Binary file not shown.
Binary file not shown.
|
@ -397,6 +397,8 @@ BRIDGE_IMPEXP LOOPTYPE DbgGetLoopTypeAt(duint addr, int depth)
|
|||
{
|
||||
if(addr==0x00401348)
|
||||
return LOOP_BEGIN;
|
||||
else if(addr==0x004013A8)
|
||||
return LOOP_ENTRY;
|
||||
else if(addr>0x00401348 && addr<0x004013B3)
|
||||
return LOOP_MIDDLE;
|
||||
else if(addr==0x004013B3)
|
||||
|
@ -406,6 +408,8 @@ BRIDGE_IMPEXP LOOPTYPE DbgGetLoopTypeAt(duint addr, int depth)
|
|||
{
|
||||
if(addr==0x00401351)
|
||||
return LOOP_BEGIN;
|
||||
else if(addr==0x00401398)
|
||||
return LOOP_ENTRY;
|
||||
else if(addr>0x00401351 && addr<0x004013A3)
|
||||
return LOOP_MIDDLE;
|
||||
else if(addr==0x004013A3)
|
||||
|
@ -415,6 +419,8 @@ BRIDGE_IMPEXP LOOPTYPE DbgGetLoopTypeAt(duint addr, int depth)
|
|||
{
|
||||
if(addr==0x0040135A)
|
||||
return LOOP_BEGIN;
|
||||
else if(addr==0x00401388)
|
||||
return LOOP_ENTRY;
|
||||
else if(addr>0x0040135A && addr<0x00401393)
|
||||
return LOOP_MIDDLE;
|
||||
else if(addr==0x00401393)
|
||||
|
|
|
@ -109,6 +109,7 @@ enum LOOPTYPE
|
|||
LOOP_NONE,
|
||||
LOOP_BEGIN,
|
||||
LOOP_MIDDLE,
|
||||
LOOP_ENTRY,
|
||||
LOOP_END
|
||||
};
|
||||
|
||||
|
|
|
@ -151,13 +151,14 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
|||
{
|
||||
char temp_string[MAX_COMMENT_SIZE]="";
|
||||
ADDRINFO newinfo;
|
||||
memset(&newinfo, 0, sizeof(ADDRINFO));
|
||||
newinfo.flags=flaglabel;
|
||||
char ascii[256]="";
|
||||
wchar_t unicode[256]=L"";
|
||||
STRING_TYPE strtype;
|
||||
if(instr.arg[i].constant==instr.arg[i].value) //avoid: call <module.label> ; addr:label
|
||||
{
|
||||
if(!disasmgetstringat(instr.arg[i].constant, &strtype, ascii, unicode) or strtype==str_none)
|
||||
if(instr.type==instr_branch or !disasmgetstringat(instr.arg[i].constant, &strtype, ascii, unicode) or strtype==str_none)
|
||||
continue;
|
||||
switch(strtype)
|
||||
{
|
||||
|
@ -177,12 +178,13 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
|||
}
|
||||
else if(instr.arg[i].value and (disasmgetstringat(instr.arg[i].value, &strtype, ascii, unicode) or _dbg_addrinfoget(instr.arg[i].value, instr.arg[i].segment, &newinfo)))
|
||||
{
|
||||
if(instr.type==instr_branch)
|
||||
if(instr.type!=instr_normal)
|
||||
strtype=str_none;
|
||||
switch(strtype)
|
||||
{
|
||||
case str_none:
|
||||
sprintf(temp_string, "%s:%s", instr.arg[i].mnemonic, newinfo.label);
|
||||
if(*newinfo.label)
|
||||
sprintf(temp_string, "%s:%s", instr.arg[i].mnemonic, newinfo.label);
|
||||
break;
|
||||
case str_ascii:
|
||||
sprintf(temp_string, "%s:\"%s\"", instr.arg[i].mnemonic, ascii);
|
||||
|
|
|
@ -7,19 +7,12 @@ char dbpath[3*deflen]="";
|
|||
|
||||
void* emalloc(size_t size)
|
||||
{
|
||||
unsigned char* a=new unsigned char[size+0x1000];
|
||||
if(!a)
|
||||
{
|
||||
MessageBoxA(0, "Could not allocate memory", "Error", MB_ICONERROR);
|
||||
ExitProcess(1);
|
||||
}
|
||||
memset(a, 0, size);
|
||||
return a;
|
||||
return emalloc(size, "emalloc:???");
|
||||
}
|
||||
|
||||
void efree(void* ptr)
|
||||
{
|
||||
delete[] (unsigned char*)ptr;
|
||||
efree(ptr, "efree:???");
|
||||
}
|
||||
|
||||
static int emalloc_count=0;
|
||||
|
@ -34,14 +27,18 @@ void* emalloc(size_t size, const char* reason)
|
|||
}
|
||||
memset(a, 0, size);
|
||||
emalloc_count++;
|
||||
//printf("DBG%.5d:alloc:"fhex":%s:"fhex"\n", emalloc_count, a, reason, size);
|
||||
FILE* file=fopen("alloctrace.txt", "a+");
|
||||
fprintf(file, "DBG%.5d:alloc:"fhex":%s:"fhex"\n", emalloc_count, a, reason, size);
|
||||
fclose(file);
|
||||
return a;
|
||||
}
|
||||
|
||||
void efree(void* ptr, const char* reason)
|
||||
{
|
||||
emalloc_count--;
|
||||
//printf("DBG%.5d:efree:"fhex":%s\n", emalloc_count, ptr, reason);
|
||||
FILE* file=fopen("alloctrace.txt", "a+");
|
||||
fprintf(file, "DBG%.5d:efree:"fhex":%s\n", emalloc_count, ptr, reason);
|
||||
fclose(file);
|
||||
delete[] (unsigned char*)ptr;
|
||||
}
|
||||
|
||||
|
|
|
@ -106,6 +106,16 @@ struct PLUG_CB_STEPPED
|
|||
void* reserved;
|
||||
};
|
||||
|
||||
struct PLUG_CB_ATTACH
|
||||
{
|
||||
DWORD dwProcessId;
|
||||
};
|
||||
|
||||
struct PLUG_CB_DETACH
|
||||
{
|
||||
PROCESS_INFORMATION* fdProcessInfo;
|
||||
};
|
||||
|
||||
//enums
|
||||
enum CBTYPE
|
||||
{
|
||||
|
@ -123,7 +133,10 @@ enum CBTYPE
|
|||
CB_BREAKPOINT, //PLUG_CB_BREAKPOINT
|
||||
CB_PAUSEDEBUG, //PLUG_CB_PAUSEDEBUG
|
||||
CB_RESUMEDEBUG, //PLUG_CB_RESUMEDEBUG
|
||||
CB_STEPPED //PLUG_CB_STEPPED
|
||||
CB_STEPPED, //PLUG_CB_STEPPED
|
||||
CB_ATTACH, //PLUG_CB_ATTACHED (before attaching, after CB_INITDEBUG)
|
||||
CB_DETACH //PLUG_CB_DETACH (before detaching, before CB_STOPDEBUG)
|
||||
|
||||
};
|
||||
|
||||
//typedefs
|
||||
|
|
|
@ -171,18 +171,18 @@ CMDRESULT cmdloop(COMMAND* command_list, CBCOMMAND cbUnknownCommand, CBCOMMANDPR
|
|||
else
|
||||
{
|
||||
int argcount=arggetcount(command);
|
||||
char** argv=(char**)emalloc((argcount+1)*sizeof(char*));
|
||||
char** argv=(char**)emalloc((argcount+1)*sizeof(char*), "cmdloop:argv");
|
||||
argv[0]=command;
|
||||
for(int i=0; i<argcount; i++)
|
||||
{
|
||||
argv[i+1]=(char*)emalloc(deflen);
|
||||
argv[i+1]=(char*)emalloc(deflen, "cmdloop:argv[i+1]");
|
||||
*argv[i+1]=0;
|
||||
argget(command, argv[i+1], i, true);
|
||||
}
|
||||
CMDRESULT res=cmd->cbCommand(argcount+1, argv);
|
||||
for(int i=0; i<argcount; i++)
|
||||
efree(argv[i+1]);
|
||||
efree(argv);
|
||||
efree(argv[i+1], "cmdloop:argv[i+1]");
|
||||
efree(argv, "cmdloop:argv");
|
||||
if((error_is_fatal and res==STATUS_ERROR) or res==STATUS_EXIT)
|
||||
bLoop=false;
|
||||
}
|
||||
|
@ -269,17 +269,17 @@ CMDRESULT cmddirectexec(COMMAND* cmd_list, const char* cmd)
|
|||
if(found->debugonly and !IsFileBeingDebugged())
|
||||
return STATUS_ERROR;
|
||||
int argcount=arggetcount(command);
|
||||
char** argv=(char**)emalloc((argcount+1)*sizeof(char*));
|
||||
char** argv=(char**)emalloc((argcount+1)*sizeof(char*), "cmddirectexec:argv");
|
||||
argv[0]=command;
|
||||
for(int i=0; i<argcount; i++)
|
||||
{
|
||||
argv[i+1]=(char*)emalloc(deflen);
|
||||
argv[i+1]=(char*)emalloc(deflen, "cmddirectexec:argv[i+1]");
|
||||
*argv[i+1]=0;
|
||||
argget(command, argv[i+1], i, true);
|
||||
}
|
||||
CMDRESULT res=found->cbCommand(argcount+1, argv);
|
||||
for(int i=0; i<argcount; i++)
|
||||
efree(argv[i+1]);
|
||||
efree(argv);
|
||||
efree(argv[i+1], "cmddirectexec:argv[i+1]");
|
||||
efree(argv, "cmddirectexec:argv");
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -683,10 +683,7 @@ CMDRESULT cbDebugInit(int argc, char* argv[])
|
|||
|
||||
CMDRESULT cbStopDebug(int argc, char* argv[])
|
||||
{
|
||||
if(bIsAttached)
|
||||
DetachDebuggerEx(fdProcessInfo->dwProcessId);
|
||||
else
|
||||
StopDebug();
|
||||
StopDebug();
|
||||
unlock(WAITID_RUN);
|
||||
return STATUS_CONTINUE;
|
||||
}
|
||||
|
@ -1494,13 +1491,16 @@ static DWORD WINAPI threadAttachLoop(void* lpParameter)
|
|||
if(len)
|
||||
strcpy(szBaseFileName, szBaseFileName+len+1);
|
||||
GuiUpdateWindowTitle(szBaseFileName);
|
||||
//call plugin callback
|
||||
//call plugin callback (init)
|
||||
PLUG_CB_INITDEBUG initInfo;
|
||||
initInfo.szFileName=szFileName;
|
||||
plugincbcall(CB_INITDEBUG, &initInfo);
|
||||
//call plugin callback (attach)
|
||||
PLUG_CB_ATTACH attachInfo;
|
||||
attachInfo.dwProcessId=pid;
|
||||
plugincbcall(CB_ATTACH, &attachInfo);
|
||||
//run debug loop (returns when process debugging is stopped)
|
||||
AttachDebugger(pid, true, fdProcessInfo, (void*)cbAttachDebugger);
|
||||
MessageBoxA(0,0,0,0);
|
||||
//call plugin callback
|
||||
PLUG_CB_STOPDEBUG stopInfo;
|
||||
stopInfo.reserved=0;
|
||||
|
@ -1572,3 +1572,13 @@ CMDRESULT cbDebugAttach(int argc, char* argv[])
|
|||
CreateThread(0, 0, threadAttachLoop, (void*)pid, 0, 0);
|
||||
return STATUS_CONTINUE;
|
||||
}
|
||||
|
||||
CMDRESULT cbDebugDetach(int argc, char* argv[])
|
||||
{
|
||||
PLUG_CB_DETACH detachInfo;
|
||||
detachInfo.fdProcessInfo=fdProcessInfo;
|
||||
plugincbcall(CB_DETACH, &detachInfo);
|
||||
DetachDebugger(fdProcessInfo->dwProcessId);
|
||||
unlock(WAITID_RUN);
|
||||
return STATUS_CONTINUE;
|
||||
}
|
||||
|
|
|
@ -47,6 +47,7 @@ CMDRESULT cbStartScylla(int argc, char* argv[]);
|
|||
CMDRESULT cbDebugDeleteHardwareBreakpoint(int argc, char* argv[]);
|
||||
CMDRESULT cbDebugDeleteMemoryBreakpoint(int argc, char* argv[]);
|
||||
CMDRESULT cbDebugAttach(int argc, char* argv[]);
|
||||
CMDRESULT cbDebugDetach(int argc, char* argv[]);
|
||||
|
||||
//variables
|
||||
extern PROCESS_INFORMATION* fdProcessInfo;
|
||||
|
|
|
@ -79,6 +79,7 @@ static void registercommands()
|
|||
cmdnew(cmd, "DeleteMemoryBPX\1membpc\1bpmc", cbDebugDeleteMemoryBreakpoint, true); //delete memory breakpoint
|
||||
cmdnew(cmd, "asm", cbAssemble, true); //assemble instruction
|
||||
cmdnew(cmd, "AttachDebugger\1attach", cbDebugAttach, false); //attach
|
||||
//cmdnew(cmd, "DetachDebugger\1detach", cbDebugDetach, true); //detach
|
||||
}
|
||||
|
||||
static bool cbCommandProvider(char* cmd, int maxlen)
|
||||
|
@ -110,6 +111,7 @@ static DWORD WINAPI DbgCommandLoopThread(void* a)
|
|||
extern "C" DLL_EXPORT const char* _dbg_dbginit()
|
||||
{
|
||||
DeleteFileA("DLLLoader.exe");
|
||||
DeleteFileA("alloctrace.txt");
|
||||
char dir[deflen]="";
|
||||
if(!GetModuleFileNameA(hInst, dir, deflen))
|
||||
return "GetModuleFileNameA failed!";
|
||||
|
|
|
@ -266,6 +266,9 @@ QString Disassembly::paintContent(QPainter* painter, int_t rowBase, int rowOffse
|
|||
case LOOP_BEGIN:
|
||||
funcType=Function_start;
|
||||
break;
|
||||
case LOOP_ENTRY:
|
||||
funcType=Function_loop_entry;
|
||||
break;
|
||||
case LOOP_MIDDLE:
|
||||
funcType=Function_middle;
|
||||
break;
|
||||
|
@ -291,7 +294,7 @@ QString Disassembly::paintContent(QPainter* painter, int_t rowBase, int rowOffse
|
|||
else
|
||||
wStr="";
|
||||
}
|
||||
break;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
|
@ -605,7 +608,8 @@ int Disassembly::paintJumpsGraphic(QPainter* painter, int x, int y, int_t addr)
|
|||
}
|
||||
else if(wPict == GD_HeadFromBottom)
|
||||
{
|
||||
QPoint wPoints[] = {
|
||||
QPoint wPoints[] =
|
||||
{
|
||||
QPoint(x + 3, y + getRowHeight() / 2 - 2),
|
||||
QPoint(x + 5, y + getRowHeight() / 2),
|
||||
QPoint(x + 3, y + getRowHeight() / 2 + 2),
|
||||
|
@ -617,7 +621,8 @@ int Disassembly::paintJumpsGraphic(QPainter* painter, int x, int y, int_t addr)
|
|||
}
|
||||
if(wPict == GD_HeadFromTop)
|
||||
{
|
||||
QPoint wPoints[] = {
|
||||
QPoint wPoints[] =
|
||||
{
|
||||
QPoint(x + 3, y + getRowHeight() / 2 - 2),
|
||||
QPoint(x + 5, y + getRowHeight() / 2),
|
||||
QPoint(x + 3, y + getRowHeight() / 2 + 2),
|
||||
|
@ -666,22 +671,46 @@ int Disassembly::paintFunctionGraphic(QPainter* painter, int x, int y, Function_
|
|||
switch(funcType)
|
||||
{
|
||||
case Function_start:
|
||||
{
|
||||
if(loop)
|
||||
y_add=height/2+1;
|
||||
painter->drawLine(x+x_add+line_width, y+y_add, x+x_add, y+y_add);
|
||||
painter->drawLine(x+x_add, y+y_add, x+x_add, y+height);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case Function_middle:
|
||||
{
|
||||
painter->drawLine(x+x_add, y, x+x_add, y+height);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case Function_loop_entry:
|
||||
{
|
||||
int trisize=2;
|
||||
int y_start=(height-trisize*2)/2+y;
|
||||
painter->drawLine(x+x_add, y_start, x+trisize+x_add, y_start+trisize);
|
||||
painter->drawLine(x+trisize+x_add, y_start+trisize, x+x_add, y_start+trisize*2);
|
||||
|
||||
painter->drawLine(x+x_add, y, x+x_add, y_start-1);
|
||||
painter->drawLine(x+x_add, y_start+trisize*2+2, x+x_add, y+height);
|
||||
}
|
||||
break;
|
||||
|
||||
case Function_end:
|
||||
{
|
||||
if(loop)
|
||||
y_add=height/2-1;
|
||||
painter->drawLine(x+x_add, y, x+x_add, y+height-y_add);
|
||||
painter->drawLine(x+x_add, y+height-y_add, x+x_add+line_width, y+height-y_add);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case Function_none:
|
||||
break;
|
||||
{
|
||||
|
||||
}
|
||||
break;
|
||||
}
|
||||
painter->restore();
|
||||
return x_add+line_width+end_add;
|
||||
|
|
|
@ -42,6 +42,7 @@ public:
|
|||
Function_none,
|
||||
Function_start,
|
||||
Function_middle,
|
||||
Function_loop_entry,
|
||||
Function_end
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue