#include #include #include #include #include #include #include char wpath[230]; char emsg=0; char* estrai(char* path, char* file) // Separa un indirizzo in Percorso (path) e Filename (file). {int fcount=0; for (int cic=0; cic<=strlen(path); cic++) {file[fcount++]=path[cic]; if (path[cic]=='\\') fcount=0; } path[(strlen(path)-strlen(file))]=0; return file; } char* aggiusta(char* path) // path punta all'indirizzo da aggiustare. {char temp[330]; estrai(path,temp); if (*path!=0) {strcat(path,temp); } else {strcat(path,wpath);strcat(path,temp);} return path; // path punta all'indirizzo aggiustato. } FILE * p1,* p3,* p4; int blocchi; unsigned long int lof; int uguali(unsigned char* a, unsigned char *b) {if (strlen(a)!=strlen(b)) return 0; int i=-1;int verita=1; while (a[++i]!=0) if (a[i]!=b[i]) verita=0; return verita; } int caseuguali(unsigned char* a, unsigned char *b) {if (strlen(a)!=strlen(b)) return 0; int i=-1;int verita=1; while (a[++i]!=0) if ( !( (a[i]==b[i]) || ((a[i]>=97)&&(a[i]<=122)&&(a[i]==b[i]+32)) || ((a[i]>=65)&&(a[i]<=90)&&(a[i]==b[i]-32)) ) ) verita=0; //if ((a[i]!=b[i]) && ( ((a[i]>97)&&(a[i]<122)&&(a[i]!=b[i]+32)) || ((a[i]>65)&&(a[i]<90)&&(a[i]!=b[i]-32)) || ((a[i]<65)&&(a[i]>90)&&(a[i]<97)&&(a[i]>122)) )) verita=0; Controllo alternativo. return verita; } void wipe(unsigned char asc) {unsigned long int cic; rewind(p1); for (cic=0;cic0) {if (app!=asc) ver=0;} else ver=0; } return ver; } int main (argc,argv) char **argv; {*wpath=0; char stk[100], temp[330]; // wpath è un array dichiarato come variabile globale. char* param2=argc>1 ? argv[1] : "default"; if (argc==2){strcpy(wpath,param2); estrai(wpath, stk); } char* param=stk; printf("Clean V 1.0 (c) 1998 Gianluca Palermo \n\n"); int handle;int proc; printf("Please enter 0 for fast procedure, 1 for standard procedure > "); scanf("%d",&proc);printf("\n"); if (proc!=0 && proc!=1) printf("Invalid choice. Terminated by user.\n"); else{ if (proc==0) printf("You chose fast procedure.\n"); else printf("You chose standard procedure (Spec. DoD 5220.22-M).\n"); // unsigned char filename1[255],filename2[255]; unsigned char filename1[135], drive; // if (argc==2) // {printf("Processing file %s. \n'\\' to abort, '+' to continue > ",param);} // else printf("Please enter name of file to be destroyed ('\\' to abort)\n > "); // scanf("%s",fname1);printf("\n"); printf("Please enter the letter of drive to be processed ('\\' to abort)\n > "); scanf("%s",filename1);printf("\n"); drive=*filename1; if (drive=='\\') ; else {if ((drive>=97)&&(drive<=122)) drive-=32; {struct diskfree_t free; long avail; if (_dos_getdiskfree(0+drive-'A'+1, &free) != 0) { printf("Error in _dos_getdiskfree() call.\n\nYou probably entered an invalid drive letter.\n\nProcess aborted.\n"); exit(1); } avail = (long) free.avail_clusters * (long) free.bytes_per_sector * (long) free.sectors_per_cluster; printf("Amount of free space on drive %c: is %ld bytes (%.2lf MB)\n",drive , avail, ((float)avail)/1024.0/1024.0); lof=avail; } //printf("Please enter amount of free space on drive %c: in bytes ('0' to abort)\n > ",drive); //scanf("%ld",&lof);printf("\n"); } if (drive=='\\') printf("Terminated by user.\n"); if (lof==0) printf("No free space to clean.\n\nNo action taken.\n"); if (drive=='\\' || lof==0) ; else {printf("\n"); //printf("Proceeding...\n\n"); //if (*wpath!=0) {strcpy(temp,path); strcat(temp, filename1);filename1=temp;} //char nomecnf[100]; strcpy(nomecnf,param); //aggiusta(filename1); // printf("Please enter name of file to be destroyed. ('\\' to abort)\n > "); // scanf("%s",filename1);printf("\n"); // if (uguali(filename1,"\\")) printf("Terminated by user.\n"); //else{ //FILE * tmpunt; //if (NULL==(tmpunt=fopen(filename1,"r"))) {printf("ERROR #2 : Couldn't find specified file : %s\n",filename1);fclose(tmpunt);} // else {char confirm[]="the first 3 characters of its name";//Per cambiare n° caratteri cambia anche riga con asterischi. // if (argc==2) // {//char confirm[]="the first 3 characters of its name"; //assegnazione già fatta. // nomecnf[3]=0; //**************************************************** // } // else {strcpy(confirm,"YyYy"); // strcpy(nomecnf,confirm); // } printf("Please confirm you want to clean free space on drive <%c:> entering YyYy\n(Note that confirming this action will definitely prevent you from\nrecovering previously deleted files -or any part of them- on drive %c:)\n > ",drive,drive); scanf("%s",filename1);printf("\n"); if (uguali(filename1,"\\")) {printf("Terminated by user.\n");} else {if (strcmp(filename1,"YyYy")!=0) {printf("Invalid confirmation. No action taken.\n");} else {printf("Confirmed.\n\nOverwriting free space...\n"); //handle = fileno(tmpunt); //lof=filelength (handle); //fclose(tmpunt); filename1[0]=drive;filename1[1]=0; strcat(filename1,":\\freespce.tmp"); p1=fopen(filename1,"wb"); if (proc) {wipe('1');wipe ('0');wipe('1');wipe ('0');wipe('1');wipe ('0');}//Specifiche DoD 5220.22-M wipe('÷'); fclose(p1); if (proc) {printf("Verifying...\n");p1=fopen(filename1,"rb");//Specifiche DoD 5220.22-M if (verifica ('÷')==0) printf ("-!- NOT PASSED. Process did not pass verification successfully.\n");//Specifiche DoD 5220.22-M else printf ("Passed.\n");//Specifiche DoD 5220.22-M fclose(p1);//Specifiche DoD 5220.22-M } if (remove(filename1)==0) printf("\nFree space on drive %c: has been cleaned. \nData permanently removed from disk.\n",drive); else printf("ERROR #6 : Service file %s could not be removed.\n Probably file is read-only or disk is write-protected.\nProcess aborted.\n",filename1); } // Non ha senso il controllo sulla dimensione perché non si avranno problemi di spazio: lo spazio è quello del file da eliminare già presente su disco. Se può essere sovrascritto il file verrà sovrascritto interamente. } //} } } }