📄 decoder.c
字号:
else r=databody(c);
return r;
}
int databody(int c)
{
if(c==1) return labeldata();
else if (c==2) return bytex();
else if (c==3) return byte();
else if (c==4) return pascalstring();
else if (c==5) return nullstring();
else if (c==6) return worddata();
else return 0;
}
int labeldata()
{
int r;
r = dword();
m_dword=result;
return r;
}
int worddata()
{
int r;
r = word();
m_dword=result;
return r;
}
int instructionbody()
{
int r;
if (PeekOneByte()!=0x0F)
{ r=onebyteinstr(); opclass=1; return r;}
else {byte(); r=twobyteinstr(); opclass=2; return r;}
}
int byte()
{
int x;
x=ReadOneByte();
if(printMode==1)printf("%02X", x);else;
a_loc++; i_col++; result=x;
return 1;
}
int bytex()
{
int x;
x=ReadOneByte();
m_byte=x;
a_loc++; i_col++; result=x;
return 1;
}
int op()
{
int x;
x=ReadOneByte();
if(printMode==1)printf("%02X", x);else;
a_loc++; i_col++; result=x;
return 1;
}
int pascalstring()
{
int i, n, x;
x=ReadOneByte();
//if(printMode==1)printf("%02X ", x);else;
a_loc++; i_col++; result=x;
stringBuf[0]=x;
n=x;
for(i=1;i<n+1;i++)
{ x=ReadOneByte(); //if(printMode==1)printf("%02X ", x);else;
a_loc++; i_col++; result=x; stringBuf[i]=x;}
return 1;
}
int nullstring()
{
int i, x;
i=0;
while(1)
{ x=ReadOneByte(); //if(printMode==1)printf("%02X ", x);else;
a_loc++; i_col++; result=x; stringBuf[i++]=x; if(!isprint(PeekOneByte()))break;}
while(getMap(cur_position+i_col)==0x08)
{
x=ReadOneByte(); //if(printMode==1)printf("%02X ", x);else;
stringBuf[i++]=x; a_loc++; i_col++;
}
stringBuf[i]=-1;
return 1;
}
int word()
{
int x,y;
byte(); x=result;
byte(); y=result;
result=y*256+x;
return 1;
}
int dword()
{
int x1,x2,x3,x4;
byte(); x1=result;
byte(); x2=result;
byte(); x3=result;
byte(); x4=result;
result=((x4*256+x3)*256+x2)*256+x1;
return 1;
}
int adword()
{
if (addressOveride) return word(); else return dword();
}
int wdword()
{
if (operandOveride) return word(); else return dword();
}
int pword()
{
int r;
r=word(); if (!r) return 0; i_word=result;
r=dword(); if (!r) return 0; i_dword=result;
return 1;
}
int prefixes()
{
int r;
if (opcodeTable[PeekOneByte()]==PREFIX)
{
r=op(); if (!r) return 0;
prefixStack[i_psp++]=result;
if (result==102) operandOveride=1;
if (result==103) addressOveride=1;
return 1;
}
else return 0;
}
int onebyteinstr()
{
int r, b, x, y, y1, y2;
b=PeekOneByte();
//fprintf(stderr, "b=%02X",b),getch();
switch(opcodeTable[b])
{
case 0: r=op(); if(!r) return 0; x=result;
//fprintf(stderr, "x=%02X",x),getch();
i_opclass=0; i_opcode=x;
break;
case 1: r=op(); if(!r) return 0; x=result;
r=byte(); if(!r) return 0; y=result;
i_opclass=1; i_opcode=x; i_byte=y;
break;
case 2: r=op(); if(!r) return 0; x=result;
r=word(); if(!r) return 0; y=result;
i_opclass=2; i_opcode=x; i_word=y;
break;
case 3: r=op(); if(!r) return 0; x=result;
r=word(); if(!r) return 0; y1=result;
r=byte(); if(!r) return 0; y2=result;
i_opclass=3; i_opcode=x; i_word=y1; i_byte=y2;
break;
case 4: r=op(); if(!r) return 0; x=result;
r=wdword(); if(!r) return 0; y=result;
i_opclass=4; i_opcode=x; i_dword=y;
break;
case 44: r=op(); if(!r) return 0; x=result;
r=adword(); if(!r) return 0; y=result;
i_opclass=4; i_opcode=x; i_dword=y;
break;
case 5: r=op(); if(!r) return 0; x=result;
r=pword(); if(!r) return 0;
i_opclass=5; i_opcode=x;
break;
case 6: r=op(); if(!r) return 0; x=result;
r=modrm(); if(!r) return 0;
i_opclass=6; i_opcode=x;
break;
case 7: r=op(); if(!r) return 0; x=result;
r=modrm(); if(!r) return 0;
r=byte(); if(!r) return 0; y=result;
i_opclass=7; i_opcode=x; i_byte=y;
break;
case 8: r=op(); if(!r) return 0; x=result;
r=modrm(); if(!r) return 0;
r=wdword(); if(!r) return 0; y=result;
i_opclass=8; i_opcode=x; i_dword=y;
break;
case 9: r=op(); if(!r) return 0; x=result;
r=opext(); if(!r) return 0;
i_opclass=9; i_opcode=x;
break;
case 10: r=op(); if(!r) return 0; x=result;
r=opext(); if(!r) return 0;
r=byte(); if(!r) return 0; y=result;
i_opclass=10; i_opcode=x; i_byte=y;
break;
case 11: r=op(); if(!r) return 0; x=result;
r=opext(); if(!r) return 0;
r=wdword(); if(!r) return 0; y=result;
i_opclass=11; i_opcode=x; i_dword=y;
break;
case 12: r=op(); if(!r) return 0; x=result;
r=opextg(); if(!r) return 0;
i_opclass=12; i_opcode=x;
break;
case 13: r=op(); if(!r) return 0; x=result; // case jump block
b=PeekOneByte();
if (b==36)
{
b=PeekSecondByte();
if (rmTable[b]==5)
{
r=op(); if(!r) return 0; y1=result;
r=op(); if(!r) return 0; y2=result;
i_opclass=13;
i_opcode=x;
i_mod=y1;
i_sib=y2;
r=labelstartposition(); if(!r) return 0;
// ..................................................................
if (nextMode)
{
r=label1();
finished=1;
if(!r) return 1; // need to be careful ...
}
return 1;
}
}
//else
{
b=PeekOneByte();
if (regTable[b]<7)
{
r=opext(); if(!r) return 0;
i_opclass=13; i_opcode=x;
}
else return 0;
}
break;
case 14: r=op(); if(!r) return 0; x=result; // test group
if (x==246)
{
b=PeekOneByte();
if (regTable[b]==0)
{
r=opext(); if(!r) return 0;
r=byte(); if(!r) return 0; y=result;
i_opclass=14; i_opcode=x; i_byte=y;
}
else if (regTable[b]>1)
{
r=opext(); if(!r) return 0;
i_opclass=14; i_opcode=x;
}
else return 0;
}
else
{
b=PeekOneByte();
if (regTable[b]==0)
{
r=opext(); if(!r) return 0;
r=wdword(); if(!r) return 0; y=result;
i_opclass=14; i_opcode=x; i_dword=y;
}
else
{
r=opext(); if(!r) return 0;
i_opclass=14; i_opcode=x;
}
}
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -