@@ -26,7 +26,8 @@ typedef struct Data_storage
2626{
2727 char fpath [300 ]; //파일 경로
2828 char fname [20 ]; //파일 이름
29- uint dcnt ; //민감정보 총 개수
29+ uint jcnt ; //주민번호 개수
30+ uint dcnt ; //운전면허 개수
3031 uint fsize ; //파일 크기
3132 char stat ; //파일 상태
3233
@@ -39,7 +40,7 @@ static gchar *path;
3940static int fcnt = 0 ;
4041static char chkfname [20 ];
4142int chk_tf ; //chk_true false
42- uint data_flag = 1 ; //어떤종류의 민감정보인지 확인하기위한 flag
43+ // uint data_flag = 1; //어떤종류의 민감정보인지 확인하기위한 flag
4344
4445
4546GtkWidget * detect_window ,
@@ -160,14 +161,14 @@ char match_regex_j (regex_t *r, const char *to_match, char *filepath, struct dir
160161 strcpy (chkfname , file -> d_name );
161162
162163 //검출된 주민등록번호의 수//
163- ds [fcnt ].dcnt ++ ;
164+ ds [fcnt ].jcnt ++ ;
164165
165- //주민번호 구조체에 저장//
166+ //data 구조체에 저장//
166167 strcpy (ds [fcnt ].fpath , filepath );
167168 strcpy (ds [fcnt ].fname , file -> d_name );
168169 ds [fcnt ].fsize = buf .st_size ;
169170
170- printf ("num: %d, cnt : %d, file_path: %s, file_name: %s, file_size: %dbyte\n" , fcnt , ds [fcnt ].dcnt , ds [fcnt ].fpath , ds [fcnt ].fname , ds [fcnt ].fsize );
171+ printf ("num: %d, jcnt : %d, dcnt: %d, file_path: %s, file_name: %s, file_size: %dbyte\n" , fcnt , ds [ fcnt ]. jcnt , ds [fcnt ].dcnt , ds [fcnt ].fpath , ds [fcnt ].fname , ds [fcnt ].fsize );
171172 }
172173 }
173174 }
@@ -177,13 +178,75 @@ char match_regex_j (regex_t *r, const char *to_match, char *filepath, struct dir
177178 }
178179}
179180
181+ //Match the string in "to_match" against the compiled regular expression in "r"//
182+ char match_regex_d (regex_t * r , const char * to_match , char * filepath , struct dirent * file , struct stat buf )
183+ {
184+ /* "P" is a pointer into the string which points to the end of the
185+ previous match. */
186+ const char * p = to_match ;
187+ /* "N_matches" is the maximum number of matches allowed. */
188+ const int n_matches = 100 ;
189+ /* "M" contains the matches found. */
190+ regmatch_t m [n_matches ];
191+
192+ //버퍼크기만큼 읽은 부분 전체를 해당 정규식과 비교//
193+ while (1 )
194+ {
195+ int nomatch = regexec (r , p , n_matches , m , 0 );
196+
197+ if (nomatch )
198+ {
199+ printf ("No more matches.\n" );
200+ return 0 ;
201+ }
202+
203+ else
204+ {
205+ for (int i = 0 ; i < n_matches ; i ++ )
206+ {
207+ if (m [i ].rm_so == -1 )
208+ {
209+ break ;
210+ }
211+
212+ //운전면허 정규식 검사 통과//
213+ if (i == 0 )
214+ {
215+ int res = strcmp (chkfname , file -> d_name ); //같은파일 = 0
216+
217+ if (res != 0 )
218+ {
219+ fcnt ++ ;
220+ }
221+
222+ //읽고있는중인 파일 이름 저장
223+ strcpy (chkfname , file -> d_name );
224+
225+ //검출된 운전면허의 수//
226+ ds [fcnt ].dcnt ++ ;
227+
228+ //data 구조체에 저장//
229+ strcpy (ds [fcnt ].fpath , filepath );
230+ strcpy (ds [fcnt ].fname , file -> d_name );
231+ ds [fcnt ].fsize = buf .st_size ;
232+
233+ printf ("num: %d, jcnt: %d, dcnt: %d, file_path: %s, file_name: %s, file_size: %dbyte\n" , fcnt , ds [fcnt ].jcnt , ds [fcnt ].dcnt , ds [fcnt ].fpath , ds [fcnt ].fname , ds [fcnt ].fsize );
234+ }
235+ }
236+ }
237+
238+ p += m [0 ].rm_eo ;
239+ }
240+ }
241+
180242//Check kind of data//
181243void check_kind_of_data (const char * to_match , char * filepath , struct dirent * file , struct stat buf )
182244{
183245 regex_t r ;
184246 const char * regex_text ;
185247
186- switch (data_flag )
248+ /*
249+ switch(data_flag) //나중에 민감정보 종류 선택 검출 할 때 사용
187250 {
188251 case 1:
189252 regex_text = "([0-9]{2}(0[1-9]|1[0-2])(0[1-9]|[1,2][0-9]|3[0,1])-[1-4][0-9]{6})"; //주민번호 정규식//
@@ -195,8 +258,17 @@ void check_kind_of_data (const char *to_match, char *filepath, struct dirent *fi
195258 case 2:
196259 regex_text = "[0-9]{2}[-~.[:space:]][0-9]{6}[-~.[:space:]][0-9]{2}"; //운전면허 정규식//
197260 compile_regex(&r, regex_text); //정규식 컴파일//
198- //match_regex_j (&r, to_match, filepath, file, buf);
261+ //match_regex_d (&r, to_match, filepath, file, buf);
199262 }
263+ */
264+
265+ regex_text = "([0-9]{2}(0[1-9]|1[0-2])(0[1-9]|[1,2][0-9]|3[0,1])-[1-4][0-9]{6})" ; //주민번호 정규식//
266+ compile_regex (& r , regex_text ); //정규식 컴파일//
267+ match_regex_j (& r , to_match , filepath , file , buf );
268+
269+ regex_text = "[0-9]{2}[-~.[:space:]][0-9]{6}[-~.[:space:]][0-9]{2}" ; //운전면허 정규식//
270+ compile_regex (& r , regex_text ); //정규식 컴파일//
271+ match_regex_d (& r , to_match , filepath , file , buf );
200272}
201273
202274int scan_dir (gchar * path )
@@ -579,12 +651,12 @@ void d_folder_btn_clicked (GtkButton *d_folder_btn, gpointer *data)
579651enum
580652{
581653 d_treeview_num = 0 ,
582- d_treeview_type ,
583654 d_treeview_filename ,
584- d_treeview_filelocation ,
585- d_treeview_cnt ,
655+ d_treeview_jcnt ,
656+ d_treeview_dcnt ,
586657 d_treeview_stat ,
587658 d_treeview_size ,
659+ d_treeview_filelocation ,
588660 NUM_COLS
589661} ;
590662
@@ -594,19 +666,19 @@ create_and_fill_model (void)
594666 GtkTreeStore * treestore ;
595667 GtkTreeIter iter ;
596668
597- treestore = gtk_tree_store_new (NUM_COLS , G_TYPE_UINT , G_TYPE_STRING , G_TYPE_STRING , G_TYPE_STRING , G_TYPE_UINT , G_TYPE_STRING , G_TYPE_UINT );
669+ treestore = gtk_tree_store_new (NUM_COLS , G_TYPE_UINT , G_TYPE_STRING , G_TYPE_UINT , G_TYPE_UINT , G_TYPE_STRING , G_TYPE_UINT , G_TYPE_STRING );
598670
599671 for (int i = 1 ; i <= fcnt ; i ++ )
600672 {
601673 gtk_tree_store_append (treestore , & iter , NULL );
602674 gtk_tree_store_set (treestore , & iter ,
603675 d_treeview_num , i ,
604- d_treeview_type , "data_flag" ,
605676 d_treeview_filename , ds [i ].fname ,
606- d_treeview_filelocation , ds [i ].fpath ,
607- d_treeview_cnt , ds [i ].dcnt ,
677+ d_treeview_jcnt , ds [i ].jcnt ,
678+ d_treeview_dcnt , ds [i ].dcnt ,
608679 d_treeview_stat , "have to define" ,
609680 d_treeview_size , ds [i ].fsize ,
681+ d_treeview_filelocation , ds [i ].fpath ,
610682 -1 );
611683 }
612684
@@ -638,14 +710,6 @@ create_view_and_model (void)
638710
639711 gtk_tree_view_column_add_attribute (col , renderer , "text" , d_treeview_num );
640712
641- /* --- Column #민감정보 종류 --- */
642- col = gtk_tree_view_column_new ();
643- gtk_tree_view_column_set_title (col , "민감정보 종류" );
644- gtk_tree_view_append_column (GTK_TREE_VIEW (view ), col );
645- renderer = gtk_cell_renderer_text_new ();
646- gtk_tree_view_column_pack_start (col , renderer , TRUE);
647- gtk_tree_view_column_add_attribute (col , renderer , "text" , d_treeview_type );
648-
649713 /* --- Column #파일 이름 --- */
650714 col = gtk_tree_view_column_new ();
651715 gtk_tree_view_column_set_title (col , "파일 이름" );
@@ -654,21 +718,21 @@ create_view_and_model (void)
654718 gtk_tree_view_column_pack_start (col , renderer , TRUE);
655719 gtk_tree_view_column_add_attribute (col , renderer , "text" , d_treeview_filename );
656720
657- /* --- Column #파일 위치 --- */
721+ /* --- Column #주민번호 개수 --- */
658722 col = gtk_tree_view_column_new ();
659- gtk_tree_view_column_set_title (col , "파일 위치 " );
723+ gtk_tree_view_column_set_title (col , "주민번호 " );
660724 gtk_tree_view_append_column (GTK_TREE_VIEW (view ), col );
661725 renderer = gtk_cell_renderer_text_new ();
662726 gtk_tree_view_column_pack_start (col , renderer , TRUE);
663- gtk_tree_view_column_add_attribute (col , renderer , "text" , d_treeview_filelocation );
727+ gtk_tree_view_column_add_attribute (col , renderer , "text" , d_treeview_jcnt );
664728
665- /* --- Column #민감정보 개수 --- */
729+ /* --- Column #운전면허 개수 --- */
666730 col = gtk_tree_view_column_new ();
667- gtk_tree_view_column_set_title (col , "민감정보 개수 " );
731+ gtk_tree_view_column_set_title (col , "운전면허 " );
668732 gtk_tree_view_append_column (GTK_TREE_VIEW (view ), col );
669733 renderer = gtk_cell_renderer_text_new ();
670734 gtk_tree_view_column_pack_start (col , renderer , TRUE);
671- gtk_tree_view_column_add_attribute (col , renderer , "text" , d_treeview_cnt );
735+ gtk_tree_view_column_add_attribute (col , renderer , "text" , d_treeview_dcnt );
672736
673737 /* --- Column #상태 --- */
674738 col = gtk_tree_view_column_new ();
@@ -685,6 +749,14 @@ create_view_and_model (void)
685749 renderer = gtk_cell_renderer_text_new ();
686750 gtk_tree_view_column_pack_start (col , renderer , TRUE);
687751 gtk_tree_view_column_add_attribute (col , renderer , "text" , d_treeview_size );
752+
753+ /* --- Column #파일 위치 --- */
754+ col = gtk_tree_view_column_new ();
755+ gtk_tree_view_column_set_title (col , "파일 위치" );
756+ gtk_tree_view_append_column (GTK_TREE_VIEW (view ), col );
757+ renderer = gtk_cell_renderer_text_new ();
758+ gtk_tree_view_column_pack_start (col , renderer , TRUE);
759+ gtk_tree_view_column_add_attribute (col , renderer , "text" , d_treeview_filelocation );
688760
689761 model = create_and_fill_model ();
690762
0 commit comments