diff --git a/include/loxoten.h b/include/loxoten.h index c8574af..5d51f28 100644 --- a/include/loxoten.h +++ b/include/loxoten.h @@ -3,7 +3,7 @@ file-corruptor: A Platform Specific file corrupting program. @file: loxoten.h @author: Aliasgar Khimani (NovusEdge) - @copyright: CC-BY-4.0 + @copyright: MPL-2.0 */ #ifndef LOXOTEN_H @@ -46,6 +46,6 @@ int write_random_bytes_to_file(const char* filename, unsigned int num bool check_for_help_option(int aargc, const char* aargv[]); bool is_valid_flag(const char* flag); bool is_flag(const char* flag); -bool check_if_file_exists(const char* filename); +bool file_exists(const char* filename); #endif // loxoten.h diff --git a/src/loxoten.c b/src/loxoten.c index 9aa7a43..6cedb17 100644 --- a/src/loxoten.c +++ b/src/loxoten.c @@ -3,7 +3,7 @@ file-corruptor: A Platform Specific file corrupting program. @file: loxoten.c @author: Aliasgar Khimani (NovusEdge) - @copyright: CC-BY-4.0 + @copyright: MPL-2.0 */ #include @@ -31,43 +31,43 @@ int main(int argc, const char* argv[]) { exit(EXIT_SUCCESS); } - if( is_flag(argv[i]) && !is_valid_flag(argv[i]) ) { + if (is_flag(argv[i]) && !is_valid_flag(argv[i])) { fprintf(stderr, "E: Invalid Flag: %s\n\n%s\n", argv[i], __FLAGS); exit(EXIT_FAILURE); } - if( strncmp(argv[i], "-V", 2) == 0 || strncmp(argv[i], "--version", 9) == 0 ) { + if (strncmp(argv[i], "-V", 2) == 0 || strncmp(argv[i], "--version", 9) == 0) { printf("loxoten version: %s\n", VERSION); exit(EXIT_SUCCESS); } - if( strncmp(argv[i], "-v", 2) == 0 || strncmp(argv[i], "--verbose", 9) == 0 ) { + if (strncmp(argv[i], "-v", 2) == 0 || strncmp(argv[i], "--verbose", 9) == 0) { verbose_flag = true; flag_end_pos++; } - if( strncmp(argv[i], "-q", 2) == 0 || strncmp(argv[i], "--quiet", 7) == 0 ) { + if (strncmp(argv[i], "-q", 2) == 0 || strncmp(argv[i], "--quiet", 7) == 0) { quiet_flag = true; flag_end_pos++; } } for(int i = flag_end_pos; i < argc; i++) { - if( !check_if_file_exists(argv[i]) ) { - if ( !quiet_flag || verbose_flag ){ - fprintf(stderr, "%s[-] E: File %s does not exist!%s\n", ANSI_COLOR_RED, argv[i], ANSI_COLOR_RESET); - } + if (!file_exists(argv[i])) { + fprintf(stderr, "%s[-] E: File %s does not exist!%s\n", ANSI_COLOR_RED, argv[i], ANSI_COLOR_RESET); exit(EXIT_FAILURE); } FILE* fd = fopen(argv[i], "rb+"); - if( !quiet_flag || verbose_flag ) { + if (!quiet_flag || verbose_flag) { printf("%s[*] Attempting to corrupt file: %s%s\n\n", ANSI_COLOR_YELLOW, argv[i], ANSI_COLOR_RESET); } fseek(fd, 0L, SEEK_END); int filesize = ftell(fd); rewind(fd); corrupt_file(fd, filesize); - + if (!quiet_flag || verbose_flag) { + printf("%s[+] SUCCESS!%s\n", ANSI_COLOR_GREEN, ANSI_COLOR_RESET); + } } exit(EXIT_SUCCESS); } @@ -81,7 +81,7 @@ int main(int argc, const char* argv[]) { void corrupt_file(FILE* file, size_t num_bytes){ unsigned char* random_bytes = generate_random_bytes(num_bytes); - for(int i = 0; i < num_bytes; i++ ) { + for (int i = 0; i < num_bytes; i++) { fwrite(random_bytes, sizeof(unsigned char), 1, file); random_bytes++; } @@ -95,13 +95,12 @@ void corrupt_file(FILE* file, size_t num_bytes){ */ unsigned char *generate_random_bytes (size_t n){ srand(time(NULL)); - unsigned char* random_bytes = (unsigned char*)malloc(n*sizeof(unsigned char)); + unsigned char* random_bytes = malloc(n*sizeof(unsigned char)); unsigned char* head = random_bytes; for (size_t i = 0; i < n; i++) { unsigned char r_byte = (unsigned char)rand(); - (*random_bytes) = r_byte; - random_bytes++; + random_bytes[i] = r_byte; } return head; @@ -117,7 +116,7 @@ unsigned char *generate_random_bytes (size_t n){ */ bool check_for_help_option(int aargc, const char* aargv[]){ for (int i = 0; i < aargc; i++) { - if ( 0 == strncmp("-h", aargv[i], 2) | 0 == strncmp("--help", aargv[i], 6)){ + if (strncmp("-h", aargv[i], 2) == 0 || strncmp("--help", aargv[i], 6) == 0){ return true; } } @@ -132,7 +131,7 @@ bool check_for_help_option(int aargc, const char* aargv[]){ bool is_valid_flag(const char* flag) { bool check = false; for (size_t i = 0; i < 8; i++) { - if( strcmp(flag, VALID_FLAGS[i]) == 0 ) { check = true; } + if (strcmp(flag, VALID_FLAGS[i]) == 0) { check = true; } } return check; } @@ -151,6 +150,6 @@ bool is_flag(const char* flag) { @param filename: Path to the/Name of the file to be checked. @return : true if [filename] exists. */ -bool check_if_file_exists(const char* filename) { +bool file_exists(const char* filename) { return access(filename, F_OK) == NULL; }