forked from dreamd/CdiuBeatUpEditor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cdiu_12.bas
264 lines (202 loc) · 7.51 KB
/
cdiu_12.bas
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
Attribute VB_Name = "cdiu_12"
Option Explicit
Dim Fso As New FileSystemObject
Dim objCompress As New clsCryptoAPIandCompression
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)
Type Cdiu_Header
Sign As String * 22
NumberOfFile As Long
FooterPos As Long
FileName As String * 60
End Type
Type FileBlog
FileName As String * 512
OSize As Long
DataSize As Long
DataAddr As Long
End Type
Public Function FindFile(Data() As String, TFolder As Object, Path As String)
Dim Folder As Object
Dim file As Object
For Each Folder In TFolder.SubFolders
FindFile Data, Folder, Path + Folder.Name + "\"
Next
For Each file In TFolder.Files
Data(UBound(Data)) = Path + file.Name
ReDim Preserve Data(UBound(Data) + 1)
Next
End Function
Public Function Enrypt_12(Path As String, NewFile As String, SaveCdiuPath As String)
Dim TTime As Long, LoadFileTime As Long, SaveTime As Long, GetFileTime As Long, SaveFileTime As Long
Dim ZlibTime As Long, XorTime As Long, StrToHexTime As Long, StrToHexTimeB As Long
Dim HeaderA As Cdiu_Header, FooterB() As FileBlog
Dim FileByteOfName() As String, RData() As Byte, FileHex() As String
Dim PathA As String, SaveFileName As String
Dim i As Long, FileNumber As Integer
Dim Folder As Object
PathA = Mid(Path, 1, InStrRev(Path, "\"))
Set Folder = Fso.GetFolder(Path)
ReDim FileByteOfName(0)
FindFile FileByteOfName, Folder, ""
Set Folder = Nothing
FileNumber = UBound(FileByteOfName)
ReDim Preserve FileByteOfName(UBound(FileByteOfName) - 1)
ReDim FooterB(FileNumber - 1)
ReDim FileHex(FileNumber - 1)
SaveFileName = NewFile + ".cdiu"
SaveFileName = Replace(SaveFileName, ".cdiu.cdiu", ".cdiu")
HeaderA.Sign = "Cdiu_Encrypt_File_1.2"
HeaderA.NumberOfFile = FileNumber
HeaderA.FileName = StrToHex(Dir(Path, vbDirectory), StrToHexTimeB)
DeleteFile PathA + SaveFileName
Open SaveCdiuPath + SaveFileName For Binary Access Write As #3
Put #3, 1, HeaderA
For i = 0 To FileNumber - 1
FileHex(i) = StrToHex(FileByteOfName(i), StrToHexTime)
FooterB(i).FileName = FileHex(i)
Open Path + "\" + FileByteOfName(i) For Binary As #1
If LOF(1) = 0 Then
ReDim RData(0)
Else
ReDim RData(LOF(1) - 1)
End If
FooterB(i).OSize = UBound(RData) + 1
Get #1, 1, RData
Close #1
LoadFileTime = timeGetTime() - LoadFileTime
ZlibTime = timeGetTime()
objCompress.CompressByteArray RData, 9
ZlibTime = timeGetTime() - ZlibTime
XorTime = timeGetTime()
objCompress.EncryptDecryptB VarPtr(RData(0)), UBound(RData) + 1, "it_is_done_by_cdiu_hahaha", True
XorTime = timeGetTime() - XorTime
FooterB(i).DataSize = UBound(RData) + 1
FooterB(i).DataAddr = Loc(3)
SaveTime = timeGetTime()
Put #3, , RData
SaveTime = timeGetTime() - SaveTime
Next
ReDim RData(0)
HeaderA.FooterPos = Loc(3)
Put #3, , FooterB
Put #3, 1, HeaderA
Close #3
End Function
Public Function Enrypt_12File(Path As String)
Dim TTime As Long, LoadFileTime As Long, SaveTime As Long, GetFileTime As Long, SaveFileTime As Long
Dim ZlibTime As Long, XorTime As Long, StrToHexTime As Long, StrToHexTimeB As Long
Dim HeaderA As Cdiu_Header, FooterB As FileBlog
Dim FileByteOfName As String, RData() As Byte, FileHex As String
Dim PathA As String, SaveFileName As String
Dim i As Long, FileNumber As Integer
Dim Folder As Object
TTime = timeGetTime()
GetFileTime = timeGetTime()
PathA = Mid(Path, 1, InStrRev(Path, "\"))
FileNumber = 1
GetFileTime = timeGetTime() - GetFileTime
SaveFileTime = timeGetTime()
HeaderA.Sign = "Cdiu_Encrypt_File_1.2"
HeaderA.NumberOfFile = FileNumber
HeaderA.FileName = StrToHex(SaveFileName, StrToHexTimeB)
DeleteFile PathA + SaveFileName
Open PathA + SaveFileName For Binary Access Write As #3
Put #3, 1, HeaderA
FileHex = StrToHex(FileByteOfName, StrToHexTime)
FooterB.FileName = FileHex
LoadFileTime = timeGetTime()
Open Path For Binary As #1
If LOF(1) = 0 Then
ReDim RData(0)
Else
ReDim RData(LOF(1) - 1)
End If
FooterB.OSize = UBound(RData) + 1
Get #1, 1, RData
Close #1
LoadFileTime = timeGetTime() - LoadFileTime
ZlibTime = timeGetTime()
objCompress.CompressByteArray RData, 9
ZlibTime = timeGetTime() - ZlibTime
XorTime = timeGetTime()
objCompress.EncryptDecryptB VarPtr(RData(0)), UBound(RData) + 1, "it_is_done_by_cdiu_hahaha", True
XorTime = timeGetTime() - XorTime
FooterB.DataSize = UBound(RData) + 1
FooterB.DataAddr = Loc(3)
SaveTime = timeGetTime()
Put #3, , RData
SaveTime = timeGetTime() - SaveTime
ReDim RData(0)
HeaderA.FooterPos = Loc(3)
Put #3, , FooterB
Put #3, 1, HeaderA
Close #3
SaveFileTime = timeGetTime() - SaveFileTime
TTime = timeGetTime() - TTime
End Function
Public Function Decrypt_12(DcodeFileName As String, TTime As Long, Optional SavePath As String, Optional SaveInTmp As Boolean)
Dim StrToHexTime As Long, XorTime As Long, StrToHexTimeB As Long, ZlibTime As Long, StrToHexTimeC As Long
Dim LoadFileTime As Long, SaveFileTime As Long, SaveTime As Long
Dim HeaderA As Cdiu_Header, FooterB() As FileBlog
Dim SaveFileName As String, NewFolder As String
Dim FileByteOfName() As String, RData() As Byte
Dim i As Long
Open DcodeFileName For Binary Access Read As #3
Get #3, 1, HeaderA
ReDim FooterB(HeaderA.NumberOfFile - 1)
Get #3, HeaderA.FooterPos + 1, FooterB
i = InStrRev(DcodeFileName, "\")
If i > 0 Then
SaveFileName = Mid(DcodeFileName, i + 1)
Else
SaveFileName = DcodeFileName
End If
If HeaderA.NumberOfFile = 1 Then
NewFolder = Mid(DcodeFileName, 1, InStrRev(DcodeFileName, "\"))
Else
NewFolder = Mid(DcodeFileName, 1, InStrRev(DcodeFileName, "\")) + StrConv(StrToBin(Trim(HeaderA.FileName), StrToHexTime), vbUnicode) + "\"
If Not (Fso.FolderExists(NewFolder)) And SaveInTmp = False Then Fso.CreateFolder NewFolder
End If
ReDim FileByteOfName(HeaderA.NumberOfFile - 1)
For i = 0 To HeaderA.NumberOfFile - 1
FileByteOfName(i) = StrConv(StrToBin(Trim(FooterB(i).FileName), StrToHexTime), vbUnicode)
ReDim RData(FooterB(i).DataSize - 1)
Get #3, FooterB(i).DataAddr + 1, RData
XorTime = timeGetTime()
objCompress.EncryptDecryptB VarPtr(RData(0)), UBound(RData) + 1, "it_is_done_by_cdiu_hahaha", False
XorTime = timeGetTime() - XorTime
ZlibTime = timeGetTime()
objCompress.DecompressByteArray RData, FooterB(i).OSize
ZlibTime = timeGetTime() - ZlibTime
SaveTime = timeGetTime()
DeleteFile NewFolder + FileByteOfName(i)
If SaveInTmp = False Then
GenFolder NewFolder + FileByteOfName(i)
If SavePath = "" Then cma5.CreateDir NewFolder + "cma\"
If SavePath = "" Then SavePath = NewFolder + "cma"
Open SavePath + "\" + FileByteOfName(i) For Binary As #2
Put #2, 1, RData
Close #2
cma4.CheckFileIn FileByteOfName(i), RData
Else
If Fso.FileExists(SavePath + "\" + FileByteOfName(i)) Then
Open SavePath + "\" + FileByteOfName(i) For Binary As #4
ReDim RData(FileLen(SavePath + "\" + FileByteOfName(i)) - 1)
Get #4, , RData
Close #4
End If
cma4.CheckFileIn FileByteOfName(i), RData
End If
Next i
Close #3
End Function
Public Function GenFolder(file As String)
Dim Pos As Long
Pos = 0
Do
Pos = InStr(Pos + 1, file, "\")
If Pos > 0 Then
If Not (Fso.FolderExists(Mid(file, 1, Pos - 1))) Then Fso.CreateFolder Mid(file, 1, Pos - 1)
End If
Loop While Pos > 0
End Function