Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************************
- * Class: MAGSHIMIM C2 *
- * Week: *
- * Name: *
- * Credits: *
- **********************************/
- #include <stdio.h>
- #include <string.h>
- #include <dirent.h>
- #define SIZE 50
- #define NORM '0'
- #define EQUIL 1
- #define OPOSITE 0
- void norm_scan(char ** argv, FILE * virus);
- int main(int argc, char ** argv) //getting the antivirus signature and the folder to check
- {
- char choice = 0;
- FILE * virus = fopen(argv[2], "rb"); //openning the Virus file
- //FILE * answears; // here will the results of checking
- printf("Welcome to my Virus Scan!\n");
- printf("Folder to scan: %s \n", argv[1]);
- printf("Virus signature: %s \n", argv[2]);
- printf("\nPress 0 for a normal scan or any onther key for a quick scan: ");
- scanf("%c", &choice); //get the choice from the user
- printf("\nScaning began...\nThis process may take several minutes\n\n");
- if (choice == NORM)
- {
- printf("norm scan\n");
- norm_scan(argv, virus);
- }
- else
- {
- printf("fast scan\n");
- //fast_scan(argv, virus);
- }
- fclose(virus);
- printf("Scan completed\n");
- printf("See log path for results:"); //here we print the results that are saved in another file
- getchar();
- getchar();
- return 0;
- }
- /*
- This function checks each file in ordenary way
- input:the folder that we need to check and the virus
- output: if the file is clean or not
- */
- void norm_scan(char ** argv, FILE * virus)
- {
- DIR*folder = NULL;
- struct dirent*file;
- FILE * content = NULL;
- char nFolder[SIZE] = { 0 }; // name of folder
- char virusSig[SIZE] = { 0 }; // virus signature
- char nFile[SIZE] = { 0 }; // name of file
- char ch1;
- char ch2;
- int search = 0;
- long int length = 0;
- strcat(nFolder, argv[1]);
- strcat(virusSig, argv[2]);
- folder = opendir(argv[1]);
- file = readdir(folder);
- while (file != NULL)
- {
- //printf("check\n");
- strcat(nFile, nFolder); //building the name of file
- strcat(nFile, "//");
- strcat(nFile, file->d_name);
- content = fopen(nFile, "rb");
- ch1 = fgetc(content);
- ch2 = fgetc(virus);
- while ((ch1 != EOF) && (ch2 != EOF))
- {
- if (ch1 == ch2)
- {
- search = EQUIL;
- }
- else
- {
- fseek(content, -1, SEEK_CUR);
- search = OPOSITE;
- break;
- }
- ch1 = fgetc(content);
- ch2 = fgetc(virus);
- }
- if (search == EQUIL)
- {
- printf("Files are equil\n");
- }
- else
- {
- printf("Files not equil\n");
- }
- fclose(content);
- file = readdir(folder); // take another file
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement