Merge branch 'master' of https://github.com/x64dbg/x64dbg
This commit is contained in:
commit
35082793d0
|
@ -16,7 +16,7 @@ AnalysisPass::AnalysisPass(uint VirtualStart, uint VirtualEnd, BBlockArray & Mai
|
|||
m_DataSize = VirtualEnd - VirtualStart;
|
||||
m_Data = (unsigned char*)BridgeAlloc(m_DataSize);
|
||||
|
||||
if(!MemRead((PVOID)VirtualStart, m_Data, m_DataSize, nullptr))
|
||||
if(!MemRead(VirtualStart, m_Data, m_DataSize, nullptr))
|
||||
{
|
||||
BridgeFree(m_Data);
|
||||
assert(false);
|
||||
|
|
|
@ -50,7 +50,7 @@ FunctionPass::FunctionPass(uint VirtualStart, uint VirtualEnd, BBlockArray & Mai
|
|||
m_FunctionInfo = BridgeAlloc(m_FunctionInfoSize);
|
||||
|
||||
if(m_FunctionInfo)
|
||||
MemRead((PVOID)(virtualOffset + m_ModuleStart), m_FunctionInfo, m_FunctionInfoSize, nullptr);
|
||||
MemRead((virtualOffset + m_ModuleStart), m_FunctionInfo, m_FunctionInfoSize, nullptr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ void FunctionPass::AnalysisWorker(uint Start, uint End, std::vector<FunctionDef>
|
|||
if(blockItr->GetFlag(BASIC_BLOCK_FLAG_INDIRPTR))
|
||||
{
|
||||
// Read it from memory
|
||||
if(!MemRead((PVOID)destination, &destination, sizeof(uint), nullptr))
|
||||
if(!MemRead(destination, &destination, sizeof(uint), nullptr))
|
||||
continue;
|
||||
|
||||
// Validity check
|
||||
|
|
|
@ -77,7 +77,7 @@ static bool _patchinrange(duint start, duint end)
|
|||
|
||||
static bool _mempatch(duint va, const unsigned char* src, duint size)
|
||||
{
|
||||
return MemPatch((void*)va, (void*)src, size, nullptr);
|
||||
return MemPatch(va, src, size, nullptr);
|
||||
}
|
||||
|
||||
static void _patchrestorerange(duint start, duint end)
|
||||
|
|
|
@ -36,12 +36,12 @@ extern "C" DLL_EXPORT duint _dbg_memfindbaseaddr(duint addr, duint* size)
|
|||
|
||||
extern "C" DLL_EXPORT bool _dbg_memread(duint addr, unsigned char* dest, duint size, duint* read)
|
||||
{
|
||||
return MemRead((void*)addr, dest, size, read);
|
||||
return MemRead(addr, dest, size, read);
|
||||
}
|
||||
|
||||
extern "C" DLL_EXPORT bool _dbg_memwrite(duint addr, const unsigned char* src, duint size, duint* written)
|
||||
{
|
||||
return MemWrite((void*)addr, (void*)src, size, written);
|
||||
return MemWrite(addr, (void*)src, size, written);
|
||||
}
|
||||
|
||||
extern "C" DLL_EXPORT bool _dbg_memmap(MEMMAP* memmap)
|
||||
|
@ -134,7 +134,7 @@ extern "C" DLL_EXPORT bool _dbg_addrinfoget(duint addr, SEGMENTREG segment, ADDR
|
|||
if(disasmfast(addr, &basicinfo) && basicinfo.branch && !basicinfo.call && basicinfo.memory.value) //thing is a JMP
|
||||
{
|
||||
uint val = 0;
|
||||
if(MemRead((void*)basicinfo.memory.value, &val, sizeof(val), 0))
|
||||
if(MemRead(basicinfo.memory.value, &val, sizeof(val), 0))
|
||||
{
|
||||
if(SafeSymFromAddr(fdProcessInfo->hProcess, (DWORD64)val, &displacement, pSymbol) && !displacement)
|
||||
{
|
||||
|
|
|
@ -181,11 +181,10 @@ void formathex(char* string)
|
|||
int len = (int)strlen(string);
|
||||
_strupr(string);
|
||||
Memory<char*> new_string(len + 1, "formathex:new_string");
|
||||
memset(new_string, 0, len + 1);
|
||||
for(int i = 0, j = 0; i < len; i++)
|
||||
if(isxdigit(string[i]))
|
||||
j += sprintf(new_string + j, "%c", string[i]);
|
||||
strcpy_s(string, len + 1, new_string);
|
||||
j += sprintf(new_string() + j, "%c", string[i]);
|
||||
strcpy_s(string, len + 1, new_string());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -197,11 +196,10 @@ void formatdec(char* string)
|
|||
int len = (int)strlen(string);
|
||||
_strupr(string);
|
||||
Memory<char*> new_string(len + 1, "formatdec:new_string");
|
||||
memset(new_string, 0, len + 1);
|
||||
for(int i = 0, j = 0; i < len; i++)
|
||||
if(isdigit(string[i]))
|
||||
j += sprintf(new_string + j, "%c", string[i]);
|
||||
strcpy_s(string, len + 1, new_string);
|
||||
j += sprintf(new_string() + j, "%c", string[i]);
|
||||
strcpy_s(string, len + 1, new_string());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
|
||||
SCRIPT_EXPORT bool Script::Memory::Read(duint addr, void* data, duint size, duint* sizeRead)
|
||||
{
|
||||
return MemRead((void*)addr, data, size, sizeRead);
|
||||
return MemRead(addr, data, size, sizeRead);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Memory::Write(duint addr, const void* data, duint size, duint* sizeWritten)
|
||||
{
|
||||
return MemWrite((void*)addr, (void*)data, size, sizeWritten);
|
||||
return MemWrite(addr, (void*)data, size, sizeWritten);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Memory::IsValidPtr(duint addr)
|
||||
|
|
|
@ -10,7 +10,7 @@ SCRIPT_EXPORT duint Script::Pattern::Find(unsigned char* data, duint datasize, c
|
|||
SCRIPT_EXPORT duint Script::Pattern::FindMem(duint start, duint size, const char* pattern)
|
||||
{
|
||||
Memory<unsigned char*> data(size, "Script::Pattern::FindMem::data");
|
||||
if(!MemRead((void*)start, data(), size, nullptr))
|
||||
if(!MemRead(start, data(), size, nullptr))
|
||||
return -1;
|
||||
return Pattern::Find(data(), data.size(), pattern) + start;
|
||||
}
|
||||
|
@ -23,10 +23,10 @@ SCRIPT_EXPORT void Script::Pattern::Write(unsigned char* data, duint datasize, c
|
|||
SCRIPT_EXPORT void Script::Pattern::WriteMem(duint start, duint size, const char* pattern)
|
||||
{
|
||||
Memory<unsigned char*> data(size, "Script::Pattern::WriteMem::data");
|
||||
if(!MemRead((void*)start, data(), data.size(), nullptr))
|
||||
if(!MemRead(start, data(), data.size(), nullptr))
|
||||
return;
|
||||
patternwrite(data(), data.size(), pattern);
|
||||
MemWrite((void*)start, data(), data.size(), nullptr);
|
||||
MemWrite(start, data(), data.size(), nullptr);
|
||||
}
|
||||
|
||||
SCRIPT_EXPORT bool Script::Pattern::SearchAndReplace(unsigned char* data, duint datasize, const char* searchpattern, const char* replacepattern)
|
||||
|
@ -37,12 +37,12 @@ SCRIPT_EXPORT bool Script::Pattern::SearchAndReplace(unsigned char* data, duint
|
|||
SCRIPT_EXPORT bool Script::Pattern::SearchAndReplaceMem(duint start, duint size, const char* searchpattern, const char* replacepattern)
|
||||
{
|
||||
Memory<unsigned char*> data(size, "Script::Pattern::SearchAndReplaceMem::data");
|
||||
if(!MemRead((void*)start, data(), size, nullptr))
|
||||
if(!MemRead(start, data(), size, nullptr))
|
||||
return false;
|
||||
duint found = patternfind(data(), data.size(), searchpattern);
|
||||
if(found == -1)
|
||||
return false;
|
||||
patternwrite(data() + found, data.size() - found, replacepattern);
|
||||
MemWrite((void*)(start + found), data() + found, data.size() - found, nullptr);
|
||||
MemWrite((start + found), data() + found, data.size() - found, nullptr);
|
||||
return true;
|
||||
}
|
|
@ -102,7 +102,7 @@ void dbload()
|
|||
|
||||
Memory<char*> jsonText(jsonFileSize + 1);
|
||||
DWORD read = 0;
|
||||
if(!ReadFile(hFile, jsonText, jsonFileSize, &read, 0))
|
||||
if(!ReadFile(hFile, jsonText(), jsonFileSize, &read, 0))
|
||||
{
|
||||
dputs("\nFailed to read database file!");
|
||||
return;
|
||||
|
@ -110,7 +110,7 @@ void dbload()
|
|||
hFile.Close();
|
||||
|
||||
// Deserialize JSON
|
||||
JSON root = json_loads(jsonText, 0, 0);
|
||||
JSON root = json_loads(jsonText(), 0, 0);
|
||||
|
||||
if(lzmaStatus != LZ4_INVALID_ARCHIVE && useCompression)
|
||||
LZ4_compress_fileW(databasePathW.c_str(), databasePathW.c_str());
|
||||
|
@ -154,14 +154,14 @@ bool apienumexports(uint base, EXPORTENUMCALLBACK cbEnum)
|
|||
VirtualQueryEx(fdProcessInfo->hProcess, (const void*)base, &mbi, sizeof(mbi));
|
||||
uint size = mbi.RegionSize;
|
||||
Memory<void*> buffer(size, "apienumexports:buffer");
|
||||
if(!MemRead((void*)base, buffer, size, 0))
|
||||
if(!MemRead(base, buffer(), size, 0))
|
||||
return false;
|
||||
IMAGE_NT_HEADERS* pnth = (IMAGE_NT_HEADERS*)((uint)buffer + GetPE32DataFromMappedFile((ULONG_PTR)buffer, 0, UE_PE_OFFSET));
|
||||
IMAGE_NT_HEADERS* pnth = (IMAGE_NT_HEADERS*)((uint)buffer() + GetPE32DataFromMappedFile((ULONG_PTR)buffer(), 0, UE_PE_OFFSET));
|
||||
uint export_dir_rva = pnth->OptionalHeader.DataDirectory[0].VirtualAddress;
|
||||
uint export_dir_size = pnth->OptionalHeader.DataDirectory[0].Size;
|
||||
IMAGE_EXPORT_DIRECTORY export_dir;
|
||||
memset(&export_dir, 0, sizeof(export_dir));
|
||||
MemRead((void*)(export_dir_rva + base), &export_dir, sizeof(export_dir), 0);
|
||||
MemRead((export_dir_rva + base), &export_dir, sizeof(export_dir), 0);
|
||||
unsigned int NumberOfNames = export_dir.NumberOfNames;
|
||||
if(!export_dir.NumberOfFunctions || !NumberOfNames) //no named exports
|
||||
return false;
|
||||
|
@ -170,28 +170,28 @@ bool apienumexports(uint base, EXPORTENUMCALLBACK cbEnum)
|
|||
uint original_name_va = export_dir.Name + base;
|
||||
char original_name[deflen] = "";
|
||||
memset(original_name, 0, sizeof(original_name));
|
||||
MemRead((void*)original_name_va, original_name, deflen, 0);
|
||||
char* AddrOfFunctions_va = (char*)(export_dir.AddressOfFunctions + base);
|
||||
char* AddrOfNames_va = (char*)(export_dir.AddressOfNames + base);
|
||||
char* AddrOfNameOrdinals_va = (char*)(export_dir.AddressOfNameOrdinals + base);
|
||||
MemRead(original_name_va, original_name, deflen, 0);
|
||||
char* AddrOfFunctions_va = (char*)(export_dir.AddressOfFunctions + base); //not a valid local pointer
|
||||
char* AddrOfNames_va = (char*)(export_dir.AddressOfNames + base); //not a valid local pointer
|
||||
char* AddrOfNameOrdinals_va = (char*)(export_dir.AddressOfNameOrdinals + base); //not a valid local pointer
|
||||
for(DWORD i = 0; i < NumberOfNames; i++)
|
||||
{
|
||||
DWORD curAddrOfName = 0;
|
||||
MemRead(AddrOfNames_va + sizeof(DWORD)*i, &curAddrOfName, sizeof(DWORD), 0);
|
||||
MemRead((uint)(AddrOfNames_va + sizeof(DWORD)*i), &curAddrOfName, sizeof(DWORD), 0);
|
||||
char* cur_name_va = (char*)(curAddrOfName + base);
|
||||
char cur_name[deflen] = "";
|
||||
memset(cur_name, 0, deflen);
|
||||
MemRead(cur_name_va, cur_name, deflen, 0);
|
||||
MemRead((uint)cur_name_va, cur_name, deflen, 0);
|
||||
WORD curAddrOfNameOrdinals = 0;
|
||||
MemRead(AddrOfNameOrdinals_va + sizeof(WORD)*i, &curAddrOfNameOrdinals, sizeof(WORD), 0);
|
||||
MemRead((uint)(AddrOfNameOrdinals_va + sizeof(WORD)*i), &curAddrOfNameOrdinals, sizeof(WORD), 0);
|
||||
DWORD curFunctionRva = 0;
|
||||
MemRead(AddrOfFunctions_va + sizeof(DWORD)*curAddrOfNameOrdinals, &curFunctionRva, sizeof(DWORD), 0);
|
||||
MemRead((uint)(AddrOfFunctions_va + sizeof(DWORD)*curAddrOfNameOrdinals), &curFunctionRva, sizeof(DWORD), 0);
|
||||
|
||||
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);
|
||||
MemRead((curFunctionRva + base), forwarded_api, deflen, 0);
|
||||
int len = (int)strlen(forwarded_api);
|
||||
int j = 0;
|
||||
while(forwarded_api[j] != '.' && j < len)
|
||||
|
|
|
@ -6,7 +6,7 @@ Analysis::Analysis(uint base, uint size)
|
|||
_base = base;
|
||||
_size = size;
|
||||
_data = new unsigned char[_size + MAX_DISASM_BUFFER];
|
||||
MemRead((void*)_base, _data, _size, 0);
|
||||
MemRead(_base, _data, _size, 0);
|
||||
}
|
||||
|
||||
Analysis::~Analysis()
|
||||
|
|
|
@ -67,12 +67,12 @@ bool assembleat(uint addr, const char* instruction, int* size, char* error, bool
|
|||
if(size)
|
||||
*size = destSize;
|
||||
|
||||
bool ret = MemPatch((void*)addr, dest, destSize, 0);
|
||||
bool ret = MemPatch(addr, dest, destSize, 0);
|
||||
if(ret && fillnop && nopsize)
|
||||
{
|
||||
if(size)
|
||||
*size += nopsize;
|
||||
if(!MemPatch((void*)(addr + destSize), nops, nopsize, 0))
|
||||
if(!MemPatch((addr + destSize), nops, nopsize, 0))
|
||||
ret = false;
|
||||
}
|
||||
GuiUpdatePatches();
|
||||
|
|
|
@ -426,9 +426,9 @@ static BOOL CALLBACK SymRegisterCallbackProc64(HANDLE hProcess, ULONG ActionCode
|
|||
if(strstr(text, " bytes - "))
|
||||
{
|
||||
Memory<char*> newtext(len + 1, "SymRegisterCallbackProc64:newtext");
|
||||
strcpy_s(newtext, len + 1, text);
|
||||
strstr(newtext, " bytes - ")[8] = 0;
|
||||
GuiSymbolLogAdd(newtext);
|
||||
strcpy_s(newtext(), len + 1, text);
|
||||
strstr(newtext(), " bytes - ")[8] = 0;
|
||||
GuiSymbolLogAdd(newtext());
|
||||
suspress = true;
|
||||
}
|
||||
else if(strstr(text, " copied "))
|
||||
|
@ -569,7 +569,7 @@ static unsigned char getCIPch()
|
|||
{
|
||||
unsigned char ch = 0x90;
|
||||
uint cip = GetContextDataEx(hActiveThread, UE_CIP);
|
||||
MemRead((void*)cip, &ch, 1, 0);
|
||||
MemRead(cip, &ch, 1, 0);
|
||||
return ch;
|
||||
}
|
||||
|
||||
|
@ -661,14 +661,14 @@ static void cbCreateProcess(CREATE_PROCESS_DEBUG_INFO* CreateProcessInfo)
|
|||
{
|
||||
dprintf("TLS Callbacks: %d\n", NumberOfCallBacks);
|
||||
Memory<uint*> TLSCallBacks(NumberOfCallBacks * sizeof(uint), "cbCreateProcess:TLSCallBacks");
|
||||
if(!TLSGrabCallBackDataW(StringUtils::Utf8ToUtf16(DebugFileName).c_str(), TLSCallBacks, &NumberOfCallBacks))
|
||||
if(!TLSGrabCallBackDataW(StringUtils::Utf8ToUtf16(DebugFileName).c_str(), TLSCallBacks(), &NumberOfCallBacks))
|
||||
dputs("Failed to get TLS callback addresses!");
|
||||
else
|
||||
{
|
||||
uint ImageBase = GetPE32DataW(StringUtils::Utf8ToUtf16(DebugFileName).c_str(), 0, UE_IMAGEBASE);
|
||||
for(unsigned int i = 0; i < NumberOfCallBacks; i++)
|
||||
{
|
||||
sprintf(command, "bp "fhex",\"TLS Callback %d\",ss", TLSCallBacks[i] - ImageBase + pDebuggedBase, i + 1);
|
||||
sprintf(command, "bp "fhex",\"TLS Callback %d\",ss", TLSCallBacks()[i] - ImageBase + pDebuggedBase, i + 1);
|
||||
cmddirectexec(dbggetcommandlist(), command);
|
||||
}
|
||||
}
|
||||
|
@ -863,7 +863,7 @@ static void cbLoadDll(LOAD_DLL_DEBUG_INFO* LoadDll)
|
|||
{
|
||||
dprintf("TLS Callbacks: %d\n", NumberOfCallBacks);
|
||||
Memory<uint*> TLSCallBacks(NumberOfCallBacks * sizeof(uint), "cbLoadDll:TLSCallBacks");
|
||||
if(!TLSGrabCallBackDataW(StringUtils::Utf8ToUtf16(DLLDebugFileName).c_str(), TLSCallBacks, &NumberOfCallBacks))
|
||||
if(!TLSGrabCallBackDataW(StringUtils::Utf8ToUtf16(DLLDebugFileName).c_str(), TLSCallBacks(), &NumberOfCallBacks))
|
||||
dputs("Failed to get TLS callback addresses!");
|
||||
else
|
||||
{
|
||||
|
@ -871,9 +871,9 @@ static void cbLoadDll(LOAD_DLL_DEBUG_INFO* LoadDll)
|
|||
for(unsigned int i = 0; i < NumberOfCallBacks; i++)
|
||||
{
|
||||
if(bIsDebuggingThis)
|
||||
sprintf(command, "bp "fhex",\"TLS Callback %d\",ss", TLSCallBacks[i] - ImageBase + (uint)base, i + 1);
|
||||
sprintf(command, "bp "fhex",\"TLS Callback %d\",ss", TLSCallBacks()[i] - ImageBase + (uint)base, i + 1);
|
||||
else
|
||||
sprintf(command, "bp "fhex",\"TLS Callback %d (%s)\",ss", TLSCallBacks[i] - ImageBase + (uint)base, i + 1, modname);
|
||||
sprintf(command, "bp "fhex",\"TLS Callback %d (%s)\",ss", TLSCallBacks()[i] - ImageBase + (uint)base, i + 1, modname);
|
||||
cmddirectexec(dbggetcommandlist(), command);
|
||||
}
|
||||
}
|
||||
|
@ -965,9 +965,9 @@ static void cbOutputDebugString(OUTPUT_DEBUG_STRING_INFO* DebugString)
|
|||
if(!DebugString->fUnicode) //ASCII
|
||||
{
|
||||
Memory<char*> DebugText(DebugString->nDebugStringLength + 1, "cbOutputDebugString:DebugText");
|
||||
if(MemRead(DebugString->lpDebugStringData, DebugText, DebugString->nDebugStringLength, 0))
|
||||
if(MemRead((uint)DebugString->lpDebugStringData, DebugText(), DebugString->nDebugStringLength, 0))
|
||||
{
|
||||
String str = String(DebugText);
|
||||
String str = String(DebugText());
|
||||
if(str != lastDebugText) //fix for every string being printed twice
|
||||
{
|
||||
if(str != "\n")
|
||||
|
@ -1040,16 +1040,16 @@ static void cbException(EXCEPTION_DEBUG_INFO* ExceptionData)
|
|||
}
|
||||
else if(ExceptionData->ExceptionRecord.ExceptionCode == MS_VC_EXCEPTION) //SetThreadName exception
|
||||
{
|
||||
THREADNAME_INFO nameInfo;
|
||||
THREADNAME_INFO nameInfo; //has no valid local pointers
|
||||
memcpy(&nameInfo, ExceptionData->ExceptionRecord.ExceptionInformation, sizeof(THREADNAME_INFO));
|
||||
if(nameInfo.dwThreadID == -1) //current thread
|
||||
nameInfo.dwThreadID = ((DEBUG_EVENT*)GetDebugData())->dwThreadId;
|
||||
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))
|
||||
if(MemRead((uint)nameInfo.szName, ThreadName(), MAX_THREAD_NAME_SIZE - 1, 0))
|
||||
{
|
||||
String ThreadNameEscaped = StringUtils::Escape(ThreadName);
|
||||
String ThreadNameEscaped = StringUtils::Escape(ThreadName());
|
||||
dprintf("SetThreadName(%X, \"%s\")\n", nameInfo.dwThreadID, ThreadNameEscaped.c_str());
|
||||
ThreadSetName(nameInfo.dwThreadID, ThreadNameEscaped.c_str());
|
||||
}
|
||||
|
@ -1818,7 +1818,7 @@ static bool getcommandlineaddr(uint* addr, cmdline_error_t* cmd_line_error)
|
|||
|
||||
//cast-trick to calculate the address of the remote peb field ProcessParameters
|
||||
cmd_line_error->addr = (uint) & (((PPEB) cmd_line_error->addr)->ProcessParameters);
|
||||
if(!MemRead((void*)cmd_line_error->addr, &pprocess_parameters, sizeof(pprocess_parameters), &size))
|
||||
if(!MemRead(cmd_line_error->addr, &pprocess_parameters, sizeof(pprocess_parameters), &size))
|
||||
{
|
||||
cmd_line_error->type = CMDL_ERR_READ_PEBBASE;
|
||||
return false;
|
||||
|
@ -1836,7 +1836,7 @@ static bool patchcmdline(uint getcommandline, uint new_command_line, cmdline_err
|
|||
unsigned char data[100];
|
||||
|
||||
cmd_line_error->addr = getcommandline;
|
||||
if(!MemRead((void*) cmd_line_error->addr, & data, sizeof(data), & size))
|
||||
if(!MemRead(cmd_line_error->addr, & data, sizeof(data), & size))
|
||||
{
|
||||
cmd_line_error->type = CMDL_ERR_READ_GETCOMMANDLINEBASE;
|
||||
return false;
|
||||
|
@ -1870,7 +1870,7 @@ static bool patchcmdline(uint getcommandline, uint new_command_line, cmdline_err
|
|||
#endif
|
||||
|
||||
//update the pointer in the debuggee
|
||||
if(!MemWrite((void*)command_line_stored, &new_command_line, sizeof(new_command_line), &size))
|
||||
if(!MemWrite(command_line_stored, &new_command_line, sizeof(new_command_line), &size))
|
||||
{
|
||||
cmd_line_error->addr = command_line_stored;
|
||||
cmd_line_error->type = CMDL_ERR_WRITE_GETCOMMANDLINESTORED;
|
||||
|
@ -1931,13 +1931,13 @@ bool dbgsetcmdline(const char* cmd_line, cmdline_error_t* cmd_line_error)
|
|||
Memory<wchar_t*> command_linewstr(new_command_line.Length);
|
||||
|
||||
// Covert to Unicode.
|
||||
if(!MultiByteToWideChar(CP_UTF8, 0, cmd_line, (int)cmd_line_size + 1, command_linewstr, (int)cmd_line_size + 1))
|
||||
if(!MultiByteToWideChar(CP_UTF8, 0, cmd_line, (int)cmd_line_size + 1, command_linewstr(), (int)cmd_line_size + 1))
|
||||
{
|
||||
cmd_line_error->type = CMDL_ERR_CONVERTUNICODE;
|
||||
return false;
|
||||
}
|
||||
|
||||
new_command_line.Buffer = command_linewstr;
|
||||
new_command_line.Buffer = command_linewstr();
|
||||
|
||||
uint mem = (uint)MemAllocRemote(0, new_command_line.Length * 2, PAGE_READWRITE);
|
||||
if(!mem)
|
||||
|
@ -1946,14 +1946,14 @@ bool dbgsetcmdline(const char* cmd_line, cmdline_error_t* cmd_line_error)
|
|||
return false;
|
||||
}
|
||||
|
||||
if(!MemWrite((void*)mem, new_command_line.Buffer, new_command_line.Length, &size))
|
||||
if(!MemWrite(mem, new_command_line.Buffer, new_command_line.Length, &size))
|
||||
{
|
||||
cmd_line_error->addr = mem;
|
||||
cmd_line_error->type = CMDL_ERR_WRITE_UNICODE_COMMANDLINE;
|
||||
return false;
|
||||
}
|
||||
|
||||
if(!MemWrite((void*)(mem + new_command_line.Length), (void*)cmd_line, strlen(cmd_line) + 1, &size))
|
||||
if(!MemWrite((mem + new_command_line.Length), (void*)cmd_line, strlen(cmd_line) + 1, &size))
|
||||
{
|
||||
cmd_line_error->addr = mem + new_command_line.Length;
|
||||
cmd_line_error->type = CMDL_ERR_WRITE_ANSI_COMMANDLINE;
|
||||
|
@ -1964,7 +1964,7 @@ bool dbgsetcmdline(const char* cmd_line, cmdline_error_t* cmd_line_error)
|
|||
return false;
|
||||
|
||||
new_command_line.Buffer = (PWSTR) mem;
|
||||
if(!MemWrite((void*)command_line_addr, &new_command_line, sizeof(new_command_line), &size))
|
||||
if(!MemWrite(command_line_addr, &new_command_line, sizeof(new_command_line), &size))
|
||||
{
|
||||
cmd_line_error->addr = command_line_addr;
|
||||
cmd_line_error->type = CMDL_ERR_WRITE_PEBUNICODE_COMMANDLINE;
|
||||
|
@ -1986,7 +1986,7 @@ bool dbggetcmdline(char** cmd_line, cmdline_error_t* cmd_line_error)
|
|||
if(!getcommandlineaddr(&cmd_line_error->addr, cmd_line_error))
|
||||
return false;
|
||||
|
||||
if(!MemRead((void*)cmd_line_error->addr, &CommandLine, sizeof(CommandLine), &size))
|
||||
if(!MemRead(cmd_line_error->addr, &CommandLine, sizeof(CommandLine), &size))
|
||||
{
|
||||
cmd_line_error->type = CMDL_ERR_READ_PROCPARM_PTR;
|
||||
return false;
|
||||
|
@ -1995,19 +1995,19 @@ bool dbggetcmdline(char** cmd_line, cmdline_error_t* cmd_line_error)
|
|||
Memory<wchar_t*> wstr_cmd(CommandLine.Length + sizeof(wchar_t));
|
||||
|
||||
cmd_line_error->addr = (uint) CommandLine.Buffer;
|
||||
if(!MemRead((void*)cmd_line_error->addr, wstr_cmd, CommandLine.Length, &size))
|
||||
if(!MemRead(cmd_line_error->addr, wstr_cmd(), CommandLine.Length, &size))
|
||||
{
|
||||
cmd_line_error->type = CMDL_ERR_READ_PROCPARM_CMDLINE;
|
||||
return false;
|
||||
}
|
||||
|
||||
SIZE_T wstr_cmd_size = wcslen(wstr_cmd) + 1;
|
||||
SIZE_T wstr_cmd_size = wcslen(wstr_cmd()) + 1;
|
||||
SIZE_T cmd_line_size = wstr_cmd_size * 2;
|
||||
|
||||
*cmd_line = (char*)emalloc(cmd_line_size, "dbggetcmdline:cmd_line");
|
||||
|
||||
//Convert TO UTF-8
|
||||
if(!WideCharToMultiByte(CP_UTF8, 0, wstr_cmd, (int)wstr_cmd_size, * cmd_line, (int)cmd_line_size, NULL, NULL))
|
||||
if(!WideCharToMultiByte(CP_UTF8, 0, wstr_cmd(), (int)wstr_cmd_size, * cmd_line, (int)cmd_line_size, NULL, NULL))
|
||||
{
|
||||
efree(*cmd_line);
|
||||
cmd_line_error->type = CMDL_ERR_CONVERTUNICODE;
|
||||
|
|
|
@ -24,8 +24,8 @@
|
|||
|
||||
static bool bScyllaLoaded = false;
|
||||
uint LoadLibThreadID;
|
||||
LPVOID DLLNameMem;
|
||||
LPVOID ASMAddr;
|
||||
uint DLLNameMem;
|
||||
uint ASMAddr;
|
||||
TITAN_ENGINE_CONTEXT_t backupctx = { 0 };
|
||||
|
||||
CMDRESULT cbDebugInit(int argc, char* argv[])
|
||||
|
@ -238,7 +238,7 @@ CMDRESULT cbDebugSetBPX(int argc, char* argv[]) //bp addr [,name [,type]]
|
|||
dprintf("Error setting breakpoint at "fhex"! (IsBPXEnabled)\n", addr);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
else if(!MemRead((void*)addr, &oldbytes, sizeof(short), 0))
|
||||
else if(!MemRead(addr, &oldbytes, sizeof(short), 0))
|
||||
{
|
||||
dprintf("Error setting breakpoint at "fhex"! (memread)\n", addr);
|
||||
return STATUS_ERROR;
|
||||
|
@ -1888,8 +1888,8 @@ CMDRESULT cbDebugLoadLib(int argc, char* argv[])
|
|||
LoadLibThreadID = fdProcessInfo->dwThreadId;
|
||||
HANDLE LoadLibThread = ThreadGetHandle((DWORD)LoadLibThreadID);
|
||||
|
||||
DLLNameMem = VirtualAllocEx(fdProcessInfo->hProcess, NULL, strlen(argv[1]) + 1, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
||||
ASMAddr = VirtualAllocEx(fdProcessInfo->hProcess, NULL, 0x1000, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
||||
DLLNameMem = (uint)VirtualAllocEx(fdProcessInfo->hProcess, NULL, strlen(argv[1]) + 1, MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE);
|
||||
ASMAddr = (uint)VirtualAllocEx(fdProcessInfo->hProcess, NULL, 0x1000, MEM_RESERVE | MEM_COMMIT, PAGE_EXECUTE_READWRITE);
|
||||
|
||||
if(!DLLNameMem || !ASMAddr)
|
||||
{
|
||||
|
@ -1962,8 +1962,8 @@ void cbDebugLoadLibBPX()
|
|||
varset("$result", LibAddr, false);
|
||||
backupctx.eflags &= ~0x100;
|
||||
SetFullContextDataEx(LoadLibThread, &backupctx);
|
||||
VirtualFreeEx(fdProcessInfo->hProcess, DLLNameMem, 0, MEM_RELEASE);
|
||||
VirtualFreeEx(fdProcessInfo->hProcess, ASMAddr, 0, MEM_RELEASE);
|
||||
VirtualFreeEx(fdProcessInfo->hProcess, (LPVOID)DLLNameMem, 0, MEM_RELEASE);
|
||||
VirtualFreeEx(fdProcessInfo->hProcess, (LPVOID)ASMAddr, 0, MEM_RELEASE);
|
||||
ThreadResumeAll();
|
||||
//update GUI
|
||||
GuiSetDebugState(paused);
|
||||
|
|
|
@ -103,7 +103,7 @@ bool disasmfast(unsigned char* data, uint addr, BASIC_INSTRUCTION_INFO* basicinf
|
|||
bool disasmfast(uint addr, BASIC_INSTRUCTION_INFO* basicinfo)
|
||||
{
|
||||
unsigned int data[16];
|
||||
if(!MemRead((void*)addr, data, sizeof(data), nullptr))
|
||||
if(!MemRead(addr, data, sizeof(data), nullptr))
|
||||
return false;
|
||||
return disasmfast((unsigned char*)data, addr, basicinfo);
|
||||
}
|
|
@ -278,7 +278,7 @@ bool disasmispossiblestring(uint addr)
|
|||
{
|
||||
unsigned char data[11];
|
||||
memset(data, 0, sizeof(data));
|
||||
if(!MemRead((void*)addr, data, sizeof(data) - 3, 0))
|
||||
if(!MemRead(addr, data, sizeof(data) - 3, 0))
|
||||
return false;
|
||||
uint test = 0;
|
||||
memcpy(&test, data, sizeof(uint));
|
||||
|
@ -294,21 +294,20 @@ bool disasmgetstringat(uint addr, STRING_TYPE* type, char* ascii, char* unicode,
|
|||
if(!disasmispossiblestring(addr))
|
||||
return false;
|
||||
Memory<unsigned char*> data((maxlen + 1) * 2, "disasmgetstringat:data");
|
||||
memset(data, 0, (maxlen + 1) * 2);
|
||||
if(!MemRead((void*)addr, data, (maxlen + 1) * 2, 0))
|
||||
if(!MemRead(addr, data(), (maxlen + 1) * 2, 0))
|
||||
return false;
|
||||
uint test = 0;
|
||||
memcpy(&test, data, sizeof(uint));
|
||||
memcpy(&test, data(), sizeof(uint));
|
||||
if(MemIsValidReadPtr(test))
|
||||
return false;
|
||||
if(isasciistring(data, maxlen))
|
||||
if(isasciistring(data(), maxlen))
|
||||
{
|
||||
if(type)
|
||||
*type = str_ascii;
|
||||
int len = (int)strlen((const char*)data);
|
||||
int len = (int)strlen((const char*)data());
|
||||
for(int i = 0, j = 0; i < len; i++)
|
||||
{
|
||||
switch(data[i])
|
||||
switch(data()[i])
|
||||
{
|
||||
case '\t':
|
||||
j += sprintf(ascii + j, "\\t");
|
||||
|
@ -332,20 +331,20 @@ bool disasmgetstringat(uint addr, STRING_TYPE* type, char* ascii, char* unicode,
|
|||
j += sprintf(ascii + j, "\\\"");
|
||||
break;
|
||||
default:
|
||||
j += sprintf(ascii + j, "%c", data[i]);
|
||||
j += sprintf(ascii + j, "%c", data()[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else if(isunicodestring(data, maxlen))
|
||||
else if(isunicodestring(data(), maxlen))
|
||||
{
|
||||
if(type)
|
||||
*type = str_unicode;
|
||||
int len = (int)wcslen((const wchar_t*)data);
|
||||
int len = (int)wcslen((const wchar_t*)data());
|
||||
for(int i = 0, j = 0; i < len * 2; i += 2)
|
||||
{
|
||||
switch(data[i])
|
||||
switch(data()[i])
|
||||
{
|
||||
case '\t':
|
||||
j += sprintf(unicode + j, "\\t");
|
||||
|
@ -369,7 +368,7 @@ bool disasmgetstringat(uint addr, STRING_TYPE* type, char* ascii, char* unicode,
|
|||
j += sprintf(unicode + j, "\\\"");
|
||||
break;
|
||||
default:
|
||||
j += sprintf(unicode + j, "%c", data[i]);
|
||||
j += sprintf(unicode + j, "%c", data()[i]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -389,7 +388,7 @@ int disasmgetsize(uint addr, unsigned char* data)
|
|||
int disasmgetsize(uint addr)
|
||||
{
|
||||
char data[MAX_DISASM_BUFFER];
|
||||
if(!MemRead((void*)addr, data, sizeof(data), 0))
|
||||
if(!MemRead(addr, data, sizeof(data), 0))
|
||||
return 1;
|
||||
return disasmgetsize(addr, (unsigned char*)data);
|
||||
}
|
|
@ -8,14 +8,14 @@ public:
|
|||
// This class guarantees that the returned allocated memory
|
||||
// will always be zeroed
|
||||
//
|
||||
Memory(const char* Reason = "Memory:???")
|
||||
explicit Memory(const char* Reason = "Memory:???")
|
||||
{
|
||||
m_Ptr = nullptr;
|
||||
m_Size = 0;
|
||||
m_Reason = Reason;
|
||||
}
|
||||
|
||||
Memory(size_t Size, const char* Reason = "Memory:???")
|
||||
explicit Memory(size_t Size, const char* Reason = "Memory:???")
|
||||
{
|
||||
m_Ptr = reinterpret_cast<T>(emalloc(Size));
|
||||
m_Size = Size;
|
||||
|
@ -44,28 +44,11 @@ public:
|
|||
return m_Size;
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
operator U()
|
||||
{
|
||||
return (U)m_Ptr;
|
||||
}
|
||||
|
||||
operator T()
|
||||
{
|
||||
return m_Ptr;
|
||||
}
|
||||
|
||||
T operator()()
|
||||
{
|
||||
return m_Ptr;
|
||||
}
|
||||
|
||||
template<typename U>
|
||||
T operator+(const U & Other)
|
||||
{
|
||||
return m_Ptr + Other;
|
||||
}
|
||||
|
||||
private:
|
||||
T m_Ptr;
|
||||
size_t m_Size;
|
||||
|
|
|
@ -13,7 +13,7 @@ bool FileReader::ReadAllText(const String & fileName, String & content)
|
|||
}
|
||||
Memory<char*> filedata(filesize + 1, "FileReader::ReadAllText:filedata");
|
||||
DWORD read = 0;
|
||||
if(!ReadFile(hFile, filedata, filesize, &read, 0))
|
||||
if(!ReadFile(hFile, filedata(), filesize, &read, 0))
|
||||
return false;
|
||||
content = String(filedata());
|
||||
return true;
|
||||
|
|
|
@ -184,10 +184,10 @@ CMDRESULT cbInstrMov(int argc, char* argv[])
|
|||
b[1] = dataText[i + 1];
|
||||
int res = 0;
|
||||
sscanf_s(b, "%X", &res);
|
||||
data[j] = res;
|
||||
data()[j] = res;
|
||||
}
|
||||
//Move data to destination
|
||||
if(!MemWrite((void*)dest, data, data.size(), 0))
|
||||
if(!MemWrite(dest, data(), data.size(), 0))
|
||||
{
|
||||
dprintf("failed to write to "fhex"\n", dest);
|
||||
return STATUS_ERROR;
|
||||
|
@ -242,7 +242,7 @@ CMDRESULT cbInstrVarList(int argc, char* argv[])
|
|||
return STATUS_CONTINUE;
|
||||
}
|
||||
Memory<VAR*> variables(cbsize, "cbInstrVarList:variables");
|
||||
if(!varenum(variables, 0))
|
||||
if(!varenum(variables(), 0))
|
||||
{
|
||||
dputs("error listing variables!");
|
||||
return STATUS_ERROR;
|
||||
|
@ -251,16 +251,16 @@ CMDRESULT cbInstrVarList(int argc, char* argv[])
|
|||
int varcount = (int)cbsize / sizeof(VAR);
|
||||
for(int i = 0; i < varcount; i++)
|
||||
{
|
||||
if(variables[i].alias.length())
|
||||
if(variables()[i].alias.length())
|
||||
continue;
|
||||
char name[deflen] = "";
|
||||
strcpy_s(name, variables[i].name.c_str());
|
||||
uint value = (uint)variables[i].value.u.value;
|
||||
if(variables[i].type != VAR_HIDDEN)
|
||||
strcpy_s(name, variables()[i].name.c_str());
|
||||
uint value = (uint)variables()[i].value.u.value;
|
||||
if(variables()[i].type != VAR_HIDDEN)
|
||||
{
|
||||
if(filter)
|
||||
{
|
||||
if(variables[i].type == filter)
|
||||
if(variables()[i].type == filter)
|
||||
{
|
||||
if(value > 15)
|
||||
dprintf("%s=%"fext"X (%"fext"ud)\n", name, value, value);
|
||||
|
@ -1022,8 +1022,7 @@ CMDRESULT cbInstrGetstr(int argc, char* argv[])
|
|||
return STATUS_ERROR;
|
||||
}
|
||||
Memory<char*> string(size + 1, "cbInstrGetstr:string");
|
||||
memset(string, 0, size + 1);
|
||||
if(!varget(argv[1], (char*)string, &size, 0))
|
||||
if(!varget(argv[1], string(), &size, 0))
|
||||
{
|
||||
dprintf("failed to get variable data \"%s\"!\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
|
@ -1057,8 +1056,7 @@ CMDRESULT cbInstrCopystr(int argc, char* argv[])
|
|||
return STATUS_ERROR;
|
||||
}
|
||||
Memory<char*> string(size + 1, "cbInstrGetstr:string");
|
||||
memset(string, 0, size + 1);
|
||||
if(!varget(argv[2], (char*)string, &size, 0))
|
||||
if(!varget(argv[2], string(), &size, 0))
|
||||
{
|
||||
dprintf("failed to get variable data \"%s\"!\n", argv[2]);
|
||||
return STATUS_ERROR;
|
||||
|
@ -1069,7 +1067,7 @@ CMDRESULT cbInstrCopystr(int argc, char* argv[])
|
|||
dprintf("invalid address \"%s\"!\n", argv[1]);
|
||||
return STATUS_ERROR;
|
||||
}
|
||||
if(!MemPatch((void*)addr, string, strlen(string), 0))
|
||||
if(!MemPatch(addr, string(), strlen(string()), 0))
|
||||
{
|
||||
dputs("memwrite failed!");
|
||||
return STATUS_ERROR;
|
||||
|
@ -1107,7 +1105,7 @@ CMDRESULT cbInstrFind(int argc, char* argv[])
|
|||
return STATUS_ERROR;
|
||||
}
|
||||
Memory<unsigned char*> data(size, "cbInstrFind:data");
|
||||
if(!MemRead((void*)base, data, size, 0))
|
||||
if(!MemRead(base, data(), size, 0))
|
||||
{
|
||||
dputs("failed to read memory!");
|
||||
return STATUS_ERROR;
|
||||
|
@ -1123,7 +1121,7 @@ CMDRESULT cbInstrFind(int argc, char* argv[])
|
|||
}
|
||||
else
|
||||
find_size = size - start;
|
||||
uint foundoffset = patternfind(data + start, find_size, pattern);
|
||||
uint foundoffset = patternfind(data() + start, find_size, pattern);
|
||||
uint result = 0;
|
||||
if(foundoffset != -1)
|
||||
result = addr + foundoffset;
|
||||
|
@ -1159,7 +1157,7 @@ CMDRESULT cbInstrFindAll(int argc, char* argv[])
|
|||
return STATUS_ERROR;
|
||||
}
|
||||
Memory<unsigned char*> data(size, "cbInstrFindAll:data");
|
||||
if(!MemRead((void*)base, data, size, 0))
|
||||
if(!MemRead(base, data(), size, 0))
|
||||
{
|
||||
dputs("failed to read memory!");
|
||||
return STATUS_ERROR;
|
||||
|
@ -1207,7 +1205,7 @@ CMDRESULT cbInstrFindAll(int argc, char* argv[])
|
|||
}
|
||||
while(refCount < 5000)
|
||||
{
|
||||
uint foundoffset = patternfind(data + start + i, find_size - i, searchpattern);
|
||||
uint foundoffset = patternfind(data() + start + i, find_size - i, searchpattern);
|
||||
if(foundoffset == -1)
|
||||
break;
|
||||
i += foundoffset + 1;
|
||||
|
@ -1219,12 +1217,12 @@ CMDRESULT cbInstrFindAll(int argc, char* argv[])
|
|||
if(findData)
|
||||
{
|
||||
Memory<unsigned char*> printData(searchpattern.size(), "cbInstrFindAll:printData");
|
||||
MemRead((void*)result, printData(), printData.size(), 0);
|
||||
MemRead(result, printData(), printData.size(), 0);
|
||||
for(size_t j = 0, k = 0; j < printData.size(); j++)
|
||||
{
|
||||
if(j)
|
||||
k += sprintf(msg + k, " ");
|
||||
k += sprintf(msg + k, "%.2X", printData[j]);
|
||||
k += sprintf(msg + k, "%.2X", printData()[j]);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -1306,18 +1304,18 @@ CMDRESULT cbInstrCommentList(int argc, char* argv[])
|
|||
return STATUS_CONTINUE;
|
||||
}
|
||||
Memory<COMMENTSINFO*> comments(cbsize, "cbInstrCommentList:comments");
|
||||
CommentEnum(comments, 0);
|
||||
CommentEnum(comments(), 0);
|
||||
int count = (int)(cbsize / sizeof(COMMENTSINFO));
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
GuiReferenceSetRowCount(i + 1);
|
||||
char addrText[20] = "";
|
||||
sprintf(addrText, "%p", comments[i].addr);
|
||||
sprintf(addrText, "%p", comments()[i].addr);
|
||||
GuiReferenceSetCellContent(i, 0, addrText);
|
||||
char disassembly[GUI_MAX_DISASSEMBLY_SIZE] = "";
|
||||
if(GuiGetDisassembly(comments[i].addr, disassembly))
|
||||
if(GuiGetDisassembly(comments()[i].addr, disassembly))
|
||||
GuiReferenceSetCellContent(i, 1, disassembly);
|
||||
GuiReferenceSetCellContent(i, 2, comments[i].text);
|
||||
GuiReferenceSetCellContent(i, 2, comments()[i].text);
|
||||
}
|
||||
varset("$result", count, false);
|
||||
dprintf("%d comment(s) listed in Reference View\n", count);
|
||||
|
@ -1341,18 +1339,18 @@ CMDRESULT cbInstrLabelList(int argc, char* argv[])
|
|||
return STATUS_CONTINUE;
|
||||
}
|
||||
Memory<LABELSINFO*> labels(cbsize, "cbInstrLabelList:labels");
|
||||
LabelEnum(labels, 0);
|
||||
LabelEnum(labels(), 0);
|
||||
int count = (int)(cbsize / sizeof(LABELSINFO));
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
GuiReferenceSetRowCount(i + 1);
|
||||
char addrText[20] = "";
|
||||
sprintf(addrText, "%p", labels[i].addr);
|
||||
sprintf(addrText, "%p", labels()[i].addr);
|
||||
GuiReferenceSetCellContent(i, 0, addrText);
|
||||
char disassembly[GUI_MAX_DISASSEMBLY_SIZE] = "";
|
||||
if(GuiGetDisassembly(labels[i].addr, disassembly))
|
||||
if(GuiGetDisassembly(labels()[i].addr, disassembly))
|
||||
GuiReferenceSetCellContent(i, 1, disassembly);
|
||||
GuiReferenceSetCellContent(i, 2, labels[i].text);
|
||||
GuiReferenceSetCellContent(i, 2, labels()[i].text);
|
||||
}
|
||||
varset("$result", count, false);
|
||||
dprintf("%d label(s) listed in Reference View\n", count);
|
||||
|
@ -1375,16 +1373,16 @@ CMDRESULT cbInstrBookmarkList(int argc, char* argv[])
|
|||
return STATUS_CONTINUE;
|
||||
}
|
||||
Memory<BOOKMARKSINFO*> bookmarks(cbsize, "cbInstrBookmarkList:bookmarks");
|
||||
BookmarkEnum(bookmarks, 0);
|
||||
BookmarkEnum(bookmarks(), 0);
|
||||
int count = (int)(cbsize / sizeof(BOOKMARKSINFO));
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
GuiReferenceSetRowCount(i + 1);
|
||||
char addrText[20] = "";
|
||||
sprintf(addrText, "%p", bookmarks[i].addr);
|
||||
sprintf(addrText, "%p", bookmarks()[i].addr);
|
||||
GuiReferenceSetCellContent(i, 0, addrText);
|
||||
char disassembly[GUI_MAX_DISASSEMBLY_SIZE] = "";
|
||||
if(GuiGetDisassembly(bookmarks[i].addr, disassembly))
|
||||
if(GuiGetDisassembly(bookmarks()[i].addr, disassembly))
|
||||
GuiReferenceSetCellContent(i, 1, disassembly);
|
||||
}
|
||||
varset("$result", count, false);
|
||||
|
@ -1410,26 +1408,26 @@ CMDRESULT cbInstrFunctionList(int argc, char* argv[])
|
|||
return STATUS_CONTINUE;
|
||||
}
|
||||
Memory<FUNCTIONSINFO*> functions(cbsize, "cbInstrFunctionList:functions");
|
||||
FunctionEnum(functions, 0);
|
||||
FunctionEnum(functions(), 0);
|
||||
int count = (int)(cbsize / sizeof(FUNCTIONSINFO));
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
GuiReferenceSetRowCount(i + 1);
|
||||
char addrText[20] = "";
|
||||
sprintf(addrText, "%p", functions[i].start);
|
||||
sprintf(addrText, "%p", functions()[i].start);
|
||||
GuiReferenceSetCellContent(i, 0, addrText);
|
||||
sprintf(addrText, "%p", functions[i].end);
|
||||
sprintf(addrText, "%p", functions()[i].end);
|
||||
GuiReferenceSetCellContent(i, 1, addrText);
|
||||
char disassembly[GUI_MAX_DISASSEMBLY_SIZE] = "";
|
||||
if(GuiGetDisassembly(functions[i].start, disassembly))
|
||||
if(GuiGetDisassembly(functions()[i].start, disassembly))
|
||||
GuiReferenceSetCellContent(i, 2, disassembly);
|
||||
char label[MAX_LABEL_SIZE] = "";
|
||||
if(LabelGet(functions[i].start, label))
|
||||
if(LabelGet(functions()[i].start, label))
|
||||
GuiReferenceSetCellContent(i, 3, label);
|
||||
else
|
||||
{
|
||||
char comment[MAX_COMMENT_SIZE] = "";
|
||||
if(CommentGet(functions[i].start, comment))
|
||||
if(CommentGet(functions()[i].start, comment))
|
||||
GuiReferenceSetCellContent(i, 3, comment);
|
||||
}
|
||||
}
|
||||
|
@ -1456,26 +1454,26 @@ CMDRESULT cbInstrLoopList(int argc, char* argv[])
|
|||
return STATUS_CONTINUE;
|
||||
}
|
||||
Memory<LOOPSINFO*> loops(cbsize, "cbInstrLoopList:loops");
|
||||
LoopEnum(loops, 0);
|
||||
LoopEnum(loops(), 0);
|
||||
int count = (int)(cbsize / sizeof(LOOPSINFO));
|
||||
for(int i = 0; i < count; i++)
|
||||
{
|
||||
GuiReferenceSetRowCount(i + 1);
|
||||
char addrText[20] = "";
|
||||
sprintf(addrText, "%p", loops[i].start);
|
||||
sprintf(addrText, "%p", loops()[i].start);
|
||||
GuiReferenceSetCellContent(i, 0, addrText);
|
||||
sprintf(addrText, "%p", loops[i].end);
|
||||
sprintf(addrText, "%p", loops()[i].end);
|
||||
GuiReferenceSetCellContent(i, 1, addrText);
|
||||
char disassembly[GUI_MAX_DISASSEMBLY_SIZE] = "";
|
||||
if(GuiGetDisassembly(loops[i].start, disassembly))
|
||||
if(GuiGetDisassembly(loops()[i].start, disassembly))
|
||||
GuiReferenceSetCellContent(i, 2, disassembly);
|
||||
char label[MAX_LABEL_SIZE] = "";
|
||||
if(LabelGet(loops[i].start, label))
|
||||
if(LabelGet(loops()[i].start, label))
|
||||
GuiReferenceSetCellContent(i, 3, label);
|
||||
else
|
||||
{
|
||||
char comment[MAX_COMMENT_SIZE] = "";
|
||||
if(CommentGet(loops[i].start, comment))
|
||||
if(CommentGet(loops()[i].start, comment))
|
||||
GuiReferenceSetCellContent(i, 3, comment);
|
||||
}
|
||||
}
|
||||
|
@ -1714,7 +1712,7 @@ CMDRESULT cbInstrYara(int argc, char* argv[])
|
|||
base = addr;
|
||||
}
|
||||
Memory<uint8_t*> data(size);
|
||||
if(!MemRead((void*)base, data(), size, 0))
|
||||
if(!MemRead(base, data(), size, 0))
|
||||
{
|
||||
dprintf("failed to read memory page %p[%X]!\n", base, size);
|
||||
return STATUS_ERROR;
|
||||
|
@ -1844,7 +1842,7 @@ CMDRESULT cbInstrCapstone(int argc, char* argv[])
|
|||
}
|
||||
|
||||
unsigned char data[16];
|
||||
if(!MemRead((void*)addr, data, sizeof(data), 0))
|
||||
if(!MemRead(addr, data, sizeof(data), 0))
|
||||
{
|
||||
dprintf("could not read memory at %p\n", addr);
|
||||
return STATUS_ERROR;
|
||||
|
@ -1965,7 +1963,7 @@ CMDRESULT cbInstrVisualize(int argc, char* argv[])
|
|||
uint _base = start;
|
||||
uint _size = maxaddr - start;
|
||||
Memory<unsigned char*> _data(_size);
|
||||
MemRead((void*)_base, _data(), _size, nullptr);
|
||||
MemRead(_base, _data(), _size, nullptr);
|
||||
FunctionClear();
|
||||
|
||||
//linear search with some trickery
|
||||
|
@ -1988,7 +1986,7 @@ CMDRESULT cbInstrVisualize(int argc, char* argv[])
|
|||
Sleep(300);
|
||||
|
||||
//continue algorithm
|
||||
const unsigned char* curData = (addr >= _base && addr < _base + _size) ? _data + (addr - _base) : nullptr;
|
||||
const unsigned char* curData = (addr >= _base && addr < _base + _size) ? _data() + (addr - _base) : nullptr;
|
||||
if(_cp.Disassemble(addr, curData, MAX_DISASM_BUFFER))
|
||||
{
|
||||
if(addr + _cp.Size() > maxaddr) //we went past the maximum allowed address
|
||||
|
|
|
@ -174,7 +174,7 @@ uint MemFindBaseAddr(uint Address, uint* Size, bool Refresh)
|
|||
return found->first.first;
|
||||
}
|
||||
|
||||
bool MemRead(const void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesRead)
|
||||
bool MemRead(uint BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesRead)
|
||||
{
|
||||
if(!MemIsCanonicalAddress((uint)BaseAddress))
|
||||
return false;
|
||||
|
@ -228,7 +228,7 @@ bool MemRead(const void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberO
|
|||
return (*NumberOfBytesRead > 0);
|
||||
}
|
||||
|
||||
bool MemWrite(void* BaseAddress, const void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesWritten)
|
||||
bool MemWrite(uint BaseAddress, const void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesWritten)
|
||||
{
|
||||
if(!MemIsCanonicalAddress((uint)BaseAddress))
|
||||
return false;
|
||||
|
@ -244,7 +244,7 @@ bool MemWrite(void* BaseAddress, const void* Buffer, SIZE_T Size, SIZE_T* Number
|
|||
NumberOfBytesWritten = &bytesWrittenTemp;
|
||||
|
||||
// Try a regular WriteProcessMemory call
|
||||
bool ret = MemoryWriteSafe(fdProcessInfo->hProcess, BaseAddress, Buffer, Size, NumberOfBytesWritten);
|
||||
bool ret = MemoryWriteSafe(fdProcessInfo->hProcess, (LPVOID)BaseAddress, Buffer, Size, NumberOfBytesWritten);
|
||||
|
||||
if(ret && *NumberOfBytesWritten == Size)
|
||||
return true;
|
||||
|
@ -282,7 +282,7 @@ bool MemWrite(void* BaseAddress, const void* Buffer, SIZE_T Size, SIZE_T* Number
|
|||
return (*NumberOfBytesWritten > 0);
|
||||
}
|
||||
|
||||
bool MemPatch(void* BaseAddress, const void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesWritten)
|
||||
bool MemPatch(uint BaseAddress, const void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesWritten)
|
||||
{
|
||||
// Buffer and size must be valid
|
||||
if(!Buffer || Size <= 0)
|
||||
|
@ -307,7 +307,7 @@ bool MemPatch(void* BaseAddress, const void* Buffer, SIZE_T Size, SIZE_T* Number
|
|||
bool MemIsValidReadPtr(uint Address)
|
||||
{
|
||||
unsigned char a = 0;
|
||||
return MemRead((const void*)Address, &a, sizeof(unsigned char), nullptr);
|
||||
return MemRead(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(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 MemRead(uint BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesRead);
|
||||
bool MemWrite(uint BaseAddress, const void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesWritten);
|
||||
bool MemPatch(uint 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);
|
||||
|
|
|
@ -106,7 +106,7 @@ bool PatchDelete(uint Address, bool Restore)
|
|||
|
||||
// Restore the original byte at this address
|
||||
if(Restore)
|
||||
MemWrite((void*)(found->second.addr + ModBaseFromAddr(Address)), &found->second.oldbyte, sizeof(char), nullptr);
|
||||
MemWrite((found->second.addr + ModBaseFromAddr(Address)), &found->second.oldbyte, sizeof(char), nullptr);
|
||||
|
||||
// Finally remove it from the list
|
||||
patches.erase(found);
|
||||
|
@ -147,7 +147,7 @@ void PatchDelRange(uint Start, uint End, bool Restore)
|
|||
{
|
||||
// Restore the original byte if necessary
|
||||
if(Restore)
|
||||
MemWrite((void*)(currentPatch.addr + moduleBase), ¤tPatch.oldbyte, sizeof(char), nullptr);
|
||||
MemWrite((currentPatch.addr + moduleBase), ¤tPatch.oldbyte, sizeof(char), nullptr);
|
||||
|
||||
itr = patches.erase(itr);
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ int RefFind(uint Address, uint Size, CBREF Callback, void* UserData, bool Silent
|
|||
// Allocate and read a buffer from the remote process
|
||||
Memory<unsigned char*> data(scanSize, "reffind:data");
|
||||
|
||||
if(!MemRead((PVOID)scanStart, data, scanSize, nullptr))
|
||||
if(!MemRead(scanStart, data(), scanSize, nullptr))
|
||||
{
|
||||
if(!Silent)
|
||||
dprintf("Error reading memory in reference search\n");
|
||||
|
|
|
@ -87,22 +87,21 @@ static bool scriptcreatelinemap(const char* filename)
|
|||
return false;
|
||||
}
|
||||
Memory<char*> filedata(filesize + 1, "createlinemap:filedata");
|
||||
memset(filedata, 0, filesize + 1);
|
||||
DWORD read = 0;
|
||||
if(!ReadFile(hFile, filedata, filesize, &read, 0))
|
||||
if(!ReadFile(hFile, filedata(), filesize, &read, 0))
|
||||
{
|
||||
GuiScriptError(0, "ReadFile failed...");
|
||||
return false;
|
||||
}
|
||||
hFile.Close();
|
||||
int len = (int)strlen(filedata);
|
||||
int len = (int)strlen(filedata());
|
||||
char temp[256] = "";
|
||||
LINEMAPENTRY entry;
|
||||
memset(&entry, 0, sizeof(entry));
|
||||
std::vector<LINEMAPENTRY>().swap(linemap);
|
||||
for(int i = 0, j = 0; i < len; i++) //make raw line map
|
||||
{
|
||||
if(filedata[i] == '\r' && filedata[i + 1] == '\n') //windows file
|
||||
if(filedata()[i] == '\r' && filedata()[i + 1] == '\n') //windows file
|
||||
{
|
||||
memset(&entry, 0, sizeof(entry));
|
||||
int add = 0;
|
||||
|
@ -114,7 +113,7 @@ static bool scriptcreatelinemap(const char* filename)
|
|||
i++;
|
||||
linemap.push_back(entry);
|
||||
}
|
||||
else if(filedata[i] == '\n') //other file
|
||||
else if(filedata()[i] == '\n') //other file
|
||||
{
|
||||
memset(&entry, 0, sizeof(entry));
|
||||
int add = 0;
|
||||
|
@ -137,7 +136,7 @@ static bool scriptcreatelinemap(const char* filename)
|
|||
linemap.push_back(entry);
|
||||
}
|
||||
else
|
||||
j += sprintf(temp + j, "%c", filedata[i]);
|
||||
j += sprintf(temp + j, "%c", filedata()[i]);
|
||||
}
|
||||
if(*temp)
|
||||
{
|
||||
|
|
|
@ -15,7 +15,7 @@ bool stackcommentget(uint addr, STACK_COMMENT* comment)
|
|||
{
|
||||
uint data = 0;
|
||||
memset(comment, 0, sizeof(STACK_COMMENT));
|
||||
MemRead((void*)addr, &data, sizeof(uint), 0);
|
||||
MemRead(addr, &data, sizeof(uint), 0);
|
||||
if(!MemIsValidReadPtr(data)) //the stack value is no pointer
|
||||
return false;
|
||||
|
||||
|
@ -25,7 +25,7 @@ bool stackcommentget(uint addr, STACK_COMMENT* comment)
|
|||
if(readStart < base)
|
||||
readStart = base;
|
||||
unsigned char disasmData[256];
|
||||
MemRead((void*)readStart, disasmData, sizeof(disasmData), 0);
|
||||
MemRead(readStart, disasmData, sizeof(disasmData), 0);
|
||||
uint prev = disasmback(disasmData, 0, sizeof(disasmData), data - readStart, 1);
|
||||
uint previousInstr = readStart + prev;
|
||||
|
||||
|
@ -126,7 +126,7 @@ void stackgetcallstack(uint csp, CALLSTACK* callstack)
|
|||
while(i != stackbase + stacksize)
|
||||
{
|
||||
uint data = 0;
|
||||
MemRead((void*)i, &data, sizeof(uint), 0);
|
||||
MemRead(i, &data, sizeof(uint), 0);
|
||||
if(MemIsValidReadPtr(data)) //the stack value is a pointer
|
||||
{
|
||||
uint size = 0;
|
||||
|
@ -135,7 +135,7 @@ void stackgetcallstack(uint csp, CALLSTACK* callstack)
|
|||
if(readStart < base)
|
||||
readStart = base;
|
||||
unsigned char disasmData[256];
|
||||
MemRead((void*)readStart, disasmData, sizeof(disasmData), 0);
|
||||
MemRead(readStart, disasmData, sizeof(disasmData), 0);
|
||||
uint prev = disasmback(disasmData, 0, sizeof(disasmData), data - readStart, 1);
|
||||
uint previousInstr = readStart + prev;
|
||||
BASIC_INSTRUCTION_INFO basicinfo;
|
||||
|
|
|
@ -123,7 +123,7 @@ bool ThreadGetTeb(uint TEBAddress, TEB* Teb)
|
|||
//
|
||||
memset(Teb, 0, sizeof(TEB));
|
||||
|
||||
return MemRead((void*)TEBAddress, Teb, sizeof(TEB), nullptr);
|
||||
return MemRead(TEBAddress, Teb, sizeof(TEB), nullptr);
|
||||
}
|
||||
|
||||
int ThreadGetSuspendCount(HANDLE Thread)
|
||||
|
|
|
@ -1387,12 +1387,12 @@ bool valapifromstring(const char* name, uint* value, int* value_size, bool print
|
|||
{
|
||||
addrfound.realloc(cbNeeded * sizeof(uint), "valapifromstring:addrfound");
|
||||
Memory<HMODULE*> hMods(cbNeeded * sizeof(HMODULE), "valapifromstring:hMods");
|
||||
if(EnumProcessModules(fdProcessInfo->hProcess, hMods, cbNeeded, &cbNeeded))
|
||||
if(EnumProcessModules(fdProcessInfo->hProcess, hMods(), cbNeeded, &cbNeeded))
|
||||
{
|
||||
for(unsigned int i = 0; i < cbNeeded / sizeof(HMODULE); i++)
|
||||
{
|
||||
wchar_t szModuleName[MAX_PATH] = L"";
|
||||
if(GetModuleFileNameExW(fdProcessInfo->hProcess, hMods[i], szModuleName, MAX_PATH))
|
||||
if(GetModuleFileNameExW(fdProcessInfo->hProcess, hMods()[i], szModuleName, MAX_PATH))
|
||||
{
|
||||
wchar_t* szBaseName = wcsrchr(szModuleName, L'\\');
|
||||
if(szBaseName)
|
||||
|
@ -1407,7 +1407,7 @@ bool valapifromstring(const char* name, uint* value, int* value_size, bool print
|
|||
if(!_wcsicmp(szBaseName, L"kernel32.dll"))
|
||||
kernel32 = found;
|
||||
uint rva = funcAddress - (uint)hModule;
|
||||
addrfound[found] = (uint)hMods[i] + rva;
|
||||
addrfound()[found] = (uint)hMods()[i] + rva;
|
||||
found++;
|
||||
}
|
||||
FreeLibrary(hModule);
|
||||
|
@ -1425,20 +1425,20 @@ bool valapifromstring(const char* name, uint* value, int* value_size, bool print
|
|||
*hexonly = true;
|
||||
if(kernel32 != -1) //prioritize kernel32 exports
|
||||
{
|
||||
*value = addrfound[kernel32];
|
||||
*value = addrfound()[kernel32];
|
||||
if(!printall || silent)
|
||||
return true;
|
||||
for(int i = 0; i < found; i++)
|
||||
if(i != kernel32)
|
||||
dprintf(fhex"\n", addrfound[i]);
|
||||
dprintf(fhex"\n", addrfound()[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
*value = *addrfound;
|
||||
*value = *addrfound();
|
||||
if(!printall || silent)
|
||||
return true;
|
||||
for(int i = 1; i < found; i++)
|
||||
dprintf(fhex"\n", addrfound[i]);
|
||||
dprintf(fhex"\n", addrfound()[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -1550,7 +1550,7 @@ bool valfromstring_noexpr(const char* string, uint* value, bool silent, bool bas
|
|||
}
|
||||
uint addr = *value;
|
||||
*value = 0;
|
||||
if(!MemRead((void*)addr, value, read_size, 0))
|
||||
if(!MemRead(addr, value, read_size, 0))
|
||||
{
|
||||
if(!silent)
|
||||
dputs("failed to read memory");
|
||||
|
@ -2122,36 +2122,36 @@ bool valtostring(const char* string, uint value, bool silent)
|
|||
for(int i = 0, j = 0; i < len; i++)
|
||||
{
|
||||
if(string[i] == ']')
|
||||
j += sprintf(newstring + j, ")");
|
||||
j += sprintf(newstring() + j, ")");
|
||||
else if(isdigit(string[i]) && string[i + 1] == ':' && string[i + 2] == '[') //n:[
|
||||
{
|
||||
j += sprintf(newstring + j, "@%c:(", string[i]);
|
||||
j += sprintf(newstring() + j, "@%c:(", string[i]);
|
||||
i += 2;
|
||||
}
|
||||
else if(string[i] == '[')
|
||||
j += sprintf(newstring + j, "@(");
|
||||
j += sprintf(newstring() + j, "@(");
|
||||
else
|
||||
j += sprintf(newstring + j, "%c", string[i]);
|
||||
j += sprintf(newstring() + j, "%c", string[i]);
|
||||
}
|
||||
}
|
||||
else
|
||||
strcpy_s(newstring, len * 2, string);
|
||||
strcpy_s(newstring(), len * 2, string);
|
||||
int read_size = sizeof(uint);
|
||||
int add = 1;
|
||||
if(newstring[2] == ':' && isdigit((newstring[1])))
|
||||
if(newstring()[2] == ':' && isdigit((newstring()[1])))
|
||||
{
|
||||
add += 2;
|
||||
int new_size = newstring[1] - 0x30;
|
||||
int new_size = newstring()[1] - 0x30;
|
||||
if(new_size < read_size)
|
||||
read_size = new_size;
|
||||
}
|
||||
uint temp;
|
||||
if(!valfromstring(newstring + add, &temp, silent, false))
|
||||
if(!valfromstring(newstring() + add, &temp, silent, false))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
uint value_ = value;
|
||||
if(!MemPatch((void*)temp, &value_, read_size, 0))
|
||||
if(!MemPatch(temp, &value_, read_size, 0))
|
||||
{
|
||||
if(!silent)
|
||||
dputs("failed to write memory");
|
||||
|
@ -2172,11 +2172,11 @@ bool valtostring(const char* string, uint value, bool silent)
|
|||
bool ok = setregister(string, value);
|
||||
int len = (int)strlen(string);
|
||||
Memory<char*> regName(len + 1, "valtostring:regname");
|
||||
strcpy_s(regName, len + 1, string);
|
||||
_strlwr(regName);
|
||||
if(strstr(regName, "ip"))
|
||||
strcpy_s(regName(), len + 1, string);
|
||||
_strlwr(regName());
|
||||
if(strstr(regName(), "ip"))
|
||||
DebugUpdateGui(GetContextDataEx(hActiveThread, UE_CIP), false); //update disassembly + register view
|
||||
else if(strstr(regName, "sp")) //update stack
|
||||
else if(strstr(regName(), "sp")) //update stack
|
||||
{
|
||||
uint csp = GetContextDataEx(hActiveThread, UE_CSP);
|
||||
GuiStackDumpAt(csp, csp);
|
||||
|
|
Loading…
Reference in New Issue