1
0
Fork 0

BRIDGE: renamed members of an enum

DBG: database in memory (1000*commentget() from 600ms -> 60ms)
DBG: added commands 'dbsave' and 'dbload' (to load databases when working in various instances)
PROJECT: updated help
This commit is contained in:
mr.exodia 2013-11-16 16:07:29 +01:00
parent 1883130fe8
commit c525e3397e
12 changed files with 198 additions and 83 deletions

33
help/loaddb_dbload.htm Normal file
View File

@ -0,0 +1,33 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>loaddb/dbload</title>
<meta name="GENERATOR" content="WinCHM">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
html,body {
/* Default Font */
font-family: Courier New;
font-size: 11pt;
}
</style>
</head>
<body>
<P>
<STRONG>
loaddb[,dbload]
<BR>
</STRONG>Load the program database from disk in memory.</P>
<P>
<SPAN class=rvts11 >
<U >
arguments</U>
<BR></SPAN>
<SPAN
class=rvts9>This command has no arguments.</SPAN></P>
<P class=rvps3><SPAN class=rvts11><U>result <BR></U></SPAN><SPAN class=rvts9>This command does not set any result variables.</SPAN> </P>
<P>&nbsp;</P></body>
</html>

35
help/savedb_dbsave.htm Normal file
View File

@ -0,0 +1,35 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>savedb/dbsave</title>
<meta name="GENERATOR" content="WinCHM">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style>
html,body {
/* Default Font */
font-family: Courier New;
font-size: 11pt;
}
</style>
</head>
<body>
<P><STRONG>savedb[,dbsave]<BR></STRONG>Save the program
database from memory to disk.</P>
<P class=rvps3><SPAN class=rvts11><U>arguments </U><BR></SPAN>
<SPAN
class=rvts9>
This command has no arguments.
</SPAN></P>
<P class=rvps3>
<SPAN class=rvts11>
<U >
result
<BR ></U></SPAN>
<SPAN class=rvts9>
This command does not set any result
variables.</SPAN>
</P></body>

View File

@ -96,7 +96,7 @@ Font=
DefaultTopic=Introduction.htm
[TOPICS]
TitleList=39
TitleList=41
TitleList.Title.0=Introduction
TitleList.Level.0=0
TitleList.Url.0=Introduction.htm
@ -105,7 +105,7 @@ TitleList.Status.0=0
TitleList.Keywords.0=
TitleList.ContextNumber.0=1000
TitleList.ApplyTemp.0=0
TitleList.Expanded.0=1
TitleList.Expanded.0=0
TitleList.Kind.0=0
TitleList.Title.1=Input
TitleList.Level.1=1
@ -467,24 +467,44 @@ TitleList.ContextNumber.36=1038
TitleList.ApplyTemp.36=0
TitleList.Expanded.36=0
TitleList.Kind.36=0
TitleList.Title.37=Special Thanks
TitleList.Level.37=0
TitleList.Url.37=Special_Thanks.htm
TitleList.Title.37=savedb/dbsave
TitleList.Level.37=1
TitleList.Url.37=savedb_dbsave.htm
TitleList.Icon.37=0
TitleList.Status.37=0
TitleList.Keywords.37=
TitleList.ContextNumber.37=1024
TitleList.ContextNumber.37=1034
TitleList.ApplyTemp.37=0
TitleList.Expanded.37=0
TitleList.Kind.37=0
TitleList.Title.38=Fixed Top Style
TitleList.Level.38=0
TitleList.Url.38=template\fixedtop.htm
TitleList.Title.38=loaddb/dbload
TitleList.Level.38=1
TitleList.Url.38=loaddb_dbload.htm
TitleList.Icon.38=0
TitleList.Status.38=0
TitleList.Keywords.38=
TitleList.ContextNumber.38=
TitleList.ContextNumber.38=1039
TitleList.ApplyTemp.38=0
TitleList.Expanded.38=0
TitleList.Kind.38=2
TitleList.Kind.38=0
TitleList.Title.39=Special Thanks
TitleList.Level.39=0
TitleList.Url.39=Special_Thanks.htm
TitleList.Icon.39=0
TitleList.Status.39=0
TitleList.Keywords.39=
TitleList.ContextNumber.39=1024
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

View File

@ -195,7 +195,7 @@ DLL_IMPEXP bool DbgGetLabelAt(duint addr, SEGMENTREG segment, char* text) //(mod
return false;
ADDRINFO info;
memset(&info, 0, sizeof(info));
info.flags=label;
info.flags=flaglabel;
if(!_dbg_addrinfoget(addr, segment, &info))
return false;
strcpy(text, info.label);
@ -208,7 +208,7 @@ DLL_IMPEXP bool DbgSetLabelAt(duint addr, const char* text)
return false;
ADDRINFO info;
memset(&info, 0, sizeof(info));
info.flags=label;
info.flags=flaglabel;
strcpy(info.label, text);
if(!_dbg_addrinfoset(addr, &info))
return false;
@ -221,7 +221,7 @@ DLL_IMPEXP bool DbgGetCommentAt(duint addr, char* text) //comment (not live)
return false;
ADDRINFO info;
memset(&info, 0, sizeof(info));
info.flags=comment;
info.flags=flagcomment;
if(!_dbg_addrinfoget(addr, SEG_DEFAULT, &info))
return false;
strcpy(text, info.comment);
@ -234,7 +234,7 @@ DLL_IMPEXP bool DbgSetCommentAt(duint addr, const char* text)
return false;
ADDRINFO info;
memset(&info, 0, sizeof(info));
info.flags=comment;
info.flags=flagcomment;
strcpy(info.comment, text);
if(!_dbg_addrinfoset(addr, &info))
return false;
@ -247,7 +247,7 @@ DLL_IMPEXP bool DbgGetModuleAt(duint addr, char* text)
return false;
ADDRINFO info;
memset(&info, 0, sizeof(info));
info.flags=module;
info.flags=flagmodule;
if(!_dbg_addrinfoget(addr, SEG_DEFAULT, &info))
return false;
strcpy(text, info.module);

View File

@ -56,9 +56,9 @@ enum SEGMENTREG
enum ADDRINFOFLAGS
{
module=1,
label=2,
comment=4
flagmodule=1,
flaglabel=2,
flagcomment=4
};
enum BPXTYPE

View File

@ -100,7 +100,7 @@ extern "C" DLL_EXPORT bool _dbg_isjumpgoingtoexecute(duint addr)
extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDRINFO* addrinfo)
{
bool retval=false;
if(addrinfo->flags&module) //get module
if(addrinfo->flags&flagmodule) //get module
{
char module[64]="";
if(modnamefromaddr(addr, module) and strlen(module)<32) //get module name
@ -109,7 +109,7 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
retval=true;
}
}
if(addrinfo->flags&label) //TODO: get label
if(addrinfo->flags&flaglabel) //TODO: get label
{
if(labelget(addr, addrinfo->label))
retval=true;
@ -118,7 +118,7 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
//TODO: label exports
}
}
if(addrinfo->flags&comment) //TODO: get comment
if(addrinfo->flags&flagcomment) //TODO: get comment
{
if(commentget(addr, addrinfo->comment))
retval=true;
@ -133,12 +133,12 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
extern "C" DLL_EXPORT bool _dbg_addrinfoset(duint addr, ADDRINFO* addrinfo)
{
bool retval=false;
if(addrinfo->flags&label) //set label
if(addrinfo->flags&flaglabel) //set label
{
if(labelset(addr, addrinfo->label))
retval=true;
}
else if(addrinfo->flags&comment) //set comment
else if(addrinfo->flags&flagcomment) //set comment
{
if(commentset(addr, addrinfo->comment))
retval=true;

View File

@ -3,15 +3,16 @@
#include "console.h"
#include "memory.h"
static sqlite3* db;
void dbinit()
{
CreateDirectoryA(sqlitedb_basedir, 0); //create database directory
sqlite3* db;
if(sqlite3_open(dbpath, &db))
if(sqlite3_open(":memory:", &db))
{
dputs("failed to open database!");
return;
}
dbload();
char sql[deflen]="";
char* errorText=0;
strcpy(sql, "CREATE TABLE IF NOT EXISTS comments (id INTEGER PRIMARY KEY AUTOINCREMENT, mod TEXT, addr INT64 NOT NULL, text TEXT NOT NULL)");
@ -26,6 +27,51 @@ void dbinit()
dprintf("SQL Error: %s\n", errorText);
sqlite3_free(errorText);
}
}
static int loadOrSaveDb(sqlite3* memory, const char* file, bool save)
{
//CREDIT: http://www.sqlite.org/backup.html
int rc;
sqlite3* pFile;
sqlite3_backup* pBackup;
sqlite3* pTo;
sqlite3* pFrom;
rc=sqlite3_open(file, &pFile);
if(rc==SQLITE_OK)
{
pFrom=(save?memory:pFile);
pTo=(save?pFile:memory);
pBackup=sqlite3_backup_init(pTo, "main", pFrom, "main");
if(pBackup)
{
sqlite3_backup_step(pBackup, -1);
sqlite3_backup_finish(pBackup);
}
rc=sqlite3_errcode(pTo);
}
sqlite3_close(pFile);
return rc;
}
bool dbload()
{
if(loadOrSaveDb(db, dbpath, false)!=SQLITE_OK)
return false;
return true;
}
bool dbsave()
{
CreateDirectoryA(sqlitedb_basedir, 0); //create database directory
if(loadOrSaveDb(db, dbpath, true)!=SQLITE_OK)
return false;
return true;
}
void dbclose()
{
dbsave();
sqlite3_close(db);
}
@ -67,12 +113,6 @@ bool commentset(uint addr, const char* text)
else
j+=sprintf(newtext+j, "%c", text[i]);
}
sqlite3* db;
if(sqlite3_open(dbpath, &db))
{
dputs("failed to open database!");
return false;
}
char modname[35]="";
char sql[256]="";
sqlite3_stmt* stmt;
@ -81,7 +121,6 @@ bool commentset(uint addr, const char* text)
sprintf(sql, "SELECT text FROM comments WHERE mod IS NULL AND addr=%"fext"u", addr);
if(sqlite3_prepare_v2(db, sql, -1, &stmt, 0)!=SQLITE_OK)
{
sqlite3_close(db);
return false;
}
if(sqlite3_step(stmt)==SQLITE_ROW) //there is a comment already
@ -96,7 +135,6 @@ bool commentset(uint addr, const char* text)
sprintf(sql, "SELECT text FROM comments WHERE mod='%s' AND addr=%"fext"u", modname, rva);
if(sqlite3_prepare_v2(db, sql, -1, &stmt, 0)!=SQLITE_OK)
{
sqlite3_close(db);
return false;
}
if(sqlite3_step(stmt)==SQLITE_ROW) //there is a comment already
@ -111,11 +149,10 @@ bool commentset(uint addr, const char* text)
{
dprintf("SQL Error: %s\n", errorText);
sqlite3_free(errorText);
sqlite3_close(db);
return false;
}
sqlite3_close(db);
GuiUpdateAllViews();
dbsave();
return true;
}
@ -123,12 +160,6 @@ bool commentget(uint addr, char* text)
{
if(!IsFileBeingDebugged() or !memisvalidreadptr(fdProcessInfo->hProcess, addr) or !text)
return false;
sqlite3* db;
if(sqlite3_open(dbpath, &db))
{
dputs("failed to open database!");
return false;
}
char modname[35]="";
char sql[256]="";
sqlite3_stmt* stmt;
@ -138,17 +169,14 @@ bool commentget(uint addr, char* text)
sprintf(sql, "SELECT text FROM comments WHERE mod='%s' AND addr=%"fext"u", modname, addr-modbasefromaddr(addr));
if(sqlite3_prepare_v2(db, sql, -1, &stmt, 0)!=SQLITE_OK)
{
sqlite3_close(db);
return false;
}
if(sqlite3_step(stmt)!=SQLITE_ROW) //there is a comment already
{
sqlite3_close(db);
return false;
}
strcpy(text, (const char*)sqlite3_column_text(stmt, 0));
sqlite3_finalize(stmt);
sqlite3_close(db);
return true;
}
@ -156,12 +184,6 @@ bool commentdel(uint addr)
{
if(!IsFileBeingDebugged() or !memisvalidreadptr(fdProcessInfo->hProcess, addr))
return false;
sqlite3* db;
if(sqlite3_open(dbpath, &db))
{
dputs("failed to open database!");
return false;
}
char modname[35]="";
char sql[256]="";
sqlite3_stmt* stmt;
@ -175,7 +197,6 @@ bool commentdel(uint addr)
}
if(sqlite3_prepare_v2(db, sql, -1, &stmt, 0)!=SQLITE_OK)
{
sqlite3_close(db);
return false;
}
if(sqlite3_step(stmt)!=SQLITE_ROW) //no comment to delete
@ -188,11 +209,10 @@ bool commentdel(uint addr)
{
dprintf("SQL Error: %s\n", errorText);
sqlite3_free(errorText);
sqlite3_close(db);
return false;
}
sqlite3_close(db);
GuiUpdateAllViews();
dbsave();
return true;
}
@ -212,12 +232,6 @@ bool labelset(uint addr, const char* text)
else
j+=sprintf(newtext+j, "%c", text[i]);
}
sqlite3* db;
if(sqlite3_open(dbpath, &db))
{
dputs("failed to open database!");
return false;
}
char modname[35]="";
char sql[256]="";
sqlite3_stmt* stmt;
@ -226,7 +240,6 @@ bool labelset(uint addr, const char* text)
sprintf(sql, "SELECT text FROM labels WHERE mod IS NULL AND addr=%"fext"u", addr);
if(sqlite3_prepare_v2(db, sql, -1, &stmt, 0)!=SQLITE_OK)
{
sqlite3_close(db);
return false;
}
if(sqlite3_step(stmt)==SQLITE_ROW) //there is a label already
@ -241,7 +254,6 @@ bool labelset(uint addr, const char* text)
sprintf(sql, "SELECT text FROM labels WHERE mod='%s' AND addr=%"fext"u", modname, rva);
if(sqlite3_prepare_v2(db, sql, -1, &stmt, 0)!=SQLITE_OK)
{
sqlite3_close(db);
return false;
}
if(sqlite3_step(stmt)==SQLITE_ROW) //there is a label already
@ -256,11 +268,10 @@ bool labelset(uint addr, const char* text)
{
dprintf("SQL Error: %s\n", errorText);
sqlite3_free(errorText);
sqlite3_close(db);
return false;
}
sqlite3_close(db);
GuiUpdateAllViews();
dbsave();
return true;
}
@ -268,12 +279,6 @@ bool labelget(uint addr, char* text)
{
if(!IsFileBeingDebugged() or !memisvalidreadptr(fdProcessInfo->hProcess, addr) or !text)
return false;
sqlite3* db;
if(sqlite3_open(dbpath, &db))
{
dputs("failed to open database!");
return false;
}
char modname[35]="";
char sql[256]="";
sqlite3_stmt* stmt;
@ -283,17 +288,14 @@ bool labelget(uint addr, char* text)
sprintf(sql, "SELECT text FROM labels WHERE mod='%s' AND addr=%"fext"u", modname, addr-modbasefromaddr(addr));
if(sqlite3_prepare_v2(db, sql, -1, &stmt, 0)!=SQLITE_OK)
{
sqlite3_close(db);
return false;
}
if(sqlite3_step(stmt)!=SQLITE_ROW) //there is a label already
{
sqlite3_close(db);
return false;
}
strcpy(text, (const char*)sqlite3_column_text(stmt, 0));
sqlite3_finalize(stmt);
sqlite3_close(db);
return true;
}
@ -301,12 +303,6 @@ bool labeldel(uint addr)
{
if(!IsFileBeingDebugged() or !memisvalidreadptr(fdProcessInfo->hProcess, addr))
return false;
sqlite3* db;
if(sqlite3_open(dbpath, &db))
{
dputs("failed to open database!");
return false;
}
char modname[35]="";
char sql[256]="";
sqlite3_stmt* stmt;
@ -320,7 +316,6 @@ bool labeldel(uint addr)
}
if(sqlite3_prepare_v2(db, sql, -1, &stmt, 0)!=SQLITE_OK)
{
sqlite3_close(db);
return false;
}
if(sqlite3_step(stmt)!=SQLITE_ROW) //no label to delete
@ -333,10 +328,9 @@ bool labeldel(uint addr)
{
dprintf("SQL Error: %s\n", errorText);
sqlite3_free(errorText);
sqlite3_close(db);
return false;
}
sqlite3_close(db);
dbsave();
GuiUpdateAllViews();
return true;
}

View File

@ -4,6 +4,9 @@
#include "_global.h"
void dbinit();
bool dbsave();
bool dbload();
void dbclose();
bool modnamefromaddr(uint addr, char* modname);
bool commentset(uint addr, const char* text);
bool commentget(uint addr, char* text);

View File

@ -382,6 +382,7 @@ static DWORD WINAPI threadDebugLoop(void* lpParameter)
DebugLoop();
DeleteFileA("DLLLoader.exe");
//message the user/do final stuff
dbclose();
GuiSetDebugState(stopped);
dputs("debugging stopped!");
varset("$hp", 0, true);
@ -1103,11 +1104,15 @@ CMDRESULT cbBenchmark(const char* cmd)
if(!valfromstring(arg1, &addr, 0, 0, false, 0))
return STATUS_ERROR;
uint ticks=GetTickCount();
commentset(addr, "benchmark");
for(int i=0; i<1000; i++)
{
char comment[MAX_COMMENT_SIZE]="";
commentget(addr, comment);
unsigned char dest[0x1000];
_dbg_memread(addr, dest, 0x1000, 0);
}
commentdel(addr);
dprintf("%ums\n", GetTickCount()-ticks);
return STATUS_CONTINUE;
}

View File

@ -280,3 +280,23 @@ CMDRESULT cbInstrLbldel(const char* cmd)
}
return STATUS_CONTINUE;
}
CMDRESULT cbLoaddb(const char* cmd)
{
if(!dbload())
{
puts("failed to load database from disk!");
return STATUS_ERROR;
}
return STATUS_CONTINUE;
}
CMDRESULT cbSavedb(const char* cmd)
{
if(!dbsave())
{
puts("failed to save database to disk!");
return STATUS_ERROR;
}
return STATUS_CONTINUE;
}

View File

@ -15,5 +15,7 @@ CMDRESULT cbInstrCmt(const char* cmd);
CMDRESULT cbInstrCmtdel(const char* cmd);
CMDRESULT cbInstrLbl(const char* cmd);
CMDRESULT cbInstrLbldel(const char* cmd);
CMDRESULT cbLoaddb(const char* cmd);
CMDRESULT cbSavedb(const char* cmd);
#endif // _INSTRUCTIONS_H

View File

@ -10,6 +10,7 @@
#include "math.h"
#include "x64_dbg.h"
#include "msgqueue.h"
#include "addrinfo.h"
static MESSAGE_STACK* gMsgStack;
@ -75,6 +76,8 @@ static void registercommands()
cmdnew(cmd, "cmtc\1cmtdel\1commentdel", cbInstrCmtdel, true); //delete comment
cmdnew(cmd, "lbl\1lblset\1labelset", cbInstrLbl, true); //set/edit label
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
}
static bool cbCommandProvider(char* cmd, int maxlen)