library/src/decoders/x86ASM/BP-x86InstDecode.cc
// The Base Decoder Function, will decode instructions in a buffer
// buff, with a second size parameter.  Returns the starting
// element in a walkable list of instruction. Base addr is
// an optional operand used for automatically assigning address values
// for decoded instructions.  They are null otherwise.  Address is
// Previous Instruction length + base address.
The Base Decoder Function, will decode instructions in a buffer
buff, with a second size parameter.  Returns the starting
element in a walkable list of instruction. Base addr is
an optional operand used for automatically assigning address values
for decoded instructions.  They are null otherwise.  Address is
Previous Instruction length + base address.
The Base Decoder Function will decode instructions in a buffer buff with a second size parameter . Returns the starting element in a walkable list of instruction . Base addr is an optional operand used for automatically assigning address values for decoded instructions . They are null otherwise . Address is Previous Instruction length + base address .
P_X86_32_DECODED_INSTRUCTION_LIST X86_32_DecodeInstructions(P_X86_32_INSTRUCTION instTable, unsigned char *buff, size_t length, void *baseAddr){
	if(length==0)
		return NULL;
	P_X86_32_DECODED_INSTRUCTION_LIST decodedList = NULL;
	P_X86_32_DECODED_INSTRUCTION_LIST decodedListFirst = NULL;
	P_X86_32_DECODED_INSTRUCTION_LIST decodedListPrev  = NULL;
	size_t address = (size_t) baseAddr;
	size_t totalLength = 0;
	size_t loopLen = 0;
	for(totalLength = 0; totalLength < length; ){
		if((length - totalLength) < 15){
			loopLen = length-totalLength;
		} else {
			loopLen = 15;
		}
		decodedList = X86_32_DecodeInstruction(instTable, &buff[totalLength], loopLen);
		if(decodedList == NULL){
			decodedList = X86_32_CreateInstructionElement(decodedListFirst, decodedListPrev, NULL);
			if(decodedListPrev != NULL)
				decodedListPrev->next = decodedList;
			decodedList->prev = decodedListPrev;
			decodedListPrev = decodedList;
			decodedList->address = (void *) (address + totalLength);
			if(decodedListFirst == NULL){
				decodedListFirst = decodedList;
			}
			totalLength++;
		    continue;
		} else {
			if(decodedListFirst == NULL){
				decodedListFirst = decodedList;
			}
			decodedList->address = (void *) (address + totalLength);
			decodedList->first = decodedListFirst;
			decodedList->prev = decodedListPrev;
			if(decodedListPrev != NULL)
				decodedListPrev->next = decodedList;
			decodedList->prev = decodedListPrev;
			decodedListPrev = decodedList;
			totalLength += decodedList->totalLength;
		}
		decodedList->intelDecode = X86_32_GetDecodedInstOperandString_INTEL(decodedList);
	}
	decodedList->first->first = decodedList->first;
	return decodedList->first;
}
P_X86_32_DECODED_INSTRUCTION_LIST X86_32_DecodeInstructions ( P_X86_32_INSTRUCTION instTable , unsigned char * buff , size_t length , void * baseAddr ) { if ( length == 0 ) return NULL ; P_X86_32_DECODED_INSTRUCTION_LIST decodedList = NULL ; P_X86_32_DECODED_INSTRUCTION_LIST decodedListFirst = NULL ; P_X86_32_DECODED_INSTRUCTION_LIST decodedListPrev = NULL ; size_t address = ( size_t ) baseAddr ; size_t totalLength = 0 ; size_t loopLen = 0 ; for ( totalLength = 0 ; totalLength < length ; ) { if ( ( length - totalLength ) < 15 ) { loopLen = length - totalLength ; } else { loopLen = 15 ; } decodedList = X86_32_DecodeInstruction ( instTable , & buff [ totalLength ] , loopLen ) ; if ( decodedList == NULL ) { decodedList = X86_32_CreateInstructionElement ( decodedListFirst , decodedListPrev , NULL ) ; if ( decodedListPrev != NULL ) decodedListPrev -> next = decodedList ; decodedList -> prev = decodedListPrev ; decodedListPrev = decodedList ; decodedList -> address = ( void * ) ( address + totalLength ) ; if ( decodedListFirst == NULL ) { decodedListFirst = decodedList ; } totalLength ++ ; continue ; } else { if ( decodedListFirst == NULL ) { decodedListFirst = decodedList ; } decodedList -> address = ( void * ) ( address + totalLength ) ; decodedList -> first = decodedListFirst ; decodedList -> prev = decodedListPrev ; if ( decodedListPrev != NULL ) decodedListPrev -> next = decodedList ; decodedList -> prev = decodedListPrev ; decodedListPrev = decodedList ; totalLength += decodedList -> totalLength ; } decodedList -> intelDecode = X86_32_GetDecodedInstOperandString_INTEL ( decodedList ) ; } decodedList -> first -> first = decodedList -> first ; return decodedList -> first ; }
The Base Decoder Function, will decode instructions in a buffer
buff, with a second size parameter.
The Base Decoder Function will decode instructions in a buffer buff with a second size parameter .
// arbitrary list pointers used for list calculations below // Save address // Total instruction list cannot pass [length] // Length Calculation // Decode instruction // Check to verify if the decoded loop was null.  If it was // create an empty element with a instruction string "(bad)" // store previous and next in previous element // reset previous // Set first pointer // Set first pointer // set address // Set first and prev, next is already null from memset // store previous and next in previous element // set previous for loop // Increase total length // instead of printing the instruction struct, perhaps // kind of a hack to fix the initial missing of the first assignment