-
-
Notifications
You must be signed in to change notification settings - Fork 191
/
zip.asm
202 lines (153 loc) · 8.76 KB
/
zip.asm
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
; a nasm source to defines a dual ZIP for MD5 collisions
; build with `nasm -o zip.zip zip.asm`
; Ange Albertini 2018
BITS 32
%include "zip.inc"
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Replace File 1 and 2 values.
; reminder: incbin "<file>", <start>, <size>
; File 1
%macro file1.name 0
db 'hello.txt'
%endmacro
%macro file1.content 0
%%start:
db 'Hello World!', 0ah
file1.compsize equ $ - %%start
%endmacro
file1.compression equ COMP_STORED
file1.decsize equ file1.compsize
file1.CRC32 equ 0x7d14dddd
; File 2
%macro file2.name 0
db 'bye.txt'
%endmacro
%macro file2.content 0
%%start:
db 'Bye World!', 0ah
file2.compsize equ $ - %%start
%endmacro
file2.compression equ COMP_STORED
file2.decsize equ file2.compsize
file2.CRC32 equ 0xcedb178e
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
file2:
istruc filerecord
at filerecord.frSignature, db "PK", 3, 4
at filerecord.frVersion, dw 0ah
at filerecord.frCompression, dw file2.compression
at filerecord.frCrc, dd file2.CRC32
at filerecord.frCompressedSize, dd file2.compsize
at filerecord.frUncompressedSize, dd file2.decsize
at filerecord.frFileNameLength, dw lfhname2.len
at filerecord.frExtraFieldLength, dw extra2.len
iend
lfhname2:
file2.name
lfhname2.len equ $ - lfhname2
extra2:
field2:
.id dw 0
.len dw extra2.len - 4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
file1:
istruc filerecord
at filerecord.frSignature, db "PK", 3, 4
at filerecord.frVersion, dw 0ah
at filerecord.frCompression, dw file1.compression
at filerecord.frCrc, dd file1.CRC32
at filerecord.frCompressedSize, dd file1.compsize
at filerecord.frUncompressedSize, dd file1.decsize
at filerecord.frFileNameLength, dw lfhname1.len
at filerecord.frExtraFieldLength, dw extra1.len
iend
lfhname1:
file1.name
lfhname1.len equ $ - lfhname1
extra1:
field1:
.id dw 0
.len dw extra1.len - 4
extra2.len equ $ - extra2
data2:
file2.content
data2.len equ $ - data2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CD2:
istruc direntry
at direntry.deSignature, db "PK", 1, 2
at direntry.deVersionToExtract, dw 0ah
at direntry.deCrc, dd file2.CRC32
at direntry.deCompressedSize, dd data2.len
at direntry.deUncompressedSize, dd data2.len
at direntry.deFileNameLength, dw cdname2.len
at direntry.deFileCommentLength,dw cdcom2.len
at direntry.deHeaderOffset, dd file2
iend
cdname2:
file2.name
.len equ $ - cdname2
cdcom2:
db 0 ; truncating
extra1.len equ $ - extra1
data1:
file1.content
data1.len equ $ - data1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CD1:
istruc direntry
at direntry.deSignature, db "PK", 1, 2
at direntry.deVersionToExtract, dw 0ah
at direntry.deCrc, dd file1.CRC32
at direntry.deCompressedSize, dd data1.len
at direntry.deUncompressedSize, dd data1.len
at direntry.deFileNameLength, dw cdname1.len
at direntry.deFileCommentLength,dw cdcom1.len
at direntry.deHeaderOffset, dd file1
iend
cdname1:
file1.name
cdname1.len equ $ - cdname1
cdcom1:
db 0 ; truncating
align 40h, db 0 ; to align EoCD1 for first collision
cdcom1.len equ $ - cdcom1
CD1.len equ $ - CD1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EoCD1:
istruc endlocator
at endlocator.elSignature, db "PK", 5, 0x06
at endlocator.elEntriesOnDisk, db 1
at endlocator.elEntriesInDirectory, db 1
at endlocator.elDirectorySize, dd CD1.len
at endlocator.elDirectoryOffset, dd CD1
at endlocator.elCommentLength, dw EoCD1com.len
iend
EoCD1com:
db 0 ; truncating
align 4, db 'M' ; UniColl prefix
align 40h, db 0 ; end of first collision block
; second collision block
db 0
align 40h, db 0
cdcom2.len equ $ - cdcom2
CD2.len equ $ - CD2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
EoCD2:
istruc endlocator
at endlocator.elSignature, db "PK", 5, 0x86 ; 0x06/0x86 because of UniColl
at endlocator.elEntriesOnDisk, db 1
at endlocator.elEntriesInDirectory, db 1
at endlocator.elDirectorySize, dd CD2.len
at endlocator.elDirectoryOffset, dd CD2
at endlocator.elCommentLength, dw EoCD2com.len
iend
EoCD2com:
db 0 ; truncating
align 4, db 'M' ; Unicoll prefix
align 40h, db 0 ; end of first collision block
; second collision block
db 0
align 40h, db 0
EoCD2com.len equ $ - EoCD2com
EoCD1com.len equ $ - EoCD1com