mirror of https://github.com/x64dbg/TitanEngine
finish basic AVX support
This commit is contained in:
parent
c084a81ba4
commit
4956d16b65
|
|
@ -835,6 +835,7 @@ __declspec(dllexport) bool TITCALL SetContextFPUDataEx(HANDLE hActiveThread, voi
|
||||||
__declspec(dllexport) bool TITCALL SetContextDataEx(HANDLE hActiveThread, DWORD IndexOfRegister, ULONG_PTR NewRegisterValue);
|
__declspec(dllexport) bool TITCALL SetContextDataEx(HANDLE hActiveThread, DWORD IndexOfRegister, ULONG_PTR NewRegisterValue);
|
||||||
__declspec(dllexport) bool TITCALL SetContextData(DWORD IndexOfRegister, ULONG_PTR NewRegisterValue);
|
__declspec(dllexport) bool TITCALL SetContextData(DWORD IndexOfRegister, ULONG_PTR NewRegisterValue);
|
||||||
__declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext);
|
__declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext);
|
||||||
|
__declspec(dllexport) bool TITCALL SetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext);
|
||||||
__declspec(dllexport) void TITCALL ClearExceptionNumber();
|
__declspec(dllexport) void TITCALL ClearExceptionNumber();
|
||||||
__declspec(dllexport) long TITCALL CurrentExceptionNumber();
|
__declspec(dllexport) long TITCALL CurrentExceptionNumber();
|
||||||
__declspec(dllexport) bool TITCALL MatchPatternEx(HANDLE hProcess, void* MemoryToCheck, int SizeOfMemoryToCheck, void* PatternToMatch, int SizeOfPatternToMatch, PBYTE WildCard);
|
__declspec(dllexport) bool TITCALL MatchPatternEx(HANDLE hProcess, void* MemoryToCheck, int SizeOfMemoryToCheck, void* PatternToMatch, int SizeOfPatternToMatch, PBYTE WildCard);
|
||||||
|
|
|
||||||
|
|
@ -66,10 +66,11 @@ __declspec(dllexport) bool TITCALL GetContextFPUDataEx(HANDLE hActiveThread, voi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
__declspec(dllexport) bool TITCALL _SetFullContextDataEx(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext)
|
__declspec(dllexport) bool TITCALL _SetFullContextDataEx(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext, bool AVX_PRIORITY)
|
||||||
{
|
{
|
||||||
CONTEXT DBGContext;
|
CONTEXT DBGContext;
|
||||||
int i;
|
int i;
|
||||||
|
bool returnf;
|
||||||
|
|
||||||
memset(&DBGContext, 0, sizeof(DBGContext));
|
memset(&DBGContext, 0, sizeof(DBGContext));
|
||||||
|
|
||||||
|
|
@ -165,7 +166,13 @@ __declspec(dllexport) bool TITCALL _SetFullContextDataEx(HANDLE hActiveThread, T
|
||||||
memcpy(& DBGContext.ExtendedRegisters[(10 + i) * 16], &(titcontext->XmmRegisters[i]), 16);
|
memcpy(& DBGContext.ExtendedRegisters[(10 + i) * 16], &(titcontext->XmmRegisters[i]), 16);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return SetThreadContext(hActiveThread, & DBGContext) ? true : false;
|
returnf = SetThreadContext(hActiveThread, & DBGContext) ? true : false;
|
||||||
|
|
||||||
|
if(AVX_PRIORITY)
|
||||||
|
SetAVXContext(hActiveThread, titcontext);
|
||||||
|
|
||||||
|
return returnf;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
__declspec(dllexport) bool TITCALL SetFullContextDataEx(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext)
|
__declspec(dllexport) bool TITCALL SetFullContextDataEx(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext)
|
||||||
|
|
@ -175,7 +182,7 @@ __declspec(dllexport) bool TITCALL SetFullContextDataEx(HANDLE hActiveThread, TI
|
||||||
if(SuspendThread(hActiveThread) == (DWORD) - 1)
|
if(SuspendThread(hActiveThread) == (DWORD) - 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
returnf = _SetFullContextDataEx(hActiveThread, titcontext);
|
returnf = _SetFullContextDataEx(hActiveThread, titcontext, false);
|
||||||
|
|
||||||
ResumeThread(hActiveThread);
|
ResumeThread(hActiveThread);
|
||||||
|
|
||||||
|
|
@ -590,6 +597,7 @@ __declspec(dllexport) bool TITCALL SetContextDataEx(HANDLE hActiveThread, DWORD
|
||||||
{
|
{
|
||||||
TITAN_ENGINE_CONTEXT_t titcontext;
|
TITAN_ENGINE_CONTEXT_t titcontext;
|
||||||
bool returnf;
|
bool returnf;
|
||||||
|
bool avx_priority = false;
|
||||||
|
|
||||||
if(SuspendThread(hActiveThread) == (DWORD) - 1)
|
if(SuspendThread(hActiveThread) == (DWORD) - 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -764,6 +772,46 @@ __declspec(dllexport) bool TITCALL SetContextDataEx(HANDLE hActiveThread, DWORD
|
||||||
{
|
{
|
||||||
memcpy(& (titcontext.XmmRegisters[15]), (void*) NewRegisterValue, 16);
|
memcpy(& (titcontext.XmmRegisters[15]), (void*) NewRegisterValue, 16);
|
||||||
}
|
}
|
||||||
|
else if(IndexOfRegister == UE_YMM8)
|
||||||
|
{
|
||||||
|
avx_priority = true;
|
||||||
|
memcpy(& (titcontext.YmmRegisters[32 * 8]), (void*) NewRegisterValue, 32);
|
||||||
|
}
|
||||||
|
else if(IndexOfRegister == UE_YMM9)
|
||||||
|
{
|
||||||
|
avx_priority = true;
|
||||||
|
memcpy(& (titcontext.YmmRegisters[32 * 9]), (void*) NewRegisterValue, 32);
|
||||||
|
}
|
||||||
|
else if(IndexOfRegister == UE_YMM10)
|
||||||
|
{
|
||||||
|
avx_priority = true;
|
||||||
|
memcpy(& (titcontext.YmmRegisters[32 * 10]), (void*) NewRegisterValue, 32);
|
||||||
|
}
|
||||||
|
else if(IndexOfRegister == UE_YMM11)
|
||||||
|
{
|
||||||
|
avx_priority = true;
|
||||||
|
memcpy(& (titcontext.YmmRegisters[32 * 11]), (void*) NewRegisterValue, 32);
|
||||||
|
}
|
||||||
|
else if(IndexOfRegister == UE_YMM12)
|
||||||
|
{
|
||||||
|
avx_priority = true;
|
||||||
|
memcpy(& (titcontext.YmmRegisters[32 * 12]), (void*) NewRegisterValue, 32);
|
||||||
|
}
|
||||||
|
else if(IndexOfRegister == UE_YMM13)
|
||||||
|
{
|
||||||
|
avx_priority = true;
|
||||||
|
memcpy(& (titcontext.YmmRegisters[32 * 13]), (void*) NewRegisterValue, 32);
|
||||||
|
}
|
||||||
|
else if(IndexOfRegister == UE_YMM14)
|
||||||
|
{
|
||||||
|
avx_priority = true;
|
||||||
|
memcpy(& (titcontext.YmmRegisters[32 * 14]), (void*) NewRegisterValue, 32);
|
||||||
|
}
|
||||||
|
else if(IndexOfRegister == UE_YMM15)
|
||||||
|
{
|
||||||
|
avx_priority = true;
|
||||||
|
memcpy(& (titcontext.YmmRegisters[32 * 15]), (void*) NewRegisterValue, 32);
|
||||||
|
}
|
||||||
#else //x86
|
#else //x86
|
||||||
if(IndexOfRegister == UE_EAX)
|
if(IndexOfRegister == UE_EAX)
|
||||||
{
|
{
|
||||||
|
|
@ -1023,44 +1071,52 @@ __declspec(dllexport) bool TITCALL SetContextDataEx(HANDLE hActiveThread, DWORD
|
||||||
memcpy(((uint64_t*) GetRegisterAreaOf87register(titcontext.RegisterArea, x87r0_position, 7)), (char*) NewRegisterValue, 10);
|
memcpy(((uint64_t*) GetRegisterAreaOf87register(titcontext.RegisterArea, x87r0_position, 7)), (char*) NewRegisterValue, 10);
|
||||||
}
|
}
|
||||||
else if(IndexOfRegister == UE_YMM0)
|
else if(IndexOfRegister == UE_YMM0)
|
||||||
|
{
|
||||||
|
avx_priority = true;
|
||||||
memcpy(& (titcontext.YmmRegisters[32 * 0]), (void*) NewRegisterValue, 32);
|
memcpy(& (titcontext.YmmRegisters[32 * 0]), (void*) NewRegisterValue, 32);
|
||||||
|
}
|
||||||
else if(IndexOfRegister == UE_YMM1)
|
else if(IndexOfRegister == UE_YMM1)
|
||||||
|
{
|
||||||
|
avx_priority = true;
|
||||||
memcpy(& (titcontext.YmmRegisters[32 * 1]), (void*) NewRegisterValue, 32);
|
memcpy(& (titcontext.YmmRegisters[32 * 1]), (void*) NewRegisterValue, 32);
|
||||||
|
}
|
||||||
else if(IndexOfRegister == UE_YMM2)
|
else if(IndexOfRegister == UE_YMM2)
|
||||||
|
{
|
||||||
|
avx_priority = true;
|
||||||
memcpy(& (titcontext.YmmRegisters[32 * 2]), (void*) NewRegisterValue, 32);
|
memcpy(& (titcontext.YmmRegisters[32 * 2]), (void*) NewRegisterValue, 32);
|
||||||
|
}
|
||||||
else if(IndexOfRegister == UE_YMM3)
|
else if(IndexOfRegister == UE_YMM3)
|
||||||
|
{
|
||||||
|
avx_priority = true;
|
||||||
memcpy(& (titcontext.YmmRegisters[32 * 3]), (void*) NewRegisterValue, 32);
|
memcpy(& (titcontext.YmmRegisters[32 * 3]), (void*) NewRegisterValue, 32);
|
||||||
|
}
|
||||||
else if(IndexOfRegister == UE_YMM4)
|
else if(IndexOfRegister == UE_YMM4)
|
||||||
|
{
|
||||||
|
avx_priority = true;
|
||||||
memcpy(& (titcontext.YmmRegisters[32 * 4]), (void*) NewRegisterValue, 32);
|
memcpy(& (titcontext.YmmRegisters[32 * 4]), (void*) NewRegisterValue, 32);
|
||||||
|
}
|
||||||
else if(IndexOfRegister == UE_YMM5)
|
else if(IndexOfRegister == UE_YMM5)
|
||||||
|
{
|
||||||
|
avx_priority = true;
|
||||||
memcpy(& (titcontext.YmmRegisters[32 * 5]), (void*) NewRegisterValue, 32);
|
memcpy(& (titcontext.YmmRegisters[32 * 5]), (void*) NewRegisterValue, 32);
|
||||||
|
}
|
||||||
else if(IndexOfRegister == UE_YMM6)
|
else if(IndexOfRegister == UE_YMM6)
|
||||||
|
{
|
||||||
|
avx_priority = true;
|
||||||
memcpy(& (titcontext.YmmRegisters[32 * 6]), (void*) NewRegisterValue, 32);
|
memcpy(& (titcontext.YmmRegisters[32 * 6]), (void*) NewRegisterValue, 32);
|
||||||
|
}
|
||||||
else if(IndexOfRegister == UE_YMM7)
|
else if(IndexOfRegister == UE_YMM7)
|
||||||
|
{
|
||||||
|
avx_priority = true;
|
||||||
memcpy(& (titcontext.YmmRegisters[32 * 7]), (void*) NewRegisterValue, 32);
|
memcpy(& (titcontext.YmmRegisters[32 * 7]), (void*) NewRegisterValue, 32);
|
||||||
else if(IndexOfRegister == UE_YMM8)
|
}
|
||||||
memcpy(& (titcontext.YmmRegisters[32 * 8]), (void*) NewRegisterValue, 32);
|
|
||||||
else if(IndexOfRegister == UE_YMM9)
|
|
||||||
memcpy(& (titcontext.YmmRegisters[32 * 9]), (void*) NewRegisterValue, 32);
|
|
||||||
else if(IndexOfRegister == UE_YMM10)
|
|
||||||
memcpy(& (titcontext.YmmRegisters[32 * 10]), (void*) NewRegisterValue, 32);
|
|
||||||
else if(IndexOfRegister == UE_YMM11)
|
|
||||||
memcpy(& (titcontext.YmmRegisters[32 * 11]), (void*) NewRegisterValue, 32);
|
|
||||||
else if(IndexOfRegister == UE_YMM12)
|
|
||||||
memcpy(& (titcontext.YmmRegisters[32 * 12]), (void*) NewRegisterValue, 32);
|
|
||||||
else if(IndexOfRegister == UE_YMM13)
|
|
||||||
memcpy(& (titcontext.YmmRegisters[32 * 13]), (void*) NewRegisterValue, 32);
|
|
||||||
else if(IndexOfRegister == UE_YMM14)
|
|
||||||
memcpy(& (titcontext.YmmRegisters[32 * 14]), (void*) NewRegisterValue, 32);
|
|
||||||
else if(IndexOfRegister == UE_YMM15)
|
|
||||||
memcpy(& (titcontext.YmmRegisters[32 * 15]), (void*) NewRegisterValue, 32);
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ResumeThread(hActiveThread);
|
ResumeThread(hActiveThread);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
returnf = _SetFullContextDataEx(hActiveThread, &titcontext);
|
returnf = _SetFullContextDataEx(hActiveThread, &titcontext, avx_priority);
|
||||||
|
|
||||||
ResumeThread(hActiveThread);
|
ResumeThread(hActiveThread);
|
||||||
|
|
||||||
|
|
@ -1137,6 +1193,90 @@ bool InitXState(void)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
__declspec(dllexport) bool TITCALL SetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext)
|
||||||
|
{
|
||||||
|
PVOID Buffer;
|
||||||
|
PCONTEXT Context;
|
||||||
|
DWORD ContextSize;
|
||||||
|
DWORD FeatureLength;
|
||||||
|
ULONG Index;
|
||||||
|
BOOL Success;
|
||||||
|
PM128A Ymm;
|
||||||
|
PM128A Xmm;
|
||||||
|
DWORD64 FeatureMask;
|
||||||
|
bool returnf = false;
|
||||||
|
|
||||||
|
if(InitXState() == false)
|
||||||
|
return returnf;
|
||||||
|
|
||||||
|
FeatureMask = pfnGetEnabledXStateFeatures();
|
||||||
|
if((FeatureMask & XSTATE_MASK_AVX) == 0)
|
||||||
|
return returnf;
|
||||||
|
|
||||||
|
ContextSize = 0;
|
||||||
|
Success = pfnInitializeContext(NULL,
|
||||||
|
CONTEXT_ALL | CONTEXT_XSTATE,
|
||||||
|
NULL,
|
||||||
|
&ContextSize);
|
||||||
|
|
||||||
|
if((Success == TRUE) || (GetLastError() != ERROR_INSUFFICIENT_BUFFER))
|
||||||
|
return returnf;
|
||||||
|
|
||||||
|
Buffer = calloc(1, ContextSize);
|
||||||
|
if(Buffer == NULL)
|
||||||
|
return returnf;
|
||||||
|
|
||||||
|
Success = pfnInitializeContext(Buffer,
|
||||||
|
CONTEXT_ALL | CONTEXT_XSTATE,
|
||||||
|
&Context,
|
||||||
|
&ContextSize);
|
||||||
|
|
||||||
|
if(Success == FALSE)
|
||||||
|
goto Cleanup;
|
||||||
|
|
||||||
|
Success = pfnSetXStateFeaturesMask(Context, XSTATE_MASK_AVX);
|
||||||
|
if(Success == FALSE)
|
||||||
|
goto Cleanup;
|
||||||
|
|
||||||
|
Success = pfnGetXStateFeaturesMask(Context, &FeatureMask);
|
||||||
|
if(Success == FALSE)
|
||||||
|
goto Cleanup;
|
||||||
|
|
||||||
|
Xmm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_LEGACY_SSE, &FeatureLength);
|
||||||
|
Ymm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_AVX, NULL);
|
||||||
|
|
||||||
|
for(Index = 0; Index < FeatureLength / sizeof(* Ymm); Index += 1)
|
||||||
|
{
|
||||||
|
memcpy
|
||||||
|
(
|
||||||
|
Xmm++,
|
||||||
|
((char*) & (titcontext->YmmRegisters[32 * Index])),
|
||||||
|
sizeof(Xmm[Index])
|
||||||
|
);
|
||||||
|
|
||||||
|
memcpy
|
||||||
|
(
|
||||||
|
Ymm++,
|
||||||
|
((char*) & (titcontext->YmmRegisters[32 * Index])) + sizeof(titcontext->XmmRegisters[Index]),
|
||||||
|
sizeof(Ymm[Index])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Success = SetThreadContext(hActiveThread, Context);
|
||||||
|
if(Success == FALSE)
|
||||||
|
goto Cleanup;
|
||||||
|
|
||||||
|
returnf = true;
|
||||||
|
|
||||||
|
Cleanup:
|
||||||
|
free(Buffer);
|
||||||
|
|
||||||
|
return returnf;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
__declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext)
|
__declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext)
|
||||||
{
|
{
|
||||||
PVOID Buffer;
|
PVOID Buffer;
|
||||||
|
|
@ -1146,6 +1286,7 @@ __declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENG
|
||||||
ULONG Index;
|
ULONG Index;
|
||||||
BOOL Success;
|
BOOL Success;
|
||||||
PM128A Ymm;
|
PM128A Ymm;
|
||||||
|
PM128A Xmm;
|
||||||
DWORD64 FeatureMask;
|
DWORD64 FeatureMask;
|
||||||
bool returnf = false;
|
bool returnf = false;
|
||||||
|
|
||||||
|
|
@ -1190,19 +1331,20 @@ __declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENG
|
||||||
goto Cleanup;
|
goto Cleanup;
|
||||||
|
|
||||||
Ymm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_AVX, &FeatureLength);
|
Ymm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_AVX, &FeatureLength);
|
||||||
|
Xmm = (PM128A)pfnLocateXStateFeature(Context, XSTATE_LEGACY_SSE, &FeatureLength);
|
||||||
|
|
||||||
for(Index = 0; Index < FeatureLength / sizeof(* Ymm); Index += 1)
|
for(Index = 0; Index < FeatureLength / sizeof(* Ymm); Index += 1)
|
||||||
{
|
{
|
||||||
memcpy
|
memcpy
|
||||||
(
|
(
|
||||||
(char*) & (titcontext->YmmRegisters[32 * Index]),
|
(char*) & (titcontext->YmmRegisters[32 * Index]),
|
||||||
&titcontext->XmmRegisters[Index],
|
Xmm++,
|
||||||
sizeof(titcontext->XmmRegisters[Index])
|
sizeof(Xmm[Index])
|
||||||
);
|
);
|
||||||
memcpy
|
memcpy
|
||||||
(
|
(
|
||||||
((char*) & (titcontext->YmmRegisters[32 * Index])) + sizeof(titcontext->XmmRegisters[Index]),
|
((char*) & (titcontext->YmmRegisters[32 * Index])) + sizeof(titcontext->XmmRegisters[Index]),
|
||||||
&Ymm[Index],
|
Ymm++,
|
||||||
sizeof(Ymm[Index])
|
sizeof(Ymm[Index])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -184,6 +184,7 @@ __declspec(dllexport) void TITCALL Getx87FPURegisters(x87FPURegister_t x87FPUReg
|
||||||
__declspec(dllexport) void TITCALL GetMMXRegisters(uint64_t mmx[8], TITAN_ENGINE_CONTEXT_t* titcontext);
|
__declspec(dllexport) void TITCALL GetMMXRegisters(uint64_t mmx[8], TITAN_ENGINE_CONTEXT_t* titcontext);
|
||||||
__declspec(dllexport) ULONG_PTR TITCALL GetContextDataEx(HANDLE hActiveThread, DWORD IndexOfRegister);
|
__declspec(dllexport) ULONG_PTR TITCALL GetContextDataEx(HANDLE hActiveThread, DWORD IndexOfRegister);
|
||||||
__declspec(dllexport) ULONG_PTR TITCALL GetContextData(DWORD IndexOfRegister);
|
__declspec(dllexport) ULONG_PTR TITCALL GetContextData(DWORD IndexOfRegister);
|
||||||
|
__declspec(dllexport) bool TITCALL SetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext);
|
||||||
__declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext);
|
__declspec(dllexport) bool TITCALL GetAVXContext(HANDLE hActiveThread, TITAN_ENGINE_CONTEXT_t* titcontext);
|
||||||
__declspec(dllexport) bool TITCALL SetContextFPUDataEx(HANDLE hActiveThread, void* FPUSaveArea);
|
__declspec(dllexport) bool TITCALL SetContextFPUDataEx(HANDLE hActiveThread, void* FPUSaveArea);
|
||||||
__declspec(dllexport) bool TITCALL SetContextDataEx(HANDLE hActiveThread, DWORD IndexOfRegister, ULONG_PTR NewRegisterValue);
|
__declspec(dllexport) bool TITCALL SetContextDataEx(HANDLE hActiveThread, DWORD IndexOfRegister, ULONG_PTR NewRegisterValue);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue