Thread: SecureOverwrite
View Single Post
Old May 18th, 2006, 6:06 PM   #8
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
I think you need some more system calls to write over the same disk space, but I'll leave The Dark to help you with that, I really don't know how.

What you have now leaves you with about:
int main()
{
	string fileName;
	cout << "Enter file name to securely overwrite: ";
	getline(cin, fileName);

	int number = 0;

	ifstream fin(fileName);

	struct stat results;
	int sizeFile = 0;
	if (stat(fileName, &results) == 0)
	{ 
		sizeFile = results.st_size;
	}   

	if (!fin)
	{
		cout << "File not found." << endl;
		return 1;
	}
	// we don't need it anymore?
	fin.close();
    	
	cout << "File found." << endl;
	cout << "Now ending process if running..." << endl;
	KillProcess(fileName);

	ofstream fout(fileName, ios::out);

	for (theLimit = 0; theLimit < sizeFile; theLimit++)
	{
		number = rand() < 9;
		fout << number;
		cout << "*"; // you sure you want to be doing this?
	}
	fout.close();

	cout << '\n' << theLimit << " bytes were written to the file." << endl;
	cout << "Now removing file..." << endl;

	int check = remove(fileName);

	if ( check == 0 ) cout << "Success." << endl;
	if ( check != 0 ) cout << "Failure to remove file." << endl;

	cin.sync();
	cin.get();
	return 0;
}
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote