-
Notifications
You must be signed in to change notification settings - Fork 0
/
eval.hta
272 lines (227 loc) · 7.12 KB
/
eval.hta
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
<head>
<title>VBScript/JScript Command-Line</title>
<hta:application>
</head>
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' File: eval.hta
'' Created: 7/17/2006
'' Author: mikeb
''
'' Modification history:
'' Date Author Desc
'' ---- ------ ----
'' 10/13/16 It's me again Wow, it's been a while. I missed your tenth
'' birthday too, huh? Well anyway, good thing I put
'' this modification history here, otherwise I
'' wouldn't know how long it's been since I had to
'' work with VBScript. Oh. Wait a minute. Yeah, that's
'' why I'm back. I suspect I'm going to need you for
'' JScript too now. So, I'm just going to go ahead and
'' add that in.
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
<body text="#ffffff" bgcolor="#000000" style="* {font-family: monospace;
font-size: 12px;}">
<div id="spnResults"></div>
<div> <span id="spnEngine">vbscript</span>:\><input type="text"
name="txtInput" onKeyUp="eval_hist_flt()" style="font-family: monospace;
font-size: 12px; width: 90%; color: #ffffff; background-color: #000000;
border: 0px;"/><button type="submit" name="btnExec"
onclick="eval_btnExec()" style="color: #000000; background-color: #000000;
border: 0px;"><u>E</u>val</button> </div>
</body>
<script Language="JScript">
function JsExecute(cmd) {
eval(cmd);
}
</script>
<script Language="VBScript">
Option Explicit
' For command history
Dim G_oHistory
Dim G_nHistoryIndex
Dim G_sAbandonedInput
Dim G_sComment_tok
' For errors
Dim oVoice
Dim oStream
' For use within the CUI environment
Dim fso
Dim wmi
Dim shell
Dim net
Dim dict
Set wmi = GetObject("winmgmts:")
Set fso = CreateObject("Scripting.FileSystemObject")
Set shell = CreateObject("WScript.Shell")
Set net = CreateObject("WScript.Network")
Set dict = CreateObject("Scripting.Dictionary")
G_sComment_tok = "'"
Function Window_OnLoad()
G_nHistoryIndex = 0
Set G_oHistory = CreateObject("Scripting.Dictionary")
Set oVoice = CreateObject("SAPI.SpVoice")
Set oStream = CreateObject("SAPI.SpFileStream.1")
Call oStream.Open("C:\windows\media\ding.wav")
StartLanguage("vbscript")
Call txtInput.Focus()
End Function
Function eval_HtmlEscape(ByVal str)
' Ampersands must be replaced first, before further SGML special
' entities (each having ampersands) are inserted into the string.
str = Replace(str, "&", "&")
str = Replace(str, "<", "<")
str = Replace(str, ">", ">")
' Any new HTML tags must be inserted last, after less-than and
' greater-than signs have been escaped.
str = Replace(str, vbNewLine, "<br/>")
eval_HtmlEscape = str
End Function
Function WriteLine_bare(ByRef str)
spnResults.InnerHTML = spnResults.InnerHTML & str & "<br/>"
End Function
Function WriteHtmlEscaped(ByRef str)
Call WriteLine_bare(eval_HtmlEscape(str))
End Function
Function Echo(ByRef str)
spnResults.InnerHTML = spnResults.InnerHTML & _
"<div style=""color: green;"">" & G_sComment_tok & " " & str & _
"</div>"
End Function
Function Clip(ByRef str)
Call Echo("Copying to clipboard: " & str)
Call window.clipboardData.setData("text", str)
End Function
Function StartLanguage(ByRef lang)
WriteHtmlEscaped("<script language='" & lang & "'>")
End Function
Function SwitchLang(ByRef newlang)
' The script tag below is seen as an un-terminated string constant if
' it is not broken up, ostensibly because the IE HTML parser doesn't
' parse script so as to realize that the tag is occurring within a
' string. Hence the seemingly superfluous string concatenations below.
If newlang = "vbscript" and spnEngine.InnerHTML = "jscript" Then
G_sComment_tok = "'"
WriteHtmlEscaped("</script" & ">")
StartLanguage("vbscript")
spnEngine.InnerHTML = "vbscript"
ElseIf newlang = "jscript" and spnEngine.InnerHTML = "vbscript" Then
G_sComment_tok = "//"
WriteHtmlEscaped("</script" & ">")
StartLanguage("jscript")
spnEngine.InnerHTML = "jscript"
End If
End Function
Function Js()
SwitchLang("jscript")
End Function
Function Vbs()
SwitchLang("vbscript")
End Function
Function Cls()
spnResults.InnerHTML = ""
End Function
Function Help()
WriteHtmlEscaped(G_sComment_tok & " Functions:")
WriteHtmlEscaped(G_sComment_tok & " Clip() - Copy to clipboard")
WriteHtmlEscaped(G_sComment_tok & " Echo() - Print to console")
WriteHtmlEscaped(G_sComment_tok & " Cls() - Clear screen")
WriteHtmlEscaped(G_sComment_tok & " Commands:")
WriteHtmlEscaped(G_sComment_tok & " jscript - Switch to JScript")
WriteHtmlEscaped(G_sComment_tok & " vbscript - Switch to VBScript")
WriteHtmlEscaped(G_sComment_tok & " exit/quit/bye Terminate")
End Function
Function eval_btnExec()
Dim cmd
Dim utcmd
Dim origcmd
origcmd = txtInput.Value
cmd = origcmd
' The prompt is omitted when reproducing the command so that you
' can just copy and paste everything into a script without removing
' extraneous prompts.
If (cmd <> vbNullString) Then
Call G_oHistory.Add(G_oHistory.Count, cmd)
G_nHistoryIndex = G_oHistory.Count
End If
G_sAbandonedInput = vbNullString
utcmd = UCase(Trim(cmd))
If utcmd = "HELP" Then
cmd = "Call Help()"
origcmd = "' " + origcmd
ElseIf utcmd = "CLS" Then
cmd = "Call Cls()"
origcmd = "' " + origcmd
ElseIf utcmd = "EXIT" Then
Call window.Close()
ElseIf utcmd = "QUIT" Then
Call window.Close()
ElseIf utcmd = "BYE" Then
Call window.Close()
ElseIf utcmd = "JSCRIPT" Then
Call Js()
cmd = ""
utcmd = ""
origcmd = "' " + origcmd
ElseIf utcmd = "VBSCRIPT" Then
Call Vbs()
cmd = ""
utcmd = ""
origcmd = "' " + origcmd
End If
If cmd <> vbNullString Then
Call WriteHtmlEscaped(origcmd)
End If
Call txtInput.Focus()
On Error Resume Next
If cmd <> vbNullString Then
If spnEngine.InnerHTML = "vbscript" Then
Execute(cmd)
Else
JsExecute(cmd)
End If
End If
If Err Then
spnResults.InnerHTML = spnResults.InnerHTML & _
"<div style=""font-weight: bold; color: red;"">" & _
G_sComment_tok & " >>> Error # " & Err.Number & _
": " & Err.Description & "</div>"
' Call eval_Ding()
Call Err.Clear()
End If
On Error Goto 0
txtInput.Value = ""
' Call txtInput.Select()
End Function
Function eval_hist_flt()
' Up
If window.event.keyCode = 38 Then
If G_nHistoryIndex > 0 Then
If (G_nHistoryIndex = G_oHistory.Count) Then
G_sAbandonedInput = txtInput.Value
End If
G_nHistoryIndex = G_nHistoryIndex - 1
txtInput.Value = G_oHistory.Item(G_nHistoryIndex)
Else
Call eval_Ding()
End If
End If
' Down
If window.event.keyCode = 40 Then
If G_nHistoryIndex < G_oHistory.Count Then
G_nHistoryIndex = G_nHistoryIndex + 1
txtInput.Value = G_oHistory.Item(G_nHistoryIndex)
Else
txtInput.Value = G_sAbandonedInput
Call eval_Ding()
End If
End If
End Function
Function eval_Ding()
Call window.setTimeout("eval_do_Ding()", 1)
End Function
Function eval_do_Ding()
Call oVoice.SpeakStream(oStream)
Set oStream = CreateObject("SAPI.SpFileStream.1")
Call oStream.Open("C:\windows\media\ding.wav")
End Function
</script>