/*Converts an edit script in half-byte format to ASCII*/ char *half_bytes_to_ASCII(char *half_bytes, int length){ int i = 0; char *edit_script = malloc((length+1)*sizeof(*edit_script)); assert(edit_script); for (i = 0; i < length; i++) { /*Copy the left half-byte of the current byte*/ if (i % 2 == 0) { char left = half_bytes[i/2] & (((char)15) << 4); left >>= 4; left &= (char)15; edit_script[i] = half_byte_to_char(left); /*Handle the direction byte so that the match bit of the *half-byte is added to the direction byte separately from the *direction bit. */ if (i == 0) { left &= (char)1; edit_script[i] = half_byte_to_char(left); if ((half_bytes[0] & (char)0x80) != 0) edit_script[i] |= (char)0x80; } } else /*Copy the right half-byte of the current byte*/
void aesm_dbg_format_hex(const uint8_t *data, uint32_t data_len, char *out_buf, uint32_t buf_size) { uint32_t i; assert(buf_size>0); if(data_len==0){ out_buf[0]='\0'; return; } if(buf_size/3>=data_len){ for(i=0;i<data_len;i++){ int low=data[i]&0xF; int high=(data[i]>>4)&0xF; out_buf[i*3]=half_byte_to_char(high); out_buf[i*3+1]=half_byte_to_char(low); out_buf[i*3+2]=' '; } out_buf[data_len*3-1]='\0'; }else if(buf_size>10){
left &= (char)15; edit_script[i] = half_byte_to_char(left); /*Handle the direction byte so that the match bit of the *half-byte is added to the direction byte separately from the *direction bit. */ if (i == 0) { left &= (char)1; edit_script[i] = half_byte_to_char(left); if ((half_bytes[0] & (char)0x80) != 0) edit_script[i] |= (char)0x80; } } else //Copy the right half-byte of the current byte edit_script[i] = half_byte_to_char(half_bytes[i/2] & (char)15); } edit_script[length] = '\0'; return edit_script; } /*Takes in two strings, a bool representing whether or not they are in the same *direction, and the length of the strings and returns an edit script that can *convert the reference string to the original string. */ char *make_edit_script(char *str, char *ref, bool dir, int length) { /*direction has its first bit set to 1 to indicate that the edit script was made from a match*/ int last_edit = 0, current = 1; char *edit_script, *octal, direction = dir ? '0' : '1';