1
0
Fork 0

Merge pull request #3140 from torusrxxx/patch000000f0

Add movups/movupd/movdqu commands to access XMM registers
This commit is contained in:
Duncan Ogilvie 2023-07-18 17:20:39 +02:00 committed by GitHub
commit ea4cc04007
Signed by: GitHub
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 124 additions and 68 deletions

View File

@ -364,4 +364,116 @@ bool cbInstrMov(int argc, char* argv[])
}
}
return true;
}
bool cbInstrMovdqu(int argc, char* argv[])
{
if(IsArgumentsLessThan(argc, 3))
return false;
String dstText = argv[1];
String srcText = argv[2];
duint address = 0;
DWORD registerindex = 0;
if(srcText[0] == '[' && srcText[srcText.length() - 1] == ']' && memicmp(dstText.c_str(), "xmm", 3) == 0)
{
char newValue[16];
// movdqu xmm0, [address]
dstText = dstText.substr(3);
srcText = srcText.substr(1, srcText.size() - 2);
DWORD registerindex;
bool found = true;
registerindex = atoi(dstText.c_str());
if(registerindex < ArchValue(8, 16))
{
registerindex += UE_XMM0;
}
else
{
goto InvalidDest;
}
if(!valfromstring(srcText.c_str(), &address))
{
goto InvalidSrc;
}
if(!MemRead(address, newValue, 16))
{
dputs(QT_TRANSLATE_NOOP("DBG", "Failed to read (all) memory..."));
return false;
}
SetContextDataEx(hActiveThread, registerindex, (ULONG_PTR)newValue);
GuiUpdateAllViews(); //refresh disassembly/dump/etc
return true;
}
else if(dstText[0] == '[' && dstText[dstText.length() - 1] == ']' && memicmp(srcText.c_str(), "xmm", 3) == 0)
{
// movdqu [address], xmm0
srcText = srcText.substr(3);
dstText = dstText.substr(1, dstText.size() - 2);
DWORD registerindex;
bool found = true;
registerindex = atoi(srcText.c_str());
if(registerindex >= ArchValue(8, 16))
{
goto InvalidSrc;
}
if(!valfromstring(dstText.c_str(), &address) || !MemIsValidReadPtr(address))
{
goto InvalidDest;
}
REGDUMP registers;
if(!DbgGetRegDumpEx(&registers, sizeof(registers)))
{
dputs(QT_TRANSLATE_NOOP("DBG", "Failed to read register context..."));
return false;
}
if(!MemWrite(address, &registers.regcontext.XmmRegisters[registerindex], 16))
{
dprintf(QT_TRANSLATE_NOOP("DBG", "Failed to write to %p\n"), address);
return false;
}
GuiUpdateAllViews(); //refresh disassembly/dump/etc
return true;
}
else if(memicmp(srcText.c_str(), "xmm", 3) == 0 && memicmp(dstText.c_str(), "xmm", 3) == 0)
{
// movdqu xmm0, xmm1
srcText = srcText.substr(3);
dstText = dstText.substr(3);
DWORD registerindex[2];
bool found = true;
registerindex[0] = atoi(srcText.c_str());
if(registerindex[0] >= ArchValue(8, 16))
{
goto InvalidSrc;
}
registerindex[1] = atoi(dstText.c_str());
if(registerindex[1] < ArchValue(8, 16))
{
registerindex[1] += UE_XMM0;
}
else
{
goto InvalidDest;
}
REGDUMP registers;
if(!DbgGetRegDumpEx(&registers, sizeof(registers)))
{
dputs(QT_TRANSLATE_NOOP("DBG", "Failed to read register context..."));
return false;
}
SetContextDataEx(hActiveThread, registerindex[1], (ULONG_PTR)&registers.regcontext.XmmRegisters[registerindex[0]]);
GuiUpdateAllViews(); //refresh disassembly/dump/etc
return true;
}
else
{
dputs(QT_TRANSLATE_NOOP("DBG", "Usage: movdqu xmm0, [address] / movdqu [address], xmm0 / movdqu xmm0, xmm1"));
return false;
}
InvalidSrc:
dprintf(QT_TRANSLATE_NOOP("DBG", "Invalid src \"%s\"\n"), argv[2]);
return false;
InvalidDest:
dprintf(QT_TRANSLATE_NOOP("DBG", "Invalid dest \"%s\"\n"), argv[1]);
return false;
}

View File

@ -23,4 +23,6 @@ bool cbInstrPush(int argc, char* argv[]);
bool cbInstrPop(int argc, char* argv[]);
bool cbInstrTest(int argc, char* argv[]);
bool cbInstrCmp(int argc, char* argv[]);
bool cbInstrMov(int argc, char* argv[]);
bool cbInstrMov(int argc, char* argv[]);
bool cbInstrMovdqu(int argc, char* argv[]);

View File

@ -2251,75 +2251,14 @@ static void setfpuvalue(const char* string, duint value)
string += STRLEN_USING_SIZEOF(XMM_PRE_FIELD_STRING);
DWORD registerindex;
bool found = true;
switch(atoi(string))
registerindex = atoi(string);
if(registerindex < ArchValue(8, 16))
{
registerindex += UE_XMM0;
}
else
{
case 0:
registerindex = UE_XMM0;
break;
case 1:
registerindex = UE_XMM1;
break;
case 2:
registerindex = UE_XMM2;
break;
case 3:
registerindex = UE_XMM3;
break;
case 4:
registerindex = UE_XMM4;
break;
case 5:
registerindex = UE_XMM5;
break;
case 6:
registerindex = UE_XMM6;
break;
case 7:
registerindex = UE_XMM7;
break;
#ifdef _WIN64
case 8:
registerindex = UE_XMM8;
break;
case 9:
registerindex = UE_XMM9;
break;
case 10:
registerindex = UE_XMM10;
break;
case 11:
registerindex = UE_XMM11;
break;
case 12:
registerindex = UE_XMM12;
break;
case 13:
registerindex = UE_XMM13;
break;
case 14:
registerindex = UE_XMM14;
break;
case 15:
registerindex = UE_XMM15;
break;
#endif
default:
found = false;
break;
}
if(found)
SetContextDataEx(hActiveThread, registerindex, value);

View File

@ -101,6 +101,9 @@ static void registercommands()
dbgcmdnew("cmp", cbInstrCmp, false);
dbgcmdnew("mov,set", cbInstrMov, false); //mov a variable, arg1:dest,arg2:src
//general purpose (SSE/AVX)
dbgcmdnew("movdqu,movups,movupd", cbInstrMovdqu, true); //move from and to XMM register
//debug control
dbgcmdnew("InitDebug,init,initdbg", cbDebugInit, false); //init debugger arg1:exefile,[arg2:commandline]
dbgcmdnew("StopDebug,stop,dbgstop", cbDebugStop, true); //stop debugger