summaryrefslogtreecommitdiffstats
path: root/H64E-2
diff options
context:
space:
mode:
authorsystemcoder <systemcoder@protonmail.com>2020-03-13 22:58:43 +0000
committersystemcoder <systemcoder@protonmail.com>2020-03-13 22:58:43 +0000
commitedc949143c3e0a93c3868f0bbcc884fe721f4e92 (patch)
tree68e3bc4e663baa42d7e5d0217ca238dcf3fec016 /H64E-2
parent07ff9b8204da0b4a5ea8ad8a66ba12ae3e48abb8 (diff)
downloadH64D-2-edc949143c3e0a93c3868f0bbcc884fe721f4e92.tar.gz
H64D-2-edc949143c3e0a93c3868f0bbcc884fe721f4e92.zip
Added code for arguments settings, all function names defined
Diffstat (limited to 'H64E-2')
-rw-r--r--H64E-2/h64e-model.h38
-rw-r--r--H64E-2/h64e.c30
-rw-r--r--H64E-2/h64e.h27
-rw-r--r--H64E-2/main.c247
4 files changed, 341 insertions, 1 deletions
diff --git a/H64E-2/h64e-model.h b/H64E-2/h64e-model.h
new file mode 100644
index 0000000..41c4a4a
--- /dev/null
+++ b/H64E-2/h64e-model.h
@@ -0,0 +1,38 @@
+//
+// h64e-model.h
+// H64E-2
+//
+// Created by dianshi on 3/13/20.
+// Copyright © 2020 dianshi. All rights reserved.
+//
+
+#ifndef h64e_model_h
+#define h64e_model_h
+
+#include <stdio.h>
+
+typedef int (*trnf_clb)(char*);
+
+typedef struct H64E_stream_in {
+ int cur_size;
+ int size;
+ uint8_t *buf;
+} H64E_stream_in;
+
+//used to get collected data
+int H64E_si_init(H64E_stream_in *in, ssize_t size);
+int H64E_si_data_in(H64E_stream_in *in, uint8_t *data, size_t size);
+int H64E_si_data_out(H64E_stream_in *in, const uint8_t *data, size_t size);
+
+typedef struct H64E_stream_out {
+ int cur_size;
+ int size;
+ uint8_t *buf;
+} H64E_stream_out;
+
+//using to collect output formated data
+int H64E_so_init(H64E_stream_out *out, ssize_t size);
+int H64E_so_data_in(H64E_stream_in *out, uint8_t *data, size_t size);
+int H64E_so_data_out(H64E_stream_in *out, const uint8_t *data, size_t size);
+
+#endif /* h64e_model_h */
diff --git a/H64E-2/h64e.c b/H64E-2/h64e.c
index a6ec1ef..ddcfc5c 100644
--- a/H64E-2/h64e.c
+++ b/H64E-2/h64e.c
@@ -7,3 +7,33 @@
//
#include "h64e.h"
+
+int h64e_init(H64E_t *s)
+{
+ return 0;
+}
+
+int h64e_check_param( H64E_t *fmt )
+{
+ return 0;
+}
+
+int h64e_set_input(H64E_t *s)
+{
+ return 0;
+}
+
+int h64e_set_output(H64E_t *s)
+{
+ return 0;
+}
+
+int h64e_convert(H64E_t *s)
+{
+ return 0;
+}
+
+int h64e_destroy(H64E_t *s)
+{
+ return 0;
+}
diff --git a/H64E-2/h64e.h b/H64E-2/h64e.h
index bd5f13f..f96edbd 100644
--- a/H64E-2/h64e.h
+++ b/H64E-2/h64e.h
@@ -15,6 +15,27 @@
Set data structure from arguments and use to handle data
*/
+
+#define H64E_G_NONE 0
+#define H64E_G_BYTE 1
+#define H64E_G_WORD 2
+#define H64E_G_DWORD 3
+#define H64E_G_QWORD 4
+
+
+#define H64E_O_START 0
+#define H64E_O_NONE 0
+#define H64E_O_STRING 1
+#define H64E_O_INT8 2
+#define H64E_O_UINT8 3
+#define H64E_O_INT16 4
+#define H64E_O_UINT16 5
+#define H64E_O_INT32 6
+#define H64E_O_UINT32 7
+#define H64E_O_INT64 8
+#define H64E_O_UINT64 9
+#define H64E_O_END H64E_O_UINT64
+
typedef struct H64E_format
{
@@ -29,14 +50,18 @@ typedef struct H64E_format
typedef struct H64E_t
{
- H64E_format format;
+ H64E_format fmt;
H64E_stream_in sin;
H64E_stream_out sout;
+ int fd_in;
+ int fd_out;
} H64E_t;
int h64e_init(H64E_t *s);
+int h64e_check_param( H64E_t *s );
int h64e_set_input(H64E_t *s);
int h64e_set_output(H64E_t *s);
+int h64e_convert(H64E_t *s);
int h64e_destroy(H64E_t *s);
diff --git a/H64E-2/main.c b/H64E-2/main.c
new file mode 100644
index 0000000..8830f1d
--- /dev/null
+++ b/H64E-2/main.c
@@ -0,0 +1,247 @@
+//
+// main.c
+// H64E-2
+//
+// Created by dianshi on 3/13/20.
+// Copyright © 2020 dianshi. All rights reserved.
+//
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <getopt.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <string.h>
+#include "h64e.h"
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+int file_open( const char *fname )
+{
+ int fd;
+
+ fd = open( fname, O_RDONLY );
+ if ( fd == -1 )
+ {
+ printf("Couldn open file %s\n", fname);
+ return -1;
+ }
+
+ return fd;
+}
+
+int file_read( int fd, char *buf, int size )
+{
+ int ret;
+
+ if ( size < 1 )
+ return -1;
+
+ ret = (int)read( fd, buf, size );
+
+ return ret;
+}
+
+int file_seek( int fd, off_t pos )
+{
+ off_t rc;
+
+ if (fd<1)
+ {
+ return -1;
+ }
+
+ rc = lseek( fd, pos, SEEK_SET );
+ if (rc == -1)
+ return -1;
+ return 0;
+
+}
+
+int file_close( int fd )
+{
+
+ close( fd );
+
+ return 0;
+}
+
+int group_name2int( char *name )
+{
+ if ( 0 == strncmp( name, "byte", 4 ) )
+ {
+ return H64E_G_BYTE;
+ }
+ if ( 0 == strncmp( name, "word", 4 ) )
+ {
+ return H64E_G_WORD;
+ }
+ if ( 0 == strncmp( name, "dword", 5 ) )
+ {
+ return H64E_G_DWORD;
+ }
+ if ( 0 == strncmp( name, "qword", 5 ) )
+ {
+ return H64E_G_QWORD;
+ }
+
+ return 1;
+}
+
+int output_name2int( char *name )
+{
+ if ( 0 == strncmp( name, "str", 3) )
+ {
+ return H64E_O_STRING;
+ }
+ if ( 0 == strncmp( name, "i8", 2) )
+ {
+ return H64E_O_INT8;
+ }
+ if ( 0 == strncmp( name, "u8", 2) )
+ {
+ return H64E_O_UINT8;
+ }
+ if ( 0 == strncmp( name, "i16", 3) )
+ {
+ return H64E_O_INT16;
+ }
+ if ( 0 == strncmp( name, "u16", 3) )
+ {
+ return H64E_O_UINT16;
+ }
+ if ( 0 == strncmp( name, "i32", 3) )
+ {
+ return H64E_O_INT32;
+ }
+ if ( 0 == strncmp( name, "u32", 3) )
+ {
+ return H64E_O_UINT32;
+ }
+ if ( 0 == strncmp( name, "i64", 3) )
+ {
+ return H64E_O_INT64;
+ }
+ if ( 0 == strncmp( name, "u64", 3) )
+ {
+ return H64E_O_UINT64;
+ }
+ return 0;
+}
+
+void helper( char *progname )
+{
+ printf("Usage: %s [OPTS] <filename>\n\n"
+ " -a - asciimode\n"
+ " -b - show offset adress\n"
+ " -o - file offset\n"
+ " -i - output hex\n"
+ " -l - length of output\n"
+ " -c - column size in byts\n"
+ " -g - datatype output: byte,word,dword\n"
+ " -e - interp data: u8,i8,u16,i16,u32,i32,u64,i64"
+ "\nVersion: 0.1 \n"
+ "\n"
+ , progname);
+}
+
+void version()
+{
+ printf("???\n");
+}
+
+
+int main(int argc, const char * argv[]) {
+ // insert code here...
+ int c;
+ int param_length = -1;
+ int param_offset = -1;
+ char *fname = NULL;
+ int fd;
+
+ printf("H64E-2 Project started 1\n");
+
+ //initialise structure
+ H64E_t h64e;
+ h64e_init(&h64e);
+
+
+ //set all params from arguments
+ /*get cmd args and set options */
+ while ( (c = getopt(argc, argv, "abo:il:vc:g:e:")) != -1 )
+ {
+ switch(c)
+ {
+ case 'a':
+ h64e.fmt.group = H64E_G_BYTE;
+ h64e.fmt.flag_output = 1;
+ h64e.fmt.output_type = H64E_O_STRING;
+ break;
+ case 'b':
+ h64e.fmt.flag_offset = 1;
+ break;
+ case 'o':
+ param_offset = atoi( optarg );
+ break;
+ case 'i':
+ h64e.fmt.group = H64E_G_BYTE;
+ h64e.fmt.flag_output = 0;
+ h64e.fmt.flag_offset = 1;
+ break;
+ case 'l':
+ param_length = atoi( optarg );
+ break;
+ case 'c':
+ h64e.fmt.column_size = atoi(optarg);
+ break;
+ case 'g':
+ h64e.fmt.group = group_name2int(optarg);
+ break;
+ case 'e':
+ h64e.fmt.flag_output = 1;
+ h64e.fmt.output_type = output_name2int(optarg);
+ break;
+ case 'v':
+ version();
+ exit(1);
+ break;
+ default:
+ helper( argv[0] );
+ exit(1);
+ }
+ }
+
+ if ( argc < 2 )
+ {
+ printf("At least one argument needed now\n");
+ helper( argv[0] );
+ return 1;
+ }
+
+ /* last argument is file name */
+ fname = argv[argc-1];
+
+ /* check params */
+ h64e_check_param( &h64e );
+
+ /* open file */
+ fd = file_open( fname );
+ if ( fd == -1 )
+ {
+ printf("Cannot open file %s\n", fname);
+ return -1;
+ }
+
+ //register formats
+
+ //do conversation, reading input and outputing
+
+ //deinit all structures
+ h64e_destroy(&h64e);
+
+ printf("Ending Execution\n");
+ return 0;
+}