Introduced EIPToString
This commit is contained in:
parent
b855b69c6f
commit
50f7e60678
|
@ -111,6 +111,18 @@ void NTAPI EmuWarning(const char *szWarningMessage, ...)
|
|||
}
|
||||
#endif
|
||||
|
||||
std::string EIPToString(xbaddr EIP)
|
||||
{
|
||||
int symbolOffset = 0;
|
||||
std::string symbolName = GetDetectedSymbolName(EIP, &symbolOffset);
|
||||
|
||||
char buffer[256];
|
||||
sprintf(buffer, "0x%.08X(=%s+0x%x)", EIP, symbolName.c_str(), symbolOffset);
|
||||
|
||||
std::string result = buffer;
|
||||
return result;
|
||||
}
|
||||
|
||||
void EmuExceptionPrintDebugInformation(LPEXCEPTION_POINTERS e, bool IsBreakpointException)
|
||||
{
|
||||
// print debug information
|
||||
|
@ -121,12 +133,14 @@ void EmuExceptionPrintDebugInformation(LPEXCEPTION_POINTERS e, bool IsBreakpoint
|
|||
printf("[0x%X] EmuMain: Recieved Exception (Code := 0x%.08X)\n", GetCurrentThreadId(), e->ExceptionRecord->ExceptionCode);
|
||||
|
||||
printf("\n"
|
||||
" EIP := 0x%.08X EFL := 0x%.08X\n"
|
||||
" EIP := %s\n"
|
||||
" EFL := 0x%.08X\n"
|
||||
" EAX := 0x%.08X EBX := 0x%.08X ECX := 0x%.08X EDX := 0x%.08X\n"
|
||||
" ESI := 0x%.08X EDI := 0x%.08X ESP := 0x%.08X EBP := 0x%.08X\n"
|
||||
" CR2 := 0x%.08X\n"
|
||||
"\n",
|
||||
e->ContextRecord->Eip, e->ContextRecord->EFlags,
|
||||
EIPToString(e->ContextRecord->Eip).c_str(),
|
||||
e->ContextRecord->EFlags,
|
||||
e->ContextRecord->Eax, e->ContextRecord->Ebx, e->ContextRecord->Ecx, e->ContextRecord->Edx,
|
||||
e->ContextRecord->Esi, e->ContextRecord->Edi, e->ContextRecord->Esp, e->ContextRecord->Ebp,
|
||||
e->ContextRecord->Dr2);
|
||||
|
@ -156,14 +170,17 @@ bool EmuExceptionBreakpointAsk(LPEXCEPTION_POINTERS e)
|
|||
{
|
||||
EmuExceptionPrintDebugInformation(e, /*IsBreakpointException=*/true);
|
||||
|
||||
int symbolOffset = 0;
|
||||
std::string symbolName = GetDetectedSymbolName(e->ContextRecord->Eip, &symbolOffset);
|
||||
|
||||
char buffer[256];
|
||||
sprintf(buffer,
|
||||
"Recieved Breakpoint Exception (int 3) @ EIP := 0x%.08X\n"
|
||||
"Recieved Breakpoint Exception (int 3) @ EIP := %s\n"
|
||||
"\n"
|
||||
" Press Abort to terminate emulation.\n"
|
||||
" Press Retry to debug.\n"
|
||||
" Press Ignore to continue emulation.",
|
||||
e->ContextRecord->Eip);
|
||||
EIPToString(e->ContextRecord->Eip).c_str());
|
||||
|
||||
int ret = MessageBox(g_hEmuWindow, buffer, "Cxbx-Reloaded", MB_ICONSTOP | MB_ABORTRETRYIGNORE);
|
||||
if (ret == IDABORT)
|
||||
|
@ -192,11 +209,11 @@ void EmuExceptionNonBreakpointUnhandledShow(LPEXCEPTION_POINTERS e)
|
|||
|
||||
char buffer[256];
|
||||
sprintf(buffer,
|
||||
"Recieved Exception Code 0x%.08X @ EIP := 0x%.08X (= %s+0x%x)\n"
|
||||
"Recieved Exception Code 0x%.08X @ EIP := %s\n"
|
||||
"\n"
|
||||
" Press \"OK\" to terminate emulation.\n"
|
||||
" Press \"Cancel\" to debug.",
|
||||
e->ExceptionRecord->ExceptionCode, e->ContextRecord->Eip, symbolName.c_str(), symbolOffset);
|
||||
e->ExceptionRecord->ExceptionCode, EIPToString(e->ContextRecord->Eip).c_str());
|
||||
|
||||
if (MessageBox(g_hEmuWindow, buffer, "Cxbx-Reloaded", MB_ICONSTOP | MB_OKCANCEL) == IDOK)
|
||||
{
|
||||
|
@ -242,9 +259,12 @@ int ExitException(LPEXCEPTION_POINTERS e)
|
|||
{
|
||||
static int count = 0;
|
||||
|
||||
// debug information
|
||||
int symbolOffset = 0;
|
||||
std::string symbolName = GetDetectedSymbolName(e->ContextRecord->Eip, &symbolOffset);
|
||||
|
||||
// debug information
|
||||
printf("[0x%X] EmuMain: * * * * * EXCEPTION * * * * *\n", GetCurrentThreadId());
|
||||
printf("[0x%X] EmuMain: Recieved Exception [0x%.08X]@0x%.08X\n", GetCurrentThreadId(), e->ExceptionRecord->ExceptionCode, e->ContextRecord->Eip);
|
||||
printf("[0x%X] EmuMain: Recieved Exception [0x%.08X]@%s\n", GetCurrentThreadId(), e->ExceptionRecord->ExceptionCode, EIPToString(e->ContextRecord->Eip).c_str());
|
||||
printf("[0x%X] EmuMain: * * * * * EXCEPTION * * * * *\n", GetCurrentThreadId());
|
||||
|
||||
fflush(stdout);
|
||||
|
|
|
@ -73,21 +73,25 @@ std::string GetDetectedSymbolName(xbaddr address, int *symbolOffset)
|
|||
|
||||
for (auto it = g_HLECache.begin(); it != g_HLECache.end(); ++it) {
|
||||
xbaddr symbolAddr = (*it).second;
|
||||
int distance = symbolAddr - address;
|
||||
if (distance >= 0)
|
||||
if (symbolAddr <= address)
|
||||
{
|
||||
int distance = address - symbolAddr;
|
||||
if (closestMatch > distance)
|
||||
{
|
||||
std::string symbolName = (*it).first;
|
||||
|
||||
closestMatch = distance;
|
||||
result = symbolName;
|
||||
result = (*it).first;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*symbolOffset = closestMatch;
|
||||
return result;
|
||||
if (closestMatch < MAXINT)
|
||||
{
|
||||
*symbolOffset = closestMatch;
|
||||
return result;
|
||||
}
|
||||
|
||||
*symbolOffset = 0;
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
void EmuHLEIntercept(Xbe::Header *pXbeHeader)
|
||||
|
|
Loading…
Reference in New Issue