Advertisement
Guest User

Anti Virus

a guest
May 24th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.25 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "dirent.h"
  5.  
  6. void FindInfected(char **argv, char* InfectedFile)
  7. {
  8. DIR* OtherDir;
  9. struct dirent *OtherEnt;
  10.  
  11.  
  12.  
  13.  
  14.  
  15. int countLoop = 0, location2;
  16. char* InfectedFolderPath = (char*)malloc(NULL);
  17.  
  18.  
  19. int location = 0, flag = 0, secSpot = 0, argvSize, spot = 0, i;
  20.  
  21.  
  22.  
  23.  
  24. argvSize = strlen(argv[1]);
  25.  
  26. for (i = 0; i < argvSize; i++)
  27. {
  28.  
  29.     if (argv[1][i] == '/')
  30.     {
  31.         spot++;
  32.  
  33.     }
  34.  
  35. }
  36.  
  37.  
  38. char* UnwantedName = (char*)malloc(NULL);
  39. for (i = 0; i < argvSize; i++)
  40. {
  41.  
  42.     if (argv[1][i] == '/')
  43.     {
  44.         if (secSpot != spot)
  45.         {
  46.             secSpot++;
  47.  
  48.         }
  49.         if (secSpot == spot)
  50.         {
  51.             if (flag == 0)
  52.             {
  53.                 location = i;
  54.                 flag++;
  55.  
  56.  
  57.             }
  58.         }
  59.  
  60.     }
  61. }
  62.  
  63.  
  64.  
  65. char* entrenceToTheFolderBefore = (char*)malloc(NULL);
  66. for (int i = 0; i < location; i++)
  67. {
  68.     entrenceToTheFolderBefore[i] = argv[1][i];
  69. }
  70.  
  71.  
  72. location2 = location;
  73.  
  74. while (location2 != argvSize)
  75. {
  76.     location2++;
  77.     UnwantedName[countLoop] = argv[1][location2];    // problem
  78.     countLoop++;
  79.  
  80. }
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. puts(entrenceToTheFolderBefore);
  88.  
  89. OtherDir = opendir(entrenceToTheFolderBefore);
  90.  
  91.  
  92. //UnwatedName =  C2_Mid_Anti-Virus_Project.zip
  93.  
  94. while (OtherEnt = readdir(OtherDir))
  95. {
  96.  
  97.     if ((strcmp(OtherEnt->d_name, UnwantedName) != 0) && (strcmp(OtherEnt->d_name, ".") != 0) && (strcmp(OtherEnt->d_name, "..") != 0))    //problem
  98.     {
  99.  
  100.         strcpy(InfectedFolderPath, entrenceToTheFolderBefore);
  101.         strcat(InfectedFolderPath, "/");
  102.         strcat(InfectedFolderPath, OtherEnt->d_name);
  103.         puts(InfectedFolderPath);
  104.  
  105.  
  106.     }
  107.  
  108.  
  109. }
  110.  
  111.  
  112.  
  113.  
  114.  
  115. closedir(OtherDir);
  116.  
  117. DIR* Infected = opendir(InfectedFolderPath);
  118.  
  119. strcpy(InfectedFile, InfectedFolderPath);
  120.  
  121. while (OtherEnt = readdir(OtherDir))
  122. {
  123.     int temp = strlen(OtherEnt->d_name);
  124.  
  125.     if (strcmp(OtherEnt->d_name[(temp - 4)], '.') != 0)
  126.     {
  127.         strcat(InfectedFile, OtherEnt->d_name);
  128.     }
  129.  
  130. }
  131.  
  132.  
  133. closedir(Infected);
  134. }
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
  144.  
  145.  
  146. int main(int argc, char** argv)
  147. {
  148.  
  149.  
  150.  
  151.  
  152.     char* InfectedFile = (char*)malloc(NULL);
  153.    
  154.     int numberOfInfections = 0;
  155.     int count = 0, size = 0, totalDirs = 0;
  156.     int sizes[3];
  157.     DIR* dir;
  158.     DIR* Infected;
  159.     struct dirent *ent;
  160.     int found = 0,temp1 = 0;
  161.  
  162.     int SumOflogsizes = 0;
  163.    
  164.     SumOflogsizes = strlen(argv[1]);
  165.     SumOflogsizes = SumOflogsizes + 1;
  166.     SumOflogsizes += strlen("AntiVirusLog.txt");
  167.    
  168.  
  169.     char* pathToLog = (char*)malloc(sizeof(char)*SumOflogsizes);
  170.  
  171.     strcpy(pathToLog, argv[1]);
  172.     strcat(pathToLog,"/AntiVirusLog.txt");
  173.  
  174.     FILE *log = fopen(pathToLog, "wt");
  175.    
  176.    
  177.  
  178.  
  179.  
  180.    
  181.  
  182.  
  183.  
  184.  
  185.    
  186.  
  187.  
  188.     int openInfected(argv);
  189.  
  190.     /* Open directory */
  191.  
  192.     dir = opendir(argv[1]);
  193.  
  194.  
  195.     if (log == NULL)
  196.     {
  197.         fprintf(log, "problem\n\n");
  198.     }
  199.  
  200.  
  201.  
  202.     while ((ent = readdir(dir)))
  203.     {
  204.         totalDirs++;
  205.        
  206.  
  207.        
  208.                 sizes[0] = strlen(argv[1]);
  209.                 sizes[1] = 2;
  210.                 sizes[2] = strlen(ent->d_name);
  211.                 size += sizes[0] + sizes[1] + sizes[2];
  212.  
  213.                 char* stringToLog = (char*)malloc(sizeof(char)*size);
  214.  
  215.                 _flushall();
  216.                 strcpy(stringToLog, argv[1]);
  217.                 strcat(stringToLog, "/");
  218.                 strcat(stringToLog, ent->d_name);
  219.  
  220.  
  221.  
  222.                 if ((strcmp(stringToLog, ".") != 0) && (strcmp(stringToLog, "..") != 0))
  223.                 {
  224.                     count++;
  225.                     FILE* youtube = fopen(stringToLog, "rb");
  226.  
  227.                     if (youtube == NULL)
  228.                     {
  229.                         fprintf(log, "problem \n",count);
  230.                     }
  231.  
  232.  
  233.                     FindInfected(argv, &InfectedFile);
  234.  
  235.                    
  236.                 Infected = opendir(InfectedFile);
  237.  
  238.  
  239. //************************************************************************************************
  240.  
  241.  
  242.                     int sizeOfFile = sizeof(youtube);
  243.                     for (int i = 0; i < (sizeOfFile - 23); i++)
  244.                     {
  245.                         char* check = (char*)malloc(sizeof(char)*23);
  246.  
  247.                         for (int j = i; j < (i + 23); j++)
  248.                         {
  249.                            
  250.                        
  251.                             check[j] = argv[1][j];
  252.  
  253.  
  254.                         }
  255.  
  256.                         if (strcmp(check, InfectedFile) == 0)
  257.                         {
  258.  
  259.                             fprintf(log, "\n%s - Infected",ent->d_name);
  260.                             numberOfInfections++;
  261.                         }
  262.  
  263.  
  264.                     }
  265.                    
  266.  
  267. //*************************************************************************************************
  268.  
  269.  
  270.  
  271.                    
  272.                     if (numberOfInfections == 0)
  273.                     {
  274.                         fprintf(log, "\n%s - Not Infected", ent->d_name);
  275.  
  276.                     }
  277.  
  278.                     fclose(youtube);
  279.                     free(stringToLog);
  280.                 }
  281.        
  282.     }
  283.  
  284.  
  285.  
  286.  
  287.  
  288.  
  289.     fclose(log);
  290.     closedir(dir);
  291.     free(InfectedFile);
  292.  
  293.  
  294.  
  295.     return(0);
  296. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement