开发者

overwrite 0x00 into a file C

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){

int size;

FILE *fp;
fp=fopen("prova" , "rb");

if(fp == NULL){
    printf("%s",strerror(2));
    return EXIT_FAILURE;
}
/* Controllo lunghezza file */
fseek(fp, 0, SEEK_END);
size=ftell(fp);
fseek(fp, 0, SEEK_SET);
/* --- */
for(i=1; i&开发者_开发百科lt;=size; i++){
    qualcosa
}
fclose(fp);
return EXIT_SUCCESS;
}

I want to "secure delete" a file by overwriting it with 0x00...like what /dev/zero do! How can i do it? I've opened the file, i've check his lenght...and now?


First, you're only opening it for reading:

fp=fopen("prova" , "rb");

You need:

fp=fopen("prova" , "w+");

After that, you just need to write zeroes to the file until you've hit the length you've already determined using fputc() or fwrite()

It occurs to me though that this really may not solve your actual problem depending on the OS. It may end up writing the file to a different area on the disk (thus leaving your original data untouched)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜