source: trunk/EraserDll/Custom.cpp @ 4

Revision 4, 4.3 KB checked in by lowjoel, 7 years ago (diff)

Added the source files from EraserDll? (SVN migration commit 2)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1// Custom.cpp
2//
3// Generic wipe function.
4//
5// Eraser. Secure data removal. For Windows.
6// Copyright © 1997-2001  Sami Tolvanen (sami@tolvanen.com).
7//
8// This program is free software; you can redistribute it and/or
9// modify it under the terms of the GNU General Public License
10// as published by the Free Software Foundation; either version 2
11// of the License, or (at your option) any later version.
12//
13// This program is distributed in the hope that it will be useful,
14// but WITHOUT ANY WARRANTY; without even the implied warranty of
15// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16// GNU General Public License for more details.
17//
18// You should have received a copy of the GNU General Public License
19// along with this program; if not, write to the Free Software
20// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21// 02111-1307, USA.
22
23#include "stdafx.h"
24#include "EraserDll.h"
25#include "Common.h"
26#include "Custom.h"
27
28bool
29wipeFileWithCustom(CEraserContext *context)
30{
31    if (!AfxIsValidAddress(context->m_lpmMethod, sizeof(METHOD)) ||
32        !AfxIsValidAddress(context->m_lpmMethod->m_lpPasses,
33                           sizeof(PASS) * context->m_lpmMethod->m_nPasses)) {
34        return false;
35    }
36
37    E_UINT32 uStartTime = GetTickCount();
38    E_UINT32 uUsedSize  = 0;
39    E_UINT32 uSavedSize = 0;
40    E_UINT64 uLength    = 0;
41    E_UINT64 uWiped     = 0;
42    E_UINT32 uWritten   = 0;
43    bool     bCompleted = true;
44
45    // send the begin message only once
46    postStartNotification(context);
47
48    setBufferSize(context, uSavedSize);
49
50    // shuffle the pass array
51    if (context->m_lpmMethod->m_bShuffle) {
52        shufflePassArray((LPPASS)context->m_lpmMethod->m_lpPasses,
53                         context->m_lpmMethod->m_nPasses);
54    }
55
56    for (E_UINT16 uCurrentPass = 0;
57         uCurrentPass < context->m_lpmMethod->m_nPasses; uCurrentPass++) {
58        eraserSafeAssign(context, context->m_uProgressCurrentPass,
59                         (E_UINT16)(uCurrentPass + 1));
60
61        // start from the beginning again
62        SetFilePointer(context->m_hFile, context->m_uiFileStart.LowPart,
63                       (E_PINT32)&context->m_uiFileStart.HighPart, FILE_BEGIN);
64
65        uLength = context->m_uiFileSize.QuadPart;
66        uUsedSize = uSavedSize;
67
68        // fill buffer
69        fillPassData(context->m_puBuffer, uUsedSize,
70                     &context->m_lpmMethod->m_lpPasses[uCurrentPass]);
71
72        while (uLength > 0) {
73            // random data needs refilling
74            if (isRandomPass(context->m_lpmMethod->m_lpPasses[uCurrentPass])) {
75                isaacFill((E_PUINT8)context->m_puBuffer, uUsedSize);
76            }
77
78            // use the whole buffer as long as we can
79            if (uLength < (E_UINT64)uUsedSize) {
80                uUsedSize = (E_UINT32)uLength;
81            }
82
83            // completed if not terminated and write is successful
84            bCompleted = !eraserInternalTerminated(context) &&
85                         WriteFile(context->m_hFile, context->m_puBuffer,
86                                   uUsedSize, &uWritten, NULL) &&
87                         (uUsedSize == uWritten);
88
89            // flush to disk
90            FlushFileBuffers(context->m_hFile);
91
92            // if not completed - stop!
93            if (!bCompleted) {
94                break;
95            }
96
97            // set statistics
98            context->m_uProgressWiped += (E_UINT64)uUsedSize;
99            uWiped += (E_UINT64)uUsedSize;
100
101            // how much left to go?
102            uLength -= (E_UINT64)uUsedSize;
103
104            // send update to window
105            postUpdateNotification(context, context->m_lpmMethod->m_nPasses);
106        }
107
108        if (context->m_uTestMode && !eraserInternalTerminated(context)) {
109            // pause, so the results can be examined
110            context->m_evTestContinue.ResetEvent();
111            eraserTestPausedNotify(context);
112            WaitForSingleObject(context->m_evTestContinue, INFINITE);
113        }
114
115        if (!bCompleted) {
116            break;
117        }
118    }
119
120    // set statistics
121    setEndStatistics(context, uWiped, uStartTime);
122
123    // shuffle the pass array again to remove traces of pass order
124    if (context->m_lpmMethod->m_bShuffle) {
125        shufflePassArray((LPPASS)context->m_lpmMethod->m_lpPasses,
126                         context->m_lpmMethod->m_nPasses);
127    }
128
129    return bCompleted;
130}
Note: See TracBrowser for help on using the repository browser.