1
0
Fork 0

resolved issue #213 (mov dest,#DATA#)

This commit is contained in:
Mr. eXoDia 2014-12-17 19:27:18 +01:00
parent c3bb3581fd
commit 54fbc038df
1 changed files with 66 additions and 16 deletions

View File

@ -130,8 +130,57 @@ CMDRESULT cbInstrMov(int argc, char* argv[])
dputs("not enough arguments"); dputs("not enough arguments");
return STATUS_ERROR; return STATUS_ERROR;
} }
String srcText = argv[2];
if(srcText[0] == '#' && srcText[srcText.length() - 1] == '#') //handle mov addr, #DATA#
{
//do some checks on the data
String dataText = srcText.substr(1, srcText.length() - 2);
int len = (int)dataText.length();
if(len % 2)
{
dprintf("invalid hex string \"%s\" (length not divisible by 2)\n");
return STATUS_ERROR;
}
for(int i = 0; i < len; i++)
{
if(!isxdigit(dataText[i]))
{
dprintf("invalid hex string \"%s\" (contains invalid characters)\n", dataText.c_str());
return STATUS_ERROR;
}
}
//Check the destination
uint dest;
if(!valfromstring(argv[1], &dest) || !memisvalidreadptr(fdProcessInfo->hProcess, dest))
{
dprintf("invalid destination \"%s\"\n", argv[1]);
return STATUS_ERROR;
}
//Convert text to byte array (very ugly)
Memory<unsigned char*> data(len / 2);
for(int i = 0, j = 0; i < len; i += 2, j++)
{
char b[3] = "";
b[0] = dataText[i];
b[1] = dataText[i + 1];
int res = 0;
sscanf_s(b, "%X", &res);
data[j] = res;
}
//Move data to destination
if(!memwrite(fdProcessInfo->hProcess, (void*)dest, data, data.size(), 0))
{
dprintf("failed to write to "fhex"\n", dest);
return STATUS_ERROR;
}
GuiUpdateAllViews(); //refresh disassembly/dump/etc
return STATUS_CONTINUE;
}
else
{
uint set_value = 0; uint set_value = 0;
if(!valfromstring(argv[2], &set_value)) if(!valfromstring(srcText.c_str(), &set_value))
{ {
dprintf("invalid src \"%s\"\n", argv[2]); dprintf("invalid src \"%s\"\n", argv[2]);
return STATUS_ERROR; return STATUS_ERROR;
@ -151,6 +200,7 @@ CMDRESULT cbInstrMov(int argc, char* argv[])
} }
varnew(argv[1], set_value, VAR_USER); varnew(argv[1], set_value, VAR_USER);
} }
}
return STATUS_CONTINUE; return STATUS_CONTINUE;
} }