diff options
Diffstat (limited to 'H64E-2/main.c')
-rw-r--r-- | H64E-2/main.c | 99 |
1 files changed, 77 insertions, 22 deletions
diff --git a/H64E-2/main.c b/H64E-2/main.c index e83ddf9..57f996a 100644 --- a/H64E-2/main.c +++ b/H64E-2/main.c @@ -132,20 +132,56 @@ int output_name2int( char *name ) return 0; } +int group_typename2int( char *name ) +{ + if ( 0 == strncmp( name, "i8", 2) ) + { + return H64E_G_BYTE; + } + if ( 0 == strncmp( name, "u8", 2) ) + { + return H64E_G_BYTE; + } + if ( 0 == strncmp( name, "i16", 3) ) + { + return H64E_G_WORD; + } + if ( 0 == strncmp( name, "u16", 3) ) + { + return H64E_G_WORD; + } + if ( 0 == strncmp( name, "i32", 3) ) + { + return H64E_G_DWORD; + } + if ( 0 == strncmp( name, "u32", 3) ) + { + return H64E_G_DWORD; + } + if ( 0 == strncmp( name, "i64", 3) ) + { + return H64E_G_QWORD; + } + if ( 0 == strncmp( name, "u64", 3) ) + { + return H64E_G_QWORD; + } + return 0; +} + void helper( char *progname ) { printf("Usage: %s [OPTS] <filename>\n\n" - " -a - asciimode\n" + " -a - ascii output\n" " -b - show offset adress\n" " -o - file offset\n" " -i - output hex\n" " -l - length of output\n" " -c - column size in bytes\n" - " -g - datatype output: byte,word,dword,qword\n" - " -e - interp data: u8,i8,u16,i16,u32,i32,u64,i64\n" + " -e - interp data output: u8,i8,u16,i16,u32,i32,u64,i64\n" " -s - disable space between columns\n" - " -t - extra output ascii output\n" - "Version: 2.0.2 \n" + " -h - extra hex output\n" + "Version: 2.0.3 \n" "\n" , progname); } @@ -193,14 +229,12 @@ int main(int argc, const char * argv[]) { //set all params from arguments /*get cmd args and set options */ - while ( (c = getopt(argc, argv, "abo:il:vc:g:e:st")) != -1 ) + while ( (c = getopt(argc, argv, "abo:il:vc:e:sh")) != -1 ) { switch(c) { case 'a': - h64e.fmt.group = H64E_G_BYTE; - h64e.fmt.flag_output_types = 1; - h64e.fmt.output_type = H64E_O_STRING; + h64e.fmt.flag_ascii = 1; break; case 'b': h64e.fmt.flag_offset = 1; @@ -221,18 +255,16 @@ int main(int argc, const char * argv[]) { case 'c': h64e.fmt.column_size = atoi(optarg); break; - case 'g': - h64e.fmt.group = group_name2int(optarg); - break; case 'e': h64e.fmt.flag_output_types = 1; h64e.fmt.output_type = output_name2int(optarg); + h64e.fmt.group = group_typename2int(optarg); break; case 's': h64e.fmt.flag_space = 1; break; - case 't': - h64e.fmt.flag_ascii = 1; + case 'h': + h64e.fmt.flag_hex = 0; break; case 'v': version(); @@ -255,7 +287,12 @@ int main(int argc, const char * argv[]) { fname = argv[argc-1]; /* check params */ - h64e_check_param( &h64e ); + if (-1 == h64e_check_param( &h64e )) + { + return -1; + } + + /* open file */ fd = file_open( fname ); @@ -278,6 +315,8 @@ int main(int argc, const char * argv[]) { int8_fmt.start_offset = h64e.fmt.offset_addr; int8_fmt.f_output_types = h64e.fmt.flag_output_types; int8_fmt.output_fmt = h64e.fmt.output_type; + int8_fmt.f_ascii = h64e.fmt.flag_ascii; + int8_fmt.f_hex = h64e.fmt.flag_hex; @@ -303,7 +342,6 @@ int main(int argc, const char * argv[]) { cnv_bytes = h64e_si_data_out(&sin, &buf_cnv_in[0], int8_fmt.column_size); //cnv_total += cnv_bytes; - //Convert output data to desired format //printf("Start converting to byte8\n"); switch (h64e.fmt.group) @@ -312,13 +350,9 @@ int main(int argc, const char * argv[]) { cnv_num = h64e_fmt_byte_align16(&int8_fmt, &buf_cnv_in[0], cnv_bytes, buf_cnv_out, 2048); break; case H64E_G_WORD: - cnv_num = h64e_fmt_word(&int8_fmt, &buf_cnv_in[0], cnv_bytes, buf_cnv_out, 512); - break; case H64E_G_DWORD: - cnv_num = h64e_fmt_dword(&int8_fmt, &buf_cnv_in[0], cnv_bytes, buf_cnv_out, 512); - break; case H64E_G_QWORD: - cnv_num = h64e_fmt_qword(&int8_fmt, &buf_cnv_in[0], cnv_bytes, buf_cnv_out, 512); + cnv_num = h64e_fmt_align(&int8_fmt, &buf_cnv_in[0], cnv_bytes, buf_cnv_out, 2048, (int32_t)h64e_data_sz(&h64e)); break; default: @@ -355,10 +389,31 @@ int main(int argc, const char * argv[]) { //check and empty all buffers while (h64e_si_len(&sin)>0) { + int cnv_num = -1; if (h64e_si_len(&sin)>int8_fmt.column_size) { - + //printf("Full column buffer\n"); + cnv_bytes = h64e_si_data_out(&sin, &buf_cnv_in[0], int8_fmt.column_size); + cnv_num = h64e_fmt_byte_align16(&int8_fmt, &buf_cnv_in[0], cnv_bytes, buf_cnv_out, 2048); + + cnv_bytes = h64e_so_data_in(&sout, &buf_cnv_out[0], cnv_num); + cnv_total += cnv_num; } else { + //printf("some buffer!!!\n"); + //less then column size + cnv_bytes = h64e_si_data_out(&sin, &buf_cnv_in[0], int8_fmt.column_size); + //printf("cnv_bytes %d\n", cnv_bytes); + cnv_num = h64e_fmt_byte_align16(&int8_fmt, &buf_cnv_in[0], cnv_bytes, buf_cnv_out, 2048); + //printf("cnv_num %d\n", cnv_num); + cnv_bytes = h64e_so_data_in(&sout, &buf_cnv_out[0], cnv_num); + cnv_total += cnv_num; + } + + if ((out_bytes = h64e_so_len(&sout)) > 0) + { + out_bytes = h64e_so_data_out(&sout, &buf_out[0],512); + buf_out[out_bytes] = 0x00; + printf("%s",buf_out); } break; } |