1
0
Fork 0

DBG: fixed a crash with addrinfoget

DBG: fixed a bug with double-set DLL entry breakpoints when debugging a DLL
GUI: fixed a bug with the exception dialog not parsing the hexadecimal value correctly
GUI: added a message box when you saved some settings
DBG: fixed an exploit with the cbDebugString callback (it didn't escape '\')
This commit is contained in:
Mr. eXoDia 2014-03-22 16:36:42 +01:00
parent bd284a385b
commit fda377a057
6 changed files with 50 additions and 11 deletions

View File

@ -98,6 +98,8 @@ extern "C" DLL_EXPORT bool _dbg_isjumpgoingtoexecute(duint addr)
extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDRINFO* addrinfo)
{
if(!IsFileBeingDebugged())
return false;
bool retval=false;
if(addrinfo->flags&flagmodule) //get module
{
@ -154,6 +156,7 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
else //no line number
{
DISASM_INSTR instr;
memset(&instr, 0, sizeof(DISASM_INSTR));
disasmget(addr, &instr);
int len_left=MAX_COMMENT_SIZE;
for(int i=0,j=0; i<instr.argcount; i++)
@ -504,6 +507,7 @@ extern "C" DLL_EXPORT int _dbg_getbplist(BPXTYPE type, BPMAP* bpmap)
extern "C" DLL_EXPORT uint _dbg_getbranchdestination(uint addr)
{
DISASM_INSTR instr;
memset(&instr, 0, sizeof(instr));
disasmget(addr, &instr);
if(instr.type!=instr_branch)
return 0;

View File

@ -662,12 +662,14 @@ static void cbLoadDll(LOAD_DLL_DEBUG_INFO* LoadDll)
char modname[256]="";
if(modnamefromaddr((uint)base, modname, true))
bpenumall(cbSetModuleBreakpoints, modname);
bool bAlreadySetEntry=false;
if(bFileIsDll and !stricmp(DLLDebugFileName, szFileName) and !bIsAttached) //Set entry breakpoint
{
pDebuggedBase=(uint)base;
char command[256]="";
if(settingboolget("Events", "EntryBreakpoint"))
{
bAlreadySetEntry=true;
sprintf(command, "bp "fhex",\"entry breakpoint\",ss", pDebuggedBase+pDebuggedEntry);
cmddirectexec(dbggetcommandlist(), command);
}
@ -694,7 +696,7 @@ static void cbLoadDll(LOAD_DLL_DEBUG_INFO* LoadDll)
wait(WAITID_RUN);
}
if(settingboolget("Events", "DllEntry"))
if(settingboolget("Events", "DllEntry") && !bAlreadySetEntry)
{
uint oep=GetPE32Data(DLLDebugFileName, 0, UE_OEP);
if(oep)
@ -744,7 +746,24 @@ static void cbOutputDebugString(OUTPUT_DEBUG_STRING_INFO* DebugString)
char* DebugText=(char*)emalloc(DebugString->nDebugStringLength+1, "cbOutputDebugString:DebugText");
memset(DebugText, 0, DebugString->nDebugStringLength+1);
if(memread(fdProcessInfo->hProcess, DebugString->lpDebugStringData, DebugText, DebugString->nDebugStringLength, 0))
dprintf("DebugString: \"%s\"\n", DebugText);
{
int len=strlen(DebugText);
int escape_count=0;
for(int i=0; i<len; i++)
if(DebugText[i]=='\\')
escape_count++;
char* DebugTextEscaped=(char*)emalloc(DebugString->nDebugStringLength+escape_count+1, "cbOutputDebugString:DebugTextEscaped");
memset(DebugTextEscaped, 0, DebugString->nDebugStringLength+escape_count+1);
for(int i=0,j=0; i<len; i++)
{
if(DebugText[i]=='\\')
j+=sprintf(DebugTextEscaped+j, "\\\\");
else
j+=sprintf(DebugTextEscaped+j, "%c", DebugText[i]);
}
dprintf("DebugString: \"%s\"\n", DebugTextEscaped);
efree(DebugTextEscaped, "cbOutputDebugString:DebugTextEscaped");
}
efree(DebugText, "cbOutputDebugString:DebugText");
}
@ -1743,6 +1762,7 @@ CMDRESULT cbBenchmark(int argc, char* argv[])
while(i<size)
{
DISASM_INSTR instr;
memset(&instr, 0, sizeof(instr));
disasmget((unsigned char*)(data+i), base+i, &instr);
i+=instr.instr_size;
count++;

View File

@ -217,8 +217,12 @@ static bool HandleArgument(ARGTYPE* Argument, INSTRTYPE* Instruction, DISASM_ARG
void disasmget(unsigned char* buffer, uint addr, DISASM_INSTR* instr)
{
if(!DbgIsDebugging() or !instr)
if(!DbgIsDebugging())
{
if(instr)
instr->argcount=0;
return;
}
memset(instr, 0, sizeof(DISASM_INSTR));
DISASM disasm;
memset(&disasm, 0, sizeof(DISASM));
@ -254,8 +258,12 @@ void disasmget(unsigned char* buffer, uint addr, DISASM_INSTR* instr)
void disasmget(uint addr, DISASM_INSTR* instr)
{
if(!DbgIsDebugging() or !instr)
if(!DbgIsDebugging())
{
if(instr)
instr->argcount=0;
return;
}
unsigned char buffer[16]="";
DbgMemRead(addr, buffer, 16);
disasmget(buffer, addr, instr);
@ -264,6 +272,7 @@ void disasmget(uint addr, DISASM_INSTR* instr)
void disasmprint(uint addr)
{
DISASM_INSTR instr;
memset(&instr, 0, sizeof(instr));
disasmget(addr, &instr);
printf(">%d:\"%s\":\n", instr.type, instr.instruction);
for(int i=0; i<instr.argcount; i++)

View File

@ -34,6 +34,7 @@ bool stackcommentget(uint addr, STACK_COMMENT* comment)
if(len!=UNKNOWN_OPCODE && disasm.Instruction.BranchType==CallType) //call
{
DISASM_INSTR instr;
memset(&instr, 0, sizeof(instr));
disasmget((unsigned char*)disasm.EIP, previousInstr, &instr);
char label[MAX_LABEL_SIZE]="";

View File

@ -28,13 +28,13 @@ void ExceptionRangeDialog::on_editStart_textChanged(const QString &arg1)
return;
}
bool converted=false;
unsigned long start=ui->editStart->text().toLong(&converted, 16);
unsigned long start=ui->editStart->text().toUInt(&converted, 16);
if(!converted)
{
ui->btnOk->setEnabled(false);
return;
}
unsigned long end=ui->editEnd->text().toLong(&converted, 16);
unsigned long end=ui->editEnd->text().toUInt(&converted, 16);
if(converted && end<start)
ui->btnOk->setEnabled(false);
else
@ -50,13 +50,13 @@ void ExceptionRangeDialog::on_editEnd_textChanged(const QString &arg1)
return;
}
bool converted=false;
unsigned long start=ui->editStart->text().toLong(&converted, 16);
unsigned long start=ui->editStart->text().toUInt(&converted, 16);
if(!converted)
{
ui->btnOk->setEnabled(false);
return;
}
unsigned long end=ui->editEnd->text().toLong(&converted, 16);
unsigned long end=ui->editEnd->text().toUInt(&converted, 16);
if(!converted)
{
ui->btnOk->setEnabled(false);
@ -70,9 +70,9 @@ void ExceptionRangeDialog::on_editEnd_textChanged(const QString &arg1)
void ExceptionRangeDialog::on_btnOk_clicked()
{
rangeStart=ui->editStart->text().toLong(0, 16);
rangeStart=ui->editStart->text().toUInt(0, 16);
bool converted=false;
rangeEnd=ui->editEnd->text().toLong(&converted, 16);
rangeEnd=ui->editEnd->text().toUInt(&converted, 16);
if(!converted)
rangeEnd=rangeStart;
accept();

View File

@ -11,6 +11,7 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
setWindowFlags(Qt::Dialog | Qt::WindowSystemMenuHint | Qt::WindowTitleHint | Qt::MSWindowsFixedSizeDialogHint);
setFixedSize(this->size()); //fixed size
LoadSettings(); //load settings from file
ui->btnAddLast->setEnabled(false);
}
SettingsDialog::~SettingsDialog()
@ -299,9 +300,13 @@ void SettingsDialog::on_radioUd2_clicked()
void SettingsDialog::on_btnSave_clicked()
{
SaveSettings();
QMessageBox msg(QMessageBox::Information, "Information", "Settings saved!");
msg.setWindowIcon(QIcon(":/icons/images/information.png"));
msg.setParent(this, Qt::Dialog);
msg.setWindowFlags(msg.windowFlags()&(~Qt::WindowContextHelpButtonHint));
msg.exec();
}
void SettingsDialog::on_btnAddRange_clicked()
{
ExceptionRangeDialog exceptionRange(this);