-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdecryptzip.vbs
More file actions
executable file
·208 lines (187 loc) · 4.15 KB
/
decryptzip.vbs
File metadata and controls
executable file
·208 lines (187 loc) · 4.15 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
'
' Easy decrypt(de-scramble?) tool for .zip in current directory
'
Option Explicit
'
' Global Variable
'
Dim objFso
Dim objFolder
Dim objFiles
Dim objFile
Dim objRegex
Dim objIn
Dim objOut
Dim bytesRec
Dim strPassword
Dim aAsciiPw()
Dim intAsciiPwTotal
Dim intPosition
Dim intFirstBlockSize
Dim i
'
' get Objects for FileSystem
'
Set objFSo = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFso.GetFolder(".")
Set objFiles = objFolder.Files
'
' get Objects for Regex(foo.enc|foo.ENC)
'
Set objRegex = CreateObject("VBScript.RegExp")
objRegex.IgnoreCase = True
objRegex.Pattern = ".enc$"
'
' get Password
'
If LCase(Right(WScript.FullName, 11)) = "wscript.exe" Then
strPassword = InputBox("Password?:")
Else
wscript.stdout.write("Password?:")
strPassword = wscript.stdin.ReadLine
End If
'
' Caluculate total of ascii code of Password
'
intAsciiPwTotal = 0
For i = 1 to Len(strPassword)
Redim preserve aAsciiPw(i - 1)
aAsciiPw(i - 1) = Asc(Mid(strPassword, i, 1))
intAsciiPwTotal = intAsciiPwTotal + aAsciiPw(i - 1)
Next
'
' Main loop for FileObjects in Current Directory
'
For Each objFile in objFiles
'
' Filename is "foo.enc|foo.ENC"
'
If objRegex.Test(objFile.Name) Then
'
' Open Input in Text mode for checking Password
'
Set objIn = CreateObject("ADODB.Stream")
objIn.Charset = "ascii"
objIn.Open
objIn.Type = 2 ' StreamTypeEnum ‚Ì adTypeText
objIn.LoadFromFile objFile.Name
'
' Caluculate First Block
'
i = 0
intPosition = (ObjIn.Size Mod intAsciiPwTotal) - aAsciiPw(i)
While intPosition > 0
i = i + 1
If i > Ubound(aAsciiPw) Then
i = 0
End If
intPosition = intPosition - aAsciiPw(i)
Wend
intFirstBlockSize = aAsciiPw(i) + intPosition
'
' get First Block
'
If intFirstBlockSize > 0 Then
intPosition = objIn.Size - intFirstBlockSize
objIn.Position = intPosition
bytesRec = objIn.ReadText(intFirstBlockSize)
i = i - 1
If i < 0 Then
i = Ubound(aAsciiPw)
End If
intPosition = intPosition - aAsciiPw(i)
Else
bytesRec = ""
i = 0
intPosition = objIn.Size - aAsciiPw(i)
End If
'
' get Second Block
'
objIn.Position = intPosition
bytesRec = bytesRec & objIn.ReadText(aAsciiPw(i))
objIn.close
'
' check Password
'
If Mid(bytesRec, 1, 2) <> "PK" Then
If LCase(Right(WScript.FullName, 11)) = "wscript.exe" Then
MsgBox("Wrong Password!")
Else
wscript.stdout.writeLine "Wrong Password!"
End If
WScript.Quit(1)
End If
'
' open Input as Binary mode
'
Set objIn = CreateObject("ADODB.Stream")
objIn.Open
objIn.Type = 1 ' StreamTypeEnum ‚Ì adTypeBinary
objIn.LoadFromFile objFile.Name
'
' open Output as Binary mode
'
Set objOut = CreateObject("ADODB.Stream")
objOut.Open
objOut.Type = 1 ' StreamTypeEnum ‚Ì adTypeBinary
'
' Caluculate First Block
'
i = 0
intPosition = (ObjIn.Size Mod intAsciiPwTotal) - aAsciiPw(i)
While intPosition > 0
i = i + 1
If i > Ubound(aAsciiPw) Then
i = 0
End If
intPosition = intPosition - aAsciiPw(i)
Wend
intFirstBlockSize = aAsciiPw(i) + intPosition
'
' get First Block
'
If intFirstBlockSize > 0 Then
intPosition = objIn.Size - intFirstBlockSize
objIn.Position = intPosition
bytesRec = objIn.Read(intFirstBlockSize)
objOut.Write bytesRec
i = i - 1
If i < 0 Then
i = Ubound(aAsciiPw)
End If
intPosition = intPosition - aAsciiPw(i)
Else
i = 0
intPosition = objIn.Size - aAsciiPw(i)
End If
'
' get Intermediate Blocks
'
While intPosition > 0
objIn.Position = intPosition
bytesRec = objIn.Read(aAsciiPw(i))
objOut.Write bytesRec
i = i - 1
If i < 0 Then
i = Ubound(aAsciiPw)
End If
intPosition = intPosition - aAsciiPw(i)
Wend
'
' get Last Block
'
objIn.Position = 0
bytesRec = objIn.Read(aAsciiPw(i) + intPosition)
objOut.Write bytesRec
'
' save Output File
'
objOut.SaveToFile objRegex.Replace(objFile.Name, ""), 2
'
' close Files
'
objIn.close
objOut.close
End If
Next