DBG: fixed some bugs in addrinfo + save breakpoints to database
This commit is contained in:
parent
d0160f2f0a
commit
e9f18c2802
|
|
@ -27,6 +27,7 @@ void dbsave()
|
|||
bookmarkcachesave(root);
|
||||
functioncachesave(root);
|
||||
loopcachesave(root);
|
||||
bpcachesave(root);
|
||||
if(json_object_size(root))
|
||||
json_dump_file(root, dbpath, JSON_INDENT(4));
|
||||
json_decref(root); //free root
|
||||
|
|
@ -48,6 +49,7 @@ void dbload()
|
|||
bookmarkcacheload(root);
|
||||
functioncacheload(root);
|
||||
loopcacheload(root);
|
||||
bpcacheload(root);
|
||||
json_decref(root); //free root
|
||||
dprintf("%ums\n", GetTickCount()-ticks);
|
||||
}
|
||||
|
|
@ -286,10 +288,7 @@ void commentcachesave(JSON root)
|
|||
{
|
||||
const COMMENTSINFO curComment=i->second;
|
||||
JSON curjsoncomment=json_object();
|
||||
if(*curComment.mod)
|
||||
json_object_set_new(curjsoncomment, "module", json_string(curComment.mod));
|
||||
else
|
||||
json_object_set_new(curjsoncomment, "module", json_null());
|
||||
json_object_set_new(curjsoncomment, "module", json_string(curComment.mod));
|
||||
json_object_set_new(curjsoncomment, "address", json_hex(curComment.addr));
|
||||
json_object_set_new(curjsoncomment, "text", json_string(curComment.text));
|
||||
if(curComment.manual)
|
||||
|
|
@ -321,7 +320,7 @@ void commentcacheload(JSON root)
|
|||
strcpy(curComment.mod, mod);
|
||||
else
|
||||
*curComment.mod='\0';
|
||||
curComment.addr=json_hex_value(json_object_get(value, "address"));
|
||||
curComment.addr=(uint)json_hex_value(json_object_get(value, "address"));
|
||||
curComment.manual=true;
|
||||
const char* text=json_string_value(json_object_get(value, "text"));
|
||||
if(text)
|
||||
|
|
@ -345,7 +344,7 @@ void commentcacheload(JSON root)
|
|||
strcpy(curComment.mod, mod);
|
||||
else
|
||||
*curComment.mod='\0';
|
||||
curComment.addr=json_hex_value(json_object_get(value, "address"));
|
||||
curComment.addr=(uint)json_hex_value(json_object_get(value, "address"));
|
||||
curComment.manual=false;
|
||||
const char* text=json_string_value(json_object_get(value, "text"));
|
||||
if(text)
|
||||
|
|
@ -419,10 +418,7 @@ void labelcachesave(JSON root)
|
|||
{
|
||||
const LABELSINFO curLabel=i->second;
|
||||
JSON curjsonlabel=json_object();
|
||||
if(*curLabel.mod)
|
||||
json_object_set_new(curjsonlabel, "module", json_string(curLabel.mod));
|
||||
else
|
||||
json_object_set_new(curjsonlabel, "module", json_null());
|
||||
json_object_set_new(curjsonlabel, "module", json_string(curLabel.mod));
|
||||
json_object_set_new(curjsonlabel, "address", json_hex(curLabel.addr));
|
||||
json_object_set_new(curjsonlabel, "text", json_string(curLabel.text));
|
||||
if(curLabel.manual)
|
||||
|
|
@ -454,7 +450,7 @@ void labelcacheload(JSON root)
|
|||
strcpy(curLabel.mod, mod);
|
||||
else
|
||||
*curLabel.mod='\0';
|
||||
curLabel.addr=json_hex_value(json_object_get(value, "address"));
|
||||
curLabel.addr=(uint)json_hex_value(json_object_get(value, "address"));
|
||||
curLabel.manual=true;
|
||||
const char* text=json_string_value(json_object_get(value, "text"));
|
||||
if(text)
|
||||
|
|
@ -478,7 +474,7 @@ void labelcacheload(JSON root)
|
|||
strcpy(curLabel.mod, mod);
|
||||
else
|
||||
*curLabel.mod='\0';
|
||||
curLabel.addr=json_hex_value(json_object_get(value, "address"));
|
||||
curLabel.addr=(uint)json_hex_value(json_object_get(value, "address"));
|
||||
curLabel.manual=false;
|
||||
const char* text=json_string_value(json_object_get(value, "text"));
|
||||
if(text)
|
||||
|
|
@ -529,10 +525,7 @@ void bookmarkcachesave(JSON root)
|
|||
{
|
||||
const BOOKMARKSINFO curBookmark=i->second;
|
||||
JSON curjsonbookmark=json_object();
|
||||
if(*curBookmark.mod)
|
||||
json_object_set_new(curjsonbookmark, "module", json_string(curBookmark.mod));
|
||||
else
|
||||
json_object_set_new(curjsonbookmark, "module", json_null());
|
||||
json_object_set_new(curjsonbookmark, "module", json_string(curBookmark.mod));
|
||||
json_object_set_new(curjsonbookmark, "address", json_hex(curBookmark.addr));
|
||||
if(curBookmark.manual)
|
||||
json_array_append_new(jsonbookmarks, curjsonbookmark);
|
||||
|
|
@ -563,7 +556,7 @@ void bookmarkcacheload(JSON root)
|
|||
strcpy(curBookmark.mod, mod);
|
||||
else
|
||||
*curBookmark.mod='\0';
|
||||
curBookmark.addr=json_hex_value(json_object_get(value, "address"));
|
||||
curBookmark.addr=(uint)json_hex_value(json_object_get(value, "address"));
|
||||
curBookmark.manual=true;
|
||||
const uint key=modhashfromname(curBookmark.mod)+curBookmark.addr;
|
||||
bookmarks.insert(std::make_pair(key, curBookmark));
|
||||
|
|
@ -582,7 +575,7 @@ void bookmarkcacheload(JSON root)
|
|||
strcpy(curBookmark.mod, mod);
|
||||
else
|
||||
*curBookmark.mod='\0';
|
||||
curBookmark.addr=json_hex_value(json_object_get(value, "address"));
|
||||
curBookmark.addr=(uint)json_hex_value(json_object_get(value, "address"));
|
||||
curBookmark.manual=false;
|
||||
const uint key=modhashfromname(curBookmark.mod)+curBookmark.addr;
|
||||
bookmarks.insert(std::make_pair(key, curBookmark));
|
||||
|
|
@ -649,10 +642,7 @@ void functioncachesave(JSON root)
|
|||
{
|
||||
const FUNCTIONSINFO curFunction=i->second;
|
||||
JSON curjsonfunction=json_object();
|
||||
if(*curFunction.mod)
|
||||
json_object_set_new(curjsonfunction, "module", json_string(curFunction.mod));
|
||||
else
|
||||
json_object_set_new(curjsonfunction, "module", json_null());
|
||||
json_object_set_new(curjsonfunction, "module", json_string(curFunction.mod));
|
||||
json_object_set_new(curjsonfunction, "start", json_hex(curFunction.start));
|
||||
json_object_set_new(curjsonfunction, "end", json_hex(curFunction.end));
|
||||
if(curFunction.manual)
|
||||
|
|
@ -684,8 +674,8 @@ void functioncacheload(JSON root)
|
|||
strcpy(curFunction.mod, mod);
|
||||
else
|
||||
*curFunction.mod='\0';
|
||||
curFunction.start=json_hex_value(json_object_get(value, "start"));
|
||||
curFunction.end=json_hex_value(json_object_get(value, "end"));
|
||||
curFunction.start=(uint)json_hex_value(json_object_get(value, "start"));
|
||||
curFunction.end=(uint)json_hex_value(json_object_get(value, "end"));
|
||||
if(curFunction.end < curFunction.start)
|
||||
continue; //invalid function
|
||||
curFunction.manual=true;
|
||||
|
|
@ -706,8 +696,8 @@ void functioncacheload(JSON root)
|
|||
strcpy(curFunction.mod, mod);
|
||||
else
|
||||
*curFunction.mod='\0';
|
||||
curFunction.start=json_hex_value(json_object_get(value, "start"));
|
||||
curFunction.end=json_hex_value(json_object_get(value, "end"));
|
||||
curFunction.start=(uint)json_hex_value(json_object_get(value, "start"));
|
||||
curFunction.end=(uint)json_hex_value(json_object_get(value, "end"));
|
||||
if(curFunction.end < curFunction.start)
|
||||
continue; //invalid function
|
||||
curFunction.manual=true;
|
||||
|
|
@ -807,10 +797,7 @@ void loopcachesave(JSON root)
|
|||
{
|
||||
const LOOPSINFO curLoop=i->second;
|
||||
JSON curjsonloop=json_object();
|
||||
if(*curLoop.mod)
|
||||
json_object_set_new(curjsonloop, "module", json_string(curLoop.mod));
|
||||
else
|
||||
json_object_set_new(curjsonloop, "module", json_null());
|
||||
json_object_set_new(curjsonloop, "module", json_string(curLoop.mod));
|
||||
json_object_set_new(curjsonloop, "start", json_hex(curLoop.start));
|
||||
json_object_set_new(curjsonloop, "end", json_hex(curLoop.end));
|
||||
json_object_set_new(curjsonloop, "depth", json_integer(curLoop.depth));
|
||||
|
|
@ -844,10 +831,10 @@ void loopcacheload(JSON root)
|
|||
strcpy(curLoop.mod, mod);
|
||||
else
|
||||
*curLoop.mod='\0';
|
||||
curLoop.start=json_hex_value(json_object_get(value, "start"));
|
||||
curLoop.end=json_hex_value(json_object_get(value, "end"));
|
||||
curLoop.depth=json_integer_value(json_object_get(value, "depth"));
|
||||
curLoop.parent=json_hex_value(json_object_get(value, "parent"));
|
||||
curLoop.start=(uint)json_hex_value(json_object_get(value, "start"));
|
||||
curLoop.end=(uint)json_hex_value(json_object_get(value, "end"));
|
||||
curLoop.depth=(int)json_integer_value(json_object_get(value, "depth"));
|
||||
curLoop.parent=(uint)json_hex_value(json_object_get(value, "parent"));
|
||||
if(curLoop.end < curLoop.start)
|
||||
continue; //invalid loop
|
||||
curLoop.manual=true;
|
||||
|
|
@ -867,10 +854,10 @@ void loopcacheload(JSON root)
|
|||
strcpy(curLoop.mod, mod);
|
||||
else
|
||||
*curLoop.mod='\0';
|
||||
curLoop.start=json_hex_value(json_object_get(value, "start"));
|
||||
curLoop.end=json_hex_value(json_object_get(value, "end"));
|
||||
curLoop.depth=json_integer_value(json_object_get(value, "depth"));
|
||||
curLoop.parent=json_hex_value(json_object_get(value, "parent"));
|
||||
curLoop.start=(uint)json_hex_value(json_object_get(value, "start"));
|
||||
curLoop.end=(uint)json_hex_value(json_object_get(value, "end"));
|
||||
curLoop.depth=(int)json_integer_value(json_object_get(value, "depth"));
|
||||
curLoop.parent=(uint)json_hex_value(json_object_get(value, "parent"));
|
||||
if(curLoop.end < curLoop.start)
|
||||
continue; //invalid loop
|
||||
curLoop.manual=false;
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
#include "memory.h"
|
||||
#include "threading.h"
|
||||
|
||||
static BreakpointsMap breakpoints;
|
||||
static BreakpointsInfo breakpoints;
|
||||
|
||||
int bpgetlist(std::vector<BREAKPOINT>* list)
|
||||
{
|
||||
|
|
@ -13,10 +13,10 @@ int bpgetlist(std::vector<BREAKPOINT>* list)
|
|||
return false;
|
||||
BREAKPOINT curBp;
|
||||
int count=0;
|
||||
for(BreakpointsMap::iterator i=breakpoints.begin(); i!=breakpoints.end(); ++i)
|
||||
for(BreakpointsInfo::iterator i=breakpoints.begin(); i!=breakpoints.end(); ++i)
|
||||
{
|
||||
curBp=i->second;
|
||||
curBp.addr+=curBp.modbase;
|
||||
curBp.addr+=modbasefromname(curBp.mod);
|
||||
curBp.active=memisvalidreadptr(fdProcessInfo->hProcess, curBp.addr);
|
||||
count++;
|
||||
if(list)
|
||||
|
|
@ -31,9 +31,9 @@ bool bpnew(uint addr, bool enabled, bool singleshoot, short oldbytes, BP_TYPE ty
|
|||
return false;
|
||||
BREAKPOINT bp;
|
||||
modnamefromaddr(addr, bp.mod, true);
|
||||
bp.modbase=modbasefromaddr(addr);
|
||||
uint modbase=modbasefromaddr(addr);
|
||||
bp.active=true;
|
||||
bp.addr=addr-bp.modbase;
|
||||
bp.addr=addr-modbase;
|
||||
bp.enabled=enabled;
|
||||
if(name and *name)
|
||||
strcpy(bp.name, name);
|
||||
|
|
@ -43,7 +43,7 @@ bool bpnew(uint addr, bool enabled, bool singleshoot, short oldbytes, BP_TYPE ty
|
|||
bp.singleshoot=singleshoot;
|
||||
bp.titantype=titantype;
|
||||
bp.type=type;
|
||||
breakpoints.insert(std::make_pair(std::make_pair(addr, type), bp));
|
||||
breakpoints.insert(std::make_pair(BreakpointKey(type, modhashfromva(addr)), bp));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -52,26 +52,35 @@ bool bpget(uint addr, BP_TYPE type, const char* name, BREAKPOINT* bp)
|
|||
if(!DbgIsDebugging())
|
||||
return false;
|
||||
BREAKPOINT curBp;
|
||||
for(BreakpointsMap::iterator i=breakpoints.begin(); i!=breakpoints.end(); ++i)
|
||||
if(!name)
|
||||
{
|
||||
BreakpointsInfo::iterator found=breakpoints.find(BreakpointKey(type, modhashfromva(addr)));
|
||||
if(found==breakpoints.end()) //not found
|
||||
return false;
|
||||
if(!bp)
|
||||
return true;
|
||||
curBp=found->second;
|
||||
curBp.addr+=modbasefromaddr(addr);
|
||||
curBp.active=memisvalidreadptr(fdProcessInfo->hProcess, curBp.addr);
|
||||
*bp=curBp;
|
||||
return true;
|
||||
}
|
||||
for(BreakpointsInfo::iterator i=breakpoints.begin(); i!=breakpoints.end(); ++i)
|
||||
{
|
||||
curBp=i->second;
|
||||
curBp.addr+=curBp.modbase;
|
||||
curBp.active=memisvalidreadptr(fdProcessInfo->hProcess, curBp.addr);
|
||||
if(name and *name)
|
||||
{
|
||||
if(i->first==std::make_pair(addr, type) or !strcmp(name, curBp.name))
|
||||
if(!strcmp(name, curBp.name))
|
||||
{
|
||||
if(bp)
|
||||
{
|
||||
curBp.addr+=modbasefromname(curBp.mod);
|
||||
curBp.active=memisvalidreadptr(fdProcessInfo->hProcess, curBp.addr);
|
||||
*bp=curBp;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if(i->first==std::make_pair(addr, type))
|
||||
{
|
||||
if(bp)
|
||||
*bp=curBp;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -80,36 +89,29 @@ bool bpdel(uint addr, BP_TYPE type)
|
|||
{
|
||||
if(!DbgIsDebugging())
|
||||
return false;
|
||||
if(breakpoints.count(std::make_pair(addr, type)))
|
||||
{
|
||||
breakpoints.erase(std::make_pair(addr, type));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
return (breakpoints.erase(BreakpointKey(type, modhashfromva(addr)))>0);
|
||||
}
|
||||
|
||||
bool bpenable(uint addr, BP_TYPE type, bool enable)
|
||||
{
|
||||
if(!DbgIsDebugging())
|
||||
return false;
|
||||
if(breakpoints.count(std::make_pair(addr, type)))
|
||||
{
|
||||
breakpoints[std::make_pair(addr, type)].enabled=true;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
BreakpointsInfo::iterator found=breakpoints.find(BreakpointKey(type, modhashfromva(addr)));
|
||||
if(found==breakpoints.end()) //not found
|
||||
return false;
|
||||
breakpoints[found->first].enabled=enable;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bpsetname(uint addr, BP_TYPE type, const char* name)
|
||||
{
|
||||
if(!DbgIsDebugging() or !name or !*name)
|
||||
return false;
|
||||
if(breakpoints.count(std::make_pair(addr, type)))
|
||||
{
|
||||
strcpy(breakpoints[std::make_pair(addr, type)].name, name);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
BreakpointsInfo::iterator found=breakpoints.find(BreakpointKey(type, modhashfromva(addr)));
|
||||
if(found==breakpoints.end()) //not found
|
||||
return false;
|
||||
strcpy(breakpoints[found->first].name, name);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool bpenumall(BPENUMCALLBACK cbEnum, const char* module)
|
||||
|
|
@ -118,10 +120,10 @@ bool bpenumall(BPENUMCALLBACK cbEnum, const char* module)
|
|||
return false;
|
||||
bool retval=true;
|
||||
BREAKPOINT curBp;
|
||||
for(BreakpointsMap::iterator i=breakpoints.begin(); i!=breakpoints.end(); ++i)
|
||||
for(BreakpointsInfo::iterator i=breakpoints.begin(); i!=breakpoints.end(); ++i)
|
||||
{
|
||||
curBp=i->second;
|
||||
curBp.addr+=curBp.modbase; //RVA to VA
|
||||
curBp.addr+=modbasefromname(curBp.mod); //RVA to VA
|
||||
curBp.active=memisvalidreadptr(fdProcessInfo->hProcess, curBp.addr); //TODO: wtf am I doing?
|
||||
if(module and *module)
|
||||
{
|
||||
|
|
@ -148,7 +150,7 @@ bool bpenumall(BPENUMCALLBACK cbEnum)
|
|||
int bpgetcount(BP_TYPE type)
|
||||
{
|
||||
int count=0;
|
||||
for(BreakpointsMap::iterator i=breakpoints.begin(); i!=breakpoints.end(); ++i)
|
||||
for(BreakpointsInfo::iterator i=breakpoints.begin(); i!=breakpoints.end(); ++i)
|
||||
{
|
||||
if(i->first.first==type)
|
||||
count++;
|
||||
|
|
@ -181,3 +183,57 @@ void bptobridge(const BREAKPOINT* bp, BRIDGEBP* bridge)
|
|||
bridge->type=bp_none;
|
||||
}
|
||||
}
|
||||
|
||||
void bpcachesave(JSON root)
|
||||
{
|
||||
const JSON jsonbreakpoints=json_array();
|
||||
for(BreakpointsInfo::iterator i=breakpoints.begin(); i!=breakpoints.end(); ++i)
|
||||
{
|
||||
const BREAKPOINT curBreakpoint=i->second;
|
||||
if(curBreakpoint.singleshoot)
|
||||
continue; //skip
|
||||
JSON curjsonbreakpoint=json_object();
|
||||
json_object_set_new(curjsonbreakpoint, "address", json_hex(curBreakpoint.addr));
|
||||
json_object_set_new(curjsonbreakpoint, "enabled", json_boolean(curBreakpoint.enabled));
|
||||
if(curBreakpoint.type==BPNORMAL)
|
||||
json_object_set_new(curjsonbreakpoint, "oldbytes", json_hex(curBreakpoint.oldbytes));
|
||||
json_object_set_new(curjsonbreakpoint, "type", json_integer(curBreakpoint.type));
|
||||
json_object_set_new(curjsonbreakpoint, "titantype", json_hex(curBreakpoint.titantype));
|
||||
json_object_set_new(curjsonbreakpoint, "name", json_string(curBreakpoint.name));
|
||||
json_object_set_new(curjsonbreakpoint, "module", json_string(curBreakpoint.mod));
|
||||
json_array_append_new(jsonbreakpoints, curjsonbreakpoint);
|
||||
}
|
||||
if(json_array_size(jsonbreakpoints))
|
||||
json_object_set(root, "breakpoints", jsonbreakpoints);
|
||||
json_decref(jsonbreakpoints);
|
||||
}
|
||||
|
||||
void bpcacheload(JSON root)
|
||||
{
|
||||
breakpoints.clear();
|
||||
const JSON jsonbreakpoints=json_object_get(root, "breakpoints");
|
||||
if(jsonbreakpoints)
|
||||
{
|
||||
size_t i;
|
||||
JSON value;
|
||||
json_array_foreach(jsonbreakpoints, i, value)
|
||||
{
|
||||
BREAKPOINT curBreakpoint;
|
||||
memset(&curBreakpoint, 0, sizeof(BREAKPOINT));
|
||||
curBreakpoint.type=(BP_TYPE)json_integer_value(json_object_get(value, "type"));
|
||||
if(curBreakpoint.type==BPNORMAL)
|
||||
curBreakpoint.oldbytes=(short)json_hex_value(json_object_get(value, "oldbytes"));
|
||||
curBreakpoint.addr=(uint)json_hex_value(json_object_get(value, "address"));
|
||||
curBreakpoint.enabled=json_boolean_value(json_object_get(value, "enabled"));
|
||||
curBreakpoint.titantype=(DWORD)json_hex_value(json_object_get(value, "titantype"));
|
||||
const char* name=json_string_value(json_object_get(value, "name"));
|
||||
if(name)
|
||||
strcpy(curBreakpoint.name, name);
|
||||
const char* mod=json_string_value(json_object_get(value, "module"));
|
||||
if(mod && *mod && strlen(mod)<MAX_MODULE_SIZE)
|
||||
strcpy(curBreakpoint.mod, mod);
|
||||
const uint key=modhashfromname(curBreakpoint.mod)+curBreakpoint.addr;
|
||||
breakpoints.insert(std::make_pair(BreakpointKey(curBreakpoint.type, key), curBreakpoint));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -15,7 +15,6 @@ enum BP_TYPE
|
|||
//structs
|
||||
struct BREAKPOINT
|
||||
{
|
||||
uint modbase;
|
||||
uint addr;
|
||||
bool enabled;
|
||||
bool singleshoot;
|
||||
|
|
@ -29,8 +28,8 @@ struct BREAKPOINT
|
|||
|
||||
//typedefs
|
||||
typedef bool (*BPENUMCALLBACK)(const BREAKPOINT* bp);
|
||||
|
||||
typedef std::map<std::pair<uint, BP_TYPE>, BREAKPOINT> BreakpointsMap;
|
||||
typedef std::pair<BP_TYPE, uint> BreakpointKey;
|
||||
typedef std::map<BreakpointKey, BREAKPOINT> BreakpointsInfo;
|
||||
|
||||
//functions
|
||||
int bpgetlist(std::vector<BREAKPOINT>* list);
|
||||
|
|
@ -43,5 +42,7 @@ bool bpenumall(BPENUMCALLBACK cbEnum);
|
|||
bool bpenumall(BPENUMCALLBACK cbEnum, const char* module);
|
||||
int bpgetcount(BP_TYPE type);
|
||||
void bptobridge(const BREAKPOINT* bp, BRIDGEBP* bridge);
|
||||
void bpcachesave(JSON root);
|
||||
void bpcacheload(JSON root);
|
||||
|
||||
#endif // _BREAKPOINT_H
|
||||
|
|
|
|||
Loading…
Reference in New Issue