This repository was archived by the owner on Apr 25, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcolpress-wipe.bat
More file actions
218 lines (203 loc) · 7.69 KB
/
Copy pathcolpress-wipe.bat
File metadata and controls
218 lines (203 loc) · 7.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
@echo off
setlocal enabledelayedexpansion
chcp 65001 >nul 2>&1
:: ================================================================
:: colpress-wipe.bat v2.0 — Secure File/Folder Erasure
:: Part of Colpress v2.0. No exe required.
::
:: Engine : PowerShell 5.1+ (.NET streaming — built into Windows 10+)
:: Free space: cipher /w: (built-in since Windows XP)
::
:: Wipe passes (DoD 5220.22-M inspired):
:: Pass 1 — 0x00 bytes
:: Pass 2 — 0xFF bytes
:: Pass 3 — RNGCryptoServiceProvider (cryptographically random)
:: Passes 4-7 repeat the cycle for 7-pass mode.
::
:: SSD note: All file-level tools (including sdelete64) cannot
:: guarantee physical erasure on SSDs due to wear-levelling.
:: For SSDs, use ATA Secure Erase (drive firmware) or full-disk
:: encryption before deletion. This tool matches sdelete64 in that regard.
::
:: Usage (standalone):
:: colpress-wipe.bat <file> (3-pass wipe + delete)
:: colpress-wipe.bat <file> /p:1 (1-pass zeros)
:: colpress-wipe.bat <file> /p:7 (7-pass)
:: colpress-wipe.bat <dir> /s (recursive, 3-pass)
:: colpress-wipe.bat <drive:> /z (wipe free space via cipher /w:)
:: colpress-wipe.bat /?
:: ================================================================
set "ROOT=%~dp0"
set "ROOT=%ROOT:~0,-1%"
if not "%~1"=="" (
if /i "%~1"=="/?" goto :HELP
set "DIRECT_PATH=%~1"
set "DIRECT_FLAGS=%~2"
goto :RUN_DIRECT
)
:MAIN
cls
echo.
echo +-- colpress-wipe Secure Erasure (no exe) --------------------+
echo ^| Engine: PowerShell .NET streaming ^| Requires: Win 10+ ^|
echo ^| Free-space: cipher /w: (built-in since XP) ^|
echo ^| ^|
echo ^| [1] Wipe a file (1 pass — zeros) ^|
echo ^| [2] Wipe a file (3 passes — zeros / 0xFF / random) ^|
echo ^| [3] Wipe a file (7 passes) ^|
echo ^| [4] Wipe all files in a directory recursively (3 passes) ^|
echo ^| [5] Wipe free space on a drive (cipher /w:) ^|
echo ^| [0] Back / Exit ^|
echo +--------------------------------------------------------------+
echo.
choice /c 123450 /n /m " Enter option: "
set "OPT=!errorlevel!"
if "!OPT!"=="6" goto :EXIT_SW
if "!OPT!"=="5" goto :WIPE_FREE
if "!OPT!"=="4" goto :WIPE_DIR
if "!OPT!"=="3" goto :WIPE_7
if "!OPT!"=="2" goto :WIPE_3
if "!OPT!"=="1" goto :WIPE_1
goto :MAIN
:WIPE_1
set /p "SW_FILE= Drag in or type file path: "
echo. & echo Target : !SW_FILE! & echo Passes : 1 (zeros)
set /p "SW_C= Confirm? (Y/N): "
if /i not "!SW_C!"=="Y" goto :MAIN
call :DO_WIPE "!SW_FILE!" 1
goto :SW_PAUSE
:WIPE_3
set /p "SW_FILE= Drag in or type file path: "
echo. & echo Target : !SW_FILE! & echo Passes : 3 (zeros, 0xFF, random)
set /p "SW_C= Confirm? (Y/N): "
if /i not "!SW_C!"=="Y" goto :MAIN
call :DO_WIPE "!SW_FILE!" 3
goto :SW_PAUSE
:WIPE_7
set /p "SW_FILE= Drag in or type file path: "
echo. & echo Target : !SW_FILE! & echo Passes : 7 (zeros, 0xFF, random x5)
set /p "SW_C= Confirm? (Y/N): "
if /i not "!SW_C!"=="Y" goto :MAIN
call :DO_WIPE "!SW_FILE!" 7
goto :SW_PAUSE
:WIPE_DIR
set /p "SW_DIR= Drag in or type directory path: "
echo.
echo WARNING: All files inside !SW_DIR! will be securely wiped.
set /p "SW_C= Confirm? (Y/N): "
if /i not "!SW_C!"=="Y" goto :MAIN
echo. & echo Wiping all files in: !SW_DIR!
for /r "!SW_DIR!" %%F in (*) do (
echo Wiping: %%F
call :DO_WIPE "%%F" 3
)
echo. & echo All files wiped. Directory structure left intact.
goto :SW_PAUSE
:WIPE_FREE
echo.
set /p "SW_DRV= Enter drive letter (e.g. C: or D:): "
echo.
echo cipher /w: writes zeros, 0xFF, then random data to all free
echo clusters on !SW_DRV! — preventing software recovery.
echo This may take a long time on large drives.
set /p "SW_C= Confirm? (Y/N): "
if /i not "!SW_C!"=="Y" goto :MAIN
echo.
echo Wiping free space on !SW_DRV! (may take minutes to hours)...
cipher /w:!SW_DRV!
echo. & echo Free-space wipe complete.
goto :SW_PAUSE
:SW_PAUSE
echo. & echo ----------------------------------------------------------------
pause
goto :MAIN
:EXIT_SW
exit /b 0
:: ── Subroutine: DO_WIPE <path> <passes> ──────────────────────────
:DO_WIPE
setlocal
set "WP_FILE=%~1"
set "WP_PASSES=%~2"
if "!WP_PASSES!"=="" set "WP_PASSES=3"
echo.
echo Wiping: !WP_FILE! (!WP_PASSES! pass(es))...
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
"& { ^
$f = '!WP_FILE!'.Trim('\"'); ^
if (-not [IO.File]::Exists($f)) { Write-Host ' ERROR: File not found.'; exit 1 } ^
$size = (Get-Item -LiteralPath $f).Length; ^
if ($size -eq 0) { Remove-Item -LiteralPath $f -Force; Write-Host ' Deleted (empty file).'; exit 0 } ^
$rng = [Security.Cryptography.RNGCryptoServiceProvider]::new(); ^
$buf = [byte[]]::new([Math]::Min($size, 1048576)); ^
$passes = !WP_PASSES!; ^
for ($p = 0; $p -lt $passes; $p++) { ^
$label = switch ($p %% 3) { 0 {'zeros'} 1 {'0xFF'} 2 {'random'} }; ^
Write-Host (' Pass ' + ($p+1) + '/' + $passes + ': ' + $label + '...') -NoNewline; ^
$s = [IO.File]::Open($f, [IO.FileMode]::Open, [IO.FileAccess]::Write, [IO.FileShare]::None); ^
$s.Seek(0, [IO.SeekOrigin]::Begin) ^| Out-Null; ^
$written = [long]0; ^
while ($written -lt $size) { ^
$n = [Math]::Min($buf.Length, $size - $written); ^
switch ($p %% 3) { ^
0 { [Array]::Clear($buf, 0, $n) } ^
1 { for ($i=0; $i -lt $n; $i++) { $buf[$i] = 0xFF } } ^
2 { $rng.GetBytes($buf); if ($n -lt $buf.Length) { $tmp=[byte[]]::new($n); [Array]::Copy($buf,0,$tmp,0,$n); $buf=$tmp } } ^
} ^
$s.Write($buf, 0, $n); ^
$written += $n; ^
} ^
$s.Flush(); $s.Close(); ^
Write-Host ' done.'; ^
} ^
$rng.Dispose(); ^
Remove-Item -LiteralPath $f -Force; ^
Write-Host ' Deleted.'; ^
}"
if errorlevel 1 (
echo.
echo [ERROR] Wipe failed. File may be in use or PowerShell unavailable.
echo Fallback: use sdelete64.exe from tools\ if PowerShell is blocked.
)
endlocal
goto :eof
:: ── Direct / CLI mode ─────────────────────────────────────────────
:RUN_DIRECT
set "SW_PASSES=3"
set "SW_RECURSE=0"
set "SW_FREE=0"
for %%A in (%DIRECT_FLAGS%) do (
if /i "%%A"=="/p:1" set "SW_PASSES=1"
if /i "%%A"=="/p:3" set "SW_PASSES=3"
if /i "%%A"=="/p:7" set "SW_PASSES=7"
if /i "%%A"=="/s" set "SW_RECURSE=1"
if /i "%%A"=="/z" set "SW_FREE=1"
)
if "!SW_FREE!"=="1" (
echo Wiping free space on !DIRECT_PATH!...
cipher /w:!DIRECT_PATH!
goto :eof
)
if "!SW_RECURSE!"=="1" (
for /r "!DIRECT_PATH!" %%F in (*) do call :DO_WIPE "%%F" !SW_PASSES!
) else (
call :DO_WIPE "!DIRECT_PATH!" !SW_PASSES!
)
goto :eof
:HELP
echo.
echo colpress-wipe.bat v2.0 — Secure File Erasure (no exe)
echo Part of Colpress v2.0. Requires: Windows 10+ / PowerShell 5.1+
echo.
echo USAGE:
echo colpress-wipe.bat (interactive menu)
echo colpress-wipe.bat ^<file^> (3-pass wipe + delete)
echo colpress-wipe.bat ^<file^> /p:1 (1 pass, zeros only)
echo colpress-wipe.bat ^<file^> /p:7 (7 passes)
echo colpress-wipe.bat ^<directory^> /s (recurse all files, 3 passes)
echo colpress-wipe.bat ^<drive:^> /z (wipe free space via cipher /w:)
echo.
echo NOTES:
echo Random bytes use RNGCryptoServiceProvider (cryptographically secure).
echo On SSDs, use ATA Secure Erase or full-disk encryption for maximum assurance.
echo.
goto :eof