library/src/decoders/x86ASM/BP-x86InstDecode.cc
// Retrieves a register string for plus encoded instructions given
Retrieves a register string for plus encoded instructions given
Retrieves a register string for plus encoded instructions given
char * X86_32_GetPlusEncodedRegString(P_X86_32_DECODED_INSTRUCTION_LIST partialDecoded, unsigned char *inBuff){
	unsigned char *binOpcode = (unsigned char *) partialDecoded->instruction->binOpcode;
	size_t encodedOpcode = X86_32_IsBytePlusEncodedOpcode((unsigned char *) binOpcode);
	size_t regField = 0;
	if(encodedOpcode != 0){
		if(binOpcode[0] == 0x0f)
		if(binOpcode[1] >= 0xC8 && binOpcode[1] < (0xc8+8)){
			binOpcode = &binOpcode[1];
			goto decode;
		}
		if(binOpcode[0] >= 0xb0 && binOpcode[0] < (0xb0+8) ||
		   binOpcode[0] >= 0xb8 && binOpcode[0] < (0xb8+8) ||
		   binOpcode[0] >= 0x48 && binOpcode[0] < (0x48+8) ||
		   binOpcode[0] >= 0x40 && binOpcode[0] < (0x40+8) ||
		   binOpcode[0] >= 0x58 && binOpcode[0] < (0x58+8) ||
		   binOpcode[0] >= 0x50 && binOpcode[0] < (0x50+8) ||
		   binOpcode[0] >= 0x90 && binOpcode[0] < (0x90+8) ){
			decode:
			regField = inBuff[partialDecoded->totalLength -
							partialDecoded->instruction->binOpcodeLen] - encodedOpcode ;
			switch(regField){
				case 0x0:
					if(partialDecoded->operSizeOverride > 0){
						return strdup("AX");
					} else {
						return strdup("EAX");
					}
					goto end;
					break;
				case 0x01:
					if(partialDecoded->operSizeOverride > 0){
						return strdup("CX");
					} else {
						return strdup("ECX");
					}
					goto end;
					break;
				case 0x02:
					if(partialDecoded->operSizeOverride > 0){
						return strdup("DX");
					} else {
						return strdup("EDX");
					}
					goto end;
					break;
				case 0x03:
					if(partialDecoded->operSizeOverride > 0){
						return strdup("BX");
					} else {
						return strdup("EBX");
					}
					goto end;
					break;
				case 0x04:
					if(partialDecoded->operSizeOverride > 0){
						return strdup("SP");
					} else {
						return strdup("ESP");
					}
					goto end;
					break;
				case 0x05:
					if(partialDecoded->operSizeOverride > 0){
						return strdup("BP");
					} else {
						return strdup("EBP");
					}
					goto end;
					break;
				case 0x06:
					if(partialDecoded->operSizeOverride > 0){
						return strdup("SI");
					} else {
						return strdup("ESI");
					}
					goto end;
					break;
				case 0x07:
					if(partialDecoded->operSizeOverride > 0){
						return strdup("DI");
					} else {
						return strdup("EDI");
					}
					goto end;
					break;
				default:
					goto end;
					break;
			}
		}
	}
	end:
	return NULL;
}
char * X86_32_GetPlusEncodedRegString ( P_X86_32_DECODED_INSTRUCTION_LIST partialDecoded , unsigned char * inBuff ) { unsigned char * binOpcode = ( unsigned char * ) partialDecoded -> instruction -> binOpcode ; size_t encodedOpcode = X86_32_IsBytePlusEncodedOpcode ( ( unsigned char * ) binOpcode ) ; size_t regField = 0 ; if ( encodedOpcode != 0 ) { if ( binOpcode [ 0 ] == 0x0f ) if ( binOpcode [ 1 ] >= 0xC8 && binOpcode [ 1 ] < ( 0xc8 + 8 ) ) { binOpcode = & binOpcode [ 1 ] ; goto decode ; } if ( binOpcode [ 0 ] >= 0xb0 && binOpcode [ 0 ] < ( 0xb0 + 8 ) || binOpcode [ 0 ] >= 0xb8 && binOpcode [ 0 ] < ( 0xb8 + 8 ) || binOpcode [ 0 ] >= 0x48 && binOpcode [ 0 ] < ( 0x48 + 8 ) || binOpcode [ 0 ] >= 0x40 && binOpcode [ 0 ] < ( 0x40 + 8 ) || binOpcode [ 0 ] >= 0x58 && binOpcode [ 0 ] < ( 0x58 + 8 ) || binOpcode [ 0 ] >= 0x50 && binOpcode [ 0 ] < ( 0x50 + 8 ) || binOpcode [ 0 ] >= 0x90 && binOpcode [ 0 ] < ( 0x90 + 8 ) ) { decode : regField = inBuff [ partialDecoded -> totalLength - partialDecoded -> instruction -> binOpcodeLen ] - encodedOpcode ; switch ( regField ) { case 0x0 : if ( partialDecoded -> operSizeOverride > 0 ) { return strdup ( " " ) ; } else { return strdup ( " " ) ; } goto end ; break ; case 0x01 : if ( partialDecoded -> operSizeOverride > 0 ) { return strdup ( " " ) ; } else { return strdup ( " " ) ; } goto end ; break ; case 0x02 : if ( partialDecoded -> operSizeOverride > 0 ) { return strdup ( " " ) ; } else { return strdup ( " " ) ; } goto end ; break ; case 0x03 : if ( partialDecoded -> operSizeOverride > 0 ) { return strdup ( " " ) ; } else { return strdup ( " " ) ; } goto end ; break ; case 0x04 : if ( partialDecoded -> operSizeOverride > 0 ) { return strdup ( " " ) ; } else { return strdup ( " " ) ; } goto end ; break ; case 0x05 : if ( partialDecoded -> operSizeOverride > 0 ) { return strdup ( " " ) ; } else { return strdup ( " " ) ; } goto end ; break ; case 0x06 : if ( partialDecoded -> operSizeOverride > 0 ) { return strdup ( " " ) ; } else { return strdup ( " " ) ; } goto end ; break ; case 0x07 : if ( partialDecoded -> operSizeOverride > 0 ) { return strdup ( " " ) ; } else { return strdup ( " " ) ; } goto end ; break ; default : goto end ; break ; } } } end : return NULL ; }
Retrieves a register string for plus encoded instructions given
Retrieves a register string for plus encoded instructions given
// if the instruction is plusbase encoded // set instruction and jump to end label. // test the plus base encoded opcode // BSWAP + rd check (requires first byte as simd 0f prefix) // advance and jump to main decoder //return 0xC8; // check all 1 byte plus encoded values and return string // arbitrary jump for 0xf0 encoded instruction // goto end;