1
0
Fork 0

BRIDGE: DLL_IMPEXP => BRIDGE_IMPEXP

BRIDGE: added _dbg_dbgcmddirectexec import
DBG: added export: _plugin_registercommand & _plugin_unregistercommand
DBG: fixed a bug in 'labelfromstring' (with modules)
DBG: different command architechture (argc, argv[] now)
DBG: different CMDRESULT enum (for compatibility with plugins)
DBG: added cmddirectexec
This commit is contained in:
mr.exodia 2013-11-24 17:27:18 +01:00
parent 2721ec8a6a
commit 4f77810f8f
22 changed files with 362 additions and 244 deletions

View File

@ -30,3 +30,4 @@ DBGGETREGDUMP _dbg_getregdump;
DBGVALTOSTRING _dbg_valtostring;
DBGMEMISVALIDREADPTR _dbg_memisvalidreadptr;
DBGGETBPLIST _dbg_getbplist;
DBGDBGCMDEXECDIRECT _dbg_dbgcmddirectexec;

View File

@ -62,6 +62,7 @@ typedef bool (*DBGGETREGDUMP)(REGDUMP* regdump);
typedef bool (*DBGVALTOSTRING)(const char* string, duint* value);
typedef bool (*DBGMEMISVALIDREADPTR)(duint addr);
typedef int (*DBGGETBPLIST)(BPXTYPE type, BPMAP* bplist);
typedef bool (*DBGDBGCMDEXECDIRECT)(const char* cmd);
//DBG functions
extern DBGDBGINIT _dbg_dbginit;
@ -80,5 +81,6 @@ extern DBGGETREGDUMP _dbg_getregdump;
extern DBGVALTOSTRING _dbg_valtostring;
extern DBGMEMISVALIDREADPTR _dbg_memisvalidreadptr;
extern DBGGETBPLIST _dbg_getbplist;
extern DBGDBGCMDEXECDIRECT _dbg_dbgcmddirectexec;
#endif // _GLOBAL_H

View File

@ -15,7 +15,7 @@ static char szIniFile[1024]="";
#endif // _WIN64
//Bridge
DLL_IMPEXP const char* BridgeInit()
BRIDGE_IMPEXP const char* BridgeInit()
{
///Settings load
GetModuleFileNameA(0, szIniFile, 1024);
@ -127,10 +127,14 @@ DLL_IMPEXP const char* BridgeInit()
_dbg_getbplist=(DBGGETBPLIST)GetProcAddress(hInstDbg, "_dbg_getbplist");
if(!_dbg_getbplist)
return "Export \"_dbg_getbplist\" could not be found!";
//_dbg_dbgcmddirectexec
_dbg_dbgcmddirectexec=(DBGDBGCMDEXECDIRECT)GetProcAddress(hInstDbg, "_dbg_dbgcmddirectexec");
if(!_dbg_dbgcmddirectexec)
return "Export \"_dbg_dbgcmddirectexec\" could not be found!";
return 0;
}
DLL_IMPEXP const char* BridgeStart()
BRIDGE_IMPEXP const char* BridgeStart()
{
if(!_dbg_dbginit || !_gui_guiinit)
return "\"_dbg_dbginit\" || \"_gui_guiinit\" was not loaded yet, call BridgeInit!";
@ -142,7 +146,7 @@ DLL_IMPEXP const char* BridgeStart()
return 0;
}
DLL_IMPEXP void* BridgeAlloc(size_t size)
BRIDGE_IMPEXP void* BridgeAlloc(size_t size)
{
unsigned char* a= new (std::nothrow)unsigned char[size];
if(!a)
@ -154,12 +158,12 @@ DLL_IMPEXP void* BridgeAlloc(size_t size)
return a;
}
DLL_IMPEXP void BridgeFree(void* ptr)
BRIDGE_IMPEXP void BridgeFree(void* ptr)
{
delete[] (unsigned char*)ptr;
}
DLL_IMPEXP bool BridgeSettingGet(const char* section, const char* key, char* value)
BRIDGE_IMPEXP bool BridgeSettingGet(const char* section, const char* key, char* value)
{
if(!section || !key || !value)
return false;
@ -168,7 +172,7 @@ DLL_IMPEXP bool BridgeSettingGet(const char* section, const char* key, char* val
return true;
}
DLL_IMPEXP bool BridgeSettingGetUint(const char* section, const char* key, duint* value)
BRIDGE_IMPEXP bool BridgeSettingGetUint(const char* section, const char* key, duint* value)
{
if(!section || !key || !value)
return false;
@ -185,7 +189,7 @@ DLL_IMPEXP bool BridgeSettingGetUint(const char* section, const char* key, duint
return false;
}
DLL_IMPEXP bool BridgeSettingSet(const char* section, const char* key, const char* value)
BRIDGE_IMPEXP bool BridgeSettingSet(const char* section, const char* key, const char* value)
{
if(!section || !key || !value)
return false;
@ -194,7 +198,7 @@ DLL_IMPEXP bool BridgeSettingSet(const char* section, const char* key, const cha
return true;
}
DLL_IMPEXP bool BridgeSettingSetUint(const char* section, const char* key, duint value)
BRIDGE_IMPEXP bool BridgeSettingSetUint(const char* section, const char* key, duint value)
{
if(!section || !key)
return false;
@ -208,51 +212,51 @@ DLL_IMPEXP bool BridgeSettingSetUint(const char* section, const char* key, duint
}
//Debugger
DLL_IMPEXP void DbgMemRead(duint va, unsigned char* dest, duint size)
BRIDGE_IMPEXP void DbgMemRead(duint va, unsigned char* dest, duint size)
{
if(!_dbg_memread(va, dest, size, 0))
memset(dest, 0x90, size);
}
DLL_IMPEXP duint DbgMemGetPageSize(duint base)
BRIDGE_IMPEXP duint DbgMemGetPageSize(duint base)
{
duint size=0;
_dbg_memfindbaseaddr(base, &size);
return size;
}
DLL_IMPEXP duint DbgMemFindBaseAddr(duint addr, duint* size)
BRIDGE_IMPEXP duint DbgMemFindBaseAddr(duint addr, duint* size)
{
return _dbg_memfindbaseaddr(addr, size);
}
DLL_IMPEXP bool DbgCmdExec(const char* cmd)
BRIDGE_IMPEXP bool DbgCmdExec(const char* cmd)
{
return _dbg_dbgcmdexec(cmd);
}
DLL_IMPEXP bool DbgMemMap(MEMMAP* memmap)
BRIDGE_IMPEXP bool DbgMemMap(MEMMAP* memmap)
{
return _dbg_memmap(memmap);
}
DLL_IMPEXP bool DbgIsValidExpression(const char* expression)
BRIDGE_IMPEXP bool DbgIsValidExpression(const char* expression)
{
duint value=0;
return _dbg_valfromstring(expression, &value);
}
DLL_IMPEXP bool DbgIsDebugging()
BRIDGE_IMPEXP bool DbgIsDebugging()
{
return _dbg_isdebugging();
}
DLL_IMPEXP bool DbgIsJumpGoingToExecute(duint addr)
BRIDGE_IMPEXP bool DbgIsJumpGoingToExecute(duint addr)
{
return _dbg_isjumpgoingtoexecute(addr);
}
DLL_IMPEXP bool DbgGetLabelAt(duint addr, SEGMENTREG segment, char* text) //(module.)+label
BRIDGE_IMPEXP bool DbgGetLabelAt(duint addr, SEGMENTREG segment, char* text) //(module.)+label
{
if(!text || !addr)
return false;
@ -265,7 +269,7 @@ DLL_IMPEXP bool DbgGetLabelAt(duint addr, SEGMENTREG segment, char* text) //(mod
return true;
}
DLL_IMPEXP bool DbgSetLabelAt(duint addr, const char* text)
BRIDGE_IMPEXP bool DbgSetLabelAt(duint addr, const char* text)
{
if(!text || strlen(text)>=MAX_LABEL_SIZE || !addr)
return false;
@ -278,7 +282,7 @@ DLL_IMPEXP bool DbgSetLabelAt(duint addr, const char* text)
return true;
}
DLL_IMPEXP bool DbgGetCommentAt(duint addr, char* text) //comment (not live)
BRIDGE_IMPEXP bool DbgGetCommentAt(duint addr, char* text) //comment (not live)
{
if(!text || !addr)
return false;
@ -291,7 +295,7 @@ DLL_IMPEXP bool DbgGetCommentAt(duint addr, char* text) //comment (not live)
return true;
}
DLL_IMPEXP bool DbgSetCommentAt(duint addr, const char* text)
BRIDGE_IMPEXP bool DbgSetCommentAt(duint addr, const char* text)
{
if(!text || strlen(text)>=MAX_COMMENT_SIZE || !addr)
return false;
@ -304,7 +308,7 @@ DLL_IMPEXP bool DbgSetCommentAt(duint addr, const char* text)
return true;
}
DLL_IMPEXP bool DbgGetModuleAt(duint addr, char* text)
BRIDGE_IMPEXP bool DbgGetModuleAt(duint addr, char* text)
{
if(!text || !addr)
return false;
@ -317,7 +321,7 @@ DLL_IMPEXP bool DbgGetModuleAt(duint addr, char* text)
return true;
}
DLL_IMPEXP bool DbgGetBookmarkAt(duint addr)
BRIDGE_IMPEXP bool DbgGetBookmarkAt(duint addr)
{
if(!addr)
return false;
@ -329,7 +333,7 @@ DLL_IMPEXP bool DbgGetBookmarkAt(duint addr)
return info.isbookmark;
}
DLL_IMPEXP bool DbgSetBookmarkAt(duint addr, bool isbookmark)
BRIDGE_IMPEXP bool DbgSetBookmarkAt(duint addr, bool isbookmark)
{
if(!addr)
return false;
@ -340,72 +344,77 @@ DLL_IMPEXP bool DbgSetBookmarkAt(duint addr, bool isbookmark)
return _dbg_addrinfoset(addr, &info);
}
DLL_IMPEXP BPXTYPE DbgGetBpxTypeAt(duint addr)
BRIDGE_IMPEXP BPXTYPE DbgGetBpxTypeAt(duint addr)
{
return _dbg_bpgettypeat(addr);
}
DLL_IMPEXP duint DbgValFromString(const char* string)
BRIDGE_IMPEXP duint DbgValFromString(const char* string)
{
duint value=0;
_dbg_valfromstring(string, &value);
return value;
}
DLL_IMPEXP bool DbgGetRegDump(REGDUMP* regdump)
BRIDGE_IMPEXP bool DbgGetRegDump(REGDUMP* regdump)
{
return _dbg_getregdump(regdump);
}
DLL_IMPEXP bool DbgValToString(const char* string, duint value)
BRIDGE_IMPEXP bool DbgValToString(const char* string, duint value)
{
duint valueCopy=value;
return _dbg_valtostring(string, &valueCopy);
}
DLL_IMPEXP bool DbgMemIsValidReadPtr(duint addr)
BRIDGE_IMPEXP bool DbgMemIsValidReadPtr(duint addr)
{
return _dbg_memisvalidreadptr(addr);
}
DLL_IMPEXP int DbgGetBpList(BPXTYPE type, BPMAP* list)
BRIDGE_IMPEXP int DbgGetBpList(BPXTYPE type, BPMAP* list)
{
return _dbg_getbplist(type, list);
}
BRIDGE_IMPEXP bool DbgCmdExecDirect(const char* cmd)
{
return _dbg_dbgcmddirectexec(cmd);
}
//GUI
DLL_IMPEXP void GuiDisasmAt(duint addr, duint cip)
BRIDGE_IMPEXP void GuiDisasmAt(duint addr, duint cip)
{
_gui_disassembleat(addr, cip);
}
DLL_IMPEXP void GuiSetDebugState(DBGSTATE state)
BRIDGE_IMPEXP void GuiSetDebugState(DBGSTATE state)
{
_gui_setdebugstate(state);
}
DLL_IMPEXP void GuiAddLogMessage(const char* msg)
BRIDGE_IMPEXP void GuiAddLogMessage(const char* msg)
{
_gui_addlogmessage(msg);
}
DLL_IMPEXP void GuiLogClear()
BRIDGE_IMPEXP void GuiLogClear()
{
_gui_logclear();
}
DLL_IMPEXP void GuiUpdateAllViews()
BRIDGE_IMPEXP void GuiUpdateAllViews()
{
GuiUpdateRegisterView();
GuiUpdateDisassemblyView();
}
DLL_IMPEXP void GuiUpdateRegisterView()
BRIDGE_IMPEXP void GuiUpdateRegisterView()
{
_gui_updateregisterview();
}
DLL_IMPEXP void GuiUpdateDisassemblyView()
BRIDGE_IMPEXP void GuiUpdateDisassemblyView()
{
_gui_updatedisassemblyview();
}

View File

@ -11,13 +11,13 @@ typedef unsigned long duint;
typedef signed long dsint;
#endif //_WIN64
#ifndef DLL_IMPEXP
#ifndef BRIDGE_IMPEXP
#ifdef BUILD_BRIDGE
#define DLL_IMPEXP __declspec(dllexport)
#define BRIDGE_IMPEXP __declspec(dllexport)
#else
#define DLL_IMPEXP __declspec(dllimport)
#define BRIDGE_IMPEXP __declspec(dllimport)
#endif //BUILD_BRIDGE
#endif //DLL_IMPEXP
#endif //BRIDGE_IMPEXP
#ifdef __cplusplus
extern "C"
@ -28,14 +28,14 @@ extern "C"
#define MAX_SETTING_SIZE 2048
//Bridge functions
DLL_IMPEXP const char* BridgeInit();
DLL_IMPEXP const char* BridgeStart();
DLL_IMPEXP void* BridgeAlloc(size_t size);
DLL_IMPEXP void BridgeFree(void* ptr);
DLL_IMPEXP bool BridgeSettingGet(const char* section, const char* key, char* value);
DLL_IMPEXP bool BridgeSettingGetUint(const char* section, const char* key, duint* value);
DLL_IMPEXP bool BridgeSettingSet(const char* section, const char* key, const char* value);
DLL_IMPEXP bool BridgeSettingSetUint(const char* section, const char* key, duint value);
BRIDGE_IMPEXP const char* BridgeInit();
BRIDGE_IMPEXP const char* BridgeStart();
BRIDGE_IMPEXP void* BridgeAlloc(size_t size);
BRIDGE_IMPEXP void BridgeFree(void* ptr);
BRIDGE_IMPEXP bool BridgeSettingGet(const char* section, const char* key, char* value);
BRIDGE_IMPEXP bool BridgeSettingGetUint(const char* section, const char* key, duint* value);
BRIDGE_IMPEXP bool BridgeSettingSet(const char* section, const char* key, const char* value);
BRIDGE_IMPEXP bool BridgeSettingSetUint(const char* section, const char* key, duint value);
//Debugger defines
#define MAX_LABEL_SIZE 256
@ -170,38 +170,38 @@ struct REGDUMP
};
//Debugger functions
DLL_IMPEXP void DbgMemRead(duint va, unsigned char* dest, duint size);
DLL_IMPEXP duint DbgMemGetPageSize(duint base);
DLL_IMPEXP duint DbgMemFindBaseAddr(duint addr, duint* size);
DLL_IMPEXP bool DbgCmdExec(const char* cmd);
DLL_IMPEXP bool DbgCmdExecWait(const char* cmd);
DLL_IMPEXP bool DbgMemMap(MEMMAP* memmap);
DLL_IMPEXP bool DbgIsValidExpression(const char* expression);
DLL_IMPEXP bool DbgIsDebugging();
DLL_IMPEXP bool DbgIsJumpGoingToExecute(duint addr);
DLL_IMPEXP bool DbgGetLabelAt(duint addr, SEGMENTREG segment, char* text);
DLL_IMPEXP bool DbgSetLabelAt(duint addr, const char* text);
DLL_IMPEXP bool DbgGetCommentAt(duint addr, char* text);
DLL_IMPEXP bool DbgSetCommentAt(duint addr, const char* text);
DLL_IMPEXP bool DbgGetBookmarkAt(duint addr);
DLL_IMPEXP bool DbgSetBookmarkAt(duint addr, bool isbookmark);
DLL_IMPEXP bool DbgGetModuleAt(duint addr, char* text);
DLL_IMPEXP BPXTYPE DbgGetBpxTypeAt(duint addr);
DLL_IMPEXP duint DbgValFromString(const char* string);
DLL_IMPEXP bool DbgGetRegDump(REGDUMP* regdump);
DLL_IMPEXP bool DbgValToString(const char* string, duint value);
DLL_IMPEXP bool DbgMemIsValidReadPtr(duint addr);
DLL_IMPEXP BPXTYPE DbgGetBpxTypeAt(duint addr);
DLL_IMPEXP int DbgGetBpList(BPXTYPE type, BPMAP* list);
BRIDGE_IMPEXP void DbgMemRead(duint va, unsigned char* dest, duint size);
BRIDGE_IMPEXP duint DbgMemGetPageSize(duint base);
BRIDGE_IMPEXP duint DbgMemFindBaseAddr(duint addr, duint* size);
BRIDGE_IMPEXP bool DbgCmdExec(const char* cmd);
BRIDGE_IMPEXP bool DbgCmdExecDirect(const char* cmd);
BRIDGE_IMPEXP bool DbgMemMap(MEMMAP* memmap);
BRIDGE_IMPEXP bool DbgIsValidExpression(const char* expression);
BRIDGE_IMPEXP bool DbgIsDebugging();
BRIDGE_IMPEXP bool DbgIsJumpGoingToExecute(duint addr);
BRIDGE_IMPEXP bool DbgGetLabelAt(duint addr, SEGMENTREG segment, char* text);
BRIDGE_IMPEXP bool DbgSetLabelAt(duint addr, const char* text);
BRIDGE_IMPEXP bool DbgGetCommentAt(duint addr, char* text);
BRIDGE_IMPEXP bool DbgSetCommentAt(duint addr, const char* text);
BRIDGE_IMPEXP bool DbgGetBookmarkAt(duint addr);
BRIDGE_IMPEXP bool DbgSetBookmarkAt(duint addr, bool isbookmark);
BRIDGE_IMPEXP bool DbgGetModuleAt(duint addr, char* text);
BRIDGE_IMPEXP BPXTYPE DbgGetBpxTypeAt(duint addr);
BRIDGE_IMPEXP duint DbgValFromString(const char* string);
BRIDGE_IMPEXP bool DbgGetRegDump(REGDUMP* regdump);
BRIDGE_IMPEXP bool DbgValToString(const char* string, duint value);
BRIDGE_IMPEXP bool DbgMemIsValidReadPtr(duint addr);
BRIDGE_IMPEXP BPXTYPE DbgGetBpxTypeAt(duint addr);
BRIDGE_IMPEXP int DbgGetBpList(BPXTYPE type, BPMAP* list);
//GUI functions
DLL_IMPEXP void GuiDisasmAt(duint addr, duint cip);
DLL_IMPEXP void GuiSetDebugState(DBGSTATE state);
DLL_IMPEXP void GuiAddLogMessage(const char* msg);
DLL_IMPEXP void GuiLogClear();
DLL_IMPEXP void GuiUpdateAllViews();
DLL_IMPEXP void GuiUpdateRegisterView();
DLL_IMPEXP void GuiUpdateDisassemblyView();
BRIDGE_IMPEXP void GuiDisasmAt(duint addr, duint cip);
BRIDGE_IMPEXP void GuiSetDebugState(DBGSTATE state);
BRIDGE_IMPEXP void GuiAddLogMessage(const char* msg);
BRIDGE_IMPEXP void GuiLogClear();
BRIDGE_IMPEXP void GuiUpdateAllViews();
BRIDGE_IMPEXP void GuiUpdateRegisterView();
BRIDGE_IMPEXP void GuiUpdateDisassemblyView();
#ifdef __cplusplus
}

View File

@ -13,6 +13,7 @@
<Option compiler="gcc" />
<Option host_application="../bin/x32/x32_dbg.exe" />
<Option run_host_application_in_terminal="0" />
<Option createDefFile="1" />
<Option createStaticLib="1" />
<Compiler>
<Add option="-O2" />
@ -28,6 +29,7 @@
<Option compiler="gnu_gcc_compiler_x64" />
<Option host_application="../bin/x64/x64_dbg.exe" />
<Option run_host_application_in_terminal="0" />
<Option createDefFile="1" />
<Option createStaticLib="1" />
<Compiler>
<Add option="-O2" />

View File

@ -47,6 +47,7 @@ void efree(void* ptr, const char* reason)
bool arraycontains(const char* cmd_list, const char* cmd)
{
//TODO: fix this function a little
if(!cmd_list or !cmd)
return false;
char temp[deflen]="";

View File

@ -11,22 +11,14 @@
#include "dbghelp\dbghelp.h"
#else
#include <dbghelp.h>
#endif //__GNUC__
#endif // __GNUC__
#ifndef deflen
#define deflen 1024
#endif // deflen
#ifdef _WIN64 //defined by default
#define fhex "%.16llX"
#define fext "ll"
typedef unsigned long long duint;
typedef long long dsint;
#else
#define fhex "%.8X"
#define fext ""
typedef unsigned long duint;
typedef long dsint;
#endif // _WIN64
#include "bridgemain.h"
#endif //BUILD_DBG
#endif // BUILD_DBG
#endif // _PLUGIN_DATA_H

View File

@ -11,3 +11,13 @@ PLUG_IMPEXP bool _plugin_unregistercallback(int pluginHandle, CBTYPE cbType)
{
return pluginunregistercallback(pluginHandle, cbType);
}
PLUG_IMPEXP bool _plugin_registercommand(int pluginHandle, const char* command, CBPLUGINCOMMAND cbCommand, bool debugonly)
{
return plugincmdregister(pluginHandle, command, cbCommand, debugonly);
}
PLUG_IMPEXP bool _plugin_unregistercommand(int pluginHandle, const char* command)
{
return plugincmdunregister(pluginHandle, command);
}

View File

@ -124,6 +124,7 @@ enum CBTYPE
//typedefs
typedef void (*CBPLUGIN)(CBTYPE cbType, void* callbackInfo);
typedef bool (*CBPLUGINCOMMAND)(int, char**);
//exports
#ifdef __cplusplus
@ -133,6 +134,8 @@ extern "C"
PLUG_IMPEXP void _plugin_registercallback(int pluginHandle, CBTYPE cbType, CBPLUGIN cbPlugin);
PLUG_IMPEXP bool _plugin_unregistercallback(int pluginHandle, CBTYPE cbType);
PLUG_IMPEXP bool _plugin_registercommand(int pluginHandle, const char* command, CBPLUGINCOMMAND cbCommand, bool debugonly);
PLUG_IMPEXP bool _plugin_unregistercommand(int pluginHandle, const char* command);
#ifdef __cplusplus
}

View File

@ -383,12 +383,15 @@ bool labelfromstring(const char* text, uint* addr)
*addr=sqlite3_column_int(stmt, 0); //addr
#endif // _WIN64
const char* modname=(const char*)sqlite3_column_text(stmt, 1); //mod
sqlite3_finalize(stmt);
if(!modname)
{
sqlite3_finalize(stmt);
return true;
}
puts(modname);
//TODO: fix this
*addr+=modbasefromname(modname);
sqlite3_finalize(stmt);
return true;
}

View File

@ -154,7 +154,9 @@ CMDRESULT cmdloop(COMMAND* command_list, CBCOMMAND cbUnknownCommand, CBCOMMANDPR
if(!cmd or !cmd->cbCommand) //unknown command
{
CMDRESULT res=cbUnknownCommand(command);
char* argv[1];
*argv=command;
CMDRESULT res=cbUnknownCommand(1, argv);
if((error_is_fatal and res==STATUS_ERROR) or res==STATUS_EXIT)
bLoop=false;
}
@ -168,7 +170,19 @@ CMDRESULT cmdloop(COMMAND* command_list, CBCOMMAND cbUnknownCommand, CBCOMMANDPR
}
else
{
CMDRESULT res=cmd->cbCommand(command);
int argcount=arggetcount(command);
char** argv=(char**)emalloc((argcount+1)*sizeof(char*));
argv[0]=command;
for(int i=0; i<argcount; i++)
{
argv[i+1]=(char*)emalloc(deflen);
*argv[i+1]=0;
argget(command, argv[i+1], i, true);
}
CMDRESULT res=cmd->cbCommand(argcount+1, argv);
for(int i=0; i<argcount; i++)
efree(argv[i+1]);
efree(argv);
if((error_is_fatal and res==STATUS_ERROR) or res==STATUS_EXIT)
bLoop=false;
}
@ -241,3 +255,31 @@ COMMAND* cmdfindmain(COMMAND* cmd_list, char* command)
mathformat(command);
return cmd;
}
CMDRESULT cmddirectexec(COMMAND* cmd_list, const char* cmd)
{
if(!cmd or !strlen(cmd))
return STATUS_ERROR;
char command[deflen]="";
strcpy(command, cmd);
argformat(command);
COMMAND* found=cmdfindmain(cmd_list, command);
if(!found or !found->cbCommand)
return STATUS_ERROR;
if(found->debugonly and !IsFileBeingDebugged())
return STATUS_ERROR;
int argcount=arggetcount(command);
char** argv=(char**)emalloc((argcount+1)*sizeof(char*));
argv[0]=command;
for(int i=0; i<argcount; i++)
{
argv[i+1]=(char*)emalloc(deflen);
*argv[i+1]=0;
argget(command, argv[i+1], i, true);
}
CMDRESULT res=found->cbCommand(argcount+1, argv);
for(int i=0; i<argcount; i++)
efree(argv[i+1]);
efree(argv);
return res;
}

View File

@ -9,12 +9,12 @@ struct COMMAND;
enum CMDRESULT
{
STATUS_EXIT=0,
STATUS_CONTINUE=1,
STATUS_ERROR=2
STATUS_ERROR=false,
STATUS_CONTINUE=true,
STATUS_EXIT=2,
};
typedef CMDRESULT (*CBCOMMAND)(const char*);
typedef CMDRESULT (*CBCOMMAND)(int, char**);
typedef bool (*CBCOMMANDPROVIDER)(char*, int);
typedef COMMAND* (*CBCOMMANDFINDER)(COMMAND*, char*);
@ -36,5 +36,6 @@ CBCOMMAND cmdset(COMMAND* command_list, const char* name, CBCOMMAND cbCommand, b
bool cmddel(COMMAND* command_list, const char* name);
CMDRESULT cmdloop(COMMAND* command_list, CBCOMMAND cbUnknownCommand, CBCOMMANDPROVIDER cbCommandProvider, CBCOMMANDFINDER cbCommandFinder, bool error_is_fatal);
COMMAND* cmdfindmain(COMMAND* cmd_list, char* command);
CMDRESULT cmddirectexec(COMMAND* cmd_list, const char* cmd);
#endif // _COMMAND_H

View File

@ -547,7 +547,7 @@ static DWORD WINAPI threadDebugLoop(void* lpParameter)
return 0;
}
CMDRESULT cbDebugInit(const char* cmd)
CMDRESULT cbDebugInit(int argc, char* argv[])
{
if(IsFileBeingDebugged())
{
@ -556,7 +556,7 @@ CMDRESULT cbDebugInit(const char* cmd)
}
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, false))
if(!argget(*argv, arg1, 0, false))
return STATUS_ERROR;
if(!FileExists(arg1))
{
@ -565,13 +565,13 @@ CMDRESULT cbDebugInit(const char* cmd)
}
char arg2[deflen]="";
argget(cmd, arg2, 1, true);
argget(*argv, arg2, 1, true);
char* commandline=0;
if(strlen(arg2))
commandline=arg2;
char arg3[deflen]="";
argget(cmd, arg3, 2, true);
argget(*argv, arg3, 2, true);
char currentfolder[deflen]="";
strcpy(currentfolder, arg1);
@ -600,14 +600,14 @@ CMDRESULT cbDebugInit(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbStopDebug(const char* cmd)
CMDRESULT cbStopDebug(int argc, char* argv[])
{
StopDebug();
unlock(WAITID_RUN);
return STATUS_CONTINUE;
}
CMDRESULT cbDebugRun(const char* cmd)
CMDRESULT cbDebugRun(int argc, char* argv[])
{
if(!waitislocked(WAITID_RUN))
{
@ -619,11 +619,11 @@ CMDRESULT cbDebugRun(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbDebugSetBPXOptions(const char* cmd)
CMDRESULT cbDebugSetBPXOptions(int argc, char* argv[])
{
char argtype[deflen]="";
uint type=0;
if(!argget(cmd, argtype, 0, false))
if(!argget(*argv, argtype, 0, false))
return STATUS_ERROR;
const char* a=0;
if(strstr(argtype, "long"))
@ -651,15 +651,15 @@ CMDRESULT cbDebugSetBPXOptions(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbDebugSetBPX(const char* cmd) //bp addr [,name [,type]]
CMDRESULT cbDebugSetBPX(int argc, char* argv[]) //bp addr [,name [,type]]
{
char argaddr[deflen]="";
if(!argget(cmd, argaddr, 0, false))
if(!argget(*argv, argaddr, 0, false))
return STATUS_ERROR;
char argname[deflen]="";
argget(cmd, argname, 1, true);
argget(*argv, argname, 1, true);
char argtype[deflen]="";
bool has_arg2=argget(cmd, argtype, 2, true);
bool has_arg2=argget(*argv, argtype, 2, true);
if(!has_arg2 and (scmp(argname, "ss") or scmp(argname, "long") or scmp(argname, "ud2")))
{
strcpy(argtype, argname);
@ -719,10 +719,10 @@ static bool cbDeleteAllBreakpoints(const BREAKPOINT* bp)
return false;
}
CMDRESULT cbDebugDeleteBPX(const char* cmd)
CMDRESULT cbDebugDeleteBPX(int argc, char* argv[])
{
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, true)) //delete all breakpoints
if(!argget(*argv, arg1, 0, true)) //delete all breakpoints
{
if(!bpgetcount(BPNORMAL))
{
@ -771,11 +771,11 @@ static bool cbEnableAllBreakpoints(const BREAKPOINT* bp)
return true;
}
CMDRESULT cbDebugEnableBPX(const char* cmd)
CMDRESULT cbDebugEnableBPX(int argc, char* argv[])
{
puts("cbDebugEnableBPX");
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, true)) //delete all breakpoints
if(!argget(*argv, arg1, 0, true)) //delete all breakpoints
{
if(!bpgetcount(BPNORMAL))
{
@ -831,10 +831,10 @@ static bool cbDisableAllBreakpoints(const BREAKPOINT* bp)
return true;
}
CMDRESULT cbDebugDisableBPX(const char* cmd)
CMDRESULT cbDebugDisableBPX(int argc, char* argv[])
{
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, true)) //delete all breakpoints
if(!argget(*argv, arg1, 0, true)) //delete all breakpoints
{
if(!bpgetcount(BPNORMAL))
{
@ -901,31 +901,31 @@ static bool cbBreakpointList(const BREAKPOINT* bp)
return true;
}
CMDRESULT cbDebugBplist(const char* cmd)
CMDRESULT cbDebugBplist(int argc, char* argv[])
{
bpenumall(cbBreakpointList);
return STATUS_CONTINUE;
}
CMDRESULT cbDebugStepInto(const char* cmd)
CMDRESULT cbDebugStepInto(int argc, char* argv[])
{
StepInto((void*)cbStep);
isStepping=true;
return cbDebugRun(cmd);
return cbDebugRun(argc, argv);
}
CMDRESULT cbDebugStepOver(const char* cmd)
CMDRESULT cbDebugStepOver(int argc, char* argv[])
{
StepOver((void*)cbStep);
isStepping=true;
return cbDebugRun(cmd);
return cbDebugRun(argc, argv);
}
CMDRESULT cbDebugSingleStep(const char* cmd)
CMDRESULT cbDebugSingleStep(int argc, char* argv[])
{
char arg1[deflen]="";
uint stepcount=1;
if(argget(cmd, arg1, 0, true))
if(argget(*argv, arg1, 0, true))
{
if(!valfromstring(arg1, &stepcount, 0, 0, true, 0))
stepcount=1;
@ -933,10 +933,10 @@ CMDRESULT cbDebugSingleStep(const char* cmd)
SingleStep((DWORD)stepcount, (void*)cbStep);
isStepping=true;
return cbDebugRun(cmd);
return cbDebugRun(argc, argv);
}
CMDRESULT cbDebugHide(const char* cmd)
CMDRESULT cbDebugHide(int argc, char* argv[])
{
if(HideDebugger(fdProcessInfo->hProcess, UE_HIDE_BASIC))
dputs("debugger hidden");
@ -945,21 +945,21 @@ CMDRESULT cbDebugHide(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbDebugDisasm(const char* cmd)
CMDRESULT cbDebugDisasm(int argc, char* argv[])
{
char arg1[deflen]="";
uint addr=GetContextData(UE_CIP);
if(argget(cmd, arg1, 0, true))
if(argget(*argv, arg1, 0, true))
if(!valfromstring(arg1, &addr, 0, 0, true, 0))
addr=GetContextData(UE_CIP);
DebugUpdateGui(addr);
return STATUS_CONTINUE;
}
CMDRESULT cbDebugSetMemoryBpx(const char* cmd)
CMDRESULT cbDebugSetMemoryBpx(int argc, char* argv[])
{
char arg1[deflen]=""; //addr
if(!argget(cmd, arg1, 0, false))
if(!argget(*argv, arg1, 0, false))
return STATUS_ERROR;
uint addr;
if(!valfromstring(arg1, &addr, 0, 0, true, 0))
@ -967,8 +967,8 @@ CMDRESULT cbDebugSetMemoryBpx(const char* cmd)
bool restore=false;
char arg2[deflen]=""; //restore
char arg3[deflen]=""; //type
argget(cmd, arg3, 2, true);
if(argget(cmd, arg2, 1, true))
argget(*argv, arg3, 2, true);
if(argget(*argv, arg2, 1, true))
{
if(*arg2=='1')
restore=true;
@ -1030,10 +1030,10 @@ static bool cbDeleteAllMemoryBreakpoints(const BREAKPOINT* bp)
return true;
}
CMDRESULT cbDebugDeleteMemoryBreakpoint(const char* cmd)
CMDRESULT cbDebugDeleteMemoryBreakpoint(int argc, char* argv[])
{
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, true)) //delete all breakpoints
if(!argget(*argv, arg1, 0, true)) //delete all breakpoints
{
if(!bpgetcount(BPMEMORY))
{
@ -1076,24 +1076,24 @@ CMDRESULT cbDebugDeleteMemoryBreakpoint(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbDebugRtr(const char* cmd)
CMDRESULT cbDebugRtr(int argc, char* argv[])
{
StepOver((void*)cbRtrStep);
cbDebugRun(cmd);
cbDebugRun(argc, argv);
return STATUS_CONTINUE;
}
CMDRESULT cbDebugSetHardwareBreakpoint(const char* cmd)
CMDRESULT cbDebugSetHardwareBreakpoint(int argc, char* argv[])
{
char arg1[deflen]=""; //addr
if(!argget(cmd, arg1, 0, false))
if(!argget(*argv, arg1, 0, false))
return STATUS_ERROR;
uint addr;
if(!valfromstring(arg1, &addr, 0, 0, true, 0))
return STATUS_ERROR;
uint type=UE_HARDWARE_EXECUTE;
char arg2[deflen]=""; //type
if(argget(cmd, arg2, 1, true))
if(argget(*argv, arg2, 1, true))
{
switch(*arg2)
{
@ -1112,7 +1112,7 @@ CMDRESULT cbDebugSetHardwareBreakpoint(const char* cmd)
}
char arg3[deflen]=""; //size
uint size=UE_HARDWARE_SIZE_1;
if(argget(cmd, arg3, 2, true))
if(argget(*argv, arg3, 2, true))
{
if(!valfromstring(arg3, &size, 0, 0, true, 0))
return STATUS_ERROR;
@ -1174,10 +1174,10 @@ static bool cbDeleteAllHardwareBreakpoints(const BREAKPOINT* bp)
return true;
}
CMDRESULT cbDebugDeleteHardwareBreakpoint(const char* cmd)
CMDRESULT cbDebugDeleteHardwareBreakpoint(int argc, char* argv[])
{
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, true)) //delete all breakpoints
if(!argget(*argv, arg1, 0, true)) //delete all breakpoints
{
if(!bpgetcount(BPHARDWARE))
{
@ -1216,11 +1216,11 @@ CMDRESULT cbDebugDeleteHardwareBreakpoint(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbDebugAlloc(const char* cmd)
CMDRESULT cbDebugAlloc(int argc, char* argv[])
{
char arg1[deflen]=""; //size
uint size=0x1000;
if(argget(cmd, arg1, 0, true))
if(argget(*argv, arg1, 0, true))
if(!valfromstring(arg1, &size, 0, 0, false, 0))
return STATUS_ERROR;
uint mem=(uint)memalloc(fdProcessInfo->hProcess, 0, size, PAGE_EXECUTE_READWRITE);
@ -1234,13 +1234,13 @@ CMDRESULT cbDebugAlloc(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbDebugFree(const char* cmd)
CMDRESULT cbDebugFree(int argc, char* argv[])
{
uint lastalloc;
varget("$lastalloc", &lastalloc, 0, 0);
char arg1[deflen]=""; //addr
uint addr=lastalloc;
if(argget(cmd, arg1, 0, true))
if(argget(*argv, arg1, 0, true))
{
if(!valfromstring(arg1, &addr, 0, 0, false, 0))
return STATUS_ERROR;
@ -1256,7 +1256,7 @@ CMDRESULT cbDebugFree(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbDebugMemset(const char* cmd)
CMDRESULT cbDebugMemset(int argc, char* argv[])
{
char arg1[deflen]=""; //addr
char arg2[deflen]=""; //value
@ -1264,11 +1264,11 @@ CMDRESULT cbDebugMemset(const char* cmd)
uint addr;
uint value;
uint size;
if(!argget(cmd, arg1, 0, false) or !argget(cmd, arg2, 1, false))
if(!argget(*argv, arg1, 0, false) or !argget(*argv, arg2, 1, false))
return STATUS_ERROR;
if(!valfromstring(arg1, &addr, 0, 0, false, 0) or !valfromstring(arg2, &value, 0, 0, false, 0))
return STATUS_ERROR;
if(argget(cmd, arg3, 2, true))
if(argget(*argv, arg3, 2, true))
{
if(!valfromstring(arg3, &size, 0, 0, false, 0))
return STATUS_ERROR;
@ -1293,10 +1293,10 @@ CMDRESULT cbDebugMemset(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbBenchmark(const char* cmd)
CMDRESULT cbBenchmark(int argc, char* argv[])
{
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, false))
if(!argget(*argv, arg1, 0, false))
return STATUS_ERROR;
uint addr=0;
if(!valfromstring(arg1, &addr, 0, 0, false, 0))
@ -1313,7 +1313,7 @@ CMDRESULT cbBenchmark(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbDebugPause(const char* cmd)
CMDRESULT cbDebugPause(int argc, char* argv[])
{
if(waitislocked(WAITID_RUN))
{
@ -1325,10 +1325,10 @@ CMDRESULT cbDebugPause(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbMemWrite(const char* cmd)
CMDRESULT cbMemWrite(int argc, char* argv[])
{
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, false))
if(!argget(*argv, arg1, 0, false))
return STATUS_ERROR;
uint addr=0;
if(!valfromstring(arg1, &addr, 0, 0, false, 0))
@ -1366,7 +1366,7 @@ DWORD WINAPI scyllaThread(void* lpParam)
return 0;
}
CMDRESULT cbStartScylla(const char* cmd)
CMDRESULT cbStartScylla(int argc, char* argv[])
{
if(bScyllaLoaded)
{

View File

@ -20,32 +20,32 @@ void dbgenablebpx();
bool dbgisrunning();
void DebugUpdateGui(uint disasm_addr);
//callbacks
CMDRESULT cbDebugInit(const char* cmd);
CMDRESULT cbStopDebug(const char* cmd);
CMDRESULT cbDebugRun(const char* cmd);
CMDRESULT cbDebugSetBPXOptions(const char* cmd);
CMDRESULT cbDebugSetBPX(const char* cmd);
CMDRESULT cbDebugDeleteBPX(const char* cmd);
CMDRESULT cbDebugEnableBPX(const char* cmd);
CMDRESULT cbDebugDisableBPX(const char* cmd);
CMDRESULT cbDebugBplist(const char* cmd);
CMDRESULT cbDebugStepInto(const char* cmd);
CMDRESULT cbDebugStepOver(const char* cmd);
CMDRESULT cbDebugSingleStep(const char* cmd);
CMDRESULT cbDebugHide(const char* cmd);
CMDRESULT cbDebugDisasm(const char* cmd);
CMDRESULT cbDebugSetMemoryBpx(const char* cmd);
CMDRESULT cbDebugRtr(const char* cmd);
CMDRESULT cbDebugSetHardwareBreakpoint(const char* cmd);
CMDRESULT cbDebugAlloc(const char* cmd);
CMDRESULT cbDebugFree(const char* cmd);
CMDRESULT cbDebugMemset(const char* cmd);
CMDRESULT cbBenchmark(const char* cmd);
CMDRESULT cbDebugPause(const char* cmd);
CMDRESULT cbMemWrite(const char* cmd);
CMDRESULT cbStartScylla(const char* cmd);
CMDRESULT cbDebugDeleteHardwareBreakpoint(const char* cmd);
CMDRESULT cbDebugDeleteMemoryBreakpoint(const char* cmd);
CMDRESULT cbDebugInit(int argc, char* argv[]);
CMDRESULT cbStopDebug(int argc, char* argv[]);
CMDRESULT cbDebugRun(int argc, char* argv[]);
CMDRESULT cbDebugSetBPXOptions(int argc, char* argv[]);
CMDRESULT cbDebugSetBPX(int argc, char* argv[]);
CMDRESULT cbDebugDeleteBPX(int argc, char* argv[]);
CMDRESULT cbDebugEnableBPX(int argc, char* argv[]);
CMDRESULT cbDebugDisableBPX(int argc, char* argv[]);
CMDRESULT cbDebugBplist(int argc, char* argv[]);
CMDRESULT cbDebugStepInto(int argc, char* argv[]);
CMDRESULT cbDebugStepOver(int argc, char* argv[]);
CMDRESULT cbDebugSingleStep(int argc, char* argv[]);
CMDRESULT cbDebugHide(int argc, char* argv[]);
CMDRESULT cbDebugDisasm(int argc, char* argv[]);
CMDRESULT cbDebugSetMemoryBpx(int argc, char* argv[]);
CMDRESULT cbDebugRtr(int argc, char* argv[]);
CMDRESULT cbDebugSetHardwareBreakpoint(int argc, char* argv[]);
CMDRESULT cbDebugAlloc(int argc, char* argv[]);
CMDRESULT cbDebugFree(int argc, char* argv[]);
CMDRESULT cbDebugMemset(int argc, char* argv[]);
CMDRESULT cbBenchmark(int argc, char* argv[]);
CMDRESULT cbDebugPause(int argc, char* argv[]);
CMDRESULT cbMemWrite(int argc, char* argv[]);
CMDRESULT cbStartScylla(int argc, char* argv[]);
CMDRESULT cbDebugDeleteHardwareBreakpoint(int argc, char* argv[]);
CMDRESULT cbDebugDeleteMemoryBreakpoint(int argc, char* argv[]);
//variables
extern PROCESS_INFORMATION* fdProcessInfo;

View File

@ -6,13 +6,13 @@
#include "command.h"
#include "addrinfo.h"
CMDRESULT cbBadCmd(const char* cmd)
CMDRESULT cbBadCmd(int argc, char* argv[])
{
uint value=0;
int valsize=0;
bool isvar=false;
bool hexonly=false;
if(valfromstring(cmd, &value, &valsize, &isvar, false, &hexonly)) //dump variable/value/register/etc
if(valfromstring(*argv, &value, &valsize, &isvar, false, &hexonly)) //dump variable/value/register/etc
{
//dprintf("[DEBUG] valsize: %d\n", valsize);
if(valsize)
@ -28,12 +28,12 @@ CMDRESULT cbBadCmd(const char* cmd)
sprintf(format_str, "%%s=%%.%d"fext"X (%%"fext"ud)\n", valsize);
else
sprintf(format_str, "%%s=%%.%d"fext"X (%%"fext"d)\n", valsize);
dprintf(format_str, cmd, value, value);
dprintf(format_str, *argv, value, value);
}
else
{
sprintf(format_str, "%%s=%%.%d"fext"X\n", valsize);
dprintf(format_str, cmd, value);
dprintf(format_str, *argv, value);
}
}
else
@ -56,19 +56,19 @@ CMDRESULT cbBadCmd(const char* cmd)
}
else //unknown command
{
dprintf("unknown command/expression: \"%s\"\n", cmd);
dprintf("unknown command/expression: \"%s\"\n", *argv);
return STATUS_ERROR;
}
return STATUS_CONTINUE;
}
CMDRESULT cbInstrVar(const char* cmd)
CMDRESULT cbInstrVar(int argc, char* argv[])
{
char arg1[deflen]="";
char arg2[deflen]="";
if(!argget(cmd, arg1, 0, false)) //var name
if(!argget(*argv, arg1, 0, false)) //var name
return STATUS_ERROR;
argget(cmd, arg2, 1, true); //var value (optional)
argget(*argv, arg2, 1, true); //var value (optional)
uint value=0;
int add=0;
if(*arg1=='$')
@ -98,10 +98,10 @@ CMDRESULT cbInstrVar(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbInstrVarDel(const char* cmd)
CMDRESULT cbInstrVarDel(int argc, char* argv[])
{
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, false)) //var name
if(!argget(*argv, arg1, 0, false)) //var name
return STATUS_ERROR;
if(!vardel(arg1, false))
dprintf("could not delete variable \"%s\"\n", arg1);
@ -110,13 +110,13 @@ CMDRESULT cbInstrVarDel(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbInstrMov(const char* cmd)
CMDRESULT cbInstrMov(int argc, char* argv[])
{
char arg1[deflen]="";
char arg2[deflen]="";
if(!argget(cmd, arg1, 0, false)) //dest name
if(!argget(*argv, arg1, 0, false)) //dest name
return STATUS_ERROR;
if(!argget(cmd, arg2, 1, false)) //src name
if(!argget(*argv, arg2, 1, false)) //src name
return STATUS_ERROR;
uint set_value=0;
if(!valfromstring(arg2, &set_value, 0, 0, false, 0))
@ -137,14 +137,14 @@ CMDRESULT cbInstrMov(const char* cmd)
}
varnew(arg1, set_value, VAR_USER);
}
cbBadCmd(arg1);
cbBadCmd(1, &argv[0]);
return STATUS_CONTINUE;
}
CMDRESULT cbInstrVarList(const char* cmd)
CMDRESULT cbInstrVarList(int argc, char* argv[])
{
char arg1[deflen]="";
argget(cmd, arg1, 0, true);
argget(*argv, arg1, 0, true);
int filter=0;
if(!_stricmp(arg1, "USER"))
filter=VAR_USER;
@ -196,10 +196,10 @@ CMDRESULT cbInstrVarList(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbInstrChd(const char* cmd)
CMDRESULT cbInstrChd(int argc, char* argv[])
{
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, false))
if(!argget(*argv, arg1, 0, false))
return STATUS_ERROR;
if(!DirExists(arg1))
{
@ -211,10 +211,10 @@ CMDRESULT cbInstrChd(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbInstrCmt(const char* cmd)
CMDRESULT cbInstrCmt(int argc, char* argv[])
{
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, false))
if(!argget(*argv, arg1, 0, false))
return STATUS_ERROR;
uint addr=0;
if(!valfromstring(arg1, &addr, 0, 0, true, 0))
@ -223,7 +223,7 @@ CMDRESULT cbInstrCmt(const char* cmd)
return STATUS_ERROR;
}
char arg2[deflen]="";
if(!argget(cmd, arg2, 1, false))
if(!argget(*argv, arg2, 1, false))
return STATUS_ERROR;
if(!commentset(addr, arg2))
{
@ -233,10 +233,10 @@ CMDRESULT cbInstrCmt(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbInstrCmtdel(const char* cmd)
CMDRESULT cbInstrCmtdel(int argc, char* argv[])
{
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, false))
if(!argget(*argv, arg1, 0, false))
return STATUS_ERROR;
uint addr=0;
if(!valfromstring(arg1, &addr, 0, 0, true, 0))
@ -252,10 +252,10 @@ CMDRESULT cbInstrCmtdel(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbInstrLbl(const char* cmd)
CMDRESULT cbInstrLbl(int argc, char* argv[])
{
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, false))
if(!argget(*argv, arg1, 0, false))
return STATUS_ERROR;
uint addr=0;
if(!valfromstring(arg1, &addr, 0, 0, true, 0))
@ -264,7 +264,7 @@ CMDRESULT cbInstrLbl(const char* cmd)
return STATUS_ERROR;
}
char arg2[deflen]="";
if(!argget(cmd, arg2, 1, false))
if(!argget(*argv, arg2, 1, false))
return STATUS_ERROR;
if(!labelset(addr, arg2))
{
@ -274,10 +274,10 @@ CMDRESULT cbInstrLbl(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbInstrLbldel(const char* cmd)
CMDRESULT cbInstrLbldel(int argc, char* argv[])
{
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, false))
if(!argget(*argv, arg1, 0, false))
return STATUS_ERROR;
uint addr=0;
if(!valfromstring(arg1, &addr, 0, 0, true, 0))
@ -294,10 +294,10 @@ CMDRESULT cbInstrLbldel(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbInstrBookmarkSet(const char* cmd)
CMDRESULT cbInstrBookmarkSet(int argc, char* argv[])
{
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, false))
if(!argget(*argv, arg1, 0, false))
return STATUS_ERROR;
uint addr=0;
if(!valfromstring(arg1, &addr, 0, 0, true, 0))
@ -314,10 +314,10 @@ CMDRESULT cbInstrBookmarkSet(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbInstrBookmarkDel(const char* cmd)
CMDRESULT cbInstrBookmarkDel(int argc, char* argv[])
{
char arg1[deflen]="";
if(!argget(cmd, arg1, 0, false))
if(!argget(*argv, arg1, 0, false))
return STATUS_ERROR;
uint addr=0;
if(!valfromstring(arg1, &addr, 0, 0, true, 0))
@ -334,7 +334,7 @@ CMDRESULT cbInstrBookmarkDel(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbLoaddb(const char* cmd)
CMDRESULT cbLoaddb(int argc, char* argv[])
{
if(!dbload())
{
@ -345,7 +345,7 @@ CMDRESULT cbLoaddb(const char* cmd)
return STATUS_CONTINUE;
}
CMDRESULT cbSavedb(const char* cmd)
CMDRESULT cbSavedb(int argc, char* argv[])
{
if(!dbsave())
{

View File

@ -5,19 +5,19 @@
#include "command.h"
//functions
CMDRESULT cbBadCmd(const char* cmd);
CMDRESULT cbInstrVar(const char* cmd);
CMDRESULT cbInstrVarDel(const char* cmd);
CMDRESULT cbInstrMov(const char* cmd);
CMDRESULT cbInstrVarList(const char* cmd);
CMDRESULT cbInstrChd(const char* cmd);
CMDRESULT cbInstrCmt(const char* cmd);
CMDRESULT cbInstrCmtdel(const char* cmd);
CMDRESULT cbInstrLbl(const char* cmd);
CMDRESULT cbInstrLbldel(const char* cmd);
CMDRESULT cbInstrBookmarkSet(const char* cmd);
CMDRESULT cbInstrBookmarkDel(const char* cmd);
CMDRESULT cbLoaddb(const char* cmd);
CMDRESULT cbSavedb(const char* cmd);
CMDRESULT cbBadCmd(int argc, char* argv[]);
CMDRESULT cbInstrVar(int argc, char* argv[]);
CMDRESULT cbInstrVarDel(int argc, char* argv[]);
CMDRESULT cbInstrMov(int argc, char* argv[]);
CMDRESULT cbInstrVarList(int argc, char* argv[]);
CMDRESULT cbInstrChd(int argc, char* argv[]);
CMDRESULT cbInstrCmt(int argc, char* argv[]);
CMDRESULT cbInstrCmtdel(int argc, char* argv[]);
CMDRESULT cbInstrLbl(int argc, char* argv[]);
CMDRESULT cbInstrLbldel(int argc, char* argv[]);
CMDRESULT cbInstrBookmarkSet(int argc, char* argv[]);
CMDRESULT cbInstrBookmarkDel(int argc, char* argv[]);
CMDRESULT cbLoaddb(int argc, char* argv[]);
CMDRESULT cbSavedb(int argc, char* argv[]);
#endif // _INSTRUCTIONS_H

View File

@ -1,9 +1,12 @@
#include "plugin_loader.h"
#include "console.h"
#include "command.h"
#include "x64_dbg.h"
static std::vector<PLUG_DATA> pluginList;
static int curPluginHandle=0;
static std::vector<PLUG_CALLBACK> pluginCallbackList;
static std::vector<PLUG_COMMAND> pluginCommandList;
///internal plugin functions
void pluginload(const char* pluginDir)
@ -115,3 +118,34 @@ void plugincbcall(CBTYPE cbType, void* callbackInfo)
}
}
}
bool plugincmdregister(int pluginHandle, const char* command, CBPLUGINCOMMAND cbCommand, bool debugonly)
{
if(!command or strlen(command)>=deflen or strstr(command, "\1"))
return false;
PLUG_COMMAND plugCmd;
plugCmd.pluginHandle=pluginHandle;
strcpy(plugCmd.command, command);
if(!cmdnew(dbggetcommandlist(), command, (CBCOMMAND)cbCommand, debugonly))
return false;
pluginCommandList.push_back(plugCmd);
return true;
}
bool plugincmdunregister(int pluginHandle, const char* command)
{
if(!command or strlen(command)>=deflen or strstr(command, "\1"))
return false;
int listsize=pluginCommandList.size();
for(int i=0; i<listsize; i++)
{
if(pluginCommandList.at(i).pluginHandle==pluginHandle and !strcmp(pluginCommandList.at(i).command, command))
{
if(!cmddel(dbggetcommandlist(), command))
return false;
pluginCommandList.erase(pluginCommandList.begin()+i);
return true;
}
}
return false;
}

View File

@ -24,11 +24,19 @@ struct PLUG_CALLBACK
CBPLUGIN cbPlugin;
};
struct PLUG_COMMAND
{
int pluginHandle;
char command[deflen];
};
//plugin management functions
void pluginload(const char* pluginDir);
void pluginunload();
void pluginregistercallback(int pluginHandle, CBTYPE cbType, CBPLUGIN cbPlugin);
bool pluginunregistercallback(int pluginHandle, CBTYPE cbType);
void plugincbcall(CBTYPE cbType, void* callbackInfo);
bool plugincmdregister(int pluginHandle, const char* command, CBPLUGINCOMMAND cbCommand, bool debugonly);
bool plugincmdunregister(int pluginHandle, const char* command);
#endif // _PLUGIN_LOADER_H

View File

@ -2,12 +2,13 @@
#include "command.h"
#include "console.h"
#include "instruction.h"
#include "x64_dbg.h"
static int total=0;
static char found[1024][1024];
static COMMAND* command_list=0;
static CMDRESULT cbRet(const char* cmd)
static CMDRESULT cbRet(int argc, char* argv[])
{
return STATUS_EXIT;
}
@ -19,20 +20,15 @@ static bool cbCommandProvider(char* cmd, int maxlen)
return true;
}
static CMDRESULT cbCollect(const char* cmd)
static CMDRESULT cbCollect(int argc, char* argv[])
{
strcpy(found[total], cmd);
strcpy(found[total], *argv);
total++;
if(total>=1024)
return STATUS_EXIT;
return STATUS_CONTINUE;
}
void scriptSetList(COMMAND* cmd_list)
{
command_list=cmd_list;
}
static int i=0;
static bool provider(char* cmd, int size)
@ -44,8 +40,9 @@ static bool provider(char* cmd, int size)
return true;
}
CMDRESULT cbScript(const char* cmd)
CMDRESULT cbScript(int argc, char* argv[])
{
command_list=dbggetcommandlist();
total=0;
i=0;
COMMAND* cmd_list=cmdinit();

View File

@ -3,7 +3,6 @@
#include "command.h"
CMDRESULT cbScript(const char* cmd);
void scriptSetList(COMMAND* cmd_list);
CMDRESULT cbScript(int argc, char* argv[]);
#endif // _SIMPLESCRIPT_H

View File

@ -17,15 +17,15 @@
static MESSAGE_STACK* gMsgStack=0;
static COMMAND* command_list=0;
static CMDRESULT cbStrLen(const char* cmd)
static CMDRESULT cbStrLen(int argc, char* argv[])
{
char arg1[deflen]="";
if(argget(cmd, arg1, 0, false))
if(argget(*argv, arg1, 0, false))
dprintf("\"%s\"[%d]\n", arg1, strlen(arg1));
return STATUS_CONTINUE;
}
static CMDRESULT cbCls(const char* cmd)
static CMDRESULT cbCls(int argc, char* argv[])
{
GuiLogClear();
return STATUS_CONTINUE;
@ -122,7 +122,6 @@ extern "C" DLL_EXPORT const char* _dbg_dbginit()
return "Could not allocate message stack!";
varinit();
registercommands();
scriptSetList(command_list);
CreateThread(0, 0, DbgCommandLoopThread, 0, 0, 0);
char plugindir[deflen]="";
strcpy(plugindir, dir);
@ -134,7 +133,7 @@ extern "C" DLL_EXPORT const char* _dbg_dbginit()
extern "C" DLL_EXPORT void _dbg_dbgexitsignal()
{
//TODO: handle exit signal
cbStopDebug("");
cbStopDebug(0, 0);
wait(WAITID_STOP); //after this, debugging stopped
pluginunload();
DeleteFileA("DLLLoader.exe");
@ -142,3 +141,15 @@ extern "C" DLL_EXPORT void _dbg_dbgexitsignal()
varfree();
msgfreestack(gMsgStack);
}
extern "C" DLL_EXPORT bool _dbg_dbgcmddirectexec(const char* cmd)
{
if(cmddirectexec(command_list, cmd)==STATUS_ERROR)
return false;
return true;
}
COMMAND* dbggetcommandlist()
{
return command_list;
}

View File

@ -11,10 +11,13 @@ extern "C"
DLL_EXPORT const char* _dbg_dbginit();
DLL_EXPORT bool _dbg_dbgcmdexec(const char* cmd);
DLL_EXPORT bool _dbg_dbgcmddirectexec(const char* cmd);
DLL_EXPORT void _dbg_dbgexitsignal();
#ifdef __cplusplus
}
#endif
COMMAND* dbggetcommandlist();
#endif // _X64_DBG_H