DBG: changed memory functions back to uint because the pointers are not valid in the debugger process anyway
This commit is contained in:
parent
3789fad460
commit
c44c89f59e
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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;
|
||||
}
|
|
@ -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));
|
||||
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();
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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,14 +1040,14 @@ 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);
|
||||
dprintf("SetThreadName(%X, \"%s\")\n", 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;
|
||||
|
@ -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,7 +1995,7 @@ 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;
|
||||
|
|
|
@ -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));
|
||||
|
@ -295,7 +295,7 @@ bool disasmgetstringat(uint addr, STRING_TYPE* type, char* ascii, char* unicode,
|
|||
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));
|
||||
|
@ -389,7 +389,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);
|
||||
}
|
|
@ -187,7 +187,7 @@ CMDRESULT cbInstrMov(int argc, char* argv[])
|
|||
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;
|
||||
|
@ -1069,7 +1069,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 +1107,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;
|
||||
|
@ -1159,7 +1159,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;
|
||||
|
@ -1219,7 +1219,7 @@ 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)
|
||||
|
@ -1714,7 +1714,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 +1844,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 +1965,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
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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");
|
||||
|
@ -2151,7 +2151,7 @@ bool valtostring(const char* string, uint value, bool silent)
|
|||
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");
|
||||
|
|
Loading…
Reference in New Issue