#include "PacketId.h" bool CompareSigs(unsigned char* pFunctionSig, unsigned char* pStoredSig, int sigSize) { ud_t sigs[2]; //Init the disasm holders for (int i=0; i<2; i++) { ud_init(&sigs[i]); ud_set_syntax(&sigs[i], UD_SYN_INTEL); ud_set_mode(&sigs[i], 32); } //Set the source input for each disassembler ud_set_input_buffer(&sigs[0], pFunctionSig, sigSize); ud_set_input_buffer(&sigs[1], pStoredSig, sigSize); //Start comparing instruction by instruction while (true) { //Disassemble the next instruction for both int f_size=ud_disassemble(&sigs[0]); int s_size=ud_disassemble(&sigs[1]); if (f_size == 0 || s_size == 0) { break; } //Check that the instruction size matches if (f_size == s_size) { //Make sure the instructions are the same if (sigs[0].mnemonic == sigs[1].mnemonic) { //Check for not processed operands bool not_processed=false; for (int i=0; i<3; i++) { //Check for operand types that use memory addresses if (sigs[1].operand[i].type == UD_OP_MEM || sigs[1].operand[i].type == UD_OP_JIMM) { //Make sure these do not use registers (i.e. can't be an offset from a register) if ((!sigs[1].operand[i].base && !sigs[1].operand[i].index)) { not_processed=true; break; } } } //Only check the operands on OK instructions if (!not_processed) { for (int i=0; i<3; i++) { //Compare the operands for exact match if (sigs[0].operand[i].type == sigs[1].operand[i].type) { } else { return false; } } }//*/ } else { return false; } } else { return false; } if (sigs[0].mnemonic == UD_Iret || sigs[1].mnemonic == UD_Iret) { break; } } return true; }