Exemple #1
0
int main(int argc, char **argv)
{
	elfdesc_t elf;

	if (argc < 2) {
		printf("Usage: %s <executable>\n", argv[0]);
		exit(0);
	}
	
	if (load_executable(argv[1], &elf) < 0) {
		printf("Failed to load executable: %s\n", argv[1]);
		exit(-1);
	}
	
	if (test_for_skeksi(&elf) == 0) {
		printf("File: %s, is not infected with the Skeksi virus\n", argv[1]);
		exit(-1);
	}
	printf("File: %s, is infected with the skeksi virus! Attempting to disinfect\n", argv[1]);

	if (disinfect(&elf) < 0) {
		printf("Failed to disinfect file: %s\n", argv[1]);
		exit(-1);
	}

	printf("Successfully disinfected: %s\n", argv[1]);
	
	
}
int scan_dir (char *directory, char *logfile, int flag)
{
    FILE *fd;
    char *fileapath;
    struct dirent **filelist;
    struct stat buf;
    int count = 0,i = 0;
    char *detectstring = "VLP";

    fd = fopen(logfile, "w+"); /* return egal */
    if ((fileapath = (char*) (malloc (1000))) == NULL)
        perror (""), exit (1);
    if ((i = scandir (directory, &filelist, 0, 0)) == -1) // dir. scannen
        perror (""), exit (2);
    for (count = 2; count < i; count++) {  /* alle gefundenen Dateien,ausser "." , ".."  */
        if ((fileapath = strcpy (fileapath, directory)) == NULL) // Pfad
            perror (""), exit (3);
        fileapath = strcat (fileapath, "/");  /* Trenner */
        if ((fileapath = strcat (fileapath, filelist[count]->d_name)) == NULL) // + Datei
            perror (""), exit (4);
        stat (fileapath, &buf);
        if ((buf.st_mode & S_IFDIR) == S_IFDIR) /* falls Unterverzeichniss */
            scan_dir (fileapath, logfile, flag); /* rekursiv weiter */
        else { /* sonst scannen */
            printf("\r                                     ");
            printf("                                     \r");
            printf("Datei <%s> ist ", fileapath);
            if (isinfected (fileapath)) {
                if (fd != NULL)
                    fprintf(fd, "Datei <%s> ist infiziert.", fileapath);
                printf ("infiziert");
                if (flag) {
                    disinfect(fileapath);
                    printf(" ... I disinfect ...");
                    if (fd != NULL)
                        fprintf(fd, " ... I disinfect ...");
                }
                if (fd != NULL)
                    fprintf(fd, "\n");
            }
            else
                printf("sauber");
            fflush(stdout);
        } /* else      */
    } /* for */
    return count;
}