How to show hidden files and folders using C++ Programming

This program is use to show all hidden files and folder in your system drive and it can run well even system has affected by virus and worms, usually some kinds of the virus or malware script can change your files and folders in a hidden state.

I wrote this script using Borland C++ 5.5 version and tested in Windows Operating System only. You can modify or reuse the codes as per your requirement, its Free to use.
unhidden.cpp
1 #include<iostream>
2 #include<conio.h>
3 #include<dirent.h>
4 #include<dir.h>
5 #include<process.h>
6 #include<string.h>
7 #include<stdio.h>
8 #include<io.h>
9 #include<dos.h>
10 #include<sys/stat.h>
11 
12 struct ffblk vfile;
13 unsigned long int udata;
14 char ch,present[MAXPATH];
15 
16 int next_directory(char *);
17 void scan_directory(char *);
18 
19 char base[]="X:\\";
20 
21 using namespace std;
22 
23 int main(int account,char *arg[],char *env[])
24 {   
25     clrscr();
26     getcwd(present,MAXPATH);
27     
28     DIR *dir; 
29     struct dirent *temp;
30     cout<<"\nWelcome to Unhidden for identify the hidden files";
31     cout<<"\n\nEnter drive:";
32     cin>>ch;
33     
34     base[0]=ch;
35     if((dir = opendir(base)) == NULL)
36     { 
37         clrscr();
38         cout<<"\nError : Derive not found ";
39         getch(); 
40         exit(0); 
41     }
42     
43     scan_directory(base);
44     while((temp = readdir(dir)) != NULL)
45     {
46         char  *directory = (char *) malloc(3+strlen(temp->d_name)+1);
47         strcpy(directory,base);
48         strcat(directory,temp->d_name);
49         next_directory(directory);
50         free(directory);
51     }
52     closedir(dir);
53     
54     clrscr();
55     cout<<"\nSystem: Successfully Unhidden it";
56     sleep(3);
57     
58     return 0;
59 }
60 
61 int next_directory(char *path)
62 {
63     int count=0;
64     DIR *dirtemp; 
65     char *hold,*temp;
66     struct dirent *ptemp;  
67     
68     hold=path;
69     if ((dirtemp = opendir(path)) != NULL)
70     scan_directory(path);
71     else
72     return 0;
73    
74     while((ptemp = readdir(dirtemp)) != NULL)
75     {     
76         char *directory = (char *) malloc(1+strlen(ptemp->d_name)+1);
77         directory[0]='\\';
78         strcpy(directory+1,ptemp->d_name);
79         if(directory[1]!='\.')
80         {
81             count=strlen(hold);
82             temp = (char *) malloc(strlen(hold)+strlen(directory)+1);
83             strcpy(temp,hold);
84             strcat(temp,directory);
85             free(directory);
86             if(opendir(temp)!=NULL)
87             next_directory(temp); 
88             temp[count]='\0'; 
89             hold=temp;
90         }
91         else
92         free(directory);
93     }
94     closedir(dirtemp);
95     return 0;
96 }
97 
98 void scan_directory(char *tempo)
99 {
100     cout<<"\n"<<tempo;
101     unsigned count;
102     if(present[0]==tempo[0])
103     chdir(tempo);  
104     else
105     {
106         setdisk(tempo[0]-65);
107         chdir(tempo); 
108     }
109     
110     udata = findfirst("*.*",&vfile,0x02);
111     while(!udata)
112     {  
113         _dos_getfileattr(vfile.ff_name,&count);
114         if (count & _A_HIDDEN)
115         {
116             _dos_getfileattr(vfile.ff_name,&count);
117             count=count & 248;
118             _dos_setfileattr(vfile.ff_name,count);
119         }
120         udata=findnext(&vfile);
121     }
122                         
123     if(present[0]==tempo[0])    
124     system("cd\\");
125     chdir(present); 
126 }

No comments:

Post a Comment