summaryrefslogtreecommitdiff
path: root/H64E-2/main.c
diff options
context:
space:
mode:
authorsystemcoder <systemcoder@protonmail.com>2020-03-21 20:27:58 +0000
committersystemcoder <systemcoder@protonmail.com>2020-03-21 20:27:58 +0000
commitdea754a95c639fa3142e1c1b1b60a9a6500377e5 (patch)
tree4d96dd504fe25fd0d8d9a97bd170c67f111b2a0f /H64E-2/main.c
parentbb47949b70525a266ebc9badae1e87496001389d (diff)
downloadH64D-2-dea754a95c639fa3142e1c1b1b60a9a6500377e5.tar.gz
H64D-2-dea754a95c639fa3142e1c1b1b60a9a6500377e5.zip
Hex output for different column sizes and different data types is working
Diffstat (limited to 'H64E-2/main.c')
-rw-r--r--H64E-2/main.c62
1 files changed, 47 insertions, 15 deletions
diff --git a/H64E-2/main.c b/H64E-2/main.c
index 02a5551..30f1bef 100644
--- a/H64E-2/main.c
+++ b/H64E-2/main.c
@@ -132,6 +132,43 @@ 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"
@@ -141,11 +178,10 @@ void helper( char *progname )
" -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 output: u8,i8,u16,i16,u32,i32,u64,i64\n"
" -s - disable space between columns\n"
" -h - extra hex output\n"
- "Version: 2.0.2 \n"
+ "Version: 2.0.3 \n"
"\n"
, progname);
}
@@ -193,14 +229,11 @@ 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:sh")) != -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':
@@ -222,12 +255,10 @@ 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;
@@ -256,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 );
@@ -314,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: