diff options
-rw-r--r-- | H64E-2.xcodeproj/project.pbxproj | 4 | ||||
-rw-r--r-- | H64E-2/README.md | 16 | ||||
-rw-r--r-- | H64E-2/TestPlan.xctestplan | 18 | ||||
-rw-r--r-- | H64E-2/h64e.c | 44 | ||||
-rw-r--r-- | H64E-2/h64e.h | 10 | ||||
-rw-r--r-- | H64E-2/main.c | 42 | ||||
-rw-r--r-- | Tests/files/test_03 | 1 |
7 files changed, 120 insertions, 15 deletions
diff --git a/H64E-2.xcodeproj/project.pbxproj b/H64E-2.xcodeproj/project.pbxproj index 05aae75..a3aa3e8 100644 --- a/H64E-2.xcodeproj/project.pbxproj +++ b/H64E-2.xcodeproj/project.pbxproj @@ -34,6 +34,8 @@ A927BDA3241C534700DC8519 /* test_01 */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = test_01; sourceTree = "<group>"; }; A927BDA5241D0B4900DC8519 /* test_02 */ = {isa = PBXFileReference; lastKnownFileType = text; path = test_02; sourceTree = "<group>"; }; A927BDA6241D0B7700DC8519 /* test_03 */ = {isa = PBXFileReference; lastKnownFileType = text; path = test_03; sourceTree = "<group>"; }; + A927BDA8241E7C8D00DC8519 /* README.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = README.md; sourceTree = "<group>"; }; + A9D11A0424214E1A00EDD4EA /* TestPlan.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = TestPlan.xctestplan; sourceTree = "<group>"; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -68,10 +70,12 @@ isa = PBXGroup; children = ( A927BD94241C279000DC8519 /* main.c */, + A9D11A0424214E1A00EDD4EA /* TestPlan.xctestplan */, A927BD9B241C344C00DC8519 /* h64e.h */, A927BD9E241C350A00DC8519 /* h64e-model.h */, A927BD9F241C350A00DC8519 /* h64e-model.c */, A927BD9C241C344C00DC8519 /* h64e.c */, + A927BDA8241E7C8D00DC8519 /* README.md */, ); path = "H64E-2"; sourceTree = "<group>"; diff --git a/H64E-2/README.md b/H64E-2/README.md new file mode 100644 index 0000000..df422bf --- /dev/null +++ b/H64E-2/README.md @@ -0,0 +1,16 @@ +# README + +## Command options +H64E-2 Project started 1 +init structure +At least one argument needed now +Usage: /Users/dianshi/Library/Developer/Xcode/DerivedData/H64E-2-gmuonpnmhjonvbdrwnhifqdptkjc/Build/Products/Debug/H64E-2 [OPTS] <filename> + + -a - asciimode + -b - show offset adress + -o - file offset + -i - output hex + -l - length of output + -c - column size in byts + -g - datatype output: byte,word,dword + -e - interp da diff --git a/H64E-2/TestPlan.xctestplan b/H64E-2/TestPlan.xctestplan new file mode 100644 index 0000000..8009b7b --- /dev/null +++ b/H64E-2/TestPlan.xctestplan @@ -0,0 +1,18 @@ +{ + "configurations" : [ + { + "id" : "0A2DF3BD-C804-408A-A28E-2C11038A9879", + "name" : "Configuration 1", + "options" : { + + } + } + ], + "defaultOptions" : { + + }, + "testTargets" : [ + + ], + "version" : 1 +} diff --git a/H64E-2/h64e.c b/H64E-2/h64e.c index 1e0662c..decaff5 100644 --- a/H64E-2/h64e.c +++ b/H64E-2/h64e.c @@ -67,31 +67,44 @@ int h64e_fmt_byte(H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *o int cur_size=0; int i,j=0; const int SZ=16; - uint8_t buf[SZ]; + uint8_t buf[SZ+1]; int buf_sz=0; int trail_size=0; for (i=0; i<in_size; i++) { - buf_sz = snprintf(&buf[0], SZ, "%02x",in_data[i]); + //group byte output string + if (((fs->group_fmt == H64E_G_BYTE)||(fs->group_fmt == H64E_G_NONE)) && (fs->output_fmt == H64E_O_STRING)) + { + if (isprint(in_data[i])) + { + buf_sz = snprintf(&buf[0], SZ, "%c",(unsigned char)in_data[i]); + } else { + buf_sz = snprintf(&buf[0], SZ, ".",(unsigned char)in_data[i]); + } + } else { + //group byte output + buf_sz = snprintf(&buf[0], SZ, "%02x",in_data[i]); + + } //count converted chars per line - fs->cur_pos += 1; + fs->column_pos += 1; //add space if configured if (fs->f_space) { - if (buf_sz+1<SZ) + if (buf_sz<SZ) { buf[buf_sz] = ' '; buf_sz += 1; } } - if (fs->cur_pos == fs->column_size) + if (fs->column_pos == fs->column_size) { if (fs->f_new_line) { //set triger to newline fs->t_new_line = 1; - fs->cur_pos = 0; + fs->column_pos = 0; //set new line to buffer if (buf_sz+1<SZ) { @@ -126,6 +139,25 @@ int h64e_fmt_byte(H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *o return ret; } +int h64e_fmt_word( H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size) +{ + return 0; +} + +int h64e_fmt_dword( H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size) +{ + return 0; +} + +int h64e_fmt_qword( H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size) +{ + return 0; +} +int h64e_fmt_string( H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size) +{ + return 0; +} + int h64e_fmt_finish(H64E_format *fs) { diff --git a/H64E-2/h64e.h b/H64E-2/h64e.h index d8a95cd..ac47b14 100644 --- a/H64E-2/h64e.h +++ b/H64E-2/h64e.h @@ -10,6 +10,7 @@ #define h64e_h #include <stdio.h> +#include <ctype.h> #include "h64e-model.h" /* Set data structure from arguments and use to handle data @@ -43,6 +44,7 @@ typedef struct H64E_params uint8_t group; /* if there is need transdorm to specific type */ int flag_output; /* output convereted types */ uint8_t output_type; /* output in many different ways */ + int flag_space; /*space between columns **/ } H64E_params; typedef struct H64E_t @@ -74,9 +76,9 @@ typedef struct H64E_format { int max_output; int column_size; int f_space; - int cur_pos; //position where output stoped + int column_pos; //position where output stoped int end_pos; //end postion before new line - int f_new_line; //should be new line set after + int f_new_line; //should be new line set after int start_offset; //start position of offset int slide_offset; //offset since stream start int state; @@ -86,6 +88,10 @@ typedef struct H64E_format { int h64e_fmt_init( H64E_format *fs); int h64e_fmt_byte( H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size); +int h64e_fmt_word( H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size); +int h64e_fmt_dword( H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size); +int h64e_fmt_qword( H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size); +int h64e_fmt_string( H64E_format *fs, uint8_t *in_data, int32_t in_size, uint8_t *out_data, int32_t out_size); int h64e_fmt_finish(H64E_format *fs); #endif /* h64e_h */ diff --git a/H64E-2/main.c b/H64E-2/main.c index bd1910e..818f165 100644 --- a/H64E-2/main.c +++ b/H64E-2/main.c @@ -141,9 +141,9 @@ void helper( char *progname ) " -i - output hex\n" " -l - length of output\n" " -c - column size in byts\n" - " -g - datatype output: byte,word,dword\n" + " -g - datatype output: byte,word,dword,qword\n" " -e - interp data: u8,i8,u16,i16,u32,i32,u64,i64" - "\nVersion: 0.1 \n" + "\nVersion: 2.0.0 \n" "\n" , progname); } @@ -153,7 +153,9 @@ void version() printf("???\n"); } - +/* + Main fucntion, of this program + */ int main(int argc, const char * argv[]) { // insert code here... int c; @@ -180,12 +182,13 @@ int main(int argc, const char * argv[]) { H64E_format int8_fmt; + //list of supported formats h64e_fmt_init(&int8_fmt); //set all params from arguments /*get cmd args and set options */ - while ( (c = getopt(argc, argv, "abo:il:vc:g:e:")) != -1 ) + while ( (c = getopt(argc, argv, "abo:il:vc:g:e:s")) != -1 ) { switch(c) { @@ -218,6 +221,9 @@ int main(int argc, const char * argv[]) { h64e.fmt.flag_output = 1; h64e.fmt.output_type = output_name2int(optarg); break; + case 's': + h64e.fmt.flag_space = 1; + break; case 'v': version(); exit(1); @@ -251,9 +257,14 @@ int main(int argc, const char * argv[]) { //register formats //configure format of u8 to terminate on new line and have space between types - int8_fmt.f_space = 1; + //printf("Column size set to %d\n",h64e.fmt.column_size); + int8_fmt.f_space = !h64e.fmt.flag_space; int8_fmt.f_new_line = 1; - int8_fmt.column_size = 16; + int8_fmt.column_size = h64e.fmt.column_size; + int8_fmt.group_fmt = h64e.fmt.group; + int8_fmt.output_fmt = h64e.fmt.output_type; + + //do conversation, reading input and outputing while ((in_bytes = file_read(fd,(char *)&buf_in,1)) != -1) @@ -280,7 +291,24 @@ int main(int argc, const char * argv[]) { //Convert output data to desired format //printf("Start converting to byte8\n"); - cnv_num = h64e_fmt_byte(&int8_fmt, &buf_cnv_in[0], cnv_bytes, buf_cnv_out, 512); + switch (h64e.fmt.group) + { + case H64E_G_BYTE: + cnv_num = h64e_fmt_byte(&int8_fmt, &buf_cnv_in[0], cnv_bytes, buf_cnv_out, 512); + 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); + break; + + default: + printf("Unknown grouping\n"); + } //printf("Conversation amount\n"); //Push all data ot output buffer //printf("Write to output stream data %d bytes\n",cnv_bytes); diff --git a/Tests/files/test_03 b/Tests/files/test_03 index 6b1a644..6bea594 100644 --- a/Tests/files/test_03 +++ b/Tests/files/test_03 @@ -6,3 +6,4 @@ EEEEEEEEEE FFFFFFFFFF GGGGGGGGGG HHHHHHHHHH + |