From b2911a60e257d493b9d5839f40e923f95df3b525 Mon Sep 17 00:00:00 2001 From: systemcoder Date: Sat, 21 Mar 2020 15:57:41 +0000 Subject: making to work byte, offset, with no space, and hex output in any combination --- H64E-2/h64e.c | 199 +++++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 157 insertions(+), 42 deletions(-) (limited to 'H64E-2/h64e.c') diff --git a/H64E-2/h64e.c b/H64E-2/h64e.c index 35875a2..80b085d 100644 --- a/H64E-2/h64e.c +++ b/H64E-2/h64e.c @@ -11,13 +11,14 @@ int h64e_init(H64E_t *s) { printf("init structure\n"); - s->fmt.column_size = 16; - s->fmt.offset_addr = 0; - s->fmt.flag_offset = 0; - s->fmt.flag_no_group = 0; - s->fmt.group = H64E_G_BYTE; + s->fmt.column_size = 16; + s->fmt.offset_addr = 0; + s->fmt.flag_offset = 0; + s->fmt.flag_no_group = 0; + s->fmt.flag_hex = 1; + s->fmt.group = H64E_G_BYTE; s->fmt.flag_output_types = 0; - s->fmt.output_type = H64E_O_NONE; + s->fmt.output_type = H64E_O_NONE; s->sin = NULL; s->sout = NULL; @@ -162,14 +163,20 @@ int h64e_fmt_byte_align16(H64E_format *fs, uint8_t *in_data, int32_t in_size, ui */ const int OUT_SZ=1024; //offset values in hex , spaces, number of hex values, second ascii characters const int BUF_SZ=64; + uint8_t buf_offset[BUF_SZ+1]; uint8_t buf1[BUF_SZ+1]; uint8_t buf2[BUF_SZ+1]; + uint8_t buf3[BUF_SZ+1]; uint8_t out_part1[OUT_SZ+1]; uint8_t out_part2[OUT_SZ+1]; + uint8_t out_part3[OUT_SZ+1]; int out_part1_sz=0; int out_part2_sz=0; + int out_part3_sz=0; + int buf_offset_sz=0; int buf1_sz=0; int buf2_sz=0; + int buf3_sz=0; int loop_size=0; int trail_size=0; @@ -178,10 +185,7 @@ int h64e_fmt_byte_align16(H64E_format *fs, uint8_t *in_data, int32_t in_size, ui { //printf("Print offset\n"); int offset = fs->start_offset + fs->total_output; - buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, "%08x: ",offset); - //no error check - memcpy(out_part1,buf1,buf1_sz); - out_part1_sz += buf1_sz; + buf_offset_sz = snprintf((char *)&buf_offset[0], BUF_SZ, "%08x: ",offset); } if (in_size%fs->column_size != 0) @@ -199,103 +203,214 @@ int h64e_fmt_byte_align16(H64E_format *fs, uint8_t *in_data, int32_t in_size, ui { if (igroup_fmt == H64E_G_BYTE)||(fs->group_fmt == H64E_G_NONE)) && (fs->output_fmt == H64E_O_STRING)) + + + + //group byte output + if (fs->f_hex) + { + + buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, "%02x",in_data[i]); + } + + //ascii output + if (fs->f_ascii) { if (isprint(in_data[i])) { - buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, "%c",(unsigned char)in_data[i]); + buf2_sz = snprintf((char *)&buf2[0], BUF_SZ, "%c",(unsigned char)in_data[i]); } else { - buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, "."); + buf2_sz = snprintf((char *)&buf2[0], BUF_SZ, "."); } - } else { - //group byte output - buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, "%02x",in_data[i]); } + + if (fs->f_space) { //printf("Space enabled\n"); - if (buf1_szf_ascii) { - buf1[buf1_sz] = ' '; - buf1_sz += 1; + if (buf2_szf_hex) + { + if (buf1_szf_output_types) + { + if (fs->output_fmt == H64E_O_INT8) + { + int ii = in_data[i]; + buf3_sz = snprintf((char *)&buf3[0], BUF_SZ, "%4d ", (int8_t)ii); + } else if (fs->output_fmt == H64E_O_UINT8) { + unsigned int uu = in_data[i]; + buf3_sz = snprintf((char *)&buf3[0], BUF_SZ, "%4u ", uu); } } + */ } else { printf("Empty spaces\n"); //group byte output string if (((fs->group_fmt == H64E_G_BYTE)||(fs->group_fmt == H64E_G_NONE)) && (fs->output_fmt == H64E_O_STRING)) { - buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, " "); + buf2_sz = snprintf((char *)&buf2[0], BUF_SZ, " "); } else { //group byte output - buf1_sz = snprintf((char *)&buf1[0], BUF_SZ, " "); + buf2_sz = snprintf((char *)&buf2[0], BUF_SZ, " "); } if (fs->f_space) { - if (buf1_szcolumn_pos += 1; - fs->total_output += 1; + //count converted chars per line + fs->column_pos += 1; + fs->total_output += 1; - if (fs->column_pos == fs->column_size) - { - if (fs->f_new_line) { - //set triger to newline - fs->t_new_line = 1; - fs->column_pos = 0; - //set new line to buffer + if (fs->column_pos == fs->column_size) + { + if (fs->f_new_line) { + //set triger to newline + fs->t_new_line = 1; + fs->column_pos = 0; + //set new line to hex buffer + //printf("%d %d %d\n",fs->f_ascii,fs->f_hex,fs->f_output_types); + if ((fs->f_ascii==1) && (fs->f_output_types==0) ) + { + if (buf2_sz+1f_hex==1) && (fs->f_ascii==0) && (fs->f_output_types==0) ) + { + if (buf1_sz+1f_output_types) + { + if (buf2_sz+1f_ascii,fs->f_hex,fs->f_space); + if ((fs->f_ascii==1) && (fs->f_hex==1) && (fs->f_space==0)) + { + if (trail_size