extern "C" DLL_EXPORT bool _dbg_getregdump(REGDUMP* regdump) { if(!DbgIsDebugging()) { memset(regdump, 0, sizeof(REGDUMP)); return true; } TITAN_ENGINE_CONTEXT_t titcontext; if(!GetFullContextDataEx(hActiveThread, &titcontext)) return false; TranslateTitanContextToRegContext(&titcontext, ®dump->regcontext); duint cflags = regdump->regcontext.eflags; regdump->flags.c = valflagfromstring(cflags, "cf"); regdump->flags.p = valflagfromstring(cflags, "pf"); regdump->flags.a = valflagfromstring(cflags, "af"); regdump->flags.z = valflagfromstring(cflags, "zf"); regdump->flags.s = valflagfromstring(cflags, "sf"); regdump->flags.t = valflagfromstring(cflags, "tf"); regdump->flags.i = valflagfromstring(cflags, "if"); regdump->flags.d = valflagfromstring(cflags, "df"); regdump->flags.o = valflagfromstring(cflags, "of"); x87FPURegister_t x87FPURegisters[8]; Getx87FPURegisters(x87FPURegisters, &titcontext); TranslateTitanFpuRegisters(x87FPURegisters, regdump->x87FPURegisters); GetMMXRegisters(regdump->mmx, &titcontext); GetMxCsrFields(& (regdump->MxCsrFields), regdump->regcontext.MxCsr); Getx87ControlWordFields(& (regdump->x87ControlWordFields), regdump->regcontext.x87fpu.ControlWord); Getx87StatusWordFields(& (regdump->x87StatusWordFields), regdump->regcontext.x87fpu.StatusWord); LASTERROR lastError; lastError.code = ThreadGetLastError(ThreadGetId(hActiveThread)); lastError.name = ErrorCodeToName(lastError.code); regdump->lastError = lastError; return true; }
bool cbDebugLoadLib(int argc, char* argv[]) { if(argc < 2) { dputs(QT_TRANSLATE_NOOP("DBG", "Error: you must specify the name of the DLL to load\n")); return false; } LoadLibThreadID = fdProcessInfo->dwThreadId; HANDLE LoadLibThread = ThreadGetHandle((DWORD)LoadLibThreadID); DLLNameMem = MemAllocRemote(0, strlen(argv[1]) + 1); ASMAddr = MemAllocRemote(0, 0x1000); if(!DLLNameMem || !ASMAddr) { dputs(QT_TRANSLATE_NOOP("DBG", "Error: couldn't allocate memory in debuggee")); return false; } if(!MemWrite(DLLNameMem, argv[1], strlen(argv[1]))) { dputs(QT_TRANSLATE_NOOP("DBG", "Error: couldn't write process memory")); return false; } int size = 0; int counter = 0; duint LoadLibraryA = 0; char command[50] = ""; char error[MAX_ERROR_SIZE] = ""; GetFullContextDataEx(LoadLibThread, &backupctx); if(!valfromstring("kernel32:LoadLibraryA", &LoadLibraryA, false)) { dputs(QT_TRANSLATE_NOOP("DBG", "Error: couldn't get kernel32:LoadLibraryA")); return false; } // Arch specific asm code #ifdef _WIN64 sprintf_s(command, "mov rcx, %p", DLLNameMem); #else sprintf_s(command, "push %p", DLLNameMem); #endif // _WIN64 assembleat(ASMAddr, command, &size, error, true); counter += size; #ifdef _WIN64 sprintf_s(command, "mov rax, %p", LoadLibraryA); assembleat(ASMAddr + counter, command, &size, error, true); counter += size; sprintf_s(command, "call rax"); #else sprintf_s(command, "call %p", LoadLibraryA); #endif // _WIN64 assembleat(ASMAddr + counter, command, &size, error, true); counter += size; SetContextDataEx(LoadLibThread, UE_CIP, ASMAddr); auto ok = SetBPX(ASMAddr + counter, UE_SINGLESHOOT | UE_BREAKPOINT_TYPE_INT3, (void*)cbDebugLoadLibBPX); ThreadSuspendAll(); ResumeThread(LoadLibThread); unlock(WAITID_RUN); return ok; }