33    file-corruptor: A Platform Specific file corrupting program. 
44    @file: loxoten.c 
55    @author: Aliasgar Khimani (NovusEdge) 
6-     @copyright: CC-BY-4 .0 
6+     @copyright: MPL-2 .0 
77*/ 
88
99#include <stdbool.h> 
@@ -31,43 +31,43 @@ int main(int argc, const char* argv[]) {
3131            exit (EXIT_SUCCESS );
3232        }
3333
34-         if (  is_flag (argv [i ]) &&  !is_valid_flag (argv [i ])  ) {
34+         if  ( is_flag (argv [i ]) &&  !is_valid_flag (argv [i ])) {
3535            fprintf (stderr , "E: Invalid Flag: %s\n\n%s\n" , argv [i ], __FLAGS );
3636            exit (EXIT_FAILURE );
3737        }
3838
39-         if (  strncmp (argv [i ], "-V" , 2 ) ==  0  ||  strncmp (argv [i ], "--version" , 9 ) ==  0   ) {
39+         if  ( strncmp (argv [i ], "-V" , 2 ) ==  0  ||  strncmp (argv [i ], "--version" , 9 ) ==  0 ) {
4040            printf ("loxoten version: %s\n" , VERSION );
4141            exit (EXIT_SUCCESS );
4242        }
4343
44-         if (  strncmp (argv [i ], "-v" , 2 ) ==  0  ||  strncmp (argv [i ], "--verbose" , 9 ) ==  0   ) {
44+         if  ( strncmp (argv [i ], "-v" , 2 ) ==  0  ||  strncmp (argv [i ], "--verbose" , 9 ) ==  0 ) {
4545            verbose_flag  =  true;
4646            flag_end_pos ++ ;
4747        }
4848
49-         if (  strncmp (argv [i ], "-q" , 2 ) ==  0  ||  strncmp (argv [i ], "--quiet" , 7 ) ==  0   ) {
49+         if  ( strncmp (argv [i ], "-q" , 2 ) ==  0  ||  strncmp (argv [i ], "--quiet" , 7 ) ==  0 ) {
5050            quiet_flag  =  true;
5151            flag_end_pos ++ ;
5252        }
5353    }
5454
5555    for (int  i  =  flag_end_pos ; i  <  argc ; i ++ ) {
56-         if ( !check_if_file_exists (argv [i ]) ) {
57-             if  ( !quiet_flag  ||  verbose_flag  ){
58-                 fprintf (stderr , "%s[-] E: File %s does not exist!%s\n" , ANSI_COLOR_RED , argv [i ], ANSI_COLOR_RESET );
59-             }
56+         if  (!file_exists (argv [i ])) {
57+             fprintf (stderr , "%s[-] E: File %s does not exist!%s\n" , ANSI_COLOR_RED , argv [i ], ANSI_COLOR_RESET );
6058            exit (EXIT_FAILURE );
6159        }
6260        FILE *  fd  =  fopen (argv [i ], "rb+" );
6361
64-         if (  !quiet_flag  ||  verbose_flag   ) {
62+         if  ( !quiet_flag  ||  verbose_flag ) {
6563            printf ("%s[*] Attempting to corrupt file: %s%s\n\n" , ANSI_COLOR_YELLOW , argv [i ], ANSI_COLOR_RESET );
6664        }
6765
6866        fseek (fd , 0L , SEEK_END ); int  filesize  =  ftell (fd ); rewind (fd );
6967        corrupt_file (fd , filesize );
70- 
68+         if  (!quiet_flag  ||  verbose_flag ) {
69+             printf ("%s[+] SUCCESS!%s\n" , ANSI_COLOR_GREEN , ANSI_COLOR_RESET );
70+         }
7171    }
7272    exit (EXIT_SUCCESS );
7373}
@@ -81,7 +81,7 @@ int main(int argc, const char* argv[]) {
8181void  corrupt_file (FILE *  file , size_t  num_bytes ){
8282    unsigned char  *  random_bytes  =  generate_random_bytes (num_bytes );
8383
84-     for (int  i  =  0 ; i  <  num_bytes ; i ++   ) {
84+     for   (int  i  =  0 ; i  <  num_bytes ; i ++ ) {
8585        fwrite (random_bytes , sizeof (unsigned char  ), 1 , file );
8686        random_bytes ++ ;
8787    }
@@ -95,13 +95,12 @@ void corrupt_file(FILE* file, size_t num_bytes){
9595*/ 
9696unsigned char   * generate_random_bytes  (size_t  n ){
9797    srand (time (NULL ));
98-     unsigned char  *  random_bytes  =  ( unsigned  char * ) malloc (n * sizeof (unsigned char  ));
98+     unsigned char  *  random_bytes  =  malloc (n * sizeof (unsigned char  ));
9999    unsigned char  *  head          =  random_bytes ;
100100
101101    for  (size_t  i  =  0 ; i  <  n ; i ++ ) {
102102        unsigned char   r_byte  =  (unsigned char  )rand ();
103-         (* random_bytes )      =  r_byte ;
104-         random_bytes ++ ;
103+         random_bytes [i ]      =  r_byte ;
105104    }
106105
107106    return  head ;
@@ -117,7 +116,7 @@ unsigned char *generate_random_bytes (size_t n){
117116*/ 
118117bool  check_for_help_option (int  aargc , const  char *  aargv []){
119118    for  (int  i  =  0 ; i  <  aargc ; i ++ ) {
120-         if  (  0   ==   strncmp ("-h" , aargv [i ], 2 ) |  0  ==  strncmp ("--help" , aargv [i ], 6 )){
119+         if  (strncmp ("-h" , aargv [i ], 2 ) ==  0  ||  strncmp ("--help" , aargv [i ], 6 )  ==   0 ){
121120            return  true;
122121        }
123122    }
@@ -132,7 +131,7 @@ bool check_for_help_option(int aargc, const char* aargv[]){
132131bool  is_valid_flag (const  char *  flag ) {
133132    bool  check  =  false;
134133    for  (size_t  i  =  0 ; i  <  8 ; i ++ ) {
135-         if (  strcmp (flag , VALID_FLAGS [i ]) ==  0   ) { check  =  true; }
134+         if  ( strcmp (flag , VALID_FLAGS [i ]) ==  0 ) { check  =  true; }
136135    }
137136    return  check ;
138137}
@@ -151,6 +150,6 @@ bool is_flag(const char* flag) {
151150    @param filename: Path to the/Name of the file to be checked. 
152151    @return        : true if [filename] exists. 
153152*/ 
154- bool  check_if_file_exists (const  char *  filename ) {
153+ bool  file_exists (const  char *  filename ) {
155154    return  access (filename , F_OK ) ==  NULL ;
156155}
0 commit comments