-
Notifications
You must be signed in to change notification settings - Fork 0
/
saw.bat
executable file
·275 lines (232 loc) · 9.84 KB
/
saw.bat
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
@echo off
rem Batch template by https://stackoverflow.com/a/45070967
goto :init
:header
echo %__NAME% v%__VERSION%
echo.
echo SAW is a batch utility that tries to decrease the chance of Windows Script Host abuse.
echo This script can modify some registry keys and also disable wscript.exe.
echo Please use at your own risk.
echo.
goto :eof
:usage
echo USAGE:
echo %__BAT_NAME% [flags]
echo.
echo. -?, --help shows this help
echo. -v, --version shows the version
echo. -d, --disable-wscript disable Windows Script Host
echo. -e, --enable-wscript enable Windows script Host
echo. -nb, --no-backup does not create a backup
rem echo. -is, --icon-swap does not swap icon
echo. -em, --edit-mode set edit by default (Open text editor)
echo. -om, --open-mode set open by default (Execute the file)
echo. -b DIR, --backup-dir define backup directory
echo. (default is "bkp" in script directory)
echo. -r DIR, --restore-dir define folder where backup is located
echo. (default is "bkp" in script direcotry)
echo. -i DIR, --icon-dir define folder where icons are located
echo. (default is "ICO" in script directory)
goto :eof
:new_icon
echo.
echo. To see changes reboot or type this command
echo. Win7: ie4uinit.exe -ClearIconCache
echo. Win10: ie4uinit.exe -show
goto :eof
:version
if "%~1"=="full" call :header & goto :eof
echo %__VERSION%
goto :eof
:missing_argument
call :header
call :usage
echo.
echo **** ****
echo **** MISSING "REQUIRED ARGUMENT" ****
echo **** ****
echo.
goto :eof
:init
set "__NAME=SAW stop abusing wscript"
set "__VERSION=1.1"
set "__YEAR=2020"
set "__BAT_FILE=%~0"
set "__BAT_PATH=%~dp0"
set "__BAT_NAME=%~nx0"
set "BackupDir=%__BAT_PATH%bkp"
set "RestoreDir=%__BAT_PATH%bkp"
set "IconDir=%__BAT_PATH%ICO"
set "NoBackup="
:parse
if "%~1"=="" goto :main
if /i "%~1"=="/?" call :header & call :usage "%~2" & goto :end
if /i "%~1"=="-?" call :header & call :usage "%~2" & goto :end
if /i "%~1"=="-h" call :header & call :usage "%~2" & goto :end
if /i "%~1"=="--help" call :header & call :usage "%~2" & goto :end
if /i "%~1"=="/v" call :version & goto :end
if /i "%~1"=="-v" call :version & goto :end
if /i "%~1"=="--version" call :version full & goto :end
rem Disable wscript params
if /i "%~1"=="/d" call :wscript_disable & goto :end
if /i "%~1"=="-d" call :wscript_disable & goto :end
if /i "%~1"=="--disable-wscript" call :wscript_disable & goto :end
rem Enable wscript params
if /i "%~1"=="/e" call :wscript_enable & goto :end
if /i "%~1"=="-e" call :wscript_enable & goto :end
if /i "%~1"=="--enable-wscript" call :wscript_enable & goto :end
rem Set default behaviour to edit
if /i "%~1"=="/em" call :set_edit & goto :end
if /i "%~1"=="-em" call :set_edit & goto :end
if /i "%~1"=="--edit-mode" call :set_edit & goto :end
rem Set default behaviour to open "execute"
if /i "%~1"=="/om" call :set_open & goto :end
if /i "%~1"=="-om" call :set_open & goto :end
if /i "%~1"=="--open-mode" call :set_open & goto :end
rem No backup params
if /i "%~1"=="/nb" set "NoBackup=yes" & shift & goto :parse
if /i "%~1"=="-nb" set "NoBackup=yes" & shift & goto :parse
if /i "%~1"=="--no-backup" set "NoBackup=yes" & shift & goto :parse
rem Disable icon swap
rem if /i "%~1"=="/is" set "NoIconSwap=yes" & shift & goto :parse
rem if /i "%~1"=="-is" set "NoIconSwap=yes" & shift & goto :parse
rem if /i "%~1"=="--icon-swap" set "NoIconSwap=yes" & shift & goto :parse
rem Backup params
if /i "%~1"=="/b" set "BackupDir=%~2" & shift & goto :parse
if /i "%~1"=="-b" set "BackupDir=%~2" & shift & goto :parse
if /i "%~1"=="--backup-dir" set "BackupDir=%~2" & shift & goto :parse
rem Icon params
if /i "%~1"=="/i" set "IconDir=%~2" & shift & goto :parse
if /i "%~1"=="-i" set "IconDir=%~2" & shift & goto :parse
if /i "%~1"=="--icon-dir" set "IconDir=%~2" & shift & goto :parse
rem Restore params
if /i "%~1"=="/r" (
if /i not "%~2"=="" (
set "RestoreDir=%~2" & goto :reg_restore
) else (
goto :reg_restore
)
)
if /i "%~1"=="-r" (
if /i not "%~2"=="" (
set "RestoreDir=%~2" & goto :reg_restore
) else (
goto :reg_restore
)
)
if /i "%~1"=="--restore-dir" (
if /i not "%~2"=="" (
set "RestoreDir=%~2" & goto :reg_restore
) else (
goto :reg_restore
)
)
shift
goto :parse
:main
call :header
if not defined NoBackup (
echo Current backup directory: "%BackupDir%"
if not exist "%BackupDir%" (
mkdir "%BackupDir%"
call :reg_backup & goto :end
)
) else (
echo Backup was not created
)
call :icon_swaper & goto :end
:wscript_disable
reg add "HKLM\SOFTWARE\Microsoft\Windows Script Host\Settings" /t REG_DWORD /v Enabled /d 0 /f > nul 2>&1
goto :eof
:wscript_enable
reg add "HKLM\SOFTWARE\Microsoft\Windows Script Host\Settings" /t REG_DWORD /v Enabled /d 1 /f > nul 2>&1
goto :eof
:set_open
reg add HKLM\SOFTWARE\Classes\JSEFile\Shell /t REG_SZ /d Open /f > nul 2>&1
reg add HKLM\SOFTWARE\Classes\JSFile\Shell /t REG_SZ /d Open /f > nul 2>&1
reg add HKLM\SOFTWARE\Classes\VBEFile\Shell /t REG_SZ /d Open /f > nul 2>&1
reg add HKLM\SOFTWARE\Classes\VBSFile\Shell /t REG_SZ /d Open /f > nul 2>&1
reg add HKLM\SOFTWARE\Classes\WSFile\Shell /t REG_SZ /d Open /f > nul 2>&1
reg add HKLM\SOFTWARE\Classes\WSHile\Shell /t REG_SZ /d Open /f > nul 2>&1
goto :eof
:set_edit
reg add HKLM\SOFTWARE\Classes\JSEFile\Shell /t REG_SZ /d Edit /f > nul 2>&1
reg add HKLM\SOFTWARE\Classes\JSFile\Shell /t REG_SZ /d Edit /f > nul 2>&1
reg add HKLM\SOFTWARE\Classes\VBEFile\Shell /t REG_SZ /d Edit /f > nul 2>&1
reg add HKLM\SOFTWARE\Classes\VBSFile\Shell /t REG_SZ /d Edit /f > nul 2>&1
reg add HKLM\SOFTWARE\Classes\WSFile\Shell /t REG_SZ /d Edit /f > nul 2>&1
reg add HKLM\SOFTWARE\Classes\WSHile\Shell /t REG_SZ /d Edit /f > nul 2>&1
goto :eof
:reg_restore
echo Backup directory used: "%RestoreDir%"
reg import "%RestoreDir%"\js_bkp.reg > nul 2>&1
reg import "%RestoreDir%"\jse_bkp.reg > nul 2>&1
reg import "%RestoreDir%"\vbe_bkp.reg > nul 2>&1
reg import "%RestoreDir%"\vbs_bkp.reg > nul 2>&1
reg import "%RestoreDir%"\wsf_bkp.reg > nul 2>&1
reg import "%RestoreDir%"\wsh_bkp.reg > nul 2>&1
call :new_icon
goto :end
:reg_backup
reg export HKLM\SOFTWARE\Classes\JSFile\DefaultIcon "%BackupDir%"\js_bkp.reg /y > nul 2>&1
reg export HKLM\SOFTWARE\Classes\JSEFile\DefaultIcon "%BackupDir%"\jse_bkp.reg /y > nul 2>&1
reg export HKLM\SOFTWARE\Classes\VBEFile\DefaultIcon "%BackupDir%"\vbe_bkp.reg /y > nul 2>&1
reg export HKLM\SOFTWARE\Classes\VBSFile\DefaultIcon "%BackupDir%"\vbs_bkp.reg /y > nul 2>&1
reg export HKLM\SOFTWARE\Classes\WSFFile\DefaultIcon "%BackupDir%"\wsf_bkp.reg /y > nul 2>&1
reg export HKLM\SOFTWARE\Classes\WSHFile\DefaultIcon "%BackupDir%"\wsh_bkp.reg /y > nul 2>&1
:icon_swaper
echo Replace current icons with icons on folder: "%IconDir%"
if exist "%IconDir%"\js.ico (
reg add HKLM\SOFTWARE\Classes\JSFile\DefaultIcon /t REG_SZ /d "%IconDir%"\js.ico,0 /f > nul 2>&1
echo [+] JS icon successfully changed
) else (
echo [-] js.ico not found
)
if exist "%IconDir%"\jse.ico (
reg add HKLM\SOFTWARE\Classes\JSEFile\DefaultIcon /t REG_SZ /d "%IconDir%"\jse.ico,0 /f > nul 2>&1
echo [+] JSE icon successfully changed
) else (
echo [-] jse.ico not found
)
if exist "%IconDir%"\vbe.ico (
reg add HKLM\SOFTWARE\Classes\VBEFile\DefaultIcon /t REG_SZ /d "%IconDir%"\vbe.ico,0 /f > nul 2>&1
echo [+] VBE icon successfully changed
) else (
echo [-] vbe.ico not found
)
if exist "%IconDir%"\vbs.ico (
reg add HKLM\SOFTWARE\Classes\VBSFile\DefaultIcon /t REG_SZ /d "%IconDir%"\vbs.ico,0 /f > nul 2>&1
echo [+] VBS icon successfully changed
) else (
echo [-] vbs.ico not found
)
if exist "%IconDir%"\wsf.ico (
reg add HKLM\SOFTWARE\Classes\WSFile\DefaultIcon /t REG_SZ /d "%IconDir%"\wsf.ico,0 /f > nul 2>&1
echo [+] WSF icon successfully changed
) else (
echo [-] wsf.ico not found
)
if exist "%IconDir%"\wsh.ico (
reg add HKLM\SOFTWARE\Classes\WSHile\DefaultIcon /t REG_SZ /d "%IconDir%"\wsh.ico,0 /f > nul 2>&1
echo [+] WSH icon successfully changed
) else (
echo [-] wsh.ico not found
)
call :new_icon
:end
call :cleanup
exit /B
:cleanup
REM The cleanup function is only really necessary if you
REM are _not_ using SETLOCAL.
set "__NAME="
set "__VERSION="
set "__YEAR="
set "__BAT_FILE="
set "__BAT_PATH="
set "__BAT_NAME="
set "BackupDir="
set "RestoreDir="
set "IconDir="
set "NoBackup="
goto :eof