From 79ba865d15c1781b4db4bd9fb7e576e9918300a5 Mon Sep 17 00:00:00 2001 From: IniKiwi Date: Thu, 26 Aug 2021 17:53:40 +0200 Subject: [PATCH] initial code and README --- README.md | 4 ++++ main.c | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 main.c diff --git a/README.md b/README.md index 2205633..a2f0608 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,6 @@ # G35EIIcompatibility-tool +##build +`gcc main.c -o G35EIIcompatibility-tool.elf` +##use +`./G35EIIcompatibility-tool.elf input output` diff --git a/main.c b/main.c new file mode 100644 index 0000000..b06b9eb --- /dev/null +++ b/main.c @@ -0,0 +1,52 @@ +#include +#include +#include + +int main(int argc, char **argv){ + if(argc == 1){ + printf("\033[1;31m"); //red + printf("error: "); + printf("\033[0;37m"); //white + printf("no input and output file!\n"); + return -1; + } + if(argc == 2){ + printf("\033[1;31m"); //red + printf("error: "); + printf("\033[0;37m"); //white + printf("no output file!\n"); + return -1; + } + + if(access(argv[1], F_OK ) == 0) { + //none + } else { + printf("\033[1;31m"); //red + printf("error: "); + printf("\033[0;37m"); //white + printf("cannot open file!\n"); + return -1; + } + printf("\033[0;37m"); //white text + + FILE * file; //file pointer + file = fopen(argv[1], "rb"); //open file + fseek(file, 0L, SEEK_END); //seek file size + size_t filesize = ftell(file); //get file size + + unsigned int filedata[filesize]; //make file data table + fread(filedata, filesize, 1, file); //set file data in filedata table + + fclose(file); //close input file + + //put here data manipulation + + file = fopen(argv[2], "wb"); //open output file + + //write final data in output file + fwrite(filedata , sizeof(char) , filesize , file); + + fclose(file); //close output file + + return 1; +}