summaryrefslogtreecommitdiffstats
path: root/H64E-2
diff options
context:
space:
mode:
authorsystemcoder <systemcoder@protonmail.com>2020-03-17 19:25:03 +0000
committersystemcoder <systemcoder@protonmail.com>2020-03-17 19:25:03 +0000
commite1e7859ef4b3353a8ac182fd456b053c653239d1 (patch)
tree7132c3f792ba8a6f3343cfa7aa7ed23f242c9167 /H64E-2
parent784076d51c3d95443b53416e593c38c612c14bbe (diff)
downloadH64D-2-e1e7859ef4b3353a8ac182fd456b053c653239d1.tar.gz
H64D-2-e1e7859ef4b3353a8ac182fd456b053c653239d1.zip
Add support for ascii, column output. Space no space is added
Diffstat (limited to 'H64E-2')
-rw-r--r--H64E-2/README.md16
-rw-r--r--H64E-2/TestPlan.xctestplan18
-rw-r--r--H64E-2/h64e.c44
-rw-r--r--H64E-2/h64e.h10
-rw-r--r--H64E-2/main.c42
5 files changed, 115 insertions, 15 deletions
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);