assembly - Numbers of opcodes in instruction -


is there other (faster) way it? x86 architecture here wrote far.

 #include <cstdio> #include <cstdlib>  typedef unsigned int uint; typedef unsigned char byte;  byte getinstructionlength(byte * data);  int main() {      //get mod      //hex:bin 0x00:00 0xc0:11 0x40:01 0x80:10     //printf("opcode 0x%x  mod: 0x%x\n", opcode, opcode&0xc0);     //get r     //hex:bin 0x28:101 0x30:110 0x8:001     //printf("opcode 0x%x  reg: 0x%x\n", opcode, opcode&0x38);     //get m     //hex:bin 0x07:111 0x2:010 0x1:001 0x6:110 0x0:000 0x3:011 0x4:100 0x5 101     //printf("opcode 0x%x  r/m: 0x%x\n", opcode, opcode&0x07);      for(byte opcode=0x0; opcode < 255; opcode++)     {         printf("opcode 0x%x mod: 0x%x  reg:0x%x  m:0x%x\n", opcode, opcode&0xc0, opcode&0x38, opcode&0x07);     }     return 0; }  byte getinstructionlength(byte * data) {     if(data[0] >= 0x3f && data[0] <= 0x61) return 1; //one opcode instructions     switch(data[0])     {     case 0x00:         switch(data[1])         {         case 0x00: return 2; //add byte ptr ds:[eax],al         case 0x01: return 2; //add byte ptr ds:[ecx],al         case 0x02: return 2; //add byte ptr ds:[edx],al          case 0x03: return 2; //add byte ptr ds:[ebx],al         case 0x04: if(data[2]&0x07 == 0x5) return 7; else return 3; //always 7 if r/m = 101          case 0x05: return 6;         case 0x06: return 2;         case 0x07: return 2;         case 0x08: return 2;         case 0x09: return 2;         case 0x0a: return 2;         case 0x0b: return 2;         case 0x0c: if(data[2]&0x07 == 0x5) return 7; else return 3;         }         case 0x06: return 1; //push es         case 0x07: return 1; //pop es         case 0x16: return 1; //push ss         case 0x17: return 1; //pop ss         case 0x90: return 1; //nop     } } 

if need able compute instruction length in bytes x86, for
length-disassembler on z0mbie's page: http://z0mbie.daemonlab.org/


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -