Advertisement
Guest User

Untitled

a guest
May 26th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. /*********************************
  2. * Class: MAGSHIMIM C2 *
  3. * Week: *
  4. * Name: *
  5. * Credits: *
  6. **********************************/
  7.  
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <dirent.h>
  11.  
  12. #define SIZE 50
  13. #define NORM '0'
  14. #define EQUIL 1
  15. #define OPOSITE 0
  16.  
  17.  
  18. void norm_scan(char ** argv, FILE * virus);
  19.  
  20. int main(int argc, char ** argv) //getting the antivirus signature and the folder to check
  21. {
  22. char choice = 0;
  23. FILE * virus = fopen(argv[2], "rb"); //openning the Virus file
  24. //FILE * answears; // here will the results of checking
  25.  
  26. printf("Welcome to my Virus Scan!\n");
  27. printf("Folder to scan: %s \n", argv[1]);
  28. printf("Virus signature: %s \n", argv[2]);
  29.  
  30. printf("\nPress 0 for a normal scan or any onther key for a quick scan: ");
  31. scanf("%c", &choice); //get the choice from the user
  32.  
  33. printf("\nScaning began...\nThis process may take several minutes\n\n");
  34.  
  35. if (choice == NORM)
  36. {
  37. printf("norm scan\n");
  38. norm_scan(argv, virus);
  39. }
  40. else
  41. {
  42. printf("fast scan\n");
  43. //fast_scan(argv, virus);
  44. }
  45.  
  46. fclose(virus);
  47.  
  48. printf("Scan completed\n");
  49. printf("See log path for results:"); //here we print the results that are saved in another file
  50.  
  51. getchar();
  52. getchar();
  53. return 0;
  54. }
  55.  
  56. /*
  57. This function checks each file in ordenary way
  58. input:the folder that we need to check and the virus
  59. output: if the file is clean or not
  60. */
  61. void norm_scan(char ** argv, FILE * virus)
  62. {
  63. DIR*folder = NULL;
  64. struct dirent*file;
  65. FILE * content = NULL;
  66. char nFolder[SIZE] = { 0 }; // name of folder
  67. char virusSig[SIZE] = { 0 }; // virus signature
  68. char nFile[SIZE] = { 0 }; // name of file
  69. char ch1;
  70. char ch2;
  71. int search = 0;
  72. long int length = 0;
  73.  
  74. strcat(nFolder, argv[1]);
  75. strcat(virusSig, argv[2]);
  76.  
  77. folder = opendir(argv[1]);
  78. file = readdir(folder);
  79.  
  80. while (file != NULL)
  81. {
  82. //printf("check\n");
  83. strcat(nFile, nFolder); //building the name of file
  84. strcat(nFile, "//");
  85. strcat(nFile, file->d_name);
  86.  
  87.  
  88. content = fopen(nFile, "rb");
  89.  
  90. ch1 = fgetc(content);
  91. ch2 = fgetc(virus);
  92.  
  93. while ((ch1 != EOF) && (ch2 != EOF))
  94. {
  95. if (ch1 == ch2)
  96. {
  97. search = EQUIL;
  98. }
  99. else
  100. {
  101. fseek(content, -1, SEEK_CUR);
  102. search = OPOSITE;
  103. break;
  104. }
  105. ch1 = fgetc(content);
  106. ch2 = fgetc(virus);
  107. }
  108.  
  109. if (search == EQUIL)
  110. {
  111. printf("Files are equil\n");
  112. }
  113. else
  114. {
  115. printf("Files not equil\n");
  116. }
  117.  
  118. fclose(content);
  119.  
  120. file = readdir(folder); // take another file
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement