Skip to content

Commit

Permalink
Merge pull request NovusEdge#7 from NovusEdge/dev-linux
Browse files Browse the repository at this point in the history
Fixing minor inconsistencies
  • Loading branch information
NovusEdge authored Mar 9, 2022
2 parents 6fc89e9 + 068798a commit fe727c9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions include/loxoten.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
35 changes: 17 additions & 18 deletions src/loxoten.c
Original file line number Diff line number Diff line change
Expand Up @@ -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<stdbool.h>
Expand Down Expand Up @@ -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);
}
Expand All @@ -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++;
}
Expand All @@ -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;
Expand All @@ -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;
}
}
Expand All @@ -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;
}
Expand All @@ -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;
}

0 comments on commit fe727c9

Please sign in to comment.