Merge branch 'master' of https://github.com/x64dbg/x64dbg
Conflicts: x64_dbg_dbg/thread.cpp
This commit is contained in:
commit
260e2eb6fb
|
|
@ -90,7 +90,7 @@ extern "C" DLL_EXPORT bool _dbg_isjumpgoingtoexecute(duint addr)
|
|||
static uint cacheFlags;
|
||||
static uint cacheAddr;
|
||||
static bool cacheResult;
|
||||
if(cacheAddr != addr or cacheFlags != GetContextDataEx(hActiveThread, UE_EFLAGS))
|
||||
if(cacheAddr != addr || cacheFlags != GetContextDataEx(hActiveThread, UE_EFLAGS))
|
||||
{
|
||||
cacheFlags = GetContextDataEx(hActiveThread, UE_EFLAGS);
|
||||
cacheAddr = addr;
|
||||
|
|
@ -120,10 +120,10 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
|||
PSYMBOL_INFO pSymbol = (PSYMBOL_INFO)buffer;
|
||||
pSymbol->SizeOfStruct = sizeof(SYMBOL_INFO);
|
||||
pSymbol->MaxNameLen = MAX_LABEL_SIZE;
|
||||
if(SafeSymFromAddr(fdProcessInfo->hProcess, (DWORD64)addr, &displacement, pSymbol) and !displacement)
|
||||
if(SafeSymFromAddr(fdProcessInfo->hProcess, (DWORD64)addr, &displacement, pSymbol) && !displacement)
|
||||
{
|
||||
pSymbol->Name[pSymbol->MaxNameLen - 1] = '\0';
|
||||
if(!bUndecorateSymbolNames or !SafeUnDecorateSymbolName(pSymbol->Name, addrinfo->label, MAX_LABEL_SIZE, UNDNAME_COMPLETE))
|
||||
if(!bUndecorateSymbolNames || !SafeUnDecorateSymbolName(pSymbol->Name, addrinfo->label, MAX_LABEL_SIZE, UNDNAME_COMPLETE))
|
||||
strcpy_s(addrinfo->label, pSymbol->Name);
|
||||
retval = true;
|
||||
}
|
||||
|
|
@ -136,10 +136,10 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
|||
uint val = 0;
|
||||
if(MemRead((void*)basicinfo.memory.value, &val, sizeof(val), 0))
|
||||
{
|
||||
if(SafeSymFromAddr(fdProcessInfo->hProcess, (DWORD64)val, &displacement, pSymbol) and !displacement)
|
||||
if(SafeSymFromAddr(fdProcessInfo->hProcess, (DWORD64)val, &displacement, pSymbol) && !displacement)
|
||||
{
|
||||
pSymbol->Name[pSymbol->MaxNameLen - 1] = '\0';
|
||||
if(!bUndecorateSymbolNames or !SafeUnDecorateSymbolName(pSymbol->Name, addrinfo->label, MAX_LABEL_SIZE, UNDNAME_COMPLETE))
|
||||
if(!bUndecorateSymbolNames || !SafeUnDecorateSymbolName(pSymbol->Name, addrinfo->label, MAX_LABEL_SIZE, UNDNAME_COMPLETE))
|
||||
sprintf_s(addrinfo->label, "JMP.&%s", pSymbol->Name);
|
||||
retval = true;
|
||||
}
|
||||
|
|
@ -173,12 +173,12 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
|||
DWORD dwDisplacement;
|
||||
IMAGEHLP_LINE64 line;
|
||||
line.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
|
||||
if(SafeSymGetLineFromAddr64(fdProcessInfo->hProcess, (DWORD64)addr, &dwDisplacement, &line) and !dwDisplacement)
|
||||
if(SafeSymGetLineFromAddr64(fdProcessInfo->hProcess, (DWORD64)addr, &dwDisplacement, &line) && !dwDisplacement)
|
||||
{
|
||||
char filename[deflen] = "";
|
||||
strcpy_s(filename, line.FileName);
|
||||
int len = (int)strlen(filename);
|
||||
while(filename[len] != '\\' and len != 0)
|
||||
while(filename[len] != '\\' && len != 0)
|
||||
len--;
|
||||
if(len)
|
||||
len++;
|
||||
|
|
@ -206,7 +206,7 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
|||
|
||||
if(instr.arg[i].constant == instr.arg[i].value) //avoid: call <module.label> ; addr:label
|
||||
{
|
||||
if(instr.type == instr_branch or !disasmgetstringat(instr.arg[i].constant, &strtype, ascii, unicode, len_left) or strtype == str_none)
|
||||
if(instr.type == instr_branch || !disasmgetstringat(instr.arg[i].constant, &strtype, ascii, unicode, len_left) || strtype == str_none)
|
||||
continue;
|
||||
switch(strtype)
|
||||
{
|
||||
|
|
@ -226,7 +226,7 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
|||
break;
|
||||
}
|
||||
}
|
||||
else if(instr.arg[i].memvalue and (disasmgetstringat(instr.arg[i].memvalue, &strtype, ascii, unicode, len_left) or _dbg_addrinfoget(instr.arg[i].memvalue, instr.arg[i].segment, &newinfo)))
|
||||
else if(instr.arg[i].memvalue && (disasmgetstringat(instr.arg[i].memvalue, &strtype, ascii, unicode, len_left) || _dbg_addrinfoget(instr.arg[i].memvalue, instr.arg[i].segment, &newinfo)))
|
||||
{
|
||||
switch(strtype)
|
||||
{
|
||||
|
|
@ -253,7 +253,7 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
|||
break;
|
||||
}
|
||||
}
|
||||
else if(instr.arg[i].value and (disasmgetstringat(instr.arg[i].value, &strtype, ascii, unicode, len_left) or _dbg_addrinfoget(instr.arg[i].value, instr.arg[i].segment, &newinfo)))
|
||||
else if(instr.arg[i].value && (disasmgetstringat(instr.arg[i].value, &strtype, ascii, unicode, len_left) || _dbg_addrinfoget(instr.arg[i].value, instr.arg[i].segment, &newinfo)))
|
||||
{
|
||||
if(instr.type != instr_normal) //stack/jumps (eg add esp,4 or jmp 401110) cannot directly point to strings
|
||||
strtype = str_none;
|
||||
|
|
@ -331,7 +331,7 @@ extern "C" DLL_EXPORT int _dbg_bpgettypeat(duint addr)
|
|||
static int cacheBpCount;
|
||||
static int cacheResult;
|
||||
int bpcount = BpGetList(nullptr);
|
||||
if(cacheAddr != addr or cacheBpCount != bpcount)
|
||||
if(cacheAddr != addr || cacheBpCount != bpcount)
|
||||
{
|
||||
BREAKPOINT bp;
|
||||
cacheAddr = addr;
|
||||
|
|
@ -790,7 +790,7 @@ extern "C" DLL_EXPORT uint _dbg_sendmessage(DBGMSG type, void* param1, void* par
|
|||
|
||||
case DBG_DISASM_FAST_AT:
|
||||
{
|
||||
if(!param1 or !param2)
|
||||
if(!param1 || !param2)
|
||||
return 0;
|
||||
BASIC_INSTRUCTION_INFO* basicinfo = (BASIC_INSTRUCTION_INFO*)param2;
|
||||
if(!disasmfast((uint)param1, basicinfo))
|
||||
|
|
|
|||
|
|
@ -135,7 +135,7 @@ void setalloctrace(const char* file)
|
|||
bool arraycontains(const char* cmd_list, const char* cmd)
|
||||
{
|
||||
//TODO: fix this function a little
|
||||
if(!cmd_list or !cmd)
|
||||
if(!cmd_list || !cmd)
|
||||
return false;
|
||||
char temp[deflen] = "";
|
||||
strcpy_s(temp, cmd_list);
|
||||
|
|
|
|||
|
|
@ -30,11 +30,6 @@
|
|||
#include "stringutils.h"
|
||||
#include "dbghelp_safe.h"
|
||||
|
||||
#ifndef __GNUC__
|
||||
#define and &&
|
||||
#define or ||
|
||||
#endif
|
||||
|
||||
#ifndef DLL_EXPORT
|
||||
#define DLL_EXPORT __declspec(dllexport)
|
||||
#endif //DLL_IMPORT
|
||||
|
|
|
|||
|
|
@ -96,8 +96,7 @@ static const char* regTable[] =
|
|||
SCRIPT_EXPORT duint Script::Register::Get(Script::Register::RegisterEnum reg)
|
||||
{
|
||||
duint value;
|
||||
valfromstring(regTable[reg], &value);
|
||||
return value;
|
||||
return valfromstring(regTable[reg], &value) ? value : 0;
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Register::Set(Script::Register::RegisterEnum reg, duint value)
|
||||
|
|
|
|||
|
|
@ -163,7 +163,7 @@ bool apienumexports(uint base, EXPORTENUMCALLBACK cbEnum)
|
|||
memset(&export_dir, 0, sizeof(export_dir));
|
||||
MemRead((void*)(export_dir_rva + base), &export_dir, sizeof(export_dir), 0);
|
||||
unsigned int NumberOfNames = export_dir.NumberOfNames;
|
||||
if(!export_dir.NumberOfFunctions or !NumberOfNames) //no named exports
|
||||
if(!export_dir.NumberOfFunctions || !NumberOfNames) //no named exports
|
||||
return false;
|
||||
char modname[MAX_MODULE_SIZE] = "";
|
||||
ModNameFromAddr(base, modname, true);
|
||||
|
|
@ -187,14 +187,14 @@ bool apienumexports(uint base, EXPORTENUMCALLBACK cbEnum)
|
|||
DWORD curFunctionRva = 0;
|
||||
MemRead(AddrOfFunctions_va + sizeof(DWORD)*curAddrOfNameOrdinals, &curFunctionRva, sizeof(DWORD), 0);
|
||||
|
||||
if(curFunctionRva >= export_dir_rva and curFunctionRva < export_dir_rva + export_dir_size)
|
||||
if(curFunctionRva >= export_dir_rva && curFunctionRva < export_dir_rva + export_dir_size)
|
||||
{
|
||||
char forwarded_api[deflen] = "";
|
||||
memset(forwarded_api, 0, deflen);
|
||||
MemRead((void*)(curFunctionRva + base), forwarded_api, deflen, 0);
|
||||
int len = (int)strlen(forwarded_api);
|
||||
int j = 0;
|
||||
while(forwarded_api[j] != '.' and j < len)
|
||||
while(forwarded_api[j] != '.' && j < len)
|
||||
j++;
|
||||
if(forwarded_api[j] == '.')
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
static bool cbUnknown(const char* text, ULONGLONG* value)
|
||||
{
|
||||
if(!text or !value)
|
||||
if(!text || !value)
|
||||
return false;
|
||||
uint val;
|
||||
if(!valfromstring(text, &val))
|
||||
|
|
|
|||
|
|
@ -79,18 +79,19 @@ void BookmarkDelRange(uint Start, uint End)
|
|||
EXCLUSIVE_ACQUIRE(LockBookmarks);
|
||||
for(auto itr = bookmarks.begin(); itr != bookmarks.end();)
|
||||
{
|
||||
const auto & currentBookmark = itr->second;
|
||||
// Ignore manually set entries
|
||||
if(itr->second.manual)
|
||||
if(currentBookmark.manual)
|
||||
{
|
||||
itr++;
|
||||
++itr;
|
||||
continue;
|
||||
}
|
||||
|
||||
// [Start, End)
|
||||
if(itr->second.addr >= Start && itr->second.addr < End)
|
||||
if(currentBookmark.addr >= Start && currentBookmark.addr < End)
|
||||
itr = bookmarks.erase(itr);
|
||||
else
|
||||
itr++;
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ void cmdfree(COMMAND* cmd_list)
|
|||
*/
|
||||
bool cmdnew(COMMAND* command_list, const char* name, CBCOMMAND cbCommand, bool debugonly)
|
||||
{
|
||||
if(!command_list or !cbCommand or !name or !*name or cmdfind(command_list, name, 0))
|
||||
if(!command_list || !cbCommand || !name || !*name || cmdfind(command_list, name, 0))
|
||||
return false;
|
||||
COMMAND* cmd;
|
||||
bool nonext = false;
|
||||
|
|
@ -111,7 +111,7 @@ COMMAND* cmdget(COMMAND* command_list, const char* cmd)
|
|||
strcpy_s(new_cmd, deflen, cmd);
|
||||
int len = (int)strlen(new_cmd);
|
||||
int start = 0;
|
||||
while(new_cmd[start] != ' ' and start < len)
|
||||
while(new_cmd[start] != ' ' && start < len)
|
||||
start++;
|
||||
new_cmd[start] = 0;
|
||||
COMMAND* found = cmdfind(command_list, new_cmd, 0);
|
||||
|
|
@ -193,7 +193,7 @@ error_is_fatal: error return of a command callback stops the command proce
|
|||
*/
|
||||
CMDRESULT cmdloop(COMMAND* command_list, CBCOMMAND cbUnknownCommand, CBCOMMANDPROVIDER cbCommandProvider, CBCOMMANDFINDER cbCommandFinder, bool error_is_fatal)
|
||||
{
|
||||
if(!cbUnknownCommand or !cbCommandProvider)
|
||||
if(!cbUnknownCommand || !cbCommandProvider)
|
||||
return STATUS_ERROR;
|
||||
char command[deflen] = "";
|
||||
bool bLoop = true;
|
||||
|
|
@ -210,17 +210,17 @@ CMDRESULT cmdloop(COMMAND* command_list, CBCOMMAND cbUnknownCommand, CBCOMMANDPR
|
|||
else //'dirty' command processing
|
||||
cmd = cbCommandFinder(command_list, command);
|
||||
|
||||
if(!cmd or !cmd->cbCommand) //unknown command
|
||||
if(!cmd || !cmd->cbCommand) //unknown command
|
||||
{
|
||||
char* argv[1];
|
||||
*argv = command;
|
||||
CMDRESULT res = cbUnknownCommand(1, argv);
|
||||
if((error_is_fatal and res == STATUS_ERROR) or res == STATUS_EXIT)
|
||||
if((error_is_fatal && res == STATUS_ERROR) || res == STATUS_EXIT)
|
||||
bLoop = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(cmd->debugonly and !DbgIsDebugging())
|
||||
if(cmd->debugonly && !DbgIsDebugging())
|
||||
{
|
||||
dputs("this command is debug-only");
|
||||
if(error_is_fatal)
|
||||
|
|
@ -242,7 +242,7 @@ CMDRESULT cmdloop(COMMAND* command_list, CBCOMMAND cbUnknownCommand, CBCOMMANDPR
|
|||
for(int i = 0; i < argcount; i++)
|
||||
efree(argv[i + 1], "cmdloop:argv[i+1]");
|
||||
efree(argv, "cmdloop:argv");
|
||||
if((error_is_fatal and res == STATUS_ERROR) or res == STATUS_EXIT)
|
||||
if((error_is_fatal && res == STATUS_ERROR) || res == STATUS_EXIT)
|
||||
bLoop = false;
|
||||
}
|
||||
}
|
||||
|
|
@ -317,7 +317,7 @@ static void specialformat(char* string)
|
|||
return;
|
||||
}
|
||||
int flen = (int)strlen(found); //n(+)=n++
|
||||
if((found[flen - 1] == '+' and found[flen - 2] == '+') or (found[flen - 1] == '-' and found[flen - 2] == '-')) //eax++/eax--
|
||||
if((found[flen - 1] == '+' && found[flen - 2] == '+') || (found[flen - 1] == '-' && found[flen - 2] == '-')) //eax++/eax--
|
||||
{
|
||||
found[flen - 2] = 0;
|
||||
char op = found[flen - 1];
|
||||
|
|
@ -342,7 +342,7 @@ static void specialformat(char* string)
|
|||
}
|
||||
strcpy(string, str);
|
||||
}
|
||||
else if((string[len - 1] == '+' and string[len - 2] == '+') or (string[len - 1] == '-' and string[len - 2] == '-')) //eax++/eax--
|
||||
else if((string[len - 1] == '+' && string[len - 2] == '+') || (string[len - 1] == '-' && string[len - 2] == '-')) //eax++/eax--
|
||||
{
|
||||
string[len - 2] = 0;
|
||||
char op = string[len - 1];
|
||||
|
|
@ -385,14 +385,14 @@ COMMAND* cmdfindmain(COMMAND* cmd_list, char* command)
|
|||
*/
|
||||
CMDRESULT cmddirectexec(COMMAND* cmd_list, const char* cmd)
|
||||
{
|
||||
if(!cmd or !strlen(cmd))
|
||||
if(!cmd || !strlen(cmd))
|
||||
return STATUS_ERROR;
|
||||
char command[deflen] = "";
|
||||
strcpy_s(command, StringUtils::Trim(cmd).c_str());
|
||||
COMMAND* found = cmdfindmain(cmd_list, command);
|
||||
if(!found or !found->cbCommand)
|
||||
if(!found || !found->cbCommand)
|
||||
return STATUS_ERROR;
|
||||
if(found->debugonly and !DbgIsDebugging())
|
||||
if(found->debugonly && !DbgIsDebugging())
|
||||
return STATUS_ERROR;
|
||||
Command cmdParsed(command);
|
||||
int argcount = cmdParsed.GetArgCount();
|
||||
|
|
|
|||
|
|
@ -109,6 +109,6 @@ void Command::dataFinish()
|
|||
if(_data.length())
|
||||
{
|
||||
_tokens.push_back(_data);
|
||||
_data = "";
|
||||
_data.clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,18 +103,19 @@ void CommentDelRange(uint Start, uint End)
|
|||
EXCLUSIVE_ACQUIRE(LockComments);
|
||||
for(auto itr = comments.begin(); itr != comments.end();)
|
||||
{
|
||||
const auto & currentComment = itr->second;
|
||||
// Ignore manually set entries
|
||||
if(itr->second.manual)
|
||||
if(currentComment.manual)
|
||||
{
|
||||
itr++;
|
||||
++itr;
|
||||
continue;
|
||||
}
|
||||
|
||||
// [Start, End)
|
||||
if(itr->second.addr >= Start && itr->second.addr < End)
|
||||
if(currentComment.addr >= Start && currentComment.addr < End)
|
||||
itr = comments.erase(itr);
|
||||
else
|
||||
itr++;
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ void ControlFlowAnalysis::BasicBlockStarts()
|
|||
|
||||
void ControlFlowAnalysis::BasicBlocks()
|
||||
{
|
||||
for(auto i = _blockStarts.begin(); i != _blockStarts.end(); i++)
|
||||
for(auto i = _blockStarts.begin(); i != _blockStarts.end(); ++i)
|
||||
{
|
||||
uint start = *i;
|
||||
if(!IsValidAddress(start))
|
||||
|
|
|
|||
|
|
@ -207,7 +207,7 @@ void cbUserBreakpoint()
|
|||
BRIDGEBP pluginBp;
|
||||
PLUG_CB_BREAKPOINT bpInfo;
|
||||
bpInfo.breakpoint = 0;
|
||||
if(!BpGet(GetContextDataEx(hActiveThread, UE_CIP), BPNORMAL, 0, &bp) and bp.enabled)
|
||||
if(!BpGet(GetContextDataEx(hActiveThread, UE_CIP), BPNORMAL, 0, &bp) && bp.enabled)
|
||||
dputs("Breakpoint reached not in list!");
|
||||
else
|
||||
{
|
||||
|
|
@ -438,7 +438,7 @@ static BOOL CALLBACK SymRegisterCallbackProc64(HANDLE hProcess, ULONG ActionCode
|
|||
suspress = true;
|
||||
zerobar = true;
|
||||
}
|
||||
else if(sscanf(text, "%*s %d percent", &percent) == 1 or sscanf(text, "%d percent", &percent) == 1)
|
||||
else if(sscanf(text, "%*s %d percent", &percent) == 1 || sscanf(text, "%d percent", &percent) == 1)
|
||||
{
|
||||
GuiSymbolSetProgress(percent);
|
||||
suspress = true;
|
||||
|
|
@ -576,7 +576,7 @@ static unsigned char getCIPch()
|
|||
void cbRtrStep()
|
||||
{
|
||||
unsigned int cipch = getCIPch();
|
||||
if(cipch == 0xC3 or cipch == 0xC2)
|
||||
if(cipch == 0xC3 || cipch == 0xC2)
|
||||
cbRtrFinalStep();
|
||||
else
|
||||
StepOver((void*)cbRtrStep);
|
||||
|
|
@ -648,7 +648,7 @@ static void cbCreateProcess(CREATE_PROCESS_DEBUG_INFO* CreateProcessInfo)
|
|||
BpEnumAll(cbSetModuleBreakpoints, modname);
|
||||
GuiUpdateBreakpointsView();
|
||||
pCreateProcessBase = (uint)CreateProcessInfo->lpBaseOfImage;
|
||||
if(!bFileIsDll and !bIsAttached) //Set entry breakpoint
|
||||
if(!bFileIsDll && !bIsAttached) //Set entry breakpoint
|
||||
{
|
||||
pDebuggedBase = pCreateProcessBase; //debugged base = executable
|
||||
char command[256] = "";
|
||||
|
|
@ -842,7 +842,7 @@ static void cbLoadDll(LOAD_DLL_DEBUG_INFO* LoadDll)
|
|||
|
||||
char command[256] = "";
|
||||
bool bIsDebuggingThis = false;
|
||||
if(bFileIsDll and !_stricmp(DLLDebugFileName, szFileName) and !bIsAttached) //Set entry breakpoint
|
||||
if(bFileIsDll && !_stricmp(DLLDebugFileName, szFileName) && !bIsAttached) //Set entry breakpoint
|
||||
{
|
||||
bIsDebuggingThis = true;
|
||||
pDebuggedBase = (uint)base;
|
||||
|
|
@ -968,14 +968,14 @@ static void cbOutputDebugString(OUTPUT_DEBUG_STRING_INFO* DebugString)
|
|||
if(MemRead(DebugString->lpDebugStringData, DebugText, DebugString->nDebugStringLength, 0))
|
||||
{
|
||||
String str = String(DebugText);
|
||||
if(str != lastDebugText) //fix for every string being printed twice
|
||||
if(str != lastDebugText) //fix for every string being printed twice
|
||||
{
|
||||
if(str != "\n")
|
||||
dprintf("DebugString: \"%s\"\n", StringUtils::Escape(str).c_str());
|
||||
lastDebugText = str;
|
||||
}
|
||||
else
|
||||
lastDebugText = "";
|
||||
lastDebugText.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1044,7 +1044,7 @@ static void cbException(EXCEPTION_DEBUG_INFO* ExceptionData)
|
|||
memcpy(&nameInfo, ExceptionData->ExceptionRecord.ExceptionInformation, sizeof(THREADNAME_INFO));
|
||||
if(nameInfo.dwThreadID == -1) //current thread
|
||||
nameInfo.dwThreadID = ((DEBUG_EVENT*)GetDebugData())->dwThreadId;
|
||||
if(nameInfo.dwType == 0x1000 and nameInfo.dwFlags == 0 and ThreadIsValid(nameInfo.dwThreadID)) //passed basic checks
|
||||
if(nameInfo.dwType == 0x1000 && nameInfo.dwFlags == 0 && ThreadIsValid(nameInfo.dwThreadID)) //passed basic checks
|
||||
{
|
||||
Memory<char*> ThreadName(MAX_THREAD_NAME_SIZE, "cbException:ThreadName");
|
||||
if(MemRead((void*)nameInfo.szName, ThreadName, MAX_THREAD_NAME_SIZE - 1, 0))
|
||||
|
|
@ -1118,14 +1118,14 @@ DWORD WINAPI threadDebugLoop(void* lpParameter)
|
|||
return 0;
|
||||
}
|
||||
BOOL wow64 = false, mewow64 = false;
|
||||
if(!IsWow64Process(fdProcessInfo->hProcess, &wow64) or !IsWow64Process(GetCurrentProcess(), &mewow64))
|
||||
if(!IsWow64Process(fdProcessInfo->hProcess, &wow64) || !IsWow64Process(GetCurrentProcess(), &mewow64))
|
||||
{
|
||||
dputs("IsWow64Process failed!");
|
||||
StopDebug();
|
||||
unlock(WAITID_STOP);
|
||||
return 0;
|
||||
}
|
||||
if((mewow64 and !wow64) or (!mewow64 and wow64))
|
||||
if((mewow64 && !wow64) || (!mewow64 && wow64))
|
||||
{
|
||||
#ifdef _WIN64
|
||||
dputs("Use x32dbg to debug this process!");
|
||||
|
|
@ -1156,7 +1156,7 @@ DWORD WINAPI threadDebugLoop(void* lpParameter)
|
|||
//set GUI title
|
||||
strcpy_s(szBaseFileName, szFileName);
|
||||
int len = (int)strlen(szBaseFileName);
|
||||
while(szBaseFileName[len] != '\\' and len)
|
||||
while(szBaseFileName[len] != '\\' && len)
|
||||
len--;
|
||||
if(len)
|
||||
strcpy_s(szBaseFileName, szBaseFileName + len + 1);
|
||||
|
|
@ -1198,7 +1198,7 @@ bool cbDeleteAllBreakpoints(const BREAKPOINT* bp)
|
|||
dprintf("Delete breakpoint failed (BpDelete): "fhex"\n", bp->addr);
|
||||
return false;
|
||||
}
|
||||
if(!bp->enabled or DeleteBPX(bp->addr))
|
||||
if(!bp->enabled || DeleteBPX(bp->addr))
|
||||
return true;
|
||||
dprintf("Delete breakpoint failed (DeleteBPX): "fhex"\n", bp->addr);
|
||||
return false;
|
||||
|
|
@ -1206,7 +1206,7 @@ bool cbDeleteAllBreakpoints(const BREAKPOINT* bp)
|
|||
|
||||
bool cbEnableAllBreakpoints(const BREAKPOINT* bp)
|
||||
{
|
||||
if(bp->type != BPNORMAL or bp->enabled)
|
||||
if(bp->type != BPNORMAL || bp->enabled)
|
||||
return true;
|
||||
|
||||
if(!BpEnable(bp->addr, BPNORMAL, true))
|
||||
|
|
@ -1224,7 +1224,7 @@ bool cbEnableAllBreakpoints(const BREAKPOINT* bp)
|
|||
|
||||
bool cbDisableAllBreakpoints(const BREAKPOINT* bp)
|
||||
{
|
||||
if(bp->type != BPNORMAL or !bp->enabled)
|
||||
if(bp->type != BPNORMAL || !bp->enabled)
|
||||
return true;
|
||||
|
||||
if(!BpEnable(bp->addr, BPNORMAL, false))
|
||||
|
|
@ -1242,7 +1242,7 @@ bool cbDisableAllBreakpoints(const BREAKPOINT* bp)
|
|||
|
||||
bool cbEnableAllHardwareBreakpoints(const BREAKPOINT* bp)
|
||||
{
|
||||
if(bp->type != BPHARDWARE or bp->enabled)
|
||||
if(bp->type != BPHARDWARE || bp->enabled)
|
||||
return true;
|
||||
DWORD drx = 0;
|
||||
if(!GetUnusedHardwareBreakPointRegister(&drx))
|
||||
|
|
@ -1268,7 +1268,7 @@ bool cbEnableAllHardwareBreakpoints(const BREAKPOINT* bp)
|
|||
|
||||
bool cbDisableAllHardwareBreakpoints(const BREAKPOINT* bp)
|
||||
{
|
||||
if(bp->type != BPHARDWARE or !bp->enabled)
|
||||
if(bp->type != BPHARDWARE || !bp->enabled)
|
||||
return true;
|
||||
if(!BpEnable(bp->addr, BPHARDWARE, false))
|
||||
{
|
||||
|
|
@ -1285,7 +1285,7 @@ bool cbDisableAllHardwareBreakpoints(const BREAKPOINT* bp)
|
|||
|
||||
bool cbEnableAllMemoryBreakpoints(const BREAKPOINT* bp)
|
||||
{
|
||||
if(bp->type != BPMEMORY or bp->enabled)
|
||||
if(bp->type != BPMEMORY || bp->enabled)
|
||||
return true;
|
||||
uint size = 0;
|
||||
MemFindBaseAddr(bp->addr, &size);
|
||||
|
|
@ -1304,7 +1304,7 @@ bool cbEnableAllMemoryBreakpoints(const BREAKPOINT* bp)
|
|||
|
||||
bool cbDisableAllMemoryBreakpoints(const BREAKPOINT* bp)
|
||||
{
|
||||
if(bp->type != BPMEMORY or !bp->enabled)
|
||||
if(bp->type != BPMEMORY || !bp->enabled)
|
||||
return true;
|
||||
if(!BpEnable(bp->addr, BPMEMORY, false))
|
||||
{
|
||||
|
|
@ -1417,7 +1417,7 @@ DWORD WINAPI threadAttachLoop(void* lpParameter)
|
|||
//set GUI title
|
||||
strcpy_s(szBaseFileName, szFileName);
|
||||
int len = (int)strlen(szBaseFileName);
|
||||
while(szBaseFileName[len] != '\\' and len)
|
||||
while(szBaseFileName[len] != '\\' && len)
|
||||
len--;
|
||||
if(len)
|
||||
strcpy_s(szBaseFileName, szBaseFileName + len + 1);
|
||||
|
|
@ -1790,9 +1790,9 @@ bool dbglistprocesses(std::vector<PROCESSENTRY32>* list)
|
|||
if(!hProcess)
|
||||
continue;
|
||||
BOOL wow64 = false, mewow64 = false;
|
||||
if(!IsWow64Process(hProcess, &wow64) or !IsWow64Process(GetCurrentProcess(), &mewow64))
|
||||
if(!IsWow64Process(hProcess, &wow64) || !IsWow64Process(GetCurrentProcess(), &mewow64))
|
||||
continue;
|
||||
if((mewow64 and !wow64) or (!mewow64 and wow64))
|
||||
if((mewow64 && !wow64) || (!mewow64 && wow64))
|
||||
continue;
|
||||
wchar_t szExePath[MAX_PATH] = L"";
|
||||
if(GetModuleFileNameExW(hProcess, 0, szExePath, MAX_PATH))
|
||||
|
|
|
|||
|
|
@ -91,7 +91,7 @@ CMDRESULT cbDebugInit(int argc, char* argv[])
|
|||
static char currentfolder[deflen] = "";
|
||||
strcpy_s(currentfolder, arg1);
|
||||
int len = (int)strlen(currentfolder);
|
||||
while(currentfolder[len] != '\\' and len != 0)
|
||||
while(currentfolder[len] != '\\' && len != 0)
|
||||
len--;
|
||||
currentfolder[len] = 0;
|
||||
|
||||
|
|
@ -197,7 +197,7 @@ CMDRESULT cbDebugSetBPX(int argc, char* argv[]) //bp addr [,name [,type]]
|
|||
bool has_arg2 = argc > 3;
|
||||
if(has_arg2)
|
||||
strcpy_s(argtype, argv[3]);
|
||||
if(!has_arg2 and (scmp(argname, "ss") or scmp(argname, "long") or scmp(argname, "ud2")))
|
||||
if(!has_arg2 && (scmp(argname, "ss") || scmp(argname, "long") || scmp(argname, "ud2")))
|
||||
{
|
||||
strcpy_s(argtype, argname);
|
||||
*argname = 0;
|
||||
|
|
@ -293,7 +293,7 @@ CMDRESULT cbDebugDeleteBPX(int argc, char* argv[])
|
|||
return STATUS_CONTINUE;
|
||||
}
|
||||
uint addr = 0;
|
||||
if(!valfromstring(argv[1], &addr) or !BpGet(addr, BPNORMAL, 0, &found)) //invalid breakpoint
|
||||
if(!valfromstring(argv[1], &addr) || !BpGet(addr, BPNORMAL, 0, &found)) //invalid breakpoint
|
||||
{
|
||||
dprintf("No such breakpoint \"%s\"\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
|
|
@ -346,7 +346,7 @@ CMDRESULT cbDebugEnableBPX(int argc, char* argv[])
|
|||
return STATUS_CONTINUE;
|
||||
}
|
||||
uint addr = 0;
|
||||
if(!valfromstring(argv[1], &addr) or !BpGet(addr, BPNORMAL, 0, &found)) //invalid breakpoint
|
||||
if(!valfromstring(argv[1], &addr) || !BpGet(addr, BPNORMAL, 0, &found)) //invalid breakpoint
|
||||
{
|
||||
dprintf("No such breakpoint \"%s\"\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
|
|
@ -404,7 +404,7 @@ CMDRESULT cbDebugDisableBPX(int argc, char* argv[])
|
|||
return STATUS_CONTINUE;
|
||||
}
|
||||
uint addr = 0;
|
||||
if(!valfromstring(argv[1], &addr) or !BpGet(addr, BPNORMAL, 0, &found)) //invalid breakpoint
|
||||
if(!valfromstring(argv[1], &addr) || !BpGet(addr, BPNORMAL, 0, &found)) //invalid breakpoint
|
||||
{
|
||||
dprintf("No such breakpoint \"%s\"\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
|
|
@ -605,7 +605,7 @@ CMDRESULT cbDebugDeleteMemoryBreakpoint(int argc, char* argv[])
|
|||
return STATUS_CONTINUE;
|
||||
}
|
||||
uint addr = 0;
|
||||
if(!valfromstring(argv[1], &addr) or !BpGet(addr, BPMEMORY, 0, &found)) //invalid breakpoint
|
||||
if(!valfromstring(argv[1], &addr) || !BpGet(addr, BPMEMORY, 0, &found)) //invalid breakpoint
|
||||
{
|
||||
dprintf("No such memory breakpoint \"%s\"\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
|
|
@ -763,7 +763,7 @@ CMDRESULT cbDebugDeleteHardwareBreakpoint(int argc, char* argv[])
|
|||
return STATUS_CONTINUE;
|
||||
}
|
||||
uint addr = 0;
|
||||
if(!valfromstring(argv[1], &addr) or !BpGet(addr, BPHARDWARE, 0, &found)) //invalid breakpoint
|
||||
if(!valfromstring(argv[1], &addr) || !BpGet(addr, BPHARDWARE, 0, &found)) //invalid breakpoint
|
||||
{
|
||||
dprintf("No such hardware breakpoint \"%s\"\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
|
|
@ -844,7 +844,7 @@ CMDRESULT cbDebugMemset(int argc, char* argv[])
|
|||
dputs("Not enough arguments");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
if(!valfromstring(argv[1], &addr, false) or !valfromstring(argv[2], &value, false))
|
||||
if(!valfromstring(argv[1], &addr, false) || !valfromstring(argv[2], &value, false))
|
||||
return STATUS_ERROR;
|
||||
if(argc > 3)
|
||||
{
|
||||
|
|
@ -875,7 +875,6 @@ CMDRESULT cbDebugBenchmark(int argc, char* argv[])
|
|||
{
|
||||
uint addr = MemFindBaseAddr(GetContextDataEx(hActiveThread, UE_CIP), 0);
|
||||
DWORD ticks = GetTickCount();
|
||||
char comment[MAX_COMMENT_SIZE] = "";
|
||||
for(uint i = addr; i < addr + 100000; i++)
|
||||
{
|
||||
CommentSet(i, "test", false);
|
||||
|
|
@ -981,12 +980,12 @@ CMDRESULT cbDebugAttach(int argc, char* argv[])
|
|||
return STATUS_ERROR;
|
||||
}
|
||||
BOOL wow64 = false, mewow64 = false;
|
||||
if(!IsWow64Process(hProcess, &wow64) or !IsWow64Process(GetCurrentProcess(), &mewow64))
|
||||
if(!IsWow64Process(hProcess, &wow64) || !IsWow64Process(GetCurrentProcess(), &mewow64))
|
||||
{
|
||||
dputs("IsWow64Process failed!");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
if((mewow64 and !wow64) or (!mewow64 and wow64))
|
||||
if((mewow64 && !wow64) || (!mewow64 && wow64))
|
||||
{
|
||||
#ifdef _WIN64
|
||||
dputs("Use x32dbg to debug this process!");
|
||||
|
|
@ -1304,7 +1303,7 @@ CMDRESULT cbDebugEnableHardwareBreakpoint(int argc, char* argv[])
|
|||
}
|
||||
BREAKPOINT found;
|
||||
uint addr = 0;
|
||||
if(!valfromstring(argv[1], &addr) or !BpGet(addr, BPHARDWARE, 0, &found)) //invalid hardware breakpoint
|
||||
if(!valfromstring(argv[1], &addr) || !BpGet(addr, BPHARDWARE, 0, &found)) //invalid hardware breakpoint
|
||||
{
|
||||
dprintf("No such hardware breakpoint \"%s\"\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
|
|
@ -1317,7 +1316,7 @@ CMDRESULT cbDebugEnableHardwareBreakpoint(int argc, char* argv[])
|
|||
}
|
||||
TITANSETDRX(found.titantype, drx);
|
||||
BpSetTitanType(found.addr, BPHARDWARE, found.titantype);
|
||||
if(!BpEnable(found.addr, BPHARDWARE, true) or !SetHardwareBreakPoint(found.addr, drx, TITANGETTYPE(found.titantype), TITANGETSIZE(found.titantype), (void*)cbHardwareBreakpoint))
|
||||
if(!BpEnable(found.addr, BPHARDWARE, true) || !SetHardwareBreakPoint(found.addr, drx, TITANGETTYPE(found.titantype), TITANGETSIZE(found.titantype), (void*)cbHardwareBreakpoint))
|
||||
{
|
||||
dprintf("Could not enable hardware breakpoint "fhex"\n", found.addr);
|
||||
return STATUS_ERROR;
|
||||
|
|
@ -1344,7 +1343,7 @@ CMDRESULT cbDebugDisableHardwareBreakpoint(int argc, char* argv[])
|
|||
}
|
||||
BREAKPOINT found;
|
||||
uint addr = 0;
|
||||
if(!valfromstring(argv[1], &addr) or !BpGet(addr, BPHARDWARE, 0, &found)) //invalid hardware breakpoint
|
||||
if(!valfromstring(argv[1], &addr) || !BpGet(addr, BPHARDWARE, 0, &found)) //invalid hardware breakpoint
|
||||
{
|
||||
dprintf("No such hardware breakpoint \"%s\"\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
|
|
@ -1354,7 +1353,7 @@ CMDRESULT cbDebugDisableHardwareBreakpoint(int argc, char* argv[])
|
|||
dputs("Hardware breakpoint already disabled!");
|
||||
return STATUS_CONTINUE;
|
||||
}
|
||||
if(!BpEnable(found.addr, BPHARDWARE, false) or !DeleteHardwareBreakPoint(TITANGETDRX(found.titantype)))
|
||||
if(!BpEnable(found.addr, BPHARDWARE, false) || !DeleteHardwareBreakPoint(TITANGETDRX(found.titantype)))
|
||||
{
|
||||
dprintf("Could not disable hardware breakpoint "fhex"\n", found.addr);
|
||||
return STATUS_ERROR;
|
||||
|
|
@ -1381,7 +1380,7 @@ CMDRESULT cbDebugEnableMemoryBreakpoint(int argc, char* argv[])
|
|||
}
|
||||
BREAKPOINT found;
|
||||
uint addr = 0;
|
||||
if(!valfromstring(argv[1], &addr) or !BpGet(addr, BPMEMORY, 0, &found)) //invalid memory breakpoint
|
||||
if(!valfromstring(argv[1], &addr) || !BpGet(addr, BPMEMORY, 0, &found)) //invalid memory breakpoint
|
||||
{
|
||||
dprintf("No such memory breakpoint \"%s\"\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
|
|
@ -1394,7 +1393,7 @@ CMDRESULT cbDebugEnableMemoryBreakpoint(int argc, char* argv[])
|
|||
}
|
||||
uint size = 0;
|
||||
MemFindBaseAddr(found.addr, &size);
|
||||
if(!BpEnable(found.addr, BPMEMORY, true) or !SetMemoryBPXEx(found.addr, size, found.titantype, !found.singleshoot, (void*)cbMemoryBreakpoint))
|
||||
if(!BpEnable(found.addr, BPMEMORY, true) || !SetMemoryBPXEx(found.addr, size, found.titantype, !found.singleshoot, (void*)cbMemoryBreakpoint))
|
||||
{
|
||||
dprintf("Could not enable memory breakpoint "fhex"\n", found.addr);
|
||||
return STATUS_ERROR;
|
||||
|
|
@ -1421,7 +1420,7 @@ CMDRESULT cbDebugDisableMemoryBreakpoint(int argc, char* argv[])
|
|||
}
|
||||
BREAKPOINT found;
|
||||
uint addr = 0;
|
||||
if(!valfromstring(argv[1], &addr) or !BpGet(addr, BPMEMORY, 0, &found)) //invalid memory breakpoint
|
||||
if(!valfromstring(argv[1], &addr) || !BpGet(addr, BPMEMORY, 0, &found)) //invalid memory breakpoint
|
||||
{
|
||||
dprintf("No such memory breakpoint \"%s\"\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
|
|
@ -1433,7 +1432,7 @@ CMDRESULT cbDebugDisableMemoryBreakpoint(int argc, char* argv[])
|
|||
}
|
||||
uint size = 0;
|
||||
MemFindBaseAddr(found.addr, &size);
|
||||
if(!BpEnable(found.addr, BPMEMORY, false) or !RemoveMemoryBPX(found.addr, size))
|
||||
if(!BpEnable(found.addr, BPMEMORY, false) || !RemoveMemoryBPX(found.addr, size))
|
||||
{
|
||||
dprintf("Could not disable memory breakpoint "fhex"\n", found.addr);
|
||||
return STATUS_ERROR;
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ void fillbasicinfo(Capstone* cp, BASIC_INSTRUCTION_INFO* basicinfo)
|
|||
|
||||
bool disasmfast(unsigned char* data, uint addr, BASIC_INSTRUCTION_INFO* basicinfo)
|
||||
{
|
||||
if(!data or !basicinfo)
|
||||
if(!data || !basicinfo)
|
||||
return false;
|
||||
Capstone cp;
|
||||
if(!cp.Disassemble(addr, data, MAX_DISASM_BUFFER))
|
||||
|
|
|
|||
|
|
@ -198,12 +198,13 @@ void disasmget(unsigned char* buffer, uint addr, DISASM_INSTR* instr)
|
|||
instr->argcount = 0;
|
||||
return;
|
||||
}
|
||||
sprintf_s(instr->instruction, "%s %s", cp.GetInstr()->mnemonic, cp.GetInstr()->op_str);
|
||||
const cs_x86 & x86 = cp.GetInstr()->detail->x86;
|
||||
instr->instr_size = cp.GetInstr()->size;
|
||||
const cs_insn* cpInstr = cp.GetInstr();
|
||||
sprintf_s(instr->instruction, "%s %s", cpInstr->mnemonic, cpInstr->op_str);
|
||||
const cs_x86 & x86 = cpInstr->detail->x86;
|
||||
instr->instr_size = cpInstr->size;
|
||||
if(cp.InGroup(CS_GRP_JUMP) || cp.IsLoop() || cp.InGroup(CS_GRP_RET) || cp.InGroup(CS_GRP_CALL))
|
||||
instr->type = instr_branch;
|
||||
else if(strstr(cp.GetInstr()->op_str, "sp") || strstr(cp.GetInstr()->op_str, "bp"))
|
||||
else if(strstr(cpInstr->op_str, "sp") || strstr(cpInstr->op_str, "bp"))
|
||||
instr->type = instr_stack;
|
||||
else
|
||||
instr->type = instr_normal;
|
||||
|
|
@ -244,10 +245,10 @@ static bool isasciistring(const unsigned char* data, int maxlen)
|
|||
break;
|
||||
}
|
||||
|
||||
if(len < 2 or len + 1 >= maxlen)
|
||||
if(len < 2 || len + 1 >= maxlen)
|
||||
return false;
|
||||
for(int i = 0; i < len; i++)
|
||||
if(!isprint(data[i]) and !isspace(data[i]))
|
||||
if(!isprint(data[i]) && !isspace(data[i]))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -261,13 +262,13 @@ static bool isunicodestring(const unsigned char* data, int maxlen)
|
|||
break;
|
||||
}
|
||||
|
||||
if(len < 2 or len + 1 >= maxlen)
|
||||
if(len < 2 || len + 1 >= maxlen)
|
||||
return false;
|
||||
for(int i = 0; i < len * 2; i += 2)
|
||||
{
|
||||
if(data[i + 1]) //Extended ASCII only
|
||||
return false;
|
||||
if(!isprint(data[i]) and !isspace(data[i]))
|
||||
if(!isprint(data[i]) && !isspace(data[i]))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
@ -281,7 +282,7 @@ bool disasmispossiblestring(uint addr)
|
|||
return false;
|
||||
uint test = 0;
|
||||
memcpy(&test, data, sizeof(uint));
|
||||
if(isasciistring(data, sizeof(data)) or isunicodestring(data, _countof(data)))
|
||||
if(isasciistring(data, sizeof(data)) || isunicodestring(data, _countof(data)))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -199,7 +199,7 @@ void ExpressionParser::addOperatorToken(const char ch, const Token::Type type)
|
|||
if(_curToken.length()) //add a new data token when there is data in the buffer
|
||||
{
|
||||
_tokens.push_back(Token(_curToken, Token::Type::Data));
|
||||
_curToken = "";
|
||||
_curToken.clear();
|
||||
}
|
||||
String data;
|
||||
data += ch;
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ bool FileReader::ReadAllText(const String & fileName, String & content)
|
|||
unsigned int filesize = GetFileSize(hFile, 0);
|
||||
if(!filesize)
|
||||
{
|
||||
content = "";
|
||||
content.clear();
|
||||
return true;
|
||||
}
|
||||
Memory<char*> filedata(filesize + 1, "FileReader::ReadAllText:filedata");
|
||||
|
|
|
|||
|
|
@ -119,18 +119,19 @@ void FunctionDelRange(uint Start, uint End)
|
|||
EXCLUSIVE_ACQUIRE(LockFunctions);
|
||||
for(auto itr = functions.begin(); itr != functions.end();)
|
||||
{
|
||||
const auto & currentFunction = itr->second;
|
||||
// Ignore manually set entries
|
||||
if(itr->second.manual)
|
||||
if(currentFunction.manual)
|
||||
{
|
||||
itr++;
|
||||
++itr;
|
||||
continue;
|
||||
}
|
||||
|
||||
// [Start, End]
|
||||
if(itr->second.end >= Start && itr->second.start <= End)
|
||||
if(currentFunction.end >= Start && currentFunction.start <= End)
|
||||
itr = functions.erase(itr);
|
||||
else
|
||||
itr++;
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,8 +87,10 @@ void FunctionAnalysis::AnalyseFunctions()
|
|||
uint end = FindFunctionEnd(function.start, maxaddr);
|
||||
if(end)
|
||||
{
|
||||
_cp.Disassemble(end, TranslateAddress(end), MAX_DISASM_BUFFER);
|
||||
function.end = end + _cp.Size() - 1;
|
||||
if(_cp.Disassemble(end, TranslateAddress(end), MAX_DISASM_BUFFER))
|
||||
function.end = end + _cp.Size() - 1;
|
||||
else
|
||||
function.end = end;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ CMDRESULT cbBadCmd(int argc, char* argv[])
|
|||
char format_str[deflen] = "";
|
||||
if(isvar)// and *cmd!='.' and *cmd!='x') //prevent stupid 0=0 stuff
|
||||
{
|
||||
if(value > 15 and !hexonly)
|
||||
if(value > 15 && !hexonly)
|
||||
{
|
||||
if(!valuesignedcalc()) //signed numbers
|
||||
sprintf(format_str, "%%s=%%.%d"fext"X (%%"fext"ud)\n", valsize);
|
||||
|
|
@ -63,7 +63,7 @@ CMDRESULT cbBadCmd(int argc, char* argv[])
|
|||
}
|
||||
else
|
||||
{
|
||||
if(value > 15 and !hexonly)
|
||||
if(value > 15 && !hexonly)
|
||||
{
|
||||
if(!valuesignedcalc()) //signed numbers
|
||||
sprintf(format_str, "%%s=%%.%d"fext"X (%%"fext"ud)\n", valsize);
|
||||
|
|
@ -207,7 +207,7 @@ CMDRESULT cbInstrMov(int argc, char* argv[])
|
|||
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))
|
||||
if(!isvar || !valtostring(argv[1], set_value, true))
|
||||
{
|
||||
uint value;
|
||||
if(valfromstring(argv[1], &value)) //if the var is a value already it's an invalid destination
|
||||
|
|
@ -464,7 +464,7 @@ CMDRESULT cbInstrFunctionAdd(int argc, char* argv[])
|
|||
}
|
||||
uint start = 0;
|
||||
uint end = 0;
|
||||
if(!valfromstring(argv[1], &start, false) or !valfromstring(argv[2], &end, false))
|
||||
if(!valfromstring(argv[1], &start, false) || !valfromstring(argv[2], &end, false))
|
||||
return STATUS_ERROR;
|
||||
if(!FunctionAdd(start, end, true))
|
||||
{
|
||||
|
|
@ -887,10 +887,10 @@ CMDRESULT cbInstrRefFindRange(int argc, char* argv[])
|
|||
VALUERANGE range;
|
||||
if(!valfromstring(argv[1], &range.start, false))
|
||||
return STATUS_ERROR;
|
||||
if(argc < 3 or !valfromstring(argv[2], &range.end, false))
|
||||
if(argc < 3 || !valfromstring(argv[2], &range.end, false))
|
||||
range.end = range.start;
|
||||
uint addr = 0;
|
||||
if(argc < 4 or !valfromstring(argv[3], &addr))
|
||||
if(argc < 4 || !valfromstring(argv[3], &addr))
|
||||
addr = GetContextDataEx(hActiveThread, UE_CIP);
|
||||
uint size = 0;
|
||||
if(argc >= 5)
|
||||
|
|
@ -932,7 +932,7 @@ bool cbRefStr(Capstone* disasm, BASIC_INSTRUCTION_INFO* basicinfo, REFINFO* refi
|
|||
}
|
||||
if((basicinfo->type & TYPE_MEMORY) == TYPE_MEMORY)
|
||||
{
|
||||
if(!found and disasmgetstringat(basicinfo->memory.value, &strtype, string, string, 500))
|
||||
if(!found && disasmgetstringat(basicinfo->memory.value, &strtype, string, string, 500))
|
||||
found = true;
|
||||
}
|
||||
if(found)
|
||||
|
|
@ -959,7 +959,7 @@ bool cbRefStr(Capstone* disasm, BASIC_INSTRUCTION_INFO* basicinfo, REFINFO* refi
|
|||
CMDRESULT cbInstrRefStr(int argc, char* argv[])
|
||||
{
|
||||
uint addr;
|
||||
if(argc < 2 or !valfromstring(argv[1], &addr, true))
|
||||
if(argc < 2 || !valfromstring(argv[1], &addr, true))
|
||||
addr = GetContextDataEx(hActiveThread, UE_CIP);
|
||||
uint size = 0;
|
||||
if(argc >= 3)
|
||||
|
|
@ -1015,7 +1015,7 @@ CMDRESULT cbInstrGetstr(int argc, char* argv[])
|
|||
return STATUS_ERROR;
|
||||
}
|
||||
int size;
|
||||
if(!varget(argv[1], (char*)0, &size, 0) or !size)
|
||||
if(!varget(argv[1], (char*)0, &size, 0) || !size)
|
||||
{
|
||||
dprintf("failed to get variable size \"%s\"!\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
|
|
@ -1050,7 +1050,7 @@ CMDRESULT cbInstrCopystr(int argc, char* argv[])
|
|||
return STATUS_ERROR;
|
||||
}
|
||||
int size;
|
||||
if(!varget(argv[2], (char*)0, &size, 0) or !size)
|
||||
if(!varget(argv[2], (char*)0, &size, 0) || !size)
|
||||
{
|
||||
dprintf("failed to get variable size \"%s\"!\n", argv[2]);
|
||||
return STATUS_ERROR;
|
||||
|
|
@ -1198,10 +1198,15 @@ CMDRESULT cbInstrFindAll(int argc, char* argv[])
|
|||
int refCount = 0;
|
||||
uint i = 0;
|
||||
uint result = 0;
|
||||
std::vector<PatternByte> searchpattern;
|
||||
if(!patterntransform(pattern, searchpattern))
|
||||
{
|
||||
dputs("failed to transform pattern!");
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
while(refCount < 5000)
|
||||
{
|
||||
int patternsize = 0;
|
||||
uint foundoffset = patternfind(data + start + i, find_size - i, pattern, &patternsize);
|
||||
uint foundoffset = patternfind(data + start + i, find_size - i, searchpattern);
|
||||
if(foundoffset == -1)
|
||||
break;
|
||||
i += foundoffset + 1;
|
||||
|
|
@ -1212,9 +1217,9 @@ CMDRESULT cbInstrFindAll(int argc, char* argv[])
|
|||
GuiReferenceSetCellContent(refCount, 0, msg);
|
||||
if(findData)
|
||||
{
|
||||
Memory<unsigned char*> printData(patternsize, "cbInstrFindAll:printData");
|
||||
MemRead((void*)result, printData, patternsize, 0);
|
||||
for(int j = 0, k = 0; j < patternsize; j++)
|
||||
Memory<unsigned char*> printData(searchpattern.size(), "cbInstrFindAll:printData");
|
||||
MemRead((void*)result, printData(), printData.size(), 0);
|
||||
for(size_t j = 0, k = 0; j < printData.size(); j++)
|
||||
{
|
||||
if(j)
|
||||
k += sprintf(msg + k, " ");
|
||||
|
|
@ -1271,7 +1276,7 @@ static bool cbModCallFind(Capstone* disasm, BASIC_INSTRUCTION_INFO* basicinfo, R
|
|||
CMDRESULT cbInstrModCallFind(int argc, char* argv[])
|
||||
{
|
||||
uint addr;
|
||||
if(argc < 2 or !valfromstring(argv[1], &addr, true))
|
||||
if(argc < 2 || !valfromstring(argv[1], &addr, true))
|
||||
addr = GetContextDataEx(hActiveThread, UE_CIP);
|
||||
uint size = 0;
|
||||
if(argc >= 3)
|
||||
|
|
@ -1506,7 +1511,7 @@ static bool cbFindAsm(Capstone* disasm, BASIC_INSTRUCTION_INFO* basicinfo, REFIN
|
|||
if(found)
|
||||
{
|
||||
char addrText[20] = "";
|
||||
sprintf(addrText, "%p", disasm->Address());
|
||||
sprintf(addrText, fhex, disasm->Address());
|
||||
GuiReferenceSetRowCount(refinfo->refcount + 1);
|
||||
GuiReferenceSetCellContent(refinfo->refcount, 0, addrText);
|
||||
char disassembly[GUI_MAX_DISASSEMBLY_SIZE] = "";
|
||||
|
|
@ -1527,7 +1532,7 @@ CMDRESULT cbInstrFindAsm(int argc, char* argv[])
|
|||
}
|
||||
|
||||
uint addr = 0;
|
||||
if(argc < 3 or !valfromstring(argv[2], &addr))
|
||||
if(argc < 3 || !valfromstring(argv[2], &addr))
|
||||
addr = GetContextDataEx(hActiveThread, UE_CIP);
|
||||
uint size = 0;
|
||||
if(argc >= 4)
|
||||
|
|
@ -1679,19 +1684,34 @@ CMDRESULT cbInstrYara(int argc, char* argv[])
|
|||
return STATUS_ERROR;
|
||||
}
|
||||
uint addr = 0;
|
||||
if(argc < 3 || !valfromstring(argv[2], &addr))
|
||||
{
|
||||
SELECTIONDATA sel;
|
||||
GuiSelectionGet(GUI_DISASSEMBLY, &sel);
|
||||
addr = sel.start;
|
||||
}
|
||||
SELECTIONDATA sel;
|
||||
GuiSelectionGet(GUI_DISASSEMBLY, &sel);
|
||||
addr = sel.start;
|
||||
|
||||
uint base = 0;
|
||||
uint size = 0;
|
||||
if(argc >= 4)
|
||||
if(!valfromstring(argv[3], &size))
|
||||
size = 0;
|
||||
if(!size)
|
||||
addr = MemFindBaseAddr(addr, &size);
|
||||
uint base = addr;
|
||||
uint mod = ModBaseFromName(argv[2]);
|
||||
if(mod)
|
||||
{
|
||||
base = mod;
|
||||
size = ModSizeFromAddr(base);
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!valfromstring(argv[2], &addr))
|
||||
{
|
||||
dprintf("invalid value \"%s\"!\n", argv[2]);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
|
||||
size = 0;
|
||||
if(argc >= 4)
|
||||
if(!valfromstring(argv[3], &size))
|
||||
size = 0;
|
||||
if(!size)
|
||||
addr = MemFindBaseAddr(addr, &size);
|
||||
base = addr;
|
||||
}
|
||||
Memory<uint8_t*> data(size);
|
||||
if(!MemRead((void*)base, data(), size, 0))
|
||||
{
|
||||
|
|
|
|||
|
|
@ -123,18 +123,19 @@ void LabelDelRange(uint Start, uint End)
|
|||
EXCLUSIVE_ACQUIRE(LockLabels);
|
||||
for(auto itr = labels.begin(); itr != labels.end();)
|
||||
{
|
||||
const auto & currentLabel = itr->second;
|
||||
// Ignore manually set entries
|
||||
if(itr->second.manual)
|
||||
if(currentLabel.manual)
|
||||
{
|
||||
itr++;
|
||||
++itr;
|
||||
continue;
|
||||
}
|
||||
|
||||
// [Start, End)
|
||||
if(itr->second.addr >= Start && itr->second.addr < End)
|
||||
if(currentLabel.addr >= Start && currentLabel.addr < End)
|
||||
itr = labels.erase(itr);
|
||||
else
|
||||
itr++;
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -77,10 +77,11 @@ void MemUpdateMap(HANDLE hProcess)
|
|||
char curMod[MAX_MODULE_SIZE] = "";
|
||||
for(int i = pagecount - 1; i > -1; i--)
|
||||
{
|
||||
if(!pageVector.at(i).info[0] || (scmp(curMod, pageVector.at(i).info) && !bListAllPages)) //there is a module
|
||||
auto & currentPage = pageVector.at(i);
|
||||
if(!currentPage.info[0] || (scmp(curMod, currentPage.info) && !bListAllPages)) //there is a module
|
||||
continue; //skip non-modules
|
||||
strcpy(curMod, pageVector.at(i).info);
|
||||
uint base = ModBaseFromName(pageVector.at(i).info);
|
||||
uint base = ModBaseFromName(currentPage.info);
|
||||
if(!base)
|
||||
continue;
|
||||
std::vector<MODSECTIONINFO> sections;
|
||||
|
|
@ -96,14 +97,15 @@ void MemUpdateMap(HANDLE hProcess)
|
|||
pageVector.erase(pageVector.begin() + i); //remove the SizeOfImage page
|
||||
for(int j = SectionNumber - 1; j > -1; j--)
|
||||
{
|
||||
const auto & currentSection = sections.at(j);
|
||||
memset(&newPage, 0, sizeof(MEMPAGE));
|
||||
VirtualQueryEx(hProcess, (LPCVOID)sections.at(j).addr, &newPage.mbi, sizeof(MEMORY_BASIC_INFORMATION));
|
||||
uint SectionSize = sections.at(j).size;
|
||||
VirtualQueryEx(hProcess, (LPCVOID)currentSection.addr, &newPage.mbi, sizeof(MEMORY_BASIC_INFORMATION));
|
||||
uint SectionSize = currentSection.size;
|
||||
if(SectionSize % PAGE_SIZE) //unaligned page size
|
||||
SectionSize += PAGE_SIZE - (SectionSize % PAGE_SIZE); //fix this
|
||||
if(SectionSize)
|
||||
newPage.mbi.RegionSize = SectionSize;
|
||||
sprintf_s(newPage.info, " \"%s\"", sections.at(j).name);
|
||||
sprintf_s(newPage.info, " \"%s\"", currentSection.name);
|
||||
pageVector.insert(pageVector.begin() + i, newPage);
|
||||
}
|
||||
//insert the module itself (the module header)
|
||||
|
|
@ -114,26 +116,27 @@ void MemUpdateMap(HANDLE hProcess)
|
|||
}
|
||||
else //list all pages
|
||||
{
|
||||
uint start = (uint)pageVector.at(i).mbi.BaseAddress;
|
||||
uint end = start + pageVector.at(i).mbi.RegionSize;
|
||||
uint start = (uint)currentPage.mbi.BaseAddress;
|
||||
uint end = start + currentPage.mbi.RegionSize;
|
||||
for(int j = 0, k = 0; j < SectionNumber; j++)
|
||||
{
|
||||
uint secStart = sections.at(j).addr;
|
||||
uint SectionSize = sections.at(j).size;
|
||||
const auto & currentSection = sections.at(j);
|
||||
uint secStart = currentSection.addr;
|
||||
uint SectionSize = currentSection.size;
|
||||
if(SectionSize % PAGE_SIZE) //unaligned page size
|
||||
SectionSize += PAGE_SIZE - (SectionSize % PAGE_SIZE); //fix this
|
||||
uint secEnd = secStart + SectionSize;
|
||||
if(secStart >= start && secEnd <= end) //section is inside the memory page
|
||||
{
|
||||
if(k)
|
||||
k += sprintf_s(pageVector.at(i).info + k, MAX_MODULE_SIZE - k, ",");
|
||||
k += sprintf_s(pageVector.at(i).info + k, MAX_MODULE_SIZE - k, " \"%s\"", sections.at(j).name);
|
||||
k += sprintf_s(currentPage.info + k, MAX_MODULE_SIZE - k, ",");
|
||||
k += sprintf_s(currentPage.info + k, MAX_MODULE_SIZE - k, " \"%s\"", currentSection.name);
|
||||
}
|
||||
else if(start >= secStart && end <= secEnd) //memory page is inside the section
|
||||
{
|
||||
if(k)
|
||||
k += sprintf_s(pageVector.at(i).info + k, MAX_MODULE_SIZE - k, ",");
|
||||
k += sprintf_s(pageVector.at(i).info + k, MAX_MODULE_SIZE - k, " \"%s\"", sections.at(j).name);
|
||||
k += sprintf_s(currentPage.info + k, MAX_MODULE_SIZE - k, ",");
|
||||
k += sprintf_s(currentPage.info + k, MAX_MODULE_SIZE - k, " \"%s\"", currentSection.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -171,7 +174,7 @@ uint MemFindBaseAddr(uint Address, uint* Size, bool Refresh)
|
|||
return found->first.first;
|
||||
}
|
||||
|
||||
bool MemRead(void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesRead)
|
||||
bool MemRead(const void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesRead)
|
||||
{
|
||||
if(!MemIsCanonicalAddress((uint)BaseAddress))
|
||||
return false;
|
||||
|
|
@ -187,7 +190,7 @@ bool MemRead(void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytes
|
|||
NumberOfBytesRead = &bytesReadTemp;
|
||||
|
||||
// Normal single-call read
|
||||
bool ret = MemoryReadSafe(fdProcessInfo->hProcess, BaseAddress, Buffer, Size, NumberOfBytesRead);
|
||||
bool ret = MemoryReadSafe(fdProcessInfo->hProcess, (LPVOID)BaseAddress, Buffer, Size, NumberOfBytesRead);
|
||||
|
||||
if(ret && *NumberOfBytesRead == Size)
|
||||
return true;
|
||||
|
|
@ -225,7 +228,7 @@ bool MemRead(void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytes
|
|||
return (*NumberOfBytesRead > 0);
|
||||
}
|
||||
|
||||
bool MemWrite(void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesWritten)
|
||||
bool MemWrite(void* BaseAddress, const void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesWritten)
|
||||
{
|
||||
if(!MemIsCanonicalAddress((uint)BaseAddress))
|
||||
return false;
|
||||
|
|
@ -279,7 +282,7 @@ bool MemWrite(void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfByte
|
|||
return (*NumberOfBytesWritten > 0);
|
||||
}
|
||||
|
||||
bool MemPatch(void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesWritten)
|
||||
bool MemPatch(void* BaseAddress, const void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesWritten)
|
||||
{
|
||||
// Buffer and size must be valid
|
||||
if(!Buffer || Size <= 0)
|
||||
|
|
@ -288,7 +291,7 @@ bool MemPatch(void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfByte
|
|||
// Allocate the memory
|
||||
Memory<unsigned char*> oldData(Size, "mempatch:oldData");
|
||||
|
||||
if(!MemRead(BaseAddress, oldData, Size, nullptr))
|
||||
if(!MemRead(BaseAddress, oldData(), Size, nullptr))
|
||||
{
|
||||
// If no memory can be read, no memory can be written. Fail out
|
||||
// of this function.
|
||||
|
|
@ -296,7 +299,7 @@ bool MemPatch(void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfByte
|
|||
}
|
||||
|
||||
for(SIZE_T i = 0; i < Size; i++)
|
||||
PatchSet((uint)BaseAddress + i, oldData[i], ((unsigned char*)Buffer)[i]);
|
||||
PatchSet((uint)BaseAddress + i, oldData()[i], ((const unsigned char*)Buffer)[i]);
|
||||
|
||||
return MemWrite(BaseAddress, Buffer, Size, NumberOfBytesWritten);
|
||||
}
|
||||
|
|
@ -304,7 +307,7 @@ bool MemPatch(void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfByte
|
|||
bool MemIsValidReadPtr(uint Address)
|
||||
{
|
||||
unsigned char a = 0;
|
||||
return MemRead((void*)Address, &a, sizeof(unsigned char), nullptr);
|
||||
return MemRead((const void*)Address, &a, sizeof(unsigned char), nullptr);
|
||||
}
|
||||
|
||||
bool MemIsCanonicalAddress(uint Address)
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ extern bool bListAllPages;
|
|||
|
||||
void MemUpdateMap(HANDLE hProcess);
|
||||
uint MemFindBaseAddr(uint Address, uint* Size, bool Refresh = false);
|
||||
bool MemRead(void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesRead);
|
||||
bool MemWrite(void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesWritten);
|
||||
bool MemPatch(void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesWritten);
|
||||
bool MemRead(const void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesRead);
|
||||
bool MemWrite(void* BaseAddress, const void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesWritten);
|
||||
bool MemPatch(void* BaseAddress, const void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesWritten);
|
||||
bool MemIsValidReadPtr(uint Address);
|
||||
bool MemIsCanonicalAddress(uint Address);
|
||||
void* MemAllocRemote(uint Address, SIZE_T Size, DWORD Protect);
|
||||
|
|
|
|||
|
|
@ -200,15 +200,16 @@ uint ModBaseFromName(const char* Module)
|
|||
|
||||
SHARED_ACQUIRE(LockModules);
|
||||
|
||||
for(auto itr = modinfo.begin(); itr != modinfo.end(); itr++)
|
||||
for(const auto & i : modinfo)
|
||||
{
|
||||
char currentModule[MAX_MODULE_SIZE];
|
||||
strcpy_s(currentModule, itr->second.name);
|
||||
strcat_s(currentModule, itr->second.extension);
|
||||
const auto & currentModule = i.second;
|
||||
char currentModuleName[MAX_MODULE_SIZE];
|
||||
strcpy_s(currentModuleName, currentModule.name);
|
||||
strcat_s(currentModuleName, currentModule.extension);
|
||||
|
||||
// Test with and without extension
|
||||
if(!_stricmp(currentModule, Module) || !_stricmp(itr->second.name, Module))
|
||||
return itr->second.base;
|
||||
if(!_stricmp(currentModuleName, Module) || !_stricmp(currentModule.name, Module))
|
||||
return currentModule.base;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -141,17 +141,18 @@ void PatchDelRange(uint Start, uint End, bool Restore)
|
|||
EXCLUSIVE_ACQUIRE(LockPatches);
|
||||
for(auto itr = patches.begin(); itr != patches.end();)
|
||||
{
|
||||
const auto & currentPatch = itr->second;
|
||||
// [Start, End)
|
||||
if(itr->second.addr >= Start && itr->second.addr < End)
|
||||
if(currentPatch.addr >= Start && currentPatch.addr < End)
|
||||
{
|
||||
// Restore the original byte if necessary
|
||||
if(Restore)
|
||||
MemWrite((void*)(itr->second.addr + moduleBase), &itr->second.oldbyte, sizeof(char), nullptr);
|
||||
MemWrite((void*)(currentPatch.addr + moduleBase), ¤tPatch.oldbyte, sizeof(char), nullptr);
|
||||
|
||||
itr = patches.erase(itr);
|
||||
}
|
||||
else
|
||||
itr++;
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -312,7 +313,7 @@ void PatchClear(const char* Module)
|
|||
if(!_stricmp(itr->second.mod, Module))
|
||||
itr = patches.erase(itr);
|
||||
else
|
||||
itr++;
|
||||
++itr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4,26 +4,22 @@
|
|||
|
||||
using namespace std;
|
||||
|
||||
struct PatternByte
|
||||
static inline bool isHex(char ch)
|
||||
{
|
||||
struct PatternNibble
|
||||
{
|
||||
unsigned char data;
|
||||
bool wildcard;
|
||||
} nibble[2];
|
||||
};
|
||||
return (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f');
|
||||
}
|
||||
|
||||
static string formathexpattern(string patterntext)
|
||||
static inline string formathexpattern(const string & patterntext)
|
||||
{
|
||||
string result;
|
||||
int len = (int)patterntext.length();
|
||||
for(int i = 0; i < len; i++)
|
||||
if(patterntext[i] == '?' || isxdigit(patterntext[i]))
|
||||
result += toupper(patterntext[i]);
|
||||
if(patterntext[i] == '?' || isHex(patterntext[i]))
|
||||
result += patterntext[i];
|
||||
return result;
|
||||
}
|
||||
|
||||
static int hexchtoint(char ch)
|
||||
static inline int hexchtoint(char ch)
|
||||
{
|
||||
if(ch >= '0' && ch <= '9')
|
||||
return ch - '0';
|
||||
|
|
@ -31,34 +27,34 @@ static int hexchtoint(char ch)
|
|||
return ch - 'A' + 10;
|
||||
else if(ch >= 'a' && ch <= 'f')
|
||||
return ch - 'a' + 10;
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static bool patterntransform(string patterntext, vector<PatternByte> & pattern)
|
||||
bool patterntransform(const string & patterntext, vector<PatternByte> & pattern)
|
||||
{
|
||||
pattern.clear();
|
||||
patterntext = formathexpattern(patterntext);
|
||||
int len = (int)patterntext.length();
|
||||
string formattext = formathexpattern(patterntext);
|
||||
int len = (int)formattext.length();
|
||||
if(!len)
|
||||
return false;
|
||||
|
||||
if(len % 2) //not a multiple of 2
|
||||
{
|
||||
patterntext += '?';
|
||||
formattext += '?';
|
||||
len++;
|
||||
}
|
||||
|
||||
PatternByte newByte;
|
||||
for(int i = 0, j = 0; i < len; i++)
|
||||
{
|
||||
if(patterntext[i] == '?') //wildcard
|
||||
if(formattext[i] == '?') //wildcard
|
||||
{
|
||||
newByte.nibble[j].wildcard = true; //match anything
|
||||
}
|
||||
else //hex
|
||||
{
|
||||
newByte.nibble[j].wildcard = false;
|
||||
newByte.nibble[j].data = hexchtoint(patterntext[i]) & 0xF;
|
||||
newByte.nibble[j].data = hexchtoint(formattext[i]) & 0xF;
|
||||
}
|
||||
|
||||
j++;
|
||||
|
|
@ -71,7 +67,7 @@ static bool patterntransform(string patterntext, vector<PatternByte> & pattern)
|
|||
return true;
|
||||
}
|
||||
|
||||
static bool patternmatchbyte(unsigned char byte, const PatternByte & pbyte)
|
||||
static inline bool patternmatchbyte(unsigned char byte, const PatternByte & pbyte)
|
||||
{
|
||||
int matched = 0;
|
||||
|
||||
|
|
@ -90,32 +86,16 @@ static bool patternmatchbyte(unsigned char byte, const PatternByte & pbyte)
|
|||
return (matched == 2);
|
||||
}
|
||||
|
||||
size_t patternfind(unsigned char* data, size_t datasize, const char* pattern, int* patternsize)
|
||||
size_t patternfind(const unsigned char* data, size_t datasize, const char* pattern, int* patternsize)
|
||||
{
|
||||
string patterntext(pattern);
|
||||
vector<PatternByte> searchpattern;
|
||||
if(!patterntransform(pattern, searchpattern))
|
||||
if(!patterntransform(patterntext, searchpattern))
|
||||
return -1;
|
||||
size_t searchpatternsize = searchpattern.size();
|
||||
if(patternsize)
|
||||
*patternsize = (int)searchpatternsize;
|
||||
for(size_t i = 0, pos = 0; i < datasize; i++) //search for the pattern
|
||||
{
|
||||
if(patternmatchbyte(data[i], searchpattern.at(pos))) //check if our pattern matches the current byte
|
||||
{
|
||||
pos++;
|
||||
if(pos == searchpatternsize) //everything matched
|
||||
return i - searchpatternsize + 1;
|
||||
}
|
||||
else if(pos > 0) //fix by Computer_Angel
|
||||
{
|
||||
i -= pos;
|
||||
pos = 0; //reset current pattern position
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return patternfind(data, datasize, searchpattern);
|
||||
}
|
||||
|
||||
size_t patternfind(unsigned char* data, size_t datasize, unsigned char* pattern, size_t patternsize)
|
||||
size_t patternfind(const unsigned char* data, size_t datasize, unsigned char* pattern, size_t patternsize)
|
||||
{
|
||||
if(patternsize > datasize)
|
||||
patternsize = datasize;
|
||||
|
|
@ -136,7 +116,7 @@ size_t patternfind(unsigned char* data, size_t datasize, unsigned char* pattern,
|
|||
return -1;
|
||||
}
|
||||
|
||||
static void patternwritebyte(unsigned char* byte, const PatternByte & pbyte)
|
||||
static inline void patternwritebyte(unsigned char* byte, const PatternByte & pbyte)
|
||||
{
|
||||
unsigned char n1 = (*byte >> 4) & 0xF;
|
||||
unsigned char n2 = *byte & 0xF;
|
||||
|
|
@ -150,7 +130,8 @@ static void patternwritebyte(unsigned char* byte, const PatternByte & pbyte)
|
|||
void patternwrite(unsigned char* data, size_t datasize, const char* pattern)
|
||||
{
|
||||
vector<PatternByte> writepattern;
|
||||
if(!patterntransform(pattern, writepattern))
|
||||
string patterntext(pattern);
|
||||
if(!patterntransform(patterntext, writepattern))
|
||||
return;
|
||||
size_t writepatternsize = writepattern.size();
|
||||
if(writepatternsize > datasize)
|
||||
|
|
@ -167,3 +148,23 @@ bool patternsnr(unsigned char* data, size_t datasize, const char* searchpattern,
|
|||
patternwrite(data + found, datasize - found, replacepattern);
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t patternfind(const unsigned char* data, size_t datasize, const std::vector<PatternByte> & pattern)
|
||||
{
|
||||
size_t searchpatternsize = pattern.size();
|
||||
for(size_t i = 0, pos = 0; i < datasize; i++) //search for the pattern
|
||||
{
|
||||
if(patternmatchbyte(data[i], pattern.at(pos))) //check if our pattern matches the current byte
|
||||
{
|
||||
pos++;
|
||||
if(pos == searchpatternsize) //everything matched
|
||||
return i - searchpatternsize + 1;
|
||||
}
|
||||
else if(pos > 0) //fix by Computer_Angel
|
||||
{
|
||||
i -= pos;
|
||||
pos = 0; //reset current pattern position
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
|
@ -1,9 +1,20 @@
|
|||
#ifndef _PATTERNFIND_H
|
||||
#define _PATTERNFIND_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
struct PatternByte
|
||||
{
|
||||
struct PatternNibble
|
||||
{
|
||||
unsigned char data;
|
||||
bool wildcard;
|
||||
} nibble[2];
|
||||
};
|
||||
|
||||
//returns: offset to data when found, -1 when not found
|
||||
size_t patternfind(
|
||||
unsigned char* data, //data
|
||||
const unsigned char* data, //data
|
||||
size_t datasize, //size of data
|
||||
const char* pattern, //pattern to search
|
||||
int* patternsize = 0 //outputs the number of bytes the pattern is
|
||||
|
|
@ -11,7 +22,7 @@ size_t patternfind(
|
|||
|
||||
//returns: offset to data when found, -1 when not found
|
||||
size_t patternfind(
|
||||
unsigned char* data, //data
|
||||
const unsigned char* data, //data
|
||||
size_t datasize, //size of data
|
||||
unsigned char* pattern, //bytes to search
|
||||
size_t patternsize //size of bytes to search
|
||||
|
|
@ -32,4 +43,16 @@ bool patternsnr(
|
|||
const char* replacepattern //pattern to write
|
||||
);
|
||||
|
||||
//returns: true on success, false on failure
|
||||
bool patterntransform(const std::string & patterntext, //pattern string
|
||||
std::vector<PatternByte> & pattern //pattern to feed to patternfind
|
||||
);
|
||||
|
||||
//returns: offset to data when found, -1 when not found
|
||||
size_t patternfind(
|
||||
const unsigned char* data, //data
|
||||
size_t datasize, //size of data
|
||||
const std::vector<PatternByte> & pattern //pattern to search
|
||||
);
|
||||
|
||||
#endif // _PATTERNFIND_H
|
||||
|
|
|
|||
|
|
@ -291,11 +291,12 @@ void pluginunload()
|
|||
int pluginCount = (int)pluginList.size();
|
||||
for(int i = pluginCount - 1; i > -1; i--)
|
||||
{
|
||||
PLUGSTOP stop = pluginList.at(i).plugstop;
|
||||
const auto & currentPlugin = pluginList.at(i);
|
||||
PLUGSTOP stop = currentPlugin.plugstop;
|
||||
if(stop)
|
||||
stop();
|
||||
plugincmdunregisterall(pluginList.at(i).initStruct.pluginHandle);
|
||||
FreeLibrary(pluginList.at(i).hPlugin);
|
||||
plugincmdunregisterall(currentPlugin.initStruct.pluginHandle);
|
||||
FreeLibrary(currentPlugin.hPlugin);
|
||||
pluginList.erase(pluginList.begin() + i);
|
||||
}
|
||||
pluginCallbackList.clear(); //remove all callbacks
|
||||
|
|
@ -329,7 +330,7 @@ bool pluginunregistercallback(int pluginHandle, CBTYPE cbType)
|
|||
int pluginCallbackCount = (int)pluginCallbackList.size();
|
||||
for(int i = 0; i < pluginCallbackCount; i++)
|
||||
{
|
||||
if(pluginCallbackList.at(i).pluginHandle == pluginHandle and pluginCallbackList.at(i).cbType == cbType)
|
||||
if(pluginCallbackList.at(i).pluginHandle == pluginHandle && pluginCallbackList.at(i).cbType == cbType)
|
||||
{
|
||||
pluginCallbackList.erase(pluginCallbackList.begin() + i);
|
||||
return true;
|
||||
|
|
@ -367,7 +368,7 @@ 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"))
|
||||
if(!command || strlen(command) >= deflen || strstr(command, "\1"))
|
||||
return false;
|
||||
PLUG_COMMAND plugCmd;
|
||||
plugCmd.pluginHandle = pluginHandle;
|
||||
|
|
@ -387,12 +388,12 @@ bool plugincmdregister(int pluginHandle, const char* command, CBPLUGINCOMMAND cb
|
|||
*/
|
||||
bool plugincmdunregister(int pluginHandle, const char* command)
|
||||
{
|
||||
if(!command or strlen(command) >= deflen or strstr(command, "\1"))
|
||||
if(!command || strlen(command) >= deflen || strstr(command, "\1"))
|
||||
return false;
|
||||
int listsize = (int)pluginCommandList.size();
|
||||
for(int i = 0; i < listsize; i++)
|
||||
{
|
||||
if(pluginCommandList.at(i).pluginHandle == pluginHandle and !strcmp(pluginCommandList.at(i).command, command))
|
||||
if(pluginCommandList.at(i).pluginHandle == pluginHandle && !strcmp(pluginCommandList.at(i).command, command))
|
||||
{
|
||||
if(!dbgcmddel(command))
|
||||
return false;
|
||||
|
|
@ -412,12 +413,12 @@ bool plugincmdunregister(int pluginHandle, const char* command)
|
|||
*/
|
||||
int pluginmenuadd(int hMenu, const char* title)
|
||||
{
|
||||
if(!title or !strlen(title))
|
||||
if(!title || !strlen(title))
|
||||
return -1;
|
||||
int nFound = -1;
|
||||
for(unsigned int i = 0; i < pluginMenuList.size(); i++)
|
||||
{
|
||||
if(pluginMenuList.at(i).hEntryMenu == hMenu and pluginMenuList.at(i).hEntryPlugin == -1)
|
||||
if(pluginMenuList.at(i).hEntryMenu == hMenu && pluginMenuList.at(i).hEntryPlugin == -1)
|
||||
{
|
||||
nFound = i;
|
||||
break;
|
||||
|
|
@ -443,15 +444,15 @@ int pluginmenuadd(int hMenu, const char* title)
|
|||
*/
|
||||
bool pluginmenuaddentry(int hMenu, int hEntry, const char* title)
|
||||
{
|
||||
if(!title or !strlen(title) or hEntry == -1)
|
||||
if(!title || !strlen(title) || hEntry == -1)
|
||||
return false;
|
||||
int pluginHandle = -1;
|
||||
//find plugin handle
|
||||
for(unsigned int i = 0; i < pluginMenuList.size(); i++)
|
||||
for(const auto & currentMenu : pluginMenuList)
|
||||
{
|
||||
if(pluginMenuList.at(i).hEntryMenu == hMenu and pluginMenuList.at(i).hEntryPlugin == -1)
|
||||
if(currentMenu.hEntryMenu == hMenu && currentMenu.hEntryPlugin == -1)
|
||||
{
|
||||
pluginHandle = pluginMenuList.at(i).pluginHandle;
|
||||
pluginHandle = currentMenu.pluginHandle;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -482,7 +483,7 @@ bool pluginmenuaddseparator(int hMenu)
|
|||
bool bFound = false;
|
||||
for(unsigned int i = 0; i < pluginMenuList.size(); i++)
|
||||
{
|
||||
if(pluginMenuList.at(i).hEntryMenu == hMenu and pluginMenuList.at(i).hEntryPlugin == -1)
|
||||
if(pluginMenuList.at(i).hEntryMenu == hMenu && pluginMenuList.at(i).hEntryPlugin == -1)
|
||||
{
|
||||
bFound = true;
|
||||
break;
|
||||
|
|
@ -504,7 +505,7 @@ bool pluginmenuclear(int hMenu)
|
|||
bool bFound = false;
|
||||
for(unsigned int i = 0; i < pluginMenuList.size(); i++)
|
||||
{
|
||||
if(pluginMenuList.at(i).hEntryMenu == hMenu and pluginMenuList.at(i).hEntryPlugin == -1)
|
||||
if(pluginMenuList.at(i).hEntryMenu == hMenu && pluginMenuList.at(i).hEntryPlugin == -1)
|
||||
{
|
||||
bFound = true;
|
||||
break;
|
||||
|
|
@ -524,20 +525,17 @@ void pluginmenucall(int hEntry)
|
|||
{
|
||||
if(hEntry == -1)
|
||||
return;
|
||||
for(unsigned int i = 0; i < pluginMenuList.size(); i++)
|
||||
for(const auto & currentMenu : pluginMenuList)
|
||||
{
|
||||
if(pluginMenuList.at(i).hEntryMenu == hEntry && pluginMenuList.at(i).hEntryPlugin != -1)
|
||||
if(currentMenu.hEntryMenu == hEntry && currentMenu.hEntryPlugin != -1)
|
||||
{
|
||||
PLUG_CB_MENUENTRY menuEntryInfo;
|
||||
menuEntryInfo.hEntry = pluginMenuList.at(i).hEntryPlugin;
|
||||
int pluginCallbackCount = (int)pluginCallbackList.size();
|
||||
int pluginHandle = pluginMenuList.at(i).pluginHandle;
|
||||
for(int j = 0; j < pluginCallbackCount; j++)
|
||||
menuEntryInfo.hEntry = currentMenu.hEntryPlugin;
|
||||
for(const auto & currentCallback : pluginCallbackList)
|
||||
{
|
||||
if(pluginCallbackList.at(j).pluginHandle == pluginHandle and pluginCallbackList.at(j).cbType == CB_MENUENTRY)
|
||||
if(currentCallback.pluginHandle == currentMenu.pluginHandle && currentCallback.cbType == CB_MENUENTRY)
|
||||
{
|
||||
//TODO: handle exceptions
|
||||
pluginCallbackList.at(j).cbPlugin(CB_MENUENTRY, &menuEntryInfo);
|
||||
currentCallback.cbPlugin(CB_MENUENTRY, &menuEntryInfo);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -585,7 +583,7 @@ void pluginmenuseticon(int hMenu, const ICONDATA* icon)
|
|||
bool bFound = false;
|
||||
for(unsigned int i = 0; i < pluginMenuList.size(); i++)
|
||||
{
|
||||
if(pluginMenuList.at(i).hEntryMenu == hMenu and pluginMenuList.at(i).hEntryPlugin == -1)
|
||||
if(pluginMenuList.at(i).hEntryMenu == hMenu && pluginMenuList.at(i).hEntryPlugin == -1)
|
||||
{
|
||||
GuiMenuSetIcon(hMenu, icon);
|
||||
break;
|
||||
|
|
@ -603,12 +601,11 @@ void pluginmenuentryseticon(int pluginHandle, int hEntry, const ICONDATA* icon)
|
|||
{
|
||||
if(hEntry == -1)
|
||||
return;
|
||||
bool bFound = false;
|
||||
for(unsigned int i = 0; i < pluginMenuList.size(); i++)
|
||||
for(const auto & currentMenu : pluginMenuList)
|
||||
{
|
||||
if(pluginMenuList.at(i).pluginHandle == pluginHandle && pluginMenuList.at(i).hEntryPlugin == hEntry)
|
||||
if(currentMenu.pluginHandle == pluginHandle && currentMenu.hEntryPlugin == hEntry)
|
||||
{
|
||||
GuiMenuSetEntryIcon(pluginMenuList.at(i).hEntryMenu, icon);
|
||||
GuiMenuSetEntryIcon(currentMenu.hEntryMenu, icon);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,19 +28,19 @@ static SCRIPTBRANCHTYPE scriptgetbranchtype(const char* text)
|
|||
strcpy_s(newtext, StringUtils::Trim(text).c_str());
|
||||
if(!strstr(newtext, " "))
|
||||
strcat(newtext, " ");
|
||||
if(!strncmp(newtext, "jmp ", 4) or !strncmp(newtext, "goto ", 5))
|
||||
if(!strncmp(newtext, "jmp ", 4) || !strncmp(newtext, "goto ", 5))
|
||||
return scriptjmp;
|
||||
else if(!strncmp(newtext, "jbe ", 4) or !strncmp(newtext, "ifbe ", 5) or !strncmp(newtext, "ifbeq ", 6) or !strncmp(newtext, "jle ", 4) or !strncmp(newtext, "ifle ", 5) or !strncmp(newtext, "ifleq ", 6))
|
||||
else if(!strncmp(newtext, "jbe ", 4) || !strncmp(newtext, "ifbe ", 5) || !strncmp(newtext, "ifbeq ", 6) || !strncmp(newtext, "jle ", 4) || !strncmp(newtext, "ifle ", 5) || !strncmp(newtext, "ifleq ", 6))
|
||||
return scriptjbejle;
|
||||
else if(!strncmp(newtext, "jae ", 4) or !strncmp(newtext, "ifae ", 5) or !strncmp(newtext, "ifaeq ", 6) or !strncmp(newtext, "jge ", 4) or !strncmp(newtext, "ifge ", 5) or !strncmp(newtext, "ifgeq ", 6))
|
||||
else if(!strncmp(newtext, "jae ", 4) || !strncmp(newtext, "ifae ", 5) || !strncmp(newtext, "ifaeq ", 6) || !strncmp(newtext, "jge ", 4) || !strncmp(newtext, "ifge ", 5) || !strncmp(newtext, "ifgeq ", 6))
|
||||
return scriptjaejge;
|
||||
else if(!strncmp(newtext, "jne ", 4) or !strncmp(newtext, "ifne ", 5) or !strncmp(newtext, "ifneq ", 6) or !strncmp(newtext, "jnz ", 4) or !strncmp(newtext, "ifnz ", 5))
|
||||
else if(!strncmp(newtext, "jne ", 4) || !strncmp(newtext, "ifne ", 5) || !strncmp(newtext, "ifneq ", 6) || !strncmp(newtext, "jnz ", 4) || !strncmp(newtext, "ifnz ", 5))
|
||||
return scriptjnejnz;
|
||||
else if(!strncmp(newtext, "je ", 3) or !strncmp(newtext, "ife ", 4) or !strncmp(newtext, "ifeq ", 5) or !strncmp(newtext, "jz ", 3) or !strncmp(newtext, "ifz ", 4))
|
||||
else if(!strncmp(newtext, "je ", 3) || !strncmp(newtext, "ife ", 4) || !strncmp(newtext, "ifeq ", 5) || !strncmp(newtext, "jz ", 3) || !strncmp(newtext, "ifz ", 4))
|
||||
return scriptjejz;
|
||||
else if(!strncmp(newtext, "jb ", 3) or !strncmp(newtext, "ifb ", 4) or !strncmp(newtext, "jl ", 3) or !strncmp(newtext, "ifl ", 4))
|
||||
else if(!strncmp(newtext, "jb ", 3) || !strncmp(newtext, "ifb ", 4) || !strncmp(newtext, "jl ", 3) || !strncmp(newtext, "ifl ", 4))
|
||||
return scriptjbjl;
|
||||
else if(!strncmp(newtext, "ja ", 3) or !strncmp(newtext, "ifa ", 4) or !strncmp(newtext, "jg ", 3) or !strncmp(newtext, "ifg ", 4))
|
||||
else if(!strncmp(newtext, "ja ", 3) || !strncmp(newtext, "ifa ", 4) || !strncmp(newtext, "jg ", 3) || !strncmp(newtext, "ifg ", 4))
|
||||
return scriptjajg;
|
||||
else if(!strncmp(newtext, "call ", 5))
|
||||
return scriptcall;
|
||||
|
|
@ -56,12 +56,17 @@ static int scriptlabelfind(const char* labelname)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static inline bool isEmptyLine(SCRIPTLINETYPE type)
|
||||
{
|
||||
return type == lineempty || type == linecomment || type == linelabel;
|
||||
}
|
||||
|
||||
static int scriptinternalstep(int fromIp) //internal step routine
|
||||
{
|
||||
int maxIp = (int)linemap.size(); //maximum ip
|
||||
if(fromIp >= maxIp) //script end
|
||||
return fromIp;
|
||||
while((linemap.at(fromIp).type == lineempty or linemap.at(fromIp).type == linecomment or linemap.at(fromIp).type == linelabel) and fromIp < maxIp) //skip empty lines
|
||||
while(isEmptyLine(linemap.at(fromIp).type) && fromIp < maxIp) //skip empty lines
|
||||
fromIp++;
|
||||
fromIp++;
|
||||
return fromIp;
|
||||
|
|
@ -97,7 +102,7 @@ static bool scriptcreatelinemap(const char* filename)
|
|||
std::vector<LINEMAPENTRY>().swap(linemap);
|
||||
for(int i = 0, j = 0; i < len; i++) //make raw line map
|
||||
{
|
||||
if(filedata[i] == '\r' and filedata[i + 1] == '\n') //windows file
|
||||
if(filedata[i] == '\r' && filedata[i + 1] == '\n') //windows file
|
||||
{
|
||||
memset(&entry, 0, sizeof(entry));
|
||||
int add = 0;
|
||||
|
|
@ -140,13 +145,13 @@ static bool scriptcreatelinemap(const char* filename)
|
|||
strcpy_s(entry.raw, temp);
|
||||
linemap.push_back(entry);
|
||||
}
|
||||
unsigned int linemapsize = (unsigned int)linemap.size();
|
||||
int linemapsize = (int)linemap.size();
|
||||
while(!*linemap.at(linemapsize - 1).raw) //remove empty lines from the end
|
||||
{
|
||||
linemapsize--;
|
||||
linemap.pop_back();
|
||||
}
|
||||
for(unsigned int i = 0; i < linemapsize; i++)
|
||||
for(int i = 0; i < linemapsize; i++)
|
||||
{
|
||||
LINEMAPENTRY cur = linemap.at(i);
|
||||
|
||||
|
|
@ -185,7 +190,7 @@ static bool scriptcreatelinemap(const char* filename)
|
|||
char temp[256] = "";
|
||||
strcpy_s(temp, cur.u.label + 2);
|
||||
strcpy_s(cur.u.label, temp); //remove fake command
|
||||
if(!*cur.u.label or !strcmp(cur.u.label, "\"\"")) //no label text
|
||||
if(!*cur.u.label || !strcmp(cur.u.label, "\"\"")) //no label text
|
||||
{
|
||||
char message[256] = "";
|
||||
sprintf(message, "Empty label detected on line %d!", i + 1);
|
||||
|
|
@ -229,24 +234,25 @@ static bool scriptcreatelinemap(const char* filename)
|
|||
linemap.at(i) = cur;
|
||||
}
|
||||
linemapsize = (int)linemap.size();
|
||||
for(unsigned int i = 0; i < linemapsize; i++)
|
||||
for(int i = 0; i < linemapsize; i++)
|
||||
{
|
||||
if(linemap.at(i).type == linebranch) //invalid branch label
|
||||
auto & currentLine = linemap.at(i);
|
||||
if(currentLine.type == linebranch) //invalid branch label
|
||||
{
|
||||
int labelline = scriptlabelfind(linemap.at(i).u.branch.branchlabel);
|
||||
int labelline = scriptlabelfind(currentLine.u.branch.branchlabel);
|
||||
if(!labelline) //invalid branch label
|
||||
{
|
||||
char message[256] = "";
|
||||
sprintf(message, "Invalid branch label \"%s\" detected on line %d!", linemap.at(i).u.branch.branchlabel, i + 1);
|
||||
sprintf(message, "Invalid branch label \"%s\" detected on line %d!", currentLine.u.branch.branchlabel, i + 1);
|
||||
GuiScriptError(0, message);
|
||||
std::vector<LINEMAPENTRY>().swap(linemap);
|
||||
return false;
|
||||
}
|
||||
else //set the branch destination line
|
||||
linemap.at(i).u.branch.dest = scriptinternalstep(labelline);
|
||||
currentLine.u.branch.dest = scriptinternalstep(labelline);
|
||||
}
|
||||
}
|
||||
if(linemap.at(linemapsize - 1).type == linecomment or linemap.at(linemapsize - 1).type == linelabel) //label/comment on the end
|
||||
if(linemap.at(linemapsize - 1).type == linecomment || linemap.at(linemapsize - 1).type == linelabel) //label/comment on the end
|
||||
{
|
||||
memset(&entry, 0, sizeof(entry));
|
||||
entry.type = linecommand;
|
||||
|
|
@ -268,7 +274,7 @@ static bool scriptinternalbpget(int line) //internal bpget routine
|
|||
|
||||
static bool scriptinternalbptoggle(int line) //internal breakpoint
|
||||
{
|
||||
if(!line or line > (int)linemap.size()) //invalid line
|
||||
if(!line || line > (int)linemap.size()) //invalid line
|
||||
return false;
|
||||
line = scriptinternalstep(line - 1); //no breakpoints on non-executable locations
|
||||
if(scriptinternalbpget(line)) //remove breakpoint
|
||||
|
|
@ -361,19 +367,19 @@ static bool scriptinternalbranch(SCRIPTBRANCHTYPE type) //determine if we should
|
|||
bJump = true;
|
||||
break;
|
||||
case scriptjbjl: //$_BS_FLAG=0 and $_EZ_FLAG=0 //below, not equal
|
||||
if(!bsflag and !ezflag)
|
||||
if(!bsflag && !ezflag)
|
||||
bJump = true;
|
||||
break;
|
||||
case scriptjajg: //$_BS_FLAG=1 and $_EZ_FLAG=0 //above, not equal
|
||||
if(bsflag and !ezflag)
|
||||
if(bsflag && !ezflag)
|
||||
bJump = true;
|
||||
break;
|
||||
case scriptjbejle: //$_BS_FLAG=0 or $_EZ_FLAG=1
|
||||
if(!bsflag or ezflag)
|
||||
if(!bsflag || ezflag)
|
||||
bJump = true;
|
||||
break;
|
||||
case scriptjaejge: //$_BS_FLAG=1 or $_EZ_FLAG=1
|
||||
if(bsflag or ezflag)
|
||||
if(bsflag || ezflag)
|
||||
bJump = true;
|
||||
break;
|
||||
default:
|
||||
|
|
@ -422,7 +428,7 @@ static bool scriptinternalcmd()
|
|||
static DWORD WINAPI scriptRunThread(void* arg)
|
||||
{
|
||||
int destline = (int)(uint)arg;
|
||||
if(!destline or destline > (int)linemap.size()) //invalid line
|
||||
if(!destline || destline > (int)linemap.size()) //invalid line
|
||||
destline = 0;
|
||||
if(destline)
|
||||
{
|
||||
|
|
@ -523,7 +529,7 @@ void scriptstep()
|
|||
|
||||
bool scriptbptoggle(int line)
|
||||
{
|
||||
if(!line or line > (int)linemap.size()) //invalid line
|
||||
if(!line || line > (int)linemap.size()) //invalid line
|
||||
return false;
|
||||
line = scriptinternalstep(line - 1); //no breakpoints on non-executable locations
|
||||
if(scriptbpget(line)) //remove breakpoint
|
||||
|
|
@ -613,7 +619,7 @@ void scriptreset()
|
|||
|
||||
bool scriptgetbranchinfo(int line, SCRIPTBRANCH* info)
|
||||
{
|
||||
if(!info or !line or line > (int)linemap.size()) //invalid line
|
||||
if(!info || !line || line > (int)linemap.size()) //invalid line
|
||||
return false;
|
||||
if(linemap.at(line - 1).type != linebranch) //no branch
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ bool stackcommentget(uint addr, STACK_COMMENT* comment)
|
|||
strcpy_s(label, addrinfo.label);
|
||||
char module[MAX_MODULE_SIZE] = "";
|
||||
ModNameFromAddr(data, module, false);
|
||||
char addrInfo[MAX_COMMENT_SIZE] = "";
|
||||
|
||||
if(*module) //module
|
||||
{
|
||||
if(*label) //+label
|
||||
|
|
@ -111,7 +111,7 @@ bool stackcommentget(uint addr, STACK_COMMENT* comment)
|
|||
void stackgetcallstack(uint csp, CALLSTACK* callstack)
|
||||
{
|
||||
callstack->total = 0;
|
||||
if(!DbgIsDebugging() or csp % sizeof(uint)) //alignment problem
|
||||
if(!DbgIsDebugging() || csp % sizeof(uint)) //alignment problem
|
||||
return;
|
||||
if(!MemIsValidReadPtr(csp))
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -85,7 +85,6 @@ static unsigned int getArgNumType(const String & formatString, ValueType::ValueT
|
|||
|
||||
static String handleFormatString(const String & formatString, const FormatValueVector & values)
|
||||
{
|
||||
String result;
|
||||
ValueType::ValueType type = ValueType::Unknown;
|
||||
unsigned int argnum = getArgNumType(formatString, type);
|
||||
if(argnum < values.size())
|
||||
|
|
|
|||
|
|
@ -166,9 +166,9 @@ static bool isregister(const char* string)
|
|||
return true;
|
||||
if(scmp(string, "dr3"))
|
||||
return true;
|
||||
if(scmp(string, "dr6") or scmp(string, "dr4"))
|
||||
if(scmp(string, "dr6") || scmp(string, "dr4"))
|
||||
return true;
|
||||
if(scmp(string, "dr7") or scmp(string, "dr5"))
|
||||
if(scmp(string, "dr7") || scmp(string, "dr5"))
|
||||
return true;
|
||||
|
||||
if(scmp(string, "cip"))
|
||||
|
|
@ -599,7 +599,7 @@ static bool setflag(const char* string, bool set)
|
|||
flag = 0x100000;
|
||||
else if(scmp(string, "id"))
|
||||
flag = 0x200000;
|
||||
if(eflags & flag and !set)
|
||||
if(eflags & flag && !set)
|
||||
xorval = flag;
|
||||
else if(set)
|
||||
xorval = flag;
|
||||
|
|
@ -841,11 +841,11 @@ static uint getregister(int* size, const char* string)
|
|||
{
|
||||
return GetContextDataEx(hActiveThread, UE_DR3);
|
||||
}
|
||||
if(scmp(string, "dr6") or scmp(string, "dr4"))
|
||||
if(scmp(string, "dr6") || scmp(string, "dr4"))
|
||||
{
|
||||
return GetContextDataEx(hActiveThread, UE_DR6);
|
||||
}
|
||||
if(scmp(string, "dr7") or scmp(string, "dr5"))
|
||||
if(scmp(string, "dr7") || scmp(string, "dr5"))
|
||||
{
|
||||
return GetContextDataEx(hActiveThread, UE_DR7);
|
||||
}
|
||||
|
|
@ -1156,9 +1156,9 @@ bool setregister(const char* string, uint value)
|
|||
return SetContextDataEx(hActiveThread, UE_DR2, value);
|
||||
if(scmp(string, "dr3"))
|
||||
return SetContextDataEx(hActiveThread, UE_DR3, value);
|
||||
if(scmp(string, "dr6") or scmp(string, "dr4"))
|
||||
if(scmp(string, "dr6") || scmp(string, "dr4"))
|
||||
return SetContextDataEx(hActiveThread, UE_DR6, value);
|
||||
if(scmp(string, "dr7") or scmp(string, "dr5"))
|
||||
if(scmp(string, "dr7") || scmp(string, "dr5"))
|
||||
return SetContextDataEx(hActiveThread, UE_DR7, value);
|
||||
|
||||
if(scmp(string, "cip"))
|
||||
|
|
@ -1272,7 +1272,7 @@ bool setregister(const char* string, uint value)
|
|||
*/
|
||||
bool valapifromstring(const char* name, uint* value, int* value_size, bool printall, bool silent, bool* hexonly)
|
||||
{
|
||||
if(!value or !DbgIsDebugging())
|
||||
if(!value || !DbgIsDebugging())
|
||||
return false;
|
||||
//explicit API handling
|
||||
const char* apiname = strchr(name, ':'); //the ':' character cannot be in a path: http://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx#naming_conventions
|
||||
|
|
@ -1327,9 +1327,9 @@ bool valapifromstring(const char* name, uint* value, int* value_size, bool print
|
|||
addr = modbase + (addr - (uint)mod); //correct for loaded base
|
||||
else //not found
|
||||
{
|
||||
if(scmp(apiname, "base") or scmp(apiname, "imagebase") or scmp(apiname, "header")) //get loaded base
|
||||
if(scmp(apiname, "base") || scmp(apiname, "imagebase") || scmp(apiname, "header")) //get loaded base
|
||||
addr = modbase;
|
||||
else if(scmp(apiname, "entry") or scmp(apiname, "oep") or scmp(apiname, "ep")) //get entry point
|
||||
else if(scmp(apiname, "entry") || scmp(apiname, "oep") || scmp(apiname, "ep")) //get entry point
|
||||
addr = modbase + GetPE32DataW(szModName, 0, UE_OEP);
|
||||
else if(*apiname == '$') //RVA
|
||||
{
|
||||
|
|
@ -1426,7 +1426,7 @@ bool valapifromstring(const char* name, uint* value, int* value_size, bool print
|
|||
if(kernel32 != -1) //prioritize kernel32 exports
|
||||
{
|
||||
*value = addrfound[kernel32];
|
||||
if(!printall or silent)
|
||||
if(!printall || silent)
|
||||
return true;
|
||||
for(int i = 0; i < found; i++)
|
||||
if(i != kernel32)
|
||||
|
|
@ -1435,7 +1435,7 @@ bool valapifromstring(const char* name, uint* value, int* value_size, bool print
|
|||
else
|
||||
{
|
||||
*value = *addrfound;
|
||||
if(!printall or silent)
|
||||
if(!printall || silent)
|
||||
return true;
|
||||
for(int i = 1; i < found; i++)
|
||||
dprintf(fhex"\n", addrfound[i]);
|
||||
|
|
@ -1450,7 +1450,7 @@ bool valapifromstring(const char* name, uint* value, int* value_size, bool print
|
|||
*/
|
||||
static bool isdecnumber(const char* string)
|
||||
{
|
||||
if(*string != '.' or !string[1]) //dec indicator/no number
|
||||
if(*string != '.' || !string[1]) //dec indicator/no number
|
||||
return false;
|
||||
int decAdd = 1;
|
||||
if(string[1] == '-') //minus
|
||||
|
|
@ -1474,7 +1474,7 @@ static bool isdecnumber(const char* string)
|
|||
static bool ishexnumber(const char* string)
|
||||
{
|
||||
int add = 0;
|
||||
if(*string == '0' and string[1] == 'x') //0x prefix
|
||||
if(*string == '0' && string[1] == 'x') //0x prefix
|
||||
add = 2;
|
||||
else if(*string == 'x') //hex indicator
|
||||
add = 1;
|
||||
|
|
@ -1500,7 +1500,7 @@ static bool ishexnumber(const char* string)
|
|||
*/
|
||||
bool valfromstring_noexpr(const char* string, uint* value, bool silent, bool baseonly, int* value_size, bool* isvar, bool* hexonly)
|
||||
{
|
||||
if(!value or !string)
|
||||
if(!value || !string)
|
||||
return false;
|
||||
if(!*string)
|
||||
{
|
||||
|
|
@ -1580,7 +1580,7 @@ bool valfromstring_noexpr(const char* string, uint* value, bool silent, bool bas
|
|||
*isvar = true;
|
||||
return true;
|
||||
}
|
||||
else if(*string == '!' and isflag(string + 1)) //flag
|
||||
else if(*string == '!' && isflag(string + 1)) //flag
|
||||
{
|
||||
if(!DbgIsDebugging())
|
||||
{
|
||||
|
|
@ -1658,7 +1658,7 @@ bool valfromstring_noexpr(const char* string, uint* value, bool silent, bool bas
|
|||
*/
|
||||
bool valfromstring(const char* string, uint* value, bool silent, bool baseonly, int* value_size, bool* isvar, bool* hexonly)
|
||||
{
|
||||
if(!value or !string)
|
||||
if(!value || !string)
|
||||
return false;
|
||||
if(!*string)
|
||||
{
|
||||
|
|
@ -1742,7 +1742,7 @@ static void setfpuvalue(const char* string, uint value)
|
|||
{
|
||||
uint flags = GetContextDataEx(hActiveThread, UE_MXCSR);
|
||||
flag = getmxcsrflagfromstring(string + STRLEN_USING_SIZEOF(MxCsr_PRE_FIELD_STRING));
|
||||
if(flags & flag and !set)
|
||||
if(flags & flag && !set)
|
||||
xorval = flag;
|
||||
else if(set)
|
||||
xorval = flag;
|
||||
|
|
@ -1790,7 +1790,7 @@ static void setfpuvalue(const char* string, uint value)
|
|||
{
|
||||
uint flags = GetContextDataEx(hActiveThread, UE_X87_STATUSWORD);
|
||||
flag = getx87statuswordflagfromstring(string + STRLEN_USING_SIZEOF(x87SW_PRE_FIELD_STRING));
|
||||
if(flags & flag and !set)
|
||||
if(flags & flag && !set)
|
||||
xorval = flag;
|
||||
else if(set)
|
||||
xorval = flag;
|
||||
|
|
@ -1823,7 +1823,7 @@ static void setfpuvalue(const char* string, uint value)
|
|||
{
|
||||
uint flags = GetContextDataEx(hActiveThread, UE_X87_CONTROLWORD);
|
||||
flag = getx87controlwordflagfromstring(string + STRLEN_USING_SIZEOF(x87CW_PRE_FIELD_STRING));
|
||||
if(flags & flag and !set)
|
||||
if(flags & flag && !set)
|
||||
xorval = flag;
|
||||
else if(set)
|
||||
xorval = flag;
|
||||
|
|
@ -2107,7 +2107,7 @@ bool valtostring(const char* string, uint value, bool silent)
|
|||
{
|
||||
if(!*string)
|
||||
return false;
|
||||
else if(*string == '@' or strstr(string, "[")) //memory location
|
||||
else if(*string == '@' || strstr(string, "[")) //memory location
|
||||
{
|
||||
if(!DbgIsDebugging())
|
||||
{
|
||||
|
|
@ -2123,7 +2123,7 @@ bool valtostring(const char* string, uint value, bool silent)
|
|||
{
|
||||
if(string[i] == ']')
|
||||
j += sprintf(newstring + j, ")");
|
||||
else if(isdigit(string[i]) and string[i + 1] == ':' and string[i + 2] == '[') //n:[
|
||||
else if(isdigit(string[i]) && string[i + 1] == ':' && string[i + 2] == '[') //n:[
|
||||
{
|
||||
j += sprintf(newstring + j, "@%c:(", string[i]);
|
||||
i += 2;
|
||||
|
|
@ -2138,7 +2138,7 @@ bool valtostring(const char* string, uint value, bool silent)
|
|||
strcpy_s(newstring, len * 2, string);
|
||||
int read_size = sizeof(uint);
|
||||
int add = 1;
|
||||
if(newstring[2] == ':' and isdigit((newstring[1])))
|
||||
if(newstring[2] == ':' && isdigit((newstring[1])))
|
||||
{
|
||||
add += 2;
|
||||
int new_size = newstring[1] - 0x30;
|
||||
|
|
@ -2198,7 +2198,7 @@ bool valtostring(const char* string, uint value, bool silent)
|
|||
GuiUpdateAllViews(); //repaint gui
|
||||
return true;
|
||||
}
|
||||
else if(*string == '!' and isflag(string + 1)) //flag
|
||||
else if(*string == '!' && isflag(string + 1)) //flag
|
||||
{
|
||||
if(!DbgIsDebugging())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -195,7 +195,7 @@ bool varget(const char* Name, uint* Value, int* Size, VAR_TYPE* Type)
|
|||
VAR_VALUE varvalue;
|
||||
int varsize;
|
||||
VAR_TYPE vartype;
|
||||
if(!varget(Name, &varvalue, &varsize, &vartype) or varvalue.type != VAR_UINT)
|
||||
if(!varget(Name, &varvalue, &varsize, &vartype) || varvalue.type != VAR_UINT)
|
||||
return false;
|
||||
if(Size)
|
||||
*Size = varsize;
|
||||
|
|
@ -219,7 +219,7 @@ 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)
|
||||
if(!varget(Name, &varvalue, &varsize, &vartype) || varvalue.type != VAR_STRING)
|
||||
return false;
|
||||
if(Size)
|
||||
*Size = varsize;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ StdTable::StdTable(QWidget* parent) : AbstractTableView(parent)
|
|||
mSelection = data;
|
||||
|
||||
mIsMultiSelctionAllowed = false;
|
||||
mIsColumnSortingAllowed = true;
|
||||
|
||||
mData.clear();
|
||||
mSort.first = -1;
|
||||
|
|
|
|||
|
|
@ -483,7 +483,8 @@ QString CPUDump::paintContent(QPainter* painter, int_t rowBase, int rowOffset, i
|
|||
int_t wRva = (rowBase + rowOffset) * getBytePerRowCount() - mByteOffset;
|
||||
mMemPage->read((byte_t*)&data, wRva, sizeof(uint_t));
|
||||
char modname[MAX_MODULE_SIZE] = "";
|
||||
DbgGetModuleAt(data, modname);
|
||||
if(!DbgGetModuleAt(data, modname))
|
||||
modname[0] = '\0';
|
||||
char label_text[MAX_LABEL_SIZE] = "";
|
||||
if(DbgGetLabelAt(data, SEG_DEFAULT, label_text))
|
||||
wStr = QString(modname) + "." + QString(label_text);
|
||||
|
|
|
|||
|
|
@ -199,9 +199,8 @@ QString MemoryMapView::paintContent(QPainter* painter, int_t rowBase, int rowOff
|
|||
}
|
||||
else if(col == 4) //CPROT
|
||||
{
|
||||
duint setting = 0;
|
||||
QString wStr = StdTable::paintContent(painter, rowBase, rowOffset, col, x, y, w, h);;
|
||||
if(BridgeSettingGetUint("Engine", "ListAllPages", &setting) && !setting)
|
||||
if(!ConfigBool("Engine", "ListAllPages"))
|
||||
{
|
||||
painter->setPen(ConfigColor("MemoryMapSectionTextColor"));
|
||||
painter->drawText(QRect(x + 4, y, getColumnWidth(col) - 4, getRowHeight()), Qt::AlignVCenter | Qt::AlignLeft, wStr);
|
||||
|
|
@ -393,11 +392,8 @@ void MemoryMapView::pageMemoryRights()
|
|||
|
||||
void MemoryMapView::switchView()
|
||||
{
|
||||
duint setting = 0;
|
||||
if(BridgeSettingGetUint("Engine", "ListAllPages", &setting) && setting)
|
||||
BridgeSettingSetUint("Engine", "ListAllPages", 0);
|
||||
else
|
||||
BridgeSettingSetUint("Engine", "ListAllPages", 1);
|
||||
Config()->setBool("Engine", "ListAllPages", !ConfigBool("Engine", "ListAllPages"));
|
||||
Config()->writeBools();
|
||||
DbgSettingsUpdated();
|
||||
DbgFunctions()->MemUpdateMap();
|
||||
setSingleSelection(0);
|
||||
|
|
|
|||
|
|
@ -559,9 +559,11 @@ void PatchDialog::on_btnImport_clicked()
|
|||
unsigned char checkbyte = 0;
|
||||
DbgMemRead(curPatch.addr, &checkbyte, sizeof(checkbyte));
|
||||
IMPORTSTATUS status;
|
||||
if(status.alreadypatched = checkbyte == newbyte)
|
||||
status.alreadypatched = (checkbyte == newbyte);
|
||||
status.badoriginal = (checkbyte != oldbyte);
|
||||
if(status.alreadypatched)
|
||||
bAlreadyDone = true;
|
||||
else if(status.badoriginal = checkbyte != oldbyte)
|
||||
else if(status.badoriginal)
|
||||
bBadOriginal = true;
|
||||
curPatch.oldbyte = oldbyte;
|
||||
curPatch.newbyte = newbyte;
|
||||
|
|
|
|||
|
|
@ -162,6 +162,10 @@ Configuration::Configuration() : QObject()
|
|||
disassemblyBool.insert("TabbedMnemonic", false);
|
||||
defaultBools.insert("Disassembler", disassemblyBool);
|
||||
|
||||
QMap<QString, bool> engineBool;
|
||||
engineBool.insert("ListAllPages", false);
|
||||
defaultBools.insert("Engine", engineBool);
|
||||
|
||||
//uint settings
|
||||
QMap<QString, uint_t> hexdumpUint;
|
||||
hexdumpUint.insert("DefaultView", 0);
|
||||
|
|
@ -372,7 +376,7 @@ void Configuration::readUints()
|
|||
{
|
||||
Uints = defaultUints;
|
||||
//read config
|
||||
for(int i = 0; i < Bools.size(); i++)
|
||||
for(int i = 0; i < Uints.size(); i++)
|
||||
{
|
||||
QString category = Uints.keys().at(i);
|
||||
QMap<QString, uint_t>* currentUint = &Uints[category];
|
||||
|
|
@ -387,7 +391,7 @@ void Configuration::readUints()
|
|||
void Configuration::writeUints()
|
||||
{
|
||||
//write config
|
||||
for(int i = 0; i < Bools.size(); i++)
|
||||
for(int i = 0; i < Uints.size(); i++)
|
||||
{
|
||||
QString category = Uints.keys().at(i);
|
||||
QMap<QString, uint_t>* currentUint = &Uints[category];
|
||||
|
|
|
|||
Loading…
Reference in New Issue