library/src/decoders/x86ASM/BP-x86InstDecode.cc
// This function will look at an arbitrary buffer string, and determine
// how many prefixes, and which specific prefixes are included in the
// following instruction.  This function actually is responsible for
// returning the decoded instruction element used with decoding.  This
// function must always be called before X86_32_DecodeOpcode and when
// calling X86_32_DecodeOpcode, it must be passed as a parameter.
This function will look at an arbitrary buffer string, and determine
how many prefixes, and which specific prefixes are included in the
following instruction.  This function actually is responsible for
returning the decoded instruction element used with decoding.  This
function must always be called before X86_32_DecodeOpcode and when
calling X86_32_DecodeOpcode, it must be passed as a parameter.
This function will look at an arbitrary buffer string and determine how many prefixes and which specific prefixes are included in the following instruction . This function actually is responsible for returning the decoded instruction element used with decoding . This function must always be called before X86_32_DecodeOpcode and when calling X86_32_DecodeOpcode it must be passed as a parameter .
P_X86_32_DECODED_INSTRUCTION X86_32_DecodePrefixes(void *buff){
	if(buff == NULL) return NULL;
	unsigned char *inBuff = (unsigned char *) buff;
	char *prefixStr = NULL;
	P_X86_32_DECODED_INSTRUCTION instruction = X86_32_CreateInstructionElement(
			       (P_X86_32_DECODED_INSTRUCTION) NULL,
			       (P_X86_32_DECODED_INSTRUCTION) NULL,
			       (P_X86_32_DECODED_INSTRUCTION) NULL);
	if(instruction == NULL) return NULL;
	for(unsigned char i = 0; i < 14; i++){
		prefixStr = X86_32_IsBytePrefix(inBuff[i]);
		if(prefixStr == NULL){
			break;
		}
		instruction->prefixCount++;
		instruction->prefixes[i].bytePrefix = inBuff[i];
		if(inBuff[i] == 0x66)
			instruction->operSizeOverride = true;
		if(inBuff[i] == 0x67)
			instruction->addrSizeOverride = true;
		instruction->prefixes[i].prefixStr = bpstrndup(prefixStr, 10);
	}
	return instruction;
}
P_X86_32_DECODED_INSTRUCTION X86_32_DecodePrefixes ( void * buff ) { if ( buff == NULL ) return NULL ; unsigned char * inBuff = ( unsigned char * ) buff ; char * prefixStr = NULL ; P_X86_32_DECODED_INSTRUCTION instruction = X86_32_CreateInstructionElement ( ( P_X86_32_DECODED_INSTRUCTION ) NULL , ( P_X86_32_DECODED_INSTRUCTION ) NULL , ( P_X86_32_DECODED_INSTRUCTION ) NULL ) ; if ( instruction == NULL ) return NULL ; for ( unsigned char i = 0 ; i < 14 ; i ++ ) { prefixStr = X86_32_IsBytePrefix ( inBuff [ i ] ) ; if ( prefixStr == NULL ) { break ; } instruction -> prefixCount ++ ; instruction -> prefixes [ i ] . bytePrefix = inBuff [ i ] ; if ( inBuff [ i ] == 0x66 ) instruction -> operSizeOverride = true ; if ( inBuff [ i ] == 0x67 ) instruction -> addrSizeOverride = true ; instruction -> prefixes [ i ] . prefixStr = bpstrndup ( prefixStr , 10 ) ; } return instruction ; }
This function will look at an arbitrary buffer string, and determine
how many prefixes, and which specific prefixes are included in the
following instruction.
This function will look at an arbitrary buffer string and determine how many prefixes and which specific prefixes are included in the following instruction .
// create the decoded structure // Return null if we cannot allocate the instruction // An instruction can have a maximum of 14 prefixes // so the string will only ever be a maximum of 14 bytes. // increment the base prefix count // assign the actual prefix values // a string representing the literal prefix // definition.