Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include "dirent.h"
- void FindInfected(char **argv, char* InfectedFile)
- {
- DIR* OtherDir;
- struct dirent *OtherEnt;
- int countLoop = 0, location2;
- char* InfectedFolderPath = (char*)malloc(NULL);
- int location = 0, flag = 0, secSpot = 0, argvSize, spot = 0, i;
- argvSize = strlen(argv[1]);
- for (i = 0; i < argvSize; i++)
- {
- if (argv[1][i] == '/')
- {
- spot++;
- }
- }
- char* UnwantedName = (char*)malloc(NULL);
- for (i = 0; i < argvSize; i++)
- {
- if (argv[1][i] == '/')
- {
- if (secSpot != spot)
- {
- secSpot++;
- }
- if (secSpot == spot)
- {
- if (flag == 0)
- {
- location = i;
- flag++;
- }
- }
- }
- }
- char* entrenceToTheFolderBefore = (char*)malloc(NULL);
- for (int i = 0; i < location; i++)
- {
- entrenceToTheFolderBefore[i] = argv[1][i];
- }
- location2 = location;
- while (location2 != argvSize)
- {
- location2++;
- UnwantedName[countLoop] = argv[1][location2]; // problem
- countLoop++;
- }
- puts(entrenceToTheFolderBefore);
- OtherDir = opendir(entrenceToTheFolderBefore);
- //UnwatedName = C2_Mid_Anti-Virus_Project.zip
- while (OtherEnt = readdir(OtherDir))
- {
- if ((strcmp(OtherEnt->d_name, UnwantedName) != 0) && (strcmp(OtherEnt->d_name, ".") != 0) && (strcmp(OtherEnt->d_name, "..") != 0)) //problem
- {
- strcpy(InfectedFolderPath, entrenceToTheFolderBefore);
- strcat(InfectedFolderPath, "/");
- strcat(InfectedFolderPath, OtherEnt->d_name);
- puts(InfectedFolderPath);
- }
- }
- closedir(OtherDir);
- DIR* Infected = opendir(InfectedFolderPath);
- strcpy(InfectedFile, InfectedFolderPath);
- while (OtherEnt = readdir(OtherDir))
- {
- int temp = strlen(OtherEnt->d_name);
- if (strcmp(OtherEnt->d_name[(temp - 4)], '.') != 0)
- {
- strcat(InfectedFile, OtherEnt->d_name);
- }
- }
- closedir(Infected);
- }
- int main(int argc, char** argv)
- {
- char* InfectedFile = (char*)malloc(NULL);
- int numberOfInfections = 0;
- int count = 0, size = 0, totalDirs = 0;
- int sizes[3];
- DIR* dir;
- DIR* Infected;
- struct dirent *ent;
- int found = 0,temp1 = 0;
- int SumOflogsizes = 0;
- SumOflogsizes = strlen(argv[1]);
- SumOflogsizes = SumOflogsizes + 1;
- SumOflogsizes += strlen("AntiVirusLog.txt");
- char* pathToLog = (char*)malloc(sizeof(char)*SumOflogsizes);
- strcpy(pathToLog, argv[1]);
- strcat(pathToLog,"/AntiVirusLog.txt");
- FILE *log = fopen(pathToLog, "wt");
- int openInfected(argv);
- /* Open directory */
- dir = opendir(argv[1]);
- if (log == NULL)
- {
- fprintf(log, "problem\n\n");
- }
- while ((ent = readdir(dir)))
- {
- totalDirs++;
- sizes[0] = strlen(argv[1]);
- sizes[1] = 2;
- sizes[2] = strlen(ent->d_name);
- size += sizes[0] + sizes[1] + sizes[2];
- char* stringToLog = (char*)malloc(sizeof(char)*size);
- _flushall();
- strcpy(stringToLog, argv[1]);
- strcat(stringToLog, "/");
- strcat(stringToLog, ent->d_name);
- if ((strcmp(stringToLog, ".") != 0) && (strcmp(stringToLog, "..") != 0))
- {
- count++;
- FILE* youtube = fopen(stringToLog, "rb");
- if (youtube == NULL)
- {
- fprintf(log, "problem \n",count);
- }
- FindInfected(argv, &InfectedFile);
- Infected = opendir(InfectedFile);
- //************************************************************************************************
- int sizeOfFile = sizeof(youtube);
- for (int i = 0; i < (sizeOfFile - 23); i++)
- {
- char* check = (char*)malloc(sizeof(char)*23);
- for (int j = i; j < (i + 23); j++)
- {
- check[j] = argv[1][j];
- }
- if (strcmp(check, InfectedFile) == 0)
- {
- fprintf(log, "\n%s - Infected",ent->d_name);
- numberOfInfections++;
- }
- }
- //*************************************************************************************************
- if (numberOfInfections == 0)
- {
- fprintf(log, "\n%s - Not Infected", ent->d_name);
- }
- fclose(youtube);
- free(stringToLog);
- }
- }
- fclose(log);
- closedir(dir);
- free(InfectedFile);
- return(0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement