#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("WipeInfo V 2.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 fname1[255],filename2[255],*filename1; 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"); if (uguali(fname1,"\\")) printf("Terminated by user.\n"); else {if (argc==2) {filename1=param; printf("Proceeding...\n");} else filename1=fname1; //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 destroy file\n <%s> \nentering %s\n > ",filename1,confirm); scanf("%s",filename2);printf("\n"); if (uguali(filename2,"\\")) {printf("Terminated by user.\n");fclose(tmpunt);} else {if (( (strcmp(filename2,nomecnf)!=0) && (argc!=2) ) || ( (!caseuguali(filename2,nomecnf)) && (argc==2) )) {printf("Invalid confirmation. No action taken.\n");fclose(tmpunt);} else {printf("Confirmed.\n\nOverwriting...\n"); handle = fileno(tmpunt); lof=filelength (handle); fclose(tmpunt); p1=fopen(filename1,"r+b"); 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("\nFile %s has been destroyed. \nData permanently removed from disk.",filename1); else printf("ERROR #6 : 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. } } } } }