DBG: fixed a bug in cbInstrMov (non-uint variables were not set)
DBG: added commands setstr & getstr (to set+get string variables) DBG: fixed a bug with deleting data variables DBG: added function 'vargettype'
This commit is contained in:
parent
ffce59a2b6
commit
a781f740aa
|
@ -136,6 +136,8 @@ CMDRESULT cbInstrMov(int argc, char* argv[])
|
|||
bool isvar=false;
|
||||
uint temp=0;
|
||||
valfromstring(argv[1], &temp, true, false, 0, &isvar, 0);
|
||||
if(!isvar)
|
||||
isvar=vargettype(argv[1], 0);
|
||||
if(!isvar or !valtostring(argv[1], &set_value, true))
|
||||
{
|
||||
uint value;
|
||||
|
@ -730,3 +732,63 @@ CMDRESULT cbInstrRefadd(int argc, char* argv[])
|
|||
GuiReferenceReloadData();
|
||||
return STATUS_CONTINUE;
|
||||
}
|
||||
|
||||
CMDRESULT cbInstrSetstr(int argc, char* argv[])
|
||||
{
|
||||
if(argc<3)
|
||||
{
|
||||
dputs("not enough arguments!");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
varnew(argv[1], 0, VAR_USER);
|
||||
if(!vargettype(argv[1], 0))
|
||||
{
|
||||
dprintf("no such variable \"%s\"!\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
if(!varset(argv[1], argv[2], false))
|
||||
{
|
||||
dprintf("failed to set variable \"%s\"!\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
char cmd[deflen]="";
|
||||
sprintf(cmd, "getstr \"%s\"", argv[1]);
|
||||
cmddirectexec(dbggetcommandlist(), cmd);
|
||||
return STATUS_CONTINUE;
|
||||
}
|
||||
|
||||
CMDRESULT cbInstrGetstr(int argc, char* argv[])
|
||||
{
|
||||
if(argc<2)
|
||||
{
|
||||
dputs("not enough arguments!");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
VAR_TYPE vartype;
|
||||
if(!vargettype(argv[1], &vartype))
|
||||
{
|
||||
dprintf("no such variable \"%s\"!\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
if(vartype!=VAR_STRING)
|
||||
{
|
||||
dprintf("variable \"%s\" is not a string!\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
int size;
|
||||
if(!varget(argv[1], (char*)0, &size, 0) or !size)
|
||||
{
|
||||
dprintf("failed to get variable size \"%s\"!\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
char* string=(char*)emalloc(size+1, "cbInstrGetstr:string");
|
||||
memset(string, 0, size+1);
|
||||
if(!varget(argv[1], string, &size, 0))
|
||||
{
|
||||
dprintf("failed to get variable data \"%s\"!\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
dprintf("%s=\"%s\"\n", argv[1], string);
|
||||
efree(string, "cbInstrGetstr:string");
|
||||
return STATUS_CONTINUE;
|
||||
}
|
||||
|
|
|
@ -45,4 +45,7 @@ CMDRESULT cbInstrXor(int argc, char* argv[]);
|
|||
CMDRESULT cbInstrRefinit(int argc, char* argv[]);
|
||||
CMDRESULT cbInstrRefadd(int argc, char* argv[]);
|
||||
|
||||
CMDRESULT cbInstrSetstr(int argc, char* argv[]);
|
||||
CMDRESULT cbInstrGetstr(int argc, char* argv[]);
|
||||
|
||||
#endif // _INSTRUCTIONS_H
|
||||
|
|
|
@ -1,77 +1,77 @@
|
|||
#include "thread.h"
|
||||
#include "console.h"
|
||||
#include "undocumented.h"
|
||||
#include "memory.h"
|
||||
|
||||
static std::vector<THREADINFO> threadList;
|
||||
static int threadNum;
|
||||
static int currentThread;
|
||||
|
||||
void threadcreate(CREATE_THREAD_DEBUG_INFO* CreateThread)
|
||||
{
|
||||
THREADINFO curInfo;
|
||||
curInfo.ThreadNumber=threadNum;
|
||||
curInfo.hThread=CreateThread->hThread;
|
||||
curInfo.dwThreadId=((DEBUG_EVENT*)GetDebugData())->dwThreadId;
|
||||
curInfo.ThreadStartAddress=(uint)CreateThread->lpStartAddress;
|
||||
curInfo.ThreadLocalBase=(uint)CreateThread->lpThreadLocalBase;
|
||||
threadList.push_back(curInfo);
|
||||
threadNum++;
|
||||
GuiUpdateThreadView();
|
||||
}
|
||||
|
||||
void threadexit(DWORD dwThreadId)
|
||||
{
|
||||
for(int i=0; i<threadList.size(); i++)
|
||||
if(threadList.at(i).dwThreadId==dwThreadId)
|
||||
{
|
||||
threadList.erase(threadList.begin()+i);
|
||||
break;
|
||||
}
|
||||
GuiUpdateThreadView();
|
||||
}
|
||||
|
||||
void threadclear()
|
||||
{
|
||||
threadNum=0;
|
||||
std::vector<THREADINFO>().swap(threadList);
|
||||
GuiUpdateThreadView();
|
||||
}
|
||||
|
||||
static THREADWAITREASON GetThreadWaitReason(DWORD dwThreadId)
|
||||
{
|
||||
return Executive;
|
||||
}
|
||||
|
||||
static DWORD GetThreadLastError(uint tebAddress)
|
||||
{
|
||||
TEB teb;
|
||||
memset(&teb, 0, sizeof(TEB));
|
||||
if(!memread(fdProcessInfo->hProcess, (void*)tebAddress, &teb, sizeof(TEB), 0))
|
||||
return 0;
|
||||
return teb.LastErrorValue;
|
||||
}
|
||||
|
||||
void threadgetlist(THREADLIST* list)
|
||||
{
|
||||
int count=threadList.size();
|
||||
list->count=count;
|
||||
if(!count)
|
||||
return;
|
||||
list->list=(THREADALLINFO*)BridgeAlloc(count*sizeof(THREADALLINFO));
|
||||
for(int i=0; i<count; i++)
|
||||
{
|
||||
if(((DEBUG_EVENT*)GetDebugData())->dwThreadId==threadList.at(i).dwThreadId)
|
||||
currentThread=i;
|
||||
memset(&list->list[i], 0, sizeof(THREADALLINFO));
|
||||
memcpy(&list->list[i].BasicInfo, &threadList.at(i), sizeof(THREADINFO));
|
||||
HANDLE hThread=list->list[i].BasicInfo.hThread;
|
||||
list->list[i].ThreadCip=GetContextDataEx(hThread, UE_CIP);
|
||||
list->list[i].SuspendCount=SuspendThread(hThread);
|
||||
ResumeThread(hThread);
|
||||
list->list[i].Priority=(THREADPRIORITY)GetThreadPriority(list->list[i].BasicInfo.hThread);
|
||||
list->list[i].WaitReason=GetThreadWaitReason(list->list[i].BasicInfo.dwThreadId);
|
||||
list->list[i].LastError=GetThreadLastError(list->list[i].BasicInfo.ThreadLocalBase);
|
||||
}
|
||||
list->CurrentThread=currentThread;
|
||||
}
|
||||
#include "thread.h"
|
||||
#include "console.h"
|
||||
#include "undocumented.h"
|
||||
#include "memory.h"
|
||||
|
||||
static std::vector<THREADINFO> threadList;
|
||||
static int threadNum;
|
||||
static int currentThread;
|
||||
|
||||
void threadcreate(CREATE_THREAD_DEBUG_INFO* CreateThread)
|
||||
{
|
||||
THREADINFO curInfo;
|
||||
curInfo.ThreadNumber=threadNum;
|
||||
curInfo.hThread=CreateThread->hThread;
|
||||
curInfo.dwThreadId=((DEBUG_EVENT*)GetDebugData())->dwThreadId;
|
||||
curInfo.ThreadStartAddress=(uint)CreateThread->lpStartAddress;
|
||||
curInfo.ThreadLocalBase=(uint)CreateThread->lpThreadLocalBase;
|
||||
threadList.push_back(curInfo);
|
||||
threadNum++;
|
||||
GuiUpdateThreadView();
|
||||
}
|
||||
|
||||
void threadexit(DWORD dwThreadId)
|
||||
{
|
||||
for(int i=0; i<threadList.size(); i++)
|
||||
if(threadList.at(i).dwThreadId==dwThreadId)
|
||||
{
|
||||
threadList.erase(threadList.begin()+i);
|
||||
break;
|
||||
}
|
||||
GuiUpdateThreadView();
|
||||
}
|
||||
|
||||
void threadclear()
|
||||
{
|
||||
threadNum=0;
|
||||
std::vector<THREADINFO>().swap(threadList);
|
||||
GuiUpdateThreadView();
|
||||
}
|
||||
|
||||
static THREADWAITREASON GetThreadWaitReason(DWORD dwThreadId)
|
||||
{
|
||||
return Executive;
|
||||
}
|
||||
|
||||
static DWORD GetThreadLastError(uint tebAddress)
|
||||
{
|
||||
TEB teb;
|
||||
memset(&teb, 0, sizeof(TEB));
|
||||
if(!memread(fdProcessInfo->hProcess, (void*)tebAddress, &teb, sizeof(TEB), 0))
|
||||
return 0;
|
||||
return teb.LastErrorValue;
|
||||
}
|
||||
|
||||
void threadgetlist(THREADLIST* list)
|
||||
{
|
||||
int count=threadList.size();
|
||||
list->count=count;
|
||||
if(!count)
|
||||
return;
|
||||
list->list=(THREADALLINFO*)BridgeAlloc(count*sizeof(THREADALLINFO));
|
||||
for(int i=0; i<count; i++)
|
||||
{
|
||||
if(((DEBUG_EVENT*)GetDebugData())->dwThreadId==threadList.at(i).dwThreadId)
|
||||
currentThread=i;
|
||||
memset(&list->list[i], 0, sizeof(THREADALLINFO));
|
||||
memcpy(&list->list[i].BasicInfo, &threadList.at(i), sizeof(THREADINFO));
|
||||
HANDLE hThread=list->list[i].BasicInfo.hThread;
|
||||
list->list[i].ThreadCip=GetContextDataEx(hThread, UE_CIP);
|
||||
list->list[i].SuspendCount=SuspendThread(hThread);
|
||||
ResumeThread(hThread);
|
||||
list->list[i].Priority=(THREADPRIORITY)GetThreadPriority(list->list[i].BasicInfo.hThread);
|
||||
list->list[i].WaitReason=GetThreadWaitReason(list->list[i].BasicInfo.dwThreadId);
|
||||
list->list[i].LastError=GetThreadLastError(list->list[i].BasicInfo.ThreadLocalBase);
|
||||
}
|
||||
list->CurrentThread=currentThread;
|
||||
}
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#ifndef _THREAD_H
|
||||
#define _THREAD_H
|
||||
|
||||
#include "_global.h"
|
||||
#include "debugger.h"
|
||||
|
||||
//functions
|
||||
void threadcreate(CREATE_THREAD_DEBUG_INFO* CreateThread);
|
||||
void threadexit(DWORD dwThreadId);
|
||||
void threadclear();
|
||||
void threadgetlist(THREADLIST* list);
|
||||
|
||||
#endif //_THREAD_H
|
||||
#ifndef _THREAD_H
|
||||
#define _THREAD_H
|
||||
|
||||
#include "_global.h"
|
||||
#include "debugger.h"
|
||||
|
||||
//functions
|
||||
void threadcreate(CREATE_THREAD_DEBUG_INFO* CreateThread);
|
||||
void threadexit(DWORD dwThreadId);
|
||||
void threadclear();
|
||||
void threadgetlist(THREADLIST* list);
|
||||
|
||||
#endif //_THREAD_H
|
||||
|
|
|
@ -26,13 +26,30 @@ static void varsetvalue(VAR* var, VAR_VALUE* value)
|
|||
{
|
||||
switch(var->value.type)
|
||||
{
|
||||
case VAR_STRING:
|
||||
delete [] var->value.u.data;
|
||||
break;
|
||||
case VAR_STRING:
|
||||
var->value.u.data->clear();
|
||||
delete var->value.u.data;
|
||||
break;
|
||||
}
|
||||
memcpy(&var->value, value, sizeof(VAR_VALUE));
|
||||
}
|
||||
|
||||
static bool varset(const char* name, VAR_VALUE* value, bool setreadonly)
|
||||
{
|
||||
char newname[deflen]="$";
|
||||
int add=0;
|
||||
if(*name=='$')
|
||||
add=1;
|
||||
strcat(newname, name+add);
|
||||
VAR* found=varfind(newname, 0);
|
||||
if(!found)
|
||||
return false;
|
||||
if(!setreadonly and (found->type==VAR_READONLY or found->type==VAR_HIDDEN))
|
||||
return false;
|
||||
varsetvalue(found, value);
|
||||
return true;
|
||||
}
|
||||
|
||||
void varinit()
|
||||
{
|
||||
vars=(VAR*)emalloc(sizeof(VAR), "varinit:vars");
|
||||
|
@ -120,7 +137,7 @@ bool varnew(const char* name_, uint value, VAR_TYPE type)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool varget(const char* name, uint* value, int* size, VAR_TYPE* type)
|
||||
static bool varget(const char* name, VAR_VALUE* value, int* size, VAR_TYPE* type)
|
||||
{
|
||||
char newname[deflen]="$";
|
||||
int add=0;
|
||||
|
@ -128,33 +145,45 @@ bool varget(const char* name, uint* value, int* size, VAR_TYPE* type)
|
|||
add=1;
|
||||
strcat(newname, name+add);
|
||||
VAR* found=varfind(newname, 0);
|
||||
if(!found)
|
||||
if(!found or !value or !size or !type)
|
||||
return false;
|
||||
if(!value)
|
||||
return false;
|
||||
if(type)
|
||||
*type=found->type;
|
||||
if(found->value.type!=VAR_UINT)
|
||||
return false;
|
||||
if(size)
|
||||
*size=found->value.size;
|
||||
*value=found->value.u.value;
|
||||
*type=found->type;
|
||||
*size=found->value.size;
|
||||
memcpy(value, &found->value, sizeof(VAR_VALUE));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool varset(const char* name, VAR_VALUE* value, bool setreadonly)
|
||||
bool varget(const char* name, uint* value, int* size, VAR_TYPE* type)
|
||||
{
|
||||
char newname[deflen]="$";
|
||||
int add=0;
|
||||
if(*name=='$')
|
||||
add=1;
|
||||
strcat(newname, name+add);
|
||||
VAR* found=varfind(newname, 0);
|
||||
if(!found)
|
||||
VAR_VALUE varvalue;
|
||||
int varsize;
|
||||
VAR_TYPE vartype;
|
||||
if(!varget(name, &varvalue, &varsize, &vartype) or varvalue.type!=VAR_UINT)
|
||||
return false;
|
||||
if(!setreadonly and (found->type==VAR_READONLY or found->type==VAR_HIDDEN))
|
||||
if(size)
|
||||
*size=varsize;
|
||||
if(!value && size)
|
||||
return true; //variable was valid, just get the size
|
||||
if(type)
|
||||
*type=vartype;
|
||||
*value=varvalue.u.value;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool varget(const char* name, char* string, int* size, VAR_TYPE* type)
|
||||
{
|
||||
VAR_VALUE varvalue;
|
||||
int varsize;
|
||||
VAR_TYPE vartype;
|
||||
if(!varget(name, &varvalue, &varsize, &vartype) or varvalue.type!=VAR_STRING)
|
||||
return false;
|
||||
varsetvalue(found, value);
|
||||
if(size)
|
||||
*size=varsize;
|
||||
if(!string && size)
|
||||
return true; //variable was valid, just get the size
|
||||
if(type)
|
||||
*type=vartype;
|
||||
memcpy(string, &varvalue.u.data->front(), varsize);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -168,15 +197,21 @@ bool varset(const char* name, uint value, bool setreadonly)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool varset(const char* name, char* data, bool setreadonly)
|
||||
bool varset(const char* name, const char* string, bool setreadonly)
|
||||
{
|
||||
VAR_VALUE varvalue;
|
||||
int size=strlen(data);
|
||||
int size=strlen(string);
|
||||
varvalue.size=size;
|
||||
varvalue.type=VAR_STRING;
|
||||
varvalue.u.data=new std::vector<unsigned char>;
|
||||
varvalue.u.data->resize(size);
|
||||
memcpy(&varvalue.u.data->front(), data, size);
|
||||
memcpy(&varvalue.u.data->front(), string, size);
|
||||
if(!varset(name, &varvalue, setreadonly))
|
||||
{
|
||||
varvalue.u.data->clear();
|
||||
delete varvalue.u.data;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -225,3 +260,18 @@ bool vardel(const char* name, bool delsystem)
|
|||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool vargettype(const char* name, VAR_TYPE* type)
|
||||
{
|
||||
char newname[deflen]="$";
|
||||
int add=0;
|
||||
if(*name=='$')
|
||||
add=1;
|
||||
strcat(newname, name+add);
|
||||
VAR* found=varfind(newname, 0);
|
||||
if(!found)
|
||||
return false;
|
||||
if(type)
|
||||
*type=found->type;
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -46,9 +46,10 @@ void varfree();
|
|||
VAR* vargetptr();
|
||||
bool varnew(const char* name, uint value, VAR_TYPE type);
|
||||
bool varget(const char* name, uint* value, int* size, VAR_TYPE* type);
|
||||
bool varset(const char* name, VAR_VALUE* value, bool setreadonly);
|
||||
bool varget(const char* name, char* string, int* size, VAR_TYPE* type);
|
||||
bool varset(const char* name, uint value, bool setreadonly);
|
||||
bool varset(const char* name, char* data, bool setreadonly);
|
||||
bool varset(const char* name, const char* string, bool setreadonly);
|
||||
bool vardel(const char* name, bool delsystem);
|
||||
bool vargettype(const char* name, VAR_TYPE* type);
|
||||
|
||||
#endif // _VARIABLE_H
|
||||
|
|
|
@ -147,6 +147,9 @@ static void registercommands()
|
|||
|
||||
cmdnew(cmd, "refinit", cbInstrRefinit, false);
|
||||
cmdnew(cmd, "refadd", cbInstrRefadd, false);
|
||||
|
||||
cmdnew(cmd, "setstr\1strset", cbInstrSetstr, false); //set a string variable
|
||||
cmdnew(cmd, "getstr\1strget", cbInstrGetstr, false); //get a string variable
|
||||
}
|
||||
|
||||
static bool cbCommandProvider(char* cmd, int maxlen)
|
||||
|
|
Loading…
Reference in New Issue