汇编引擎思路
1) 切割指令
mov ax,bx
inc ax
xlat
mov byte ptr [bx+si+4433],11
切割出三部分:
助记符:mov,inc,xlat,mov
操作数1:ax,ax,,byte ptr [bx+si+4433]
操作数2:bx,,,,11
2) 解析操作数
mov [bx+si],ax
struct Oprand
{
enum Type{REG16,REG8,IMM8,REG_SEG,MEM8,MEM16,MEM}
char reg16;
char reg8;
char IMM8;
short reg_mem;
short offset;
}
ax,ax,,byte ptr [bx+si+4433]
opand{REG16,REG16=0}
opand{MEM8,reg_mem = 3,short = 4433};
3)合成指令
//1
#include
#include
#include
using namespace std;
int main()
{
string strAsm = “mov byte [ bx + si + 6541 ] , 87”;
smatch mResult;
regex e(“ .+,”);
std::regex_search(strAsm, mResult, e);
for (auto s : mResult)
{
cout << s << endl;
cout << mResult.prefix() << endl;
cout << mResult.suffix() << endl;
}
std::cout << “Hello World!\n”;
}
//2
#include
#include
#include
using namespace std;
int main()
{
string strAsm = “mov byte [ bx + si + 6541 ] , 87”;
smatch mResult;
regex e(“[a-z]+ “);
std::regex_search(strAsm, mResult, e);
while (std::regex_search(strAsm, mResult, e))
{
cout << mResult[0] << endl;
/cout << mResult.prefix() << endl;
cout << mResult.suffix() << endl;/
strAsm = mResult.suffix();
}
std::cout << “Hello World!\n”;
}
//3
#include
#include
#include
using namespace std;
int main()
{
string s(“mov ax,bx”);//待匹配数据
smatch m;
regex e(“\S+”); //正则指令
while (regex_search(s, m, e)) <br /> {<br /> for (auto x : m)<br /> {<br /> cout << x << endl;<br /> }<br /> s = m.suffix().str();<br /> }
return 0;<br />}