首页 > 技术文章 > 随机复写硬盘,可以防止一般的数据恢复???

utank 2016-08-05 10:55 原文

随机复写硬盘,可以防止一般的数据恢复???

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 
 5 #define FILE_SIZE        ( 1024 * 1024 * 1 )
 6 #define FILE_COUNT        ( 1 * 100 )
 7 #define FCK_LOOP        ( 3 )
 8 
 9 int main(void)
10 {
11     FILE *fp = NULL;
12     char file_name[32];
13     unsigned char *data = NULL;
14     int i, j, len, fck_loop;
15     
16     data = (unsigned char *)malloc(FILE_SIZE);
17     if(data == NULL)
18     {
19         printf("malloc %d error!!\n", i);
20         goto end;
21     }
22     
23     fck_loop = 0;
24     while(fck_loop < FCK_LOOP)
25     {
26         //for(i = 0; i < FILE_COUNT; i++)
27         i = 0;
28         while(1)
29         {
30             if(fck_loop == 0)
31             {
32                 memset(data, 0x00, FILE_SIZE);
33             }
34             else if(fck_loop == 1)
35             {
36                 memset(data, 0xff, FILE_SIZE);
37             }
38             else
39             {
40                 srand(i ^ 0x835);
41                 
42                 for(j = 0; j < FILE_SIZE; j++)
43                 {
44                     data[j] = rand() % 0xff;    
45                 }
46             }
47 
48             
49             snprintf(file_name, sizeof(file_name)-1, "fck_file_%08d", i);
50             printf("%s\n", file_name);
51             
52             fp = fopen(file_name, "w+");
53             if(fp == NULL)
54             {
55                 printf("create %s error!!\n", file_name);
56                 //goto end;
57                 break;
58             }
59             
60             len = fwrite(data, 1, FILE_SIZE, fp);
61             //printf("fwrite len: %d\n", len);
62             if(len != FILE_SIZE * 1)
63             {
64                 printf("write %s error!!\n", file_name);
65                 //goto end;
66                 break;
67             }
68             
69             fclose(fp);
70             i++;
71         }
72         system("del fck_file_*");
73         fck_loop++;
74     }
75     free(data);
76     
77 end:    
78     return 0;
79 }

 

推荐阅读