1
0
Fork 0

Stylize code

This commit is contained in:
Nukem 2015-04-04 21:49:09 -04:00
parent f2edbfa95a
commit 0d31badd62
23 changed files with 302 additions and 302 deletions

View File

@ -65,13 +65,13 @@ static bool _patchget(duint addr)
static bool _patchinrange(duint start, duint end)
{
if(start > end)
std::swap(start, end);
std::swap(start, end);
for (duint i = start; i <= end; i++)
{
if (_patchget(i))
return true;
}
for (duint i = start; i <= end; i++)
{
if (_patchget(i))
return true;
}
return false;
}
@ -83,8 +83,8 @@ static bool _mempatch(duint va, const unsigned char* src, duint size)
static void _patchrestorerange(duint start, duint end)
{
if (start > end)
std::swap(start, end);
if (start > end)
std::swap(start, end);
for(duint i = start; i <= end; i++)
PatchDelete(i, true);

View File

@ -55,16 +55,16 @@ extern "C" DLL_EXPORT bool _dbg_memmap(MEMMAP* memmap)
if(!pagecount)
return true;
// Allocate memory that is already zeroed
// Allocate memory that is already zeroed
memmap->page = (MEMPAGE*)BridgeAlloc(sizeof(MEMPAGE) * pagecount);
// Copy all elements over
// Copy all elements over
int i = 0;
for (auto& itr : memoryPages)
memcpy(&memmap->page[i++], &itr.second, sizeof(MEMPAGE));
for (auto& itr : memoryPages)
memcpy(&memmap->page[i++], &itr.second, sizeof(MEMPAGE));
// Done
// Done
return true;
}
@ -513,7 +513,7 @@ extern "C" DLL_EXPORT bool _dbg_getregdump(REGDUMP* regdump)
extern "C" DLL_EXPORT bool _dbg_valtostring(const char* string, duint value)
{
return valtostring(string, value, true);
return valtostring(string, value, true);
}
extern "C" DLL_EXPORT int _dbg_getbplist(BPXTYPE type, BPMAP* bpmap)

View File

@ -36,8 +36,8 @@ PLUG_IMPEXP void _plugin_logprintf(const char* format, ...)
va_list args;
va_start(args, format);
dprintf_args(format, args);
va_end(args);
dprintf_args(format, args);
va_end(args);
}
PLUG_IMPEXP void _plugin_logputs(const char* text)

View File

@ -20,10 +20,10 @@ void dputs(const char* Text)
*/
void dprintf(const char* Format, ...)
{
va_list args;
va_list args;
va_start(args, Format);
dprintf_args(Format, args);
dprintf_args(Format, args);
va_end(args);
}
@ -34,8 +34,8 @@ void dprintf(const char* Format, ...)
*/
void dprintf_args(const char* Format, va_list Args)
{
char buffer[16384];
vsnprintf_s(buffer, _TRUNCATE, Format, Args);
char buffer[16384];
vsnprintf_s(buffer, _TRUNCATE, Format, Args);
GuiAddLogMessage(buffer);
GuiAddLogMessage(buffer);
}

View File

@ -3,65 +3,65 @@
#include "threading.h"
DWORD
SafeUnDecorateSymbolName(
SafeUnDecorateSymbolName(
__in PCSTR name,
__out_ecount(maxStringLength) PSTR outputString,
__in DWORD maxStringLength,
__in DWORD flags
)
)
{
// NOTE: Disabled because of potential recursive deadlocks
// EXCLUSIVE_ACQUIRE(LockSym);
// NOTE: Disabled because of potential recursive deadlocks
// EXCLUSIVE_ACQUIRE(LockSym);
return UnDecorateSymbolName(name, outputString, maxStringLength, flags);
}
BOOL
SafeSymUnloadModule64(
SafeSymUnloadModule64(
__in HANDLE hProcess,
__in DWORD64 BaseOfDll
)
)
{
EXCLUSIVE_ACQUIRE(LockSym);
return SymUnloadModule64(hProcess, BaseOfDll);
}
BOOL
SafeSymSetSearchPath(
SafeSymSetSearchPath(
__in HANDLE hProcess,
__in_opt PCSTR SearchPath
)
)
{
EXCLUSIVE_ACQUIRE(LockSym);
return SymSetSearchPath(hProcess, SearchPath);
}
DWORD
SafeSymSetOptions(
SafeSymSetOptions(
__in DWORD SymOptions
)
)
{
EXCLUSIVE_ACQUIRE(LockSym);
return SymSetOptions(SymOptions);
}
BOOL
SafeSymInitialize(
SafeSymInitialize(
__in HANDLE hProcess,
__in_opt PCSTR UserSearchPath,
__in BOOL fInvadeProcess
)
)
{
EXCLUSIVE_ACQUIRE(LockSym);
return SymInitialize(hProcess, UserSearchPath, fInvadeProcess);
}
BOOL
SafeSymRegisterCallback64(
SafeSymRegisterCallback64(
__in HANDLE hProcess,
__in PSYMBOL_REGISTERED_CALLBACK64 CallbackFunction,
__in ULONG64 UserContext
)
)
{
EXCLUSIVE_ACQUIRE(LockSym);
return SymRegisterCallback64(hProcess, CallbackFunction, UserContext);
}
DWORD64
SafeSymLoadModuleEx(
SafeSymLoadModuleEx(
__in HANDLE hProcess,
__in_opt HANDLE hFile,
__in_opt PCSTR ImageName,
@ -70,89 +70,89 @@ DWORD64
__in DWORD DllSize,
__in_opt PMODLOAD_DATA Data,
__in_opt DWORD Flags
)
)
{
EXCLUSIVE_ACQUIRE(LockSym);
return SymLoadModuleEx(hProcess, hFile, ImageName, ModuleName, BaseOfDll, DllSize, Data, Flags);
}
BOOL
SafeSymGetModuleInfo64(
SafeSymGetModuleInfo64(
__in HANDLE hProcess,
__in DWORD64 qwAddr,
__out PIMAGEHLP_MODULE64 ModuleInfo
)
)
{
EXCLUSIVE_ACQUIRE(LockSym);
return SymGetModuleInfo64(hProcess, qwAddr, ModuleInfo);
}
BOOL
SafeSymGetSearchPath(
SafeSymGetSearchPath(
__in HANDLE hProcess,
__out_ecount(SearchPathLength) PSTR SearchPath,
__in DWORD SearchPathLength
)
)
{
EXCLUSIVE_ACQUIRE(LockSym);
return SymGetSearchPath(hProcess, SearchPath, SearchPathLength);
}
BOOL
SafeSymEnumSymbols(
SafeSymEnumSymbols(
__in HANDLE hProcess,
__in ULONG64 BaseOfDll,
__in_opt PCSTR Mask,
__in PSYM_ENUMERATESYMBOLS_CALLBACK EnumSymbolsCallback,
__in_opt PVOID UserContext
)
)
{
EXCLUSIVE_ACQUIRE(LockSym);
return SymEnumSymbols(hProcess, BaseOfDll, Mask, EnumSymbolsCallback, UserContext);
}
BOOL
SafeSymEnumerateModules64(
__in HANDLE hProcess,
__in PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,
__in_opt PVOID UserContext
)
SafeSymEnumerateModules64(
__in HANDLE hProcess,
__in PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,
__in_opt PVOID UserContext
)
{
EXCLUSIVE_ACQUIRE(LockSym);
return SymEnumerateModules64(hProcess, EnumModulesCallback, UserContext);
EXCLUSIVE_ACQUIRE(LockSym);
return SymEnumerateModules64(hProcess, EnumModulesCallback, UserContext);
}
BOOL
SafeSymGetLineFromAddr64(
SafeSymGetLineFromAddr64(
__in HANDLE hProcess,
__in DWORD64 qwAddr,
__out PDWORD pdwDisplacement,
__out PIMAGEHLP_LINE64 Line64
)
)
{
EXCLUSIVE_ACQUIRE(LockSym);
return SymGetLineFromAddr64(hProcess, qwAddr, pdwDisplacement, Line64);
}
BOOL
SafeSymFromName(
SafeSymFromName(
__in HANDLE hProcess,
__in PCSTR Name,
__inout PSYMBOL_INFO Symbol
)
)
{
EXCLUSIVE_ACQUIRE(LockSym);
return SymFromName(hProcess, Name, Symbol);
}
BOOL
SafeSymFromAddr(
SafeSymFromAddr(
__in HANDLE hProcess,
__in DWORD64 Address,
__out_opt PDWORD64 Displacement,
__inout PSYMBOL_INFO Symbol
)
)
{
EXCLUSIVE_ACQUIRE(LockSym);
return SymFromAddr(hProcess, Address, Displacement, Symbol);
}
BOOL
SafeSymCleanup(
SafeSymCleanup(
__in HANDLE hProcess
)
)
{
EXCLUSIVE_ACQUIRE(LockSym);
return SymCleanup(hProcess);

View File

@ -73,9 +73,9 @@ SafeSymEnumSymbols(
);
BOOL
SafeSymEnumerateModules64(
__in HANDLE hProcess,
__in PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,
__in_opt PVOID UserContext
__in HANDLE hProcess,
__in PSYM_ENUMMODULES_CALLBACK64 EnumModulesCallback,
__in_opt PVOID UserContext
);
BOOL
SafeSymGetLineFromAddr64(

View File

@ -189,18 +189,18 @@ DWORD WINAPI updateCallStackThread(void* ptr)
void DebugUpdateGui(uint disasm_addr, bool stack)
{
uint cip = GetContextDataEx(hActiveThread, UE_CIP);
if (MemIsValidReadPtr(disasm_addr))
{
if (bEnableSourceDebugging)
{
char szSourceFile[MAX_STRING_SIZE] = "";
int line = 0;
if (SymGetSourceLine(cip, szSourceFile, &line))
GuiLoadSourceFile(szSourceFile, line);
}
GuiDisasmAt(disasm_addr, cip);
}
uint cip = GetContextDataEx(hActiveThread, UE_CIP);
if (MemIsValidReadPtr(disasm_addr))
{
if (bEnableSourceDebugging)
{
char szSourceFile[MAX_STRING_SIZE] = "";
int line = 0;
if (SymGetSourceLine(cip, szSourceFile, &line))
GuiLoadSourceFile(szSourceFile, line);
}
GuiDisasmAt(disasm_addr, cip);
}
uint csp = GetContextDataEx(hActiveThread, UE_CSP);
if(stack)
GuiStackDumpAt(csp, csp);

View File

@ -4,45 +4,45 @@ template<typename T>
class Memory
{
public:
//
// This class guarantees that the returned allocated memory
// will always be zeroed
//
//
// This class guarantees that the returned allocated memory
// will always be zeroed
//
Memory(const char* Reason = "Memory:???")
{
m_Ptr = nullptr;
m_Size = 0;
m_Reason = Reason;
m_Ptr = nullptr;
m_Size = 0;
m_Reason = Reason;
}
Memory(size_t Size, const char* Reason = "Memory:???")
{
m_Ptr = reinterpret_cast<T>(emalloc(Size));
m_Size = Size;
m_Reason = Reason;
m_Ptr = reinterpret_cast<T>(emalloc(Size));
m_Size = Size;
m_Reason = Reason;
memset(m_Ptr, 0, Size);
}
~Memory()
{
if (m_Ptr)
efree(m_Ptr);
if (m_Ptr)
efree(m_Ptr);
}
T realloc(size_t Size, const char* Reason = "Memory:???")
{
m_Ptr = reinterpret_cast<T>(erealloc(m_Ptr, Size));
m_Size = Size;
m_Reason = Reason;
m_Ptr = reinterpret_cast<T>(erealloc(m_Ptr, Size));
m_Size = Size;
m_Reason = Reason;
return (T)memset(m_Ptr, 0, m_Size);
}
size_t size()
{
return m_Size;
}
size_t size()
{
return m_Size;
}
template<typename U>
operator U()
@ -60,14 +60,14 @@ public:
return m_Ptr;
}
template<typename U>
T operator+(const U& Other)
{
return m_Ptr + Other;
}
template<typename U>
T operator+(const U& Other)
{
return m_Ptr + Other;
}
private:
T m_Ptr;
size_t m_Size;
T m_Ptr;
size_t m_Size;
const char* m_Reason;
};

View File

@ -5,7 +5,7 @@ std::unordered_map<unsigned int, const char*> ErrorNames;
void ErrorCodeInit()
{
ErrorNames.clear();
ErrorNames.clear();
ErrorNames.insert(std::make_pair(0, "ERROR_SUCCESS"));
ErrorNames.insert(std::make_pair(1, "ERROR_INVALID_FUNCTION"));
ErrorNames.insert(std::make_pair(2, "ERROR_FILE_NOT_FOUND"));

View File

@ -5,7 +5,7 @@ std::unordered_map<unsigned int, const char*> ExceptionNames;
void ExceptionCodeInit()
{
ExceptionNames.clear();
ExceptionNames.clear();
ExceptionNames.insert(std::make_pair(0x04242420, "CLRDBG_NOTIFICATION_EXCEPTION_CODE"));
ExceptionNames.insert(std::make_pair(0x40000005, "STATUS_SEGMENT_NOTIFICATION"));
ExceptionNames.insert(std::make_pair(0x4000001C, "STATUS_WX86_UNSIMULATE"));

View File

@ -100,7 +100,7 @@ void FunctionDelRange(uint Start, uint End)
return;
// Should all functions be deleted?
// 0x00000000 - 0xFFFFFFFF
// 0x00000000 - 0xFFFFFFFF
if(Start == 0 && End == ~0)
{
EXCLUSIVE_ACQUIRE(LockFunctions);
@ -185,7 +185,7 @@ void FunctionCacheLoad(JSON Root)
json_array_foreach(Object, i, value)
{
FUNCTIONSINFO functionInfo;
memset(&functionInfo, 0, sizeof(FUNCTIONSINFO));
memset(&functionInfo, 0, sizeof(FUNCTIONSINFO));
// Copy module name
const char* mod = json_string_value(json_object_get(value, "module"));
@ -212,11 +212,11 @@ void FunctionCacheLoad(JSON Root)
const JSON jsonFunctions = json_object_get(Root, "functions");
const JSON jsonAutoFunctions = json_object_get(Root, "autofunctions");
// Manual
// Manual
if(jsonFunctions)
InsertFunctions(jsonFunctions, true);
// Auto
// Auto
if(jsonAutoFunctions)
InsertFunctions(jsonAutoFunctions, false);
}

View File

@ -514,4 +514,4 @@ bool mathfromstring(const char* string, uint* value, bool silent, bool baseonly,
else
math_ok = mathdounsignedoperation(string[highestop_pos], left, right, value);
return math_ok;
}
}

View File

@ -11,11 +11,11 @@
#include "threading.h"
#include "module.h"
#define PAGE_SHIFT (12)
#define PAGE_SIZE (4096)
#define PAGE_ALIGN(Va) ((ULONG_PTR)((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
#define BYTES_TO_PAGES(Size) (((Size) >> PAGE_SHIFT) + (((Size) & (PAGE_SIZE - 1)) != 0))
#define ROUND_TO_PAGES(Size) (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
#define PAGE_SHIFT (12)
#define PAGE_SIZE (4096)
#define PAGE_ALIGN(Va) ((ULONG_PTR)((ULONG_PTR)(Va) & ~(PAGE_SIZE - 1)))
#define BYTES_TO_PAGES(Size) (((Size) >> PAGE_SHIFT) + (((Size) & (PAGE_SIZE - 1)) != 0))
#define ROUND_TO_PAGES(Size) (((ULONG_PTR)(Size) + PAGE_SIZE - 1) & ~(PAGE_SIZE - 1))
std::map<Range, MEMPAGE, RangeCompare> memoryPages;
bool bListAllPages = false;
@ -158,64 +158,64 @@ uint MemFindBaseAddr(uint Address, uint* Size, bool Refresh)
bool MemRead(void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesRead)
{
// Fast fail if address is invalid
if (!MemIsCanonicalAddress((uint)BaseAddress))
return false;
// Fast fail if address is invalid
if (!MemIsCanonicalAddress((uint)BaseAddress))
return false;
// Buffer must be supplied and size must be greater than 0
if (!Buffer || Size <= 0)
return false;
// Buffer must be supplied and size must be greater than 0
if (!Buffer || Size <= 0)
return false;
// If the 'bytes read' parameter is null, use a temp
SIZE_T bytesReadTemp = 0;
// If the 'bytes read' parameter is null, use a temp
SIZE_T bytesReadTemp = 0;
if (!NumberOfBytesRead)
NumberOfBytesRead = &bytesReadTemp;
if (!NumberOfBytesRead)
NumberOfBytesRead = &bytesReadTemp;
// Normal single-call read
bool ret = MemoryReadSafe(fdProcessInfo->hProcess, BaseAddress, Buffer, Size, NumberOfBytesRead);
// Normal single-call read
bool ret = MemoryReadSafe(fdProcessInfo->hProcess, BaseAddress, Buffer, Size, NumberOfBytesRead);
if (ret && *NumberOfBytesRead == Size)
return true;
if (ret && *NumberOfBytesRead == Size)
return true;
// Read page-by-page (Skip if only 1 page exists)
// If (SIZE > PAGE_SIZE) or (ADDRESS exceeds boundary), multiple reads will be needed
SIZE_T pageCount = BYTES_TO_PAGES(Size);
// Read page-by-page (Skip if only 1 page exists)
// If (SIZE > PAGE_SIZE) or (ADDRESS exceeds boundary), multiple reads will be needed
SIZE_T pageCount = BYTES_TO_PAGES(Size);
if (pageCount > 1)
{
// Determine the number of bytes between ADDRESS and the next page
uint offset = 0;
uint readBase = (uint)BaseAddress;
uint readSize = ROUND_TO_PAGES(readBase) - readBase;
if (pageCount > 1)
{
// Determine the number of bytes between ADDRESS and the next page
uint offset = 0;
uint readBase = (uint)BaseAddress;
uint readSize = ROUND_TO_PAGES(readBase) - readBase;
// Reset the bytes read count
*NumberOfBytesRead = 0;
// Reset the bytes read count
*NumberOfBytesRead = 0;
for (SIZE_T i = 0; i < pageCount; i++)
{
SIZE_T bytesRead = 0;
for (SIZE_T i = 0; i < pageCount; i++)
{
SIZE_T bytesRead = 0;
if (MemoryReadSafe(fdProcessInfo->hProcess, (PVOID)readBase, ((PBYTE)Buffer + offset), readSize, &bytesRead))
*NumberOfBytesRead += bytesRead;
if (MemoryReadSafe(fdProcessInfo->hProcess, (PVOID)readBase, ((PBYTE)Buffer + offset), readSize, &bytesRead))
*NumberOfBytesRead += bytesRead;
offset += readSize;
readBase += readSize;
offset += readSize;
readBase += readSize;
Size -= readSize;
readSize = (Size > PAGE_SIZE) ? PAGE_SIZE : Size;
}
}
Size -= readSize;
readSize = (Size > PAGE_SIZE) ? PAGE_SIZE : Size;
}
}
SetLastError(ERROR_PARTIAL_COPY);
SetLastError(ERROR_PARTIAL_COPY);
return (*NumberOfBytesRead > 0);
}
bool MemWrite(void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesWritten)
{
// Fast fail if address is invalid
if (!MemIsCanonicalAddress((uint)BaseAddress))
return false;
// Fast fail if address is invalid
if (!MemIsCanonicalAddress((uint)BaseAddress))
return false;
// Buffer must be supplied and size must be greater than 0
if(!Buffer || Size <= 0)
@ -233,37 +233,37 @@ bool MemWrite(void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfByte
if(ret && *NumberOfBytesWritten == Size)
return true;
// Write page-by-page (Skip if only 1 page exists)
// See: MemRead
SIZE_T pageCount = BYTES_TO_PAGES(Size);
// Write page-by-page (Skip if only 1 page exists)
// See: MemRead
SIZE_T pageCount = BYTES_TO_PAGES(Size);
if (pageCount > 1)
{
// Determine the number of bytes between ADDRESS and the next page
uint offset = 0;
uint writeBase = (uint)BaseAddress;
uint writeSize = ROUND_TO_PAGES(writeBase) - writeBase;
if (pageCount > 1)
{
// Determine the number of bytes between ADDRESS and the next page
uint offset = 0;
uint writeBase = (uint)BaseAddress;
uint writeSize = ROUND_TO_PAGES(writeBase) - writeBase;
// Reset the bytes read count
*NumberOfBytesWritten = 0;
// Reset the bytes read count
*NumberOfBytesWritten = 0;
for (SIZE_T i = 0; i < pageCount; i++)
{
SIZE_T bytesWritten = 0;
for (SIZE_T i = 0; i < pageCount; i++)
{
SIZE_T bytesWritten = 0;
if (MemoryWriteSafe(fdProcessInfo->hProcess, (PVOID)writeBase, ((PBYTE)Buffer + offset), writeSize, &bytesWritten))
*NumberOfBytesWritten += bytesWritten;
if (MemoryWriteSafe(fdProcessInfo->hProcess, (PVOID)writeBase, ((PBYTE)Buffer + offset), writeSize, &bytesWritten))
*NumberOfBytesWritten += bytesWritten;
offset += writeSize;
writeBase += writeSize;
offset += writeSize;
writeBase += writeSize;
Size -= writeSize;
writeSize = (Size > PAGE_SIZE) ? PAGE_SIZE : Size;
}
}
Size -= writeSize;
writeSize = (Size > PAGE_SIZE) ? PAGE_SIZE : Size;
}
}
SetLastError(ERROR_PARTIAL_COPY);
return (*NumberOfBytesWritten > 0);
SetLastError(ERROR_PARTIAL_COPY);
return (*NumberOfBytesWritten > 0);
}
bool MemPatch(void* BaseAddress, void* Buffer, SIZE_T Size, SIZE_T* NumberOfBytesWritten)
@ -297,16 +297,16 @@ bool MemIsValidReadPtr(uint Address)
bool MemIsCanonicalAddress(uint Address)
{
#ifndef _WIN64
// 32-bit mode only supports 4GB max, so limits are
// not an issue
return true;
// 32-bit mode only supports 4GB max, so limits are
// not an issue
return true;
#else
// The most-significant 16 bits must be all 1 or all 0.
// (64 - 16) = 48bit linear address range.
//
// 0xFFFF800000000000 = Significant 16 bits set
// 0x0000800000000000 = 48th bit set
return (((Address & 0xFFFF800000000000) + 0x800000000000) & ~0x800000000000) == 0;
// The most-significant 16 bits must be all 1 or all 0.
// (64 - 16) = 48bit linear address range.
//
// 0xFFFF800000000000 = Significant 16 bits set
// 0x0000800000000000 = 48th bit set
return (((Address & 0xFFFF800000000000) + 0x800000000000) & ~0x800000000000) == 0;
#endif // _WIN64
}

View File

@ -93,10 +93,10 @@ bool ModUnload(uint Base)
if(found == modinfo.end())
return false;
// Unload everything from TitanEngine
StaticFileUnloadW(nullptr, false, found->second.Handle, found->second.FileMapSize, found->second.MapHandle, found->second.FileMapVA);
// Unload everything from TitanEngine
StaticFileUnloadW(nullptr, false, found->second.Handle, found->second.FileMapSize, found->second.MapHandle, found->second.FileMapVA);
// Remove it from the list
// Remove it from the list
modinfo.erase(found);
EXCLUSIVE_RELEASE();
@ -199,8 +199,8 @@ uint ModBaseFromName(const char* Module)
for(auto itr = modinfo.begin(); itr != modinfo.end(); itr++)
{
char currentModule[MAX_MODULE_SIZE];
strcpy_s(currentModule, itr->second.name);
strcat_s(currentModule, itr->second.extension);
strcpy_s(currentModule, itr->second.name);
strcat_s(currentModule, itr->second.extension);
// Test with and without extension
if(!_stricmp(currentModule, Module) || !_stricmp(itr->second.name, Module))

View File

@ -5,28 +5,28 @@
struct MODSECTIONINFO
{
uint addr; // Virtual address
uint size; // Virtual size
char name[50]; // Escaped section name
uint addr; // Virtual address
uint size; // Virtual size
char name[50]; // Escaped section name
};
struct MODINFO
{
uint base; // Module base
uint size; // Module size
uint hash; // Full module name hash
uint entry; // Entry point
uint base; // Module base
uint size; // Module size
uint hash; // Full module name hash
uint entry; // Entry point
char name[MAX_MODULE_SIZE]; // Module name (without extension)
char extension[MAX_MODULE_SIZE]; // File extension
char path[MAX_PATH]; // File path (in UTF8)
char name[MAX_MODULE_SIZE]; // Module name (without extension)
char extension[MAX_MODULE_SIZE]; // File extension
char path[MAX_PATH]; // File path (in UTF8)
HANDLE Handle; // Handle to the file opened by TitanEngine
HANDLE MapHandle; // Handle to the memory map
ULONG_PTR FileMapVA; // File map virtual address (Debugger local)
DWORD FileMapSize; // File map virtual size
HANDLE Handle; // Handle to the file opened by TitanEngine
HANDLE MapHandle; // Handle to the memory map
ULONG_PTR FileMapVA; // File map virtual address (Debugger local)
DWORD FileMapSize; // File map virtual size
std::vector<MODSECTIONINFO> sections;
std::vector<MODSECTIONINFO> sections;
};
bool ModLoad(uint Base, uint Size, const char* FullPath);

View File

@ -9,47 +9,47 @@
// Allocate a message stack
MESSAGE_STACK* MsgAllocStack()
{
// Allocate memory for the structure
PVOID memoryBuffer = emalloc(sizeof(MESSAGE_STACK), "MsgAllocStack:memoryBuffer");
// Allocate memory for the structure
PVOID memoryBuffer = emalloc(sizeof(MESSAGE_STACK), "MsgAllocStack:memoryBuffer");
if (!memoryBuffer)
return nullptr;
if (!memoryBuffer)
return nullptr;
// Use placement new to ensure all constructors are called correctly
// Use placement new to ensure all constructors are called correctly
return new(memoryBuffer) MESSAGE_STACK;
}
// Free a message stack and all messages in the queue
void MsgFreeStack(MESSAGE_STACK* Stack)
{
// Destructor must be called manually due to placement new
Stack->FIFOStack.~unbounded_buffer();
// Destructor must be called manually due to placement new
Stack->FIFOStack.~unbounded_buffer();
// Free memory
efree(Stack, "MsgFreeStack:Stack");
// Free memory
efree(Stack, "MsgFreeStack:Stack");
}
// Add a message to the stack
bool MsgSend(MESSAGE_STACK* Stack, int Msg, uint Param1, uint Param2)
{
MESSAGE messageInfo;
messageInfo.msg = Msg;
messageInfo.param1 = Param1;
messageInfo.param2 = Param2;
MESSAGE messageInfo;
messageInfo.msg = Msg;
messageInfo.param1 = Param1;
messageInfo.param2 = Param2;
// Asynchronous send. Return value doesn't matter.
concurrency::asend(Stack->FIFOStack, messageInfo);
// Asynchronous send. Return value doesn't matter.
concurrency::asend(Stack->FIFOStack, messageInfo);
return true;
}
// Get a message from the stack (will return false when there are no messages)
bool MsgGet(MESSAGE_STACK* Stack, MESSAGE* Message)
{
return concurrency::try_receive(Stack->FIFOStack, *Message);
return concurrency::try_receive(Stack->FIFOStack, *Message);
}
// Wait for a message on the specified stack
void MsgWait(MESSAGE_STACK* Stack, MESSAGE* Message)
{
*Message = concurrency::receive(Stack->FIFOStack);
*Message = concurrency::receive(Stack->FIFOStack);
}

View File

@ -17,7 +17,7 @@ struct MESSAGE
// Supports an unlimited number of messages.
struct MESSAGE_STACK
{
concurrency::unbounded_buffer<MESSAGE> FIFOStack;
concurrency::unbounded_buffer<MESSAGE> FIFOStack;
};
MESSAGE_STACK* MsgAllocStack();

View File

@ -15,7 +15,7 @@ int RefFind(uint Address, uint Size, CBREF Callback, void* UserData, bool Silent
uint regionSize = 0;
uint regionBase = MemFindBaseAddr(Address, &regionSize, true);
// If the memory page wasn't found, fail
// If the memory page wasn't found, fail
if(!regionBase || !regionSize)
{
if(!Silent)
@ -24,21 +24,21 @@ int RefFind(uint Address, uint Size, CBREF Callback, void* UserData, bool Silent
return 0;
}
// Assume the entire range is used
uint scanStart = regionBase;
uint scanSize = regionSize;
// Assume the entire range is used
uint scanStart = regionBase;
uint scanSize = regionSize;
// Otherwise use custom boundaries if size was supplied
if (Size)
{
// Otherwise use custom boundaries if size was supplied
if (Size)
{
uint maxsize = Size - (Address - regionBase);
// Make sure the size fits in one page
scanStart = Address;
scanSize = min(Size, maxsize);
// Make sure the size fits in one page
scanStart = Address;
scanSize = min(Size, maxsize);
}
// Allocate and read a buffer from the remote process
// Allocate and read a buffer from the remote process
Memory<unsigned char*> data(scanSize, "reffind:data");
if(!MemRead((PVOID)scanStart, data, scanSize, nullptr))
@ -49,67 +49,67 @@ int RefFind(uint Address, uint Size, CBREF Callback, void* UserData, bool Silent
return 0;
}
// Determine the full module name
char fullName[deflen];
char moduleName[MAX_MODULE_SIZE];
// Determine the full module name
char fullName[deflen];
char moduleName[MAX_MODULE_SIZE];
if (ModNameFromAddr(scanStart, moduleName, true))
sprintf_s(fullName, "%s (%s)", Name, moduleName);
else
sprintf_s(fullName, "%s (%p)", Name, scanStart);
if (ModNameFromAddr(scanStart, moduleName, true))
sprintf_s(fullName, "%s (%s)", Name, moduleName);
else
sprintf_s(fullName, "%s (%p)", Name, scanStart);
// Initialize the disassembler
DISASM disasm;
memset(&disasm, 0, sizeof(disasm));
// Initialize the disassembler
DISASM disasm;
memset(&disasm, 0, sizeof(disasm));
#ifdef _WIN64
disasm.Archi = 64;
disasm.Archi = 64;
#endif // _WIN64
disasm.EIP = (UIntPtr)data;
disasm.VirtualAddr = (UInt64)scanStart;
disasm.EIP = (UIntPtr)data;
disasm.VirtualAddr = (UInt64)scanStart;
// Allow an "initialization" notice
REFINFO refInfo;
refInfo.refcount = 0;
refInfo.userinfo = UserData;
refInfo.name = fullName;
// Allow an "initialization" notice
REFINFO refInfo;
refInfo.refcount = 0;
refInfo.userinfo = UserData;
refInfo.name = fullName;
Callback(0, 0, &refInfo);
//concurrency::parallel_for(uint(0), scanSize, [&](uint i)
for (uint i = 0; i < scanSize;)
{
// Print the progress every 4096 bytes
//concurrency::parallel_for(uint(0), scanSize, [&](uint i)
for (uint i = 0; i < scanSize;)
{
// Print the progress every 4096 bytes
if((i % 0x1000) == 0)
{
// Percent = (current / total) * 100
// Integer = floor(percent)
// Percent = (current / total) * 100
// Integer = floor(percent)
float percent = floor(((float)i / (float)scanSize) * 100.0f);
GuiReferenceSetProgress((int)percent);
}
// Disassemble the instruction
// Disassemble the instruction
int len = Disasm(&disasm);
if(len != UNKNOWN_OPCODE)
{
BASIC_INSTRUCTION_INFO basicinfo;
BASIC_INSTRUCTION_INFO basicinfo;
fillbasicinfo(&disasm, &basicinfo);
basicinfo.size = len;
if(Callback(&disasm, &basicinfo, &refInfo))
refInfo.refcount++;
refInfo.refcount++;
}
else
{
// Invalid instruction detected, so just skip the byte
len = 1;
}
else
{
// Invalid instruction detected, so just skip the byte
len = 1;
}
disasm.EIP += len;
disasm.VirtualAddr += len;
i += len;
disasm.EIP += len;
disasm.VirtualAddr += len;
i += len;
}
GuiReferenceSetProgress(100);

View File

@ -99,12 +99,12 @@ void SymUpdateModuleList()
if(!SymGetModuleList(&modList))
return;
// Create a new array to be sent to the GUI thread
size_t moduleCount = modList.size();
SYMBOLMODULEINFO *data = (SYMBOLMODULEINFO *)BridgeAlloc(moduleCount * sizeof(SYMBOLMODULEINFO));
// Create a new array to be sent to the GUI thread
size_t moduleCount = modList.size();
SYMBOLMODULEINFO *data = (SYMBOLMODULEINFO *)BridgeAlloc(moduleCount * sizeof(SYMBOLMODULEINFO));
// Direct copy from std::vector data
memcpy(data, modList.data(), moduleCount * sizeof(SYMBOLMODULEINFO));
// Direct copy from std::vector data
memcpy(data, modList.data(), moduleCount * sizeof(SYMBOLMODULEINFO));
// Send the module data to the GUI for updating
GuiSymbolUpdateModuleList((int)moduleCount, data);
@ -252,21 +252,21 @@ const char* SymGetSymbolicName(uint Address)
bool SymGetSourceLine(uint Cip, char* FileName, int* Line)
{
IMAGEHLP_LINE64 lineInfo;
memset(&lineInfo, 0, sizeof(IMAGEHLP_LINE64));
memset(&lineInfo, 0, sizeof(IMAGEHLP_LINE64));
lineInfo.SizeOfStruct = sizeof(IMAGEHLP_LINE64);
// Perform a symbol lookup from a specific address
DWORD displacement;
// Perform a symbol lookup from a specific address
DWORD displacement;
if(!SafeSymGetLineFromAddr64(fdProcessInfo->hProcess, Cip, &displacement, &lineInfo))
return false;
// Copy line number if requested
// Copy line number if requested
if(Line)
*Line = lineInfo.LineNumber;
// Copy file name if requested
// Copy file name if requested
if(FileName)
strcpy_s(FileName, MAX_STRING_SIZE, lineInfo.FileName);

View File

@ -161,20 +161,20 @@ THREADWAITREASON ThreadGetWaitReason(HANDLE Thread)
DWORD ThreadGetLastError(DWORD ThreadId)
{
SHARED_ACQUIRE(LockThreads);
SHARED_ACQUIRE(LockThreads);
TEB teb;
for (auto & entry : threadList)
{
if (entry.ThreadId != ThreadId)
continue;
TEB teb;
for (auto & entry : threadList)
{
if (entry.ThreadId != ThreadId)
continue;
if (!ThreadGetTeb(entry.ThreadLocalBase, &teb))
{
// TODO: Assert (Why would the TEB fail?)
return 0;
}
}
if (!ThreadGetTeb(entry.ThreadLocalBase, &teb))
{
// TODO: Assert (Why would the TEB fail?)
return 0;
}
}
return teb.LastErrorValue;
}
@ -226,7 +226,7 @@ DWORD ThreadGetId(HANDLE Thread)
}
// Wasn't found, check with Windows
// NOTE: Requires VISTA+
// NOTE: Requires VISTA+
DWORD id = GetThreadId(Thread);
// Returns 0 on error;

View File

@ -45,7 +45,7 @@ enum SectionLock
LockPatches,
LockThreads,
LockDprintf,
LockSym,
LockSym,
// This is defined because of a bug in the Windows 8.1 kernel;
// Calling VirtualQuery/VirtualProtect/ReadProcessMemory can and will cause
@ -85,8 +85,8 @@ public:
Unlock();
#ifdef _DEBUG
// TODO: Assert that the lock count is zero on destructor
if (m_LockCount > 0)
// TODO: Assert that the lock count is zero on destructor
if (m_LockCount > 0)
__debugbreak();
#endif
}

View File

@ -94,16 +94,16 @@ void varinit()
*/
void varfree()
{
EXCLUSIVE_ACQUIRE(LockVariables);
EXCLUSIVE_ACQUIRE(LockVariables);
// Each variable must be deleted manually; strings especially
// because there are sub-allocations
VAR_VALUE emptyValue;
// Each variable must be deleted manually; strings especially
// because there are sub-allocations
VAR_VALUE emptyValue;
for (auto& itr : variables)
varsetvalue(&itr.second, &emptyValue);
for (auto& itr : variables)
varsetvalue(&itr.second, &emptyValue);
// Now clear all vector elements
// Now clear all vector elements
variables.clear();
}

View File

@ -247,7 +247,7 @@ extern "C" DLL_EXPORT const char* _dbg_dbginit()
return "Invalid TITAN_ENGINE_CONTEXT_t alignment!";
if(sizeof(TITAN_ENGINE_CONTEXT_t) != sizeof(REGISTERCONTEXT))
return "Invalid REGISTERCONTEXT alignment!";
SectionLockerGlobal::Initialize();
SectionLockerGlobal::Initialize();
dbginit();
dbgfunctionsinit();
json_set_alloc_funcs(emalloc_json, efree_json);