From 101ba59d37ea87ff38c8a85c17d8c8e8d5fc2362 Mon Sep 17 00:00:00 2001 From: "Mr. eXoDia" Date: Mon, 7 Jul 2014 03:11:11 +0200 Subject: [PATCH] DBG: slightly changed various command behaviors. --- x64_dbg_dbg/_dbgfunctions.cpp | 7 ++++++- x64_dbg_dbg/_exports.cpp | 2 +- x64_dbg_dbg/assemble.cpp | 9 ++++++++- x64_dbg_dbg/assemble.h | 2 +- x64_dbg_dbg/instruction.cpp | 10 +++++++++- x64_dbg_dbg/x64_dbg.cpp | 22 +++++++++++----------- 6 files changed, 36 insertions(+), 16 deletions(-) diff --git a/x64_dbg_dbg/_dbgfunctions.cpp b/x64_dbg_dbg/_dbgfunctions.cpp index 1ec778d7..20af187b 100644 --- a/x64_dbg_dbg/_dbgfunctions.cpp +++ b/x64_dbg_dbg/_dbgfunctions.cpp @@ -13,6 +13,11 @@ const DBGFUNCTIONS* dbgfunctionsget() return &_dbgfunctions; } +static bool _assembleatex(duint addr, const char* instruction, char* error, bool fillnop) +{ + return assembleat(addr, instruction, 0, error, fillnop); +} + static bool _sectionfromaddr(duint addr, char* section) { HMODULE hMod=(HMODULE)modbasefromaddr(addr); @@ -96,7 +101,7 @@ static int _modpathfromname(const char* modname, char* path, int size) void dbgfunctionsinit() { - _dbgfunctions.AssembleAtEx=assembleat; + _dbgfunctions.AssembleAtEx=_assembleatex; _dbgfunctions.SectionFromAddr=_sectionfromaddr; _dbgfunctions.ModNameFromAddr=modnamefromaddr; _dbgfunctions.ModBaseFromAddr=modbasefromaddr; diff --git a/x64_dbg_dbg/_exports.cpp b/x64_dbg_dbg/_exports.cpp index 751581eb..11eca11e 100644 --- a/x64_dbg_dbg/_exports.cpp +++ b/x64_dbg_dbg/_exports.cpp @@ -768,7 +768,7 @@ extern "C" DLL_EXPORT uint _dbg_sendmessage(DBGMSG type, void* param1, void* par case DBG_ASSEMBLE_AT: { - return assembleat((duint)param1, (const char*)param2, 0, false); + return assembleat((duint)param1, (const char*)param2, 0, 0, false); } break; diff --git a/x64_dbg_dbg/assemble.cpp b/x64_dbg_dbg/assemble.cpp index e9b396ee..2d2079d9 100644 --- a/x64_dbg_dbg/assemble.cpp +++ b/x64_dbg_dbg/assemble.cpp @@ -46,7 +46,7 @@ bool assemble(uint addr, unsigned char* dest, int* size, const char* instruction return true; } -bool assembleat(uint addr, const char* instruction, char* error, bool fillnop) +bool assembleat(uint addr, const char* instruction, int* size, char* error, bool fillnop) { int destSize; unsigned char dest[16]; @@ -60,10 +60,17 @@ bool assembleat(uint addr, const char* instruction, char* error, bool fillnop) unsigned char nops[16]; memset(nops, 0x90, sizeof(nops)); + if(size) + *size=destSize; + bool ret=mempatch(fdProcessInfo->hProcess, (void*)addr, dest, destSize, 0); if(ret && fillnop && nopsize) + { + if(size) + *size+=nopsize; if(!mempatch(fdProcessInfo->hProcess, (void*)(addr+destSize), nops, nopsize, 0)) ret=false; + } GuiUpdatePatches(); return true; } diff --git a/x64_dbg_dbg/assemble.h b/x64_dbg_dbg/assemble.h index 488d6fbf..7b766c3b 100644 --- a/x64_dbg_dbg/assemble.h +++ b/x64_dbg_dbg/assemble.h @@ -4,6 +4,6 @@ #include "_global.h" bool assemble(uint addr, unsigned char* dest, int* size, const char* instruction, char* error); -bool assembleat(uint addr, const char* instruction, char* error, bool fillnop); +bool assembleat(uint addr, const char* instruction, int* size, char* error, bool fillnop); #endif // _ASSEMBLE_H diff --git a/x64_dbg_dbg/instruction.cpp b/x64_dbg_dbg/instruction.cpp index b358f684..0f991def 100644 --- a/x64_dbg_dbg/instruction.cpp +++ b/x64_dbg_dbg/instruction.cpp @@ -373,11 +373,14 @@ CMDRESULT cbAssemble(int argc, char* argv[]) if(argc>3) fillnop=true; char error[256]=""; - if(!assembleat(addr, argv[2], error, fillnop)) + int size=0; + if(!assembleat(addr, argv[2], &size, error, fillnop)) { + varset("$result", size, false); dprintf("failed to assemble \"%s\" (%s)\n", argv[2], error); return STATUS_ERROR; } + varset("$result", size, false); GuiUpdateAllViews(); return STATUS_CONTINUE; } @@ -1213,6 +1216,7 @@ CMDRESULT cbInstrCommentList(int argc, char* argv[]) GuiReferenceSetCellContent(i, 2, comments[i].text); } efree(comments, "cbInstrCommentList:comments"); + varset("$result", loops, false); dprintf("%d comment(s) listed in Reference View\n", count); GuiReferenceReloadData(); return STATUS_CONTINUE; @@ -1248,6 +1252,7 @@ CMDRESULT cbInstrLabelList(int argc, char* argv[]) GuiReferenceSetCellContent(i, 2, labels[i].text); } efree(labels, "cbInstrLabelList:labels"); + varset("$result", loops, false); dprintf("%d label(s) listed in Reference View\n", count); GuiReferenceReloadData(); return STATUS_CONTINUE; @@ -1281,6 +1286,7 @@ CMDRESULT cbInstrBookmarkList(int argc, char* argv[]) GuiReferenceSetCellContent(i, 1, disassembly); } efree(bookmarks, "cbInstrBookmarkList:bookmarks"); + varset("$result", loops, false); dprintf("%d bookmark(s) listed in Reference View\n", count); GuiReferenceReloadData(); return STATUS_CONTINUE; @@ -1327,6 +1333,7 @@ CMDRESULT cbInstrFunctionList(int argc, char* argv[]) } } efree(functions, "cbInstrFunctionList:functions"); + varset("$result", loops, false); dprintf("%d function(s) listed in Reference View\n", count); GuiReferenceReloadData(); return STATUS_CONTINUE; @@ -1373,6 +1380,7 @@ CMDRESULT cbInstrLoopList(int argc, char* argv[]) } } efree(loops, "cbInstrLoopList:loops"); + varset("$result", loops, false); dprintf("%d loop(s) listed in Reference View\n", count); GuiReferenceReloadData(); return STATUS_CONTINUE; diff --git a/x64_dbg_dbg/x64_dbg.cpp b/x64_dbg_dbg/x64_dbg.cpp index 8b6ca0e8..6406d9a3 100644 --- a/x64_dbg_dbg/x64_dbg.cpp +++ b/x64_dbg_dbg/x64_dbg.cpp @@ -92,6 +92,9 @@ static void registercommands() dbgcmdnew("eSingleStep\1esstep\1esst", cbDebugeSingleStep, true); //SingleStep arg1:count + skip first chance exceptions dbgcmdnew("StepOut\1rtr", cbDebugRtr, true); //rtr dbgcmdnew("eStepOut\1ertr", cbDebugeRtr, true); //rtr + skip first chance exceptions + dbgcmdnew("DebugContinue\1con", cbDebugContinue, true); //set continue status + dbgcmdnew("LibrarianSetBreakPoint\1bpdll", cbBpDll, true); //set dll breakpoint + dbgcmdnew("LibrarianRemoveBreakPoint\1bcdll", cbBcDll, true); //remove dll breakpoint //breakpoints dbgcmdnew("bplist", cbDebugBplist, true); //breakpoint list @@ -119,6 +122,9 @@ static void registercommands() dbgcmdnew("HideDebugger\1dbh\1hide", cbDebugHide, true); //HideDebugger dbgcmdnew("dump", cbDebugDump, true); //dump at address dbgcmdnew("sdump", cbDebugStackDump, true); //dump at stack address + dbgcmdnew("refinit", cbInstrRefinit, false); + dbgcmdnew("refadd", cbInstrRefadd, false); + dbgcmdnew("asm", cbAssemble, true); //assemble instruction //user database dbgcmdnew("cmt\1cmtset\1commentset", cbInstrCmt, true); //set/edit comment @@ -131,6 +137,10 @@ static void registercommands() dbgcmdnew("loaddb\1dbload", cbLoaddb, true); //load program database dbgcmdnew("functionadd\1func", cbFunctionAdd, true); //function dbgcmdnew("functiondel\1funcc", cbFunctionDel, true); //function + dbgcmdnew("commentlist", cbInstrCommentList, true); //list comments + dbgcmdnew("labellist", cbInstrLabelList, true); //list labels + dbgcmdnew("bookmarklist", cbInstrBookmarkList, true); //list bookmarks + dbgcmdnew("functionlist", cbInstrFunctionList, true); //list functions //memory operations dbgcmdnew("alloc", cbDebugAlloc, true); //allocate memory @@ -170,25 +180,15 @@ static void registercommands() dbgcmdnew("refstr\1strref", cbInstrRefStr, true); dbgcmdnew("find", cbInstrFind, true); //find a pattern dbgcmdnew("findall", cbInstrFindAll, true); //find all patterns + dbgcmdnew("modcallfind", cbInstrModCallFind, true); //find intermodular calls //undocumented dbgcmdnew("bench", cbBenchmark, true); //benchmark test (readmem etc) dbgcmdnew("memwrite", cbMemWrite, true); //memwrite test - dbgcmdnew("asm", cbAssemble, true); //assemble instruction dbgcmdnew("dprintf", cbPrintf, false); //printf - dbgcmdnew("refinit", cbInstrRefinit, false); - dbgcmdnew("refadd", cbInstrRefadd, false); dbgcmdnew("setstr\1strset", cbInstrSetstr, false); //set a string variable dbgcmdnew("getstr\1strget", cbInstrGetstr, false); //get a string variable dbgcmdnew("copystr\1strcpy", cbInstrCopystr, true); //write a string variable to memory - dbgcmdnew("DebugContinue\1con", cbDebugContinue, true); //set continue status - dbgcmdnew("bpdll", cbBpDll, true); //set dll breakpoint - dbgcmdnew("bcdll", cbBcDll, true); //remove dll breakpoint - dbgcmdnew("modcallfind", cbInstrModCallFind, true); //find intermodular calls - dbgcmdnew("commentlist", cbInstrCommentList, true); //list comments - dbgcmdnew("labellist", cbInstrLabelList, true); //list labels - dbgcmdnew("bookmarklist", cbInstrBookmarkList, true); //list bookmarks - dbgcmdnew("functionlist", cbInstrFunctionList, true); //list functions dbgcmdnew("looplist", cbInstrLoopList, true); //list loops }