能力值:
( LV2,RANK:10 )
|
-
-
3 楼
1.53的mov命令 代码
bool OllyLang:oMOV(string args)
{
string ops[3];
bool bDeclared=false;
DWORD maxsize=0;
/*
if(CreateOp(args, ops, 3)){
GetDWOpValue(ops[2], maxsize);
}
else
if(!CreateOp(args, ops, 2))
return false;
*/
if(CreateOp(args, ops, 3)){
GetDWOpValue(ops[2], maxsize);
}
else
if(!CreateOp(args, ops, 2))
return false;
// Check source
DWORD dw = 0, addr = 0;
string str = "";
string tmpops=ops[0];
long double flt;
// Used to retry after automatic variable declaration
retry_DoMOV:
// Check destination
if(variables.find(ops[0]) != variables.end())
{
// Dest is variable
if(GetDWOpValue(ops[1], dw) && maxsize <= 4)
{
dw = resizeDW(dw,maxsize);
variables[ops[0]].vt = DW;
variables[ops[0]] = dw;
}
else if(GetSTROpValue(ops[1], str, maxsize))
{
variables[ops[0]].vt = STR;
variables[ops[0]] = str;
}
else if(GetFLTOpValue(ops[1], flt))
{
variables[ops[0]].vt = FLT;
variables[ops[0]] = flt;
}
else
return false;
return true;
}
else if(is_register(ops[0]))
{
// Dest is register
if(GetDWOpValue(ops[1], dw))
{
t_thread* pt = Findthread(Getcputhreadid());
int regnr = GetRegNr(ops[0]);
if(regnr != -1) {
if (ops[0].length()==2)
{
if (ops[0][1] == 'l') {
//R8
dw &= 0xFF;
pt->reg.r[regnr] &= 0xFFFFFF00;
pt->reg.r[regnr] |= dw;
}
else if ( ops[0][1] == 'h')
{
//R8
dw &= 0xFF;
pt->reg.r[regnr] &= 0xFFFF00FF;
pt->reg.r[regnr] |= dw * 0x100;
}
else
{
//R16
dw &= 0xFFFF;
pt->reg.r[regnr] &= 0xFFFF0000;
pt->reg.r[regnr] |= dw;
}
}
else
//R32
pt->reg.r[regnr] = dw;
}
else
if(ops[0] == "eip"
pt->reg.ip = dw;
pt->reg.modified = 1;
pt->regvalid = 1;
Broadcast(WM_USER_CHREG, 0, 0);
require_ollyloop = 1;
dw = resizeDW(dw,maxsize);
return true;
}
return false;
}
else if(is_flag(ops[0]))
{
// Dest is flag
if(GetDWOpValue(ops[1], dw))
{
if(dw != 0 && dw != 1)
{
errorstr = "非法标志位!";
return false;
}
eflags flags;
ZeroMemory(&flags, sizeof DWORD);
t_thread* pt = Findthread(Getcputhreadid());
flags.dwFlags = pt->reg.flags;
if(stricmp(ops[0].c_str(), "!af" == 0)
flags.bitFlags.AF = dw;
else if(stricmp(ops[0].c_str(), "!cf" == 0)
flags.bitFlags.CF = dw;
else if(stricmp(ops[0].c_str(), "!df" == 0)
flags.bitFlags.DF = dw;
else if(stricmp(ops[0].c_str(), "!of" == 0)
flags.bitFlags.OF = dw;
else if(stricmp(ops[0].c_str(), "!pf" == 0)
flags.bitFlags.PF = dw;
else if(stricmp(ops[0].c_str(), "!sf") == 0)
flags.bitFlags.SF = dw;
else if(stricmp(ops[0].c_str(), "!zf") == 0)
flags.bitFlags.ZF = dw;
pt->reg.flags = flags.dwFlags;
pt->reg.modified = 1;
pt->regvalid = 1;
Broadcast(WM_USER_CHREG, 0, 0);
require_ollyloop = 1;
return true;
}
return false;
}
else if(is_floatreg(ops[0]))
{
// Dest is float register
if(GetFLTOpValue(ops[1], flt))
{
t_thread* pt = Findthread(Getcputhreadid());
pt->reg.f[(ops[0][3]-0x30)] = flt;
pt->reg.modified = 1;
pt->regvalid = 1;
Broadcast(WM_USER_CHREG, 0, 0);
require_ollyloop = 1;
return true;
}
return false;
}
else if(UnquoteString(ops[0], '[', ']'))
{
// Dest is memory address
int len;
if(tmpops.find('+')!=-1)
{
GetAddrOpValue(tmpops,addr);
goto ok; //jmp ok
}
if(GetDWOpValue(ops[0], addr))
{
ok:
if(ops[1].length() % 2 == 0 && UnquoteString(ops[1], '#', '#'))
{
len = Str2Rgch(ops[1], buffer, sizeof(buffer)); //BUGFIX sizeof(buffer)
Writememory(buffer, addr, len, MM_DELANAL|MM_SILENT);
Broadcast(WM_USER_CHALL, 0, 0);
}
else if(GetDWOpValue(ops[1], dw) && maxsize <= 4)
{
if (maxsize==0) maxsize=4;
dw = resizeDW(dw,maxsize);
Writememory(&dw, addr, maxsize, MM_DELANAL|MM_SILENT);
Broadcast(WM_USER_CHALL, 0, 0);
}
else if(GetSTROpValue(ops[1], str, maxsize))
{
if (UnquoteString(str, '#', '#'))
{
len = Str2Rgch(str, buffer, sizeof(buffer)); // bugfix sizeof(buffer)
Writememory(buffer, addr, len, MM_DELANAL|MM_SILENT);
}
else
{
strcpy(buffer, str.c_str());
Writememory(buffer, addr, str.length(), MM_DELANAL|MM_SILENT);
}
Broadcast(WM_USER_CHALL, 0, 0);
}
else if(GetFLTOpValue(ops[1], flt))
{
Writememory(&flt, addr, 8, MM_DELANAL|MM_SILENT);
Broadcast(WM_USER_CHALL, 0, 0);
}
else
{
errorstr = "错误的操作 \"" + ops[1] + "\"";
return false;
}
Broadcast(WM_USER_CHMEM, 0, 0);
return true;
}
return false;
}
else if (!bDeclared && ops[0][0] >= 'A' )
{
bDeclared=true;
DoVAR(ops[0]);
//DoLOG("\"automatic declaration of variable "+ops[0]+"\"");
goto retry_DoMOV;
}
//errorstr = "Variable '" + ops[0] + "' is not declared";
return false;
}
1.65版本的mov代码
bool OllyLang:oMOV(string args)
{
string ops[3];
bool bDeclared=false;
ulong addr=0,maxsize=0;
if(CreateOperands(args, ops, 3)){
GetDWOpValue(ops[2], maxsize);
}
else
if(!CreateOperands(args, ops, 2))
return false;
//resolve address with operands
if(UnquoteString(ops[1], '[', ']')) {
if (!CreateOperands(ops[1],&ops[1],1))
return false;
ops[1]="["+ops[1]+"]";
}
// Check source
ulong dw = 0; addr=0;
string str = "";
string tmpops=ops[0];
long double flt;
// Used to retry after automatic variable declaration
retry_DoMOV:
// Check destination
if(is_variable(ops[0]))
{
// Dest is variable
if(maxsize <= 4 && variables[ops[0]].vt != STR && GetDWOpValue(ops[1], dw) )
{
// DW to DW/FLT var
if (maxsize==0) maxsize=4;
dw = resizeDW(dw,maxsize);
variables[ops[0]] = dw;
variables[ops[0]].size = maxsize;
}
else if(GetSTROpValue(ops[1], str, maxsize))
{
// STR to any var
variables[ops[0]] = str;
}
else if(maxsize <= 4 && GetDWOpValue(ops[1], dw) )
{
// DW to STR var
if (maxsize==0) maxsize=4;
dw = resizeDW(dw,maxsize);
variables[ops[0]] = dw;
variables[ops[0]].size = maxsize;
}
else if(GetFLTOpValue(ops[1], flt))
{
variables[ops[0]] = flt;
}
else
return false;
return true;
}
else if(is_register(ops[0]))
{
// Dest is register
if(GetDWOpValue(ops[1], dw))
{
t_thread* pt = Findthread(Getcputhreadid());
int regnr = GetRegNr(ops[0]);
if(regnr != -1) {
if (ops[0].length()==2)
{
if (ops[0][1] == 'l') {
//R8
dw &= 0xFF;
pt->reg.r[regnr] &= 0xFFFFFF00;
pt->reg.r[regnr] |= dw;
}
else if ( ops[0][1] == 'h')
{
//R8
dw &= 0xFF;
pt->reg.r[regnr] &= 0xFFFF00FF;
pt->reg.r[regnr] |= dw * 0x100;
}
else
{
//R16
dw &= 0xFFFF;
pt->reg.r[regnr] &= 0xFFFF0000;
pt->reg.r[regnr] |= dw;
}
}
else
{
//R32
pt->reg.r[regnr] = dw;
}
}
else
if(ops[0] == "eip") {
pt->reg.ip = dw;
//synch disasm window position
Setdisasm(dw,1,CPU_ASMHIST);
}
pt->reg.modified = 1;
pt->regvalid = 1;
Broadcast(WM_USER_CHREG, 0, 0);
require_ollyloop = 1;
dw = resizeDW(dw,maxsize);
return true;
}
return false;
}
else if(is_flag(ops[0]))
{
// Dest is flag
if(GetDWOpValue(ops[1], dw))
{
if(dw != 0 && dw != 1)
{
errorstr = "Invalid flag value";
return false;
}
eflags flags;
ZeroMemory(&flags, sizeof DWORD);
t_thread* pt = Findthread(Getcputhreadid());
flags.dwFlags = pt->reg.flags;
if(stricmp(ops[0].c_str(), "!af") == 0)
flags.bitFlags.AF = dw;
else if(stricmp(ops[0].c_str(), "!cf") == 0)
flags.bitFlags.CF = dw;
else if(stricmp(ops[0].c_str(), "!df") == 0)
flags.bitFlags.DF = dw;
else if(stricmp(ops[0].c_str(), "!of") == 0)
flags.bitFlags.OF = dw;
else if(stricmp(ops[0].c_str(), "!pf") == 0)
flags.bitFlags.PF = dw;
else if(stricmp(ops[0].c_str(), "!sf") == 0)
flags.bitFlags.SF = dw;
else if(stricmp(ops[0].c_str(), "!zf") == 0)
flags.bitFlags.ZF = dw;
pt->reg.flags = flags.dwFlags;
pt->reg.modified = 1;
pt->regvalid = 1;
Broadcast(WM_USER_CHREG, 0, 0);
require_ollyloop = 1;
return true;
}
return false;
}
else if(is_floatreg(ops[0]))
{
// Dest is float register
if(GetFLTOpValue(ops[1], flt))
{
t_thread* pt = Findthread(Getcputhreadid());
pt->reg.f[(ops[0][3]-0x30)] = flt;
pt->reg.modified = 1;
pt->regvalid = 1;
Broadcast(WM_USER_CHREG, 0, 0);
require_ollyloop = 1;
return true;
}
return false;
}
else if(UnquoteString(ops[0], '[', ']'))
{
// Destination is memory address
// Get Address from Operators (+_*...)
nIgnoreNextValuesHist=1;
CreateOperands(ops[0], &ops[0], 1);
if(GetDWOpValue(ops[0], addr))
{
if (addr==0)
{
DoLOG("\"WARNING: writing to address 0 !\"");
return true;
}
tmpops=ops[1];
if (maxsize > 8 && UnquoteString(ops[1], '[', ']'))
{
//Get Addr from Operators
CreateOperands(ops[1], &ops[1], 1);
//Optimized Mem Copy
ulong src;
if (!GetDWOpValue(ops[1], src) || src==0) {
DoLOG("\"WARNING: copy from address 0 !\"");
return true;
}
char* copybuffer= new char[maxsize];
if (maxsize != Readmemory((void*) copybuffer, src, maxsize, MM_RESTORE)) {
delete[] copybuffer;
return false;
}
Writememory((void*) copybuffer, addr, maxsize, MM_DELANAL);
delete[] copybuffer;
Broadcast(WM_USER_CHALL, 0, 0);
}
else if (GetDWOpValue(ops[1], dw) && maxsize <= 4)
{
if (maxsize==0) maxsize=4;
dw = resizeDW(dw,maxsize);
Writememory(&dw, addr, maxsize, MM_DELANAL|MM_SILENT);
Broadcast(WM_USER_CHALL, 0, 0);
}
else if (GetSTROpValue(ops[1], str, maxsize))
{
var v=str;
if (maxsize==0) maxsize=v.size;
maxsize=min(maxsize,v.size);
Writememory((void*)v.strbuff().c_str(), addr, maxsize, MM_DELANAL|MM_SILENT);
Broadcast(WM_USER_CHALL, 0, 0);
}
else if (GetFLTOpValue(ops[1], flt))
{
Writememory(&flt, addr, 8, MM_DELANAL|MM_SILENT);
Broadcast(WM_USER_CHALL, 0, 0);
}
else
{
errorstr = "Bad operator \"" + ops[1] + "\"";
return false;
}
Broadcast(WM_USER_CHMEM, 0, 0);
return true;
}
return false;
}
else if (!bDeclared && ops[0][0] >= 'A' )
{
bDeclared=true;
DoVAR(ops[0]);
//DoLOG("\"automatic declaration of variable "+ops[0]+"\"");
goto retry_DoMOV;
}
//errorstr = "Variable '" + ops[0] + "' is not declared";
return false;
}
可见有所不同的,请熟悉编程语言的高手帮看看!!!
|