static UInt32 lookup_opcode(long offset, byte table, ref OPCODE_DESCRIPTOR opcode_descr, INTERNAL_DATA idata)
{
byte max;
byte opcode;
UInt32 res;
res = 0;
//opcode_descr = NULL;
do
{
opcode = assembly.Image.ReadBytes(offset, 1)[0];
opcode >>= tables[table].shift;
opcode &= tables[table].mask;
opcode -= tables[table].min;
//It looks strange, but I want that table descriptors contain
// "real" values.
max = (byte)(tables[table].max - tables[table].min);
if (opcode > max)
{
idata.severe_err = ERRS.ERR_BADCODE;
break;
}
if (res > MAX_INSTRUCTION_LEN)
{
idata.severe_err = ERRS.ERR_TOO_LONG;
break;
}
if ( (tables[table].props & TBL_PROP_MODRM)==0 )
{
res++;
offset++;
}
if ((tables[table].opcodes[opcode].groups & GRP_SWITCH)!=0)
{
table = (byte)tables[table].opcodes[opcode].props;// &0xFF;
continue;
}
break;
}
while(true);
if (idata.severe_err == ERRS.ERR_OK)
opcode_descr = tables[table].opcodes[opcode];
return res;
}