Skip to content

Instantly share code, notes, and snippets.

@gynvael
Created August 10, 2018 12:16
Show Gist options
  • Save gynvael/e729ec2ebc134147dd24f5005e6d13cc to your computer and use it in GitHub Desktop.
Save gynvael/e729ec2ebc134147dd24f5005e6d13cc to your computer and use it in GitHub Desktop.
Additional "ZIP source" files (build with nasm)
; So... what would happen if the compressed size mismatches
; uncompressed size in a *compressed* file? Let's find out!
; Note, there are three variants here:
; A - only Local File Header has mismatched sizes.
; B - only Central Directory has mismatched sizes.
; C - both have mismatched sizes.
;
; This is variant: A
;
; by gynvael.coldwind//vx
[bits 32]
; Let's make a ZIP! :)
; Note: how to calculate crc-32? easy! just try to unpack the file
; with commandline unzip, it shows the good crc ;p
; File #1 Local File Hedaer
file_1:
dd 0x04034b50 ; local file header signature 4 bytes (0x04034b50)
dw 0x0014 ; version needed to extract 2 bytes (1.0)
dw 2 ; general purpose bit flag 2 bytes
dw 8 ; compression method 2 bytes (0 - store)
dw 0 ; last mod file time 2 bytes
dw 0 ; last mod file date 2 bytes
dd 0x9ea71e4b ; crc-32 4 bytes
dd .data_e - .data_s ; compressed size 4 bytes
dd 0x01000000 ; uncompressed size 4 bytes
dw .name_e - .name_s ; file name length 2 bytes
dw 0 ; extra field length 2 bytes
; name
.name_s:
db "file2.txt"
.name_e:
; extra header would be here
; file data (this is stored, so plaintext)
.data_s:
db 0xF3,0x2A,0x2D,0x2E,0x51,0x48,0xCD,0x2B,0x49,0x2D,0x52,0x48,0xCC,0xAB
db 0x54,0x48,0x49,0x2C,0x49,0x54,0xC8,0x48,0x2D,0x4A,0xD5,0xE3,0xE5,0x02
db 0x00
.data_e:
; -------------------------------------------------------------------
central_directory:
.s:
; Central directory entries
dd 0x02014b50 ; central file header signature 4 bytes (0x02014b50)
dw 0x031e ; version made by 2 bytes
dw 0x000a ; version needed to extract 2 bytes
dw 2 ; general purpose bit flag 2 bytes
dw 8 ; compression method 2 bytes
dw 0 ; last mod file time 2 bytes
dw 0 ; last mod file date 2 bytes
dd 0x9ea71e4b ; crc-32 4 bytes
dd file_1.data_e - file_1.data_s ; compressed size 4 bytes
dd 0x1b ; uncompressed size 4 bytes (XXX: quite big)
dw file_1.name_e - file_1.name_s ; file name length 2 bytes
dw 0 ; extra field length 2 bytes
dw 0 ; file comment length 2 bytes
dw 0 ; disk number start 2 bytes
dw 0 ; internal file attributes 2 bytes
dd 0 ; external file attributes 4 bytes
dd file_1 ; relative offset of local header 4 bytes
; name
db "file2.txt"
; extra header would be here
; comment would be here
.e:
; -------------------------------------------------------------------
; End of central directory record:
dd 0x06054b50 ; end of central dir signature 4 bytes (0x06054b50)
dw 0 ; number of this disk 2 bytes
dw 0 ; number of the disk with the
; start of the central directory 2 bytes
dw 1 ; total number of entries in the
; central directory on this disk 2 bytes
dw 1 ; total number of entries in
; the central directory 2 bytes
dd central_directory.e - central_directory.s
; size of the central directory 4 bytes
dd central_directory ; offset of start of central
; directory with respect to
; the starting disk number 4 bytes
dw 0 ; .ZIP file comment length 2 bytes
; .ZIP file comment (variable size)
; -------------------------------------------------------------------
; End of file.
end_of_file:
; vim: syntax=nasm
; So... what would happen if the compressed size mismatches
; uncompressed size in a *compressed* file? Let's find out!
; Note, there are three variants here:
; A - only Local File Header has mismatched sizes.
; B - only Central Directory has mismatched sizes.
; C - both have mismatched sizes.
;
; This is variant: B
;
; by gynvael.coldwind//vx
[bits 32]
; Let's make a ZIP! :)
; Note: how to calculate crc-32? easy! just try to unpack the file
; with commandline unzip, it shows the good crc ;p
; File #1 Local File Hedaer
file_1:
dd 0x04034b50 ; local file header signature 4 bytes (0x04034b50)
dw 0x0014 ; version needed to extract 2 bytes (1.0)
dw 2 ; general purpose bit flag 2 bytes
dw 8 ; compression method 2 bytes (0 - store)
dw 0 ; last mod file time 2 bytes
dw 0 ; last mod file date 2 bytes
dd 0x9ea71e4b ; crc-32 4 bytes
dd .data_e - .data_s ; compressed size 4 bytes
dd 0x1b ; uncompressed size 4 bytes
dw .name_e - .name_s ; file name length 2 bytes
dw 0 ; extra field length 2 bytes
; name
.name_s:
db "file2.txt"
.name_e:
; extra header would be here
; file data (this is stored, so plaintext)
.data_s:
db 0xF3,0x2A,0x2D,0x2E,0x51,0x48,0xCD,0x2B,0x49,0x2D,0x52,0x48,0xCC,0xAB
db 0x54,0x48,0x49,0x2C,0x49,0x54,0xC8,0x48,0x2D,0x4A,0xD5,0xE3,0xE5,0x02
db 0x00
.data_e:
; -------------------------------------------------------------------
central_directory:
.s:
; Central directory entries
dd 0x02014b50 ; central file header signature 4 bytes (0x02014b50)
dw 0x031e ; version made by 2 bytes
dw 0x000a ; version needed to extract 2 bytes
dw 2 ; general purpose bit flag 2 bytes
dw 8 ; compression method 2 bytes
dw 0 ; last mod file time 2 bytes
dw 0 ; last mod file date 2 bytes
dd 0x9ea71e4b ; crc-32 4 bytes
dd file_1.data_e - file_1.data_s ; compressed size 4 bytes
dd 0x01000000 ; uncompressed size 4 bytes (XXX: quite big)
dw file_1.name_e - file_1.name_s ; file name length 2 bytes
dw 0 ; extra field length 2 bytes
dw 0 ; file comment length 2 bytes
dw 0 ; disk number start 2 bytes
dw 0 ; internal file attributes 2 bytes
dd 0 ; external file attributes 4 bytes
dd file_1 ; relative offset of local header 4 bytes
; name
db "file2.txt"
; extra header would be here
; comment would be here
.e:
; -------------------------------------------------------------------
; End of central directory record:
dd 0x06054b50 ; end of central dir signature 4 bytes (0x06054b50)
dw 0 ; number of this disk 2 bytes
dw 0 ; number of the disk with the
; start of the central directory 2 bytes
dw 1 ; total number of entries in the
; central directory on this disk 2 bytes
dw 1 ; total number of entries in
; the central directory 2 bytes
dd central_directory.e - central_directory.s
; size of the central directory 4 bytes
dd central_directory ; offset of start of central
; directory with respect to
; the starting disk number 4 bytes
dw 0 ; .ZIP file comment length 2 bytes
; .ZIP file comment (variable size)
; -------------------------------------------------------------------
; End of file.
end_of_file:
; vim: syntax=nasm
; So... what would happen if the compressed size mismatches
; uncompressed size in a *compressed* file? Let's find out!
; Note, there are three variants here:
; A - only Local File Header has mismatched sizes.
; B - only Central Directory has mismatched sizes.
; C - both have mismatched sizes.
;
; This is variant: C
;
; by gynvael.coldwind//vx
[bits 32]
; Let's make a ZIP! :)
; Note: how to calculate crc-32? easy! just try to unpack the file
; with commandline unzip, it shows the good crc ;p
; File #1 Local File Hedaer
file_1:
dd 0x04034b50 ; local file header signature 4 bytes (0x04034b50)
dw 0x0014 ; version needed to extract 2 bytes (1.0)
dw 2 ; general purpose bit flag 2 bytes
dw 8 ; compression method 2 bytes (0 - store)
dw 0 ; last mod file time 2 bytes
dw 0 ; last mod file date 2 bytes
dd 0x9ea71e4b ; crc-32 4 bytes
dd .data_e - .data_s ; compressed size 4 bytes
dd 0x01000000 ; uncompressed size 4 bytes
dw .name_e - .name_s ; file name length 2 bytes
dw 0 ; extra field length 2 bytes
; name
.name_s:
db "file2.txt"
.name_e:
; extra header would be here
; file data (this is stored, so plaintext)
.data_s:
db 0xF3,0x2A,0x2D,0x2E,0x51,0x48,0xCD,0x2B,0x49,0x2D,0x52,0x48,0xCC,0xAB
db 0x54,0x48,0x49,0x2C,0x49,0x54,0xC8,0x48,0x2D,0x4A,0xD5,0xE3,0xE5,0x02
db 0x00
.data_e:
; -------------------------------------------------------------------
central_directory:
.s:
; Central directory entries
dd 0x02014b50 ; central file header signature 4 bytes (0x02014b50)
dw 0x031e ; version made by 2 bytes
dw 0x000a ; version needed to extract 2 bytes
dw 2 ; general purpose bit flag 2 bytes
dw 8 ; compression method 2 bytes
dw 0 ; last mod file time 2 bytes
dw 0 ; last mod file date 2 bytes
dd 0x9ea71e4b ; crc-32 4 bytes
dd file_1.data_e - file_1.data_s ; compressed size 4 bytes
dd 0x01000000 ; uncompressed size 4 bytes (XXX: quite big)
dw file_1.name_e - file_1.name_s ; file name length 2 bytes
dw 0 ; extra field length 2 bytes
dw 0 ; file comment length 2 bytes
dw 0 ; disk number start 2 bytes
dw 0 ; internal file attributes 2 bytes
dd 0 ; external file attributes 4 bytes
dd file_1 ; relative offset of local header 4 bytes
; name
db "file2.txt"
; extra header would be here
; comment would be here
.e:
; -------------------------------------------------------------------
; End of central directory record:
dd 0x06054b50 ; end of central dir signature 4 bytes (0x06054b50)
dw 0 ; number of this disk 2 bytes
dw 0 ; number of the disk with the
; start of the central directory 2 bytes
dw 1 ; total number of entries in the
; central directory on this disk 2 bytes
dw 1 ; total number of entries in
; the central directory 2 bytes
dd central_directory.e - central_directory.s
; size of the central directory 4 bytes
dd central_directory ; offset of start of central
; directory with respect to
; the starting disk number 4 bytes
dw 0 ; .ZIP file comment length 2 bytes
; .ZIP file comment (variable size)
; -------------------------------------------------------------------
; End of file.
end_of_file:
; vim: syntax=nasm
; ZIP Template.
; by gynvael.coldwind//vx
[bits 32]
; Let's make a ZIP! :)
; Note: how to calculate crc-32? easy! just try to unpack the file
; with commandline unzip, it shows the good crc ;p
; or: you can use python zlib.crc32
; File #1 Local File Hedaer
file_1:
dd 0x04034b50 ; local file header signature 4 bytes (0x04034b50)
dw 0x000a ; version needed to extract 2 bytes (1.0)
dw 0 ; general purpose bit flag 2 bytes
dw 0 ; compression method 2 bytes (0 - store)
dw 0 ; last mod file time 2 bytes
dw 0 ; last mod file date 2 bytes
dd 0x9ea71e4b ; crc-32 4 bytes
dd .data_e - .data_s ; compressed size 4 bytes
dd .data_e - .data_s ; uncompressed size 4 bytes
dw .name_e - .name_s ; file name length 2 bytes
dw 0 ; extra field length 2 bytes
; name
.name_s:
db "file1.txt"
.name_e:
; extra header would be here
; file data (this is stored, so plaintext)
.data_s:
db "Just enter any data here.", 0x0d, 0x0a
.data_e:
; -------------------------------------------------------------------
central_directory:
.s:
; Central directory entries
dd 0x02014b50 ; central file header signature 4 bytes (0x02014b50)
dw 0x031e ; version made by 2 bytes
dw 0x000a ; version needed to extract 2 bytes
dw 0 ; general purpose bit flag 2 bytes
dw 0 ; compression method 2 bytes
dw 0 ; last mod file time 2 bytes
dw 0 ; last mod file date 2 bytes
dd 0x9ea71e4b ; crc-32 4 bytes
dd file_1.data_e - file_1.data_s ; compressed size 4 bytes
dd file_1.data_e - file_1.data_s ; uncompressed size 4 bytes
dw file_1.name_e - file_1.name_s ; file name length 2 bytes
dw 0 ; extra field length 2 bytes
dw 0 ; file comment length 2 bytes
dw 0 ; disk number start 2 bytes
dw 0 ; internal file attributes 2 bytes
dd 0 ; external file attributes 4 bytes
dd file_1 ; relative offset of local header 4 bytes
; name
db "file1.txt"
; extra header would be here
; comment would be here
.e:
; -------------------------------------------------------------------
; End of central directory record:
dd 0x06054b50 ; end of central dir signature 4 bytes (0x06054b50)
dw 0 ; number of this disk 2 bytes
dw 0 ; number of the disk with the
; start of the central directory 2 bytes
dw 1 ; total number of entries in the
; central directory on this disk 2 bytes
dw 1 ; total number of entries in
; the central directory 2 bytes
dd central_directory.e - central_directory.s
; size of the central directory 4 bytes
dd central_directory ; offset of start of central
; directory with respect to
; the starting disk number 4 bytes
dw 0 ; .ZIP file comment length 2 bytes
; .ZIP file comment (variable size)
; -------------------------------------------------------------------
; End of file.
end_of_file:
; vim: syntax=nasm
; So... what would happen if the compressed size mismatches
; uncompressed size in a stored file? Let's find out!
; Note, there are three variants here:
; A - only Local File Header has mismatched sizes.
; B - only Central Directory has mismatched sizes.
; C - both have mismatched sizes.
;
; This is variant: A
;
; by gynvael.coldwind//vx
[bits 32]
; Let's make a ZIP! :)
; Note: how to calculate crc-32? easy! just try to unpack the file
; with commandline unzip, it shows the good crc ;p
; File #1 Local File Hedaer
file_1:
dd 0x04034b50 ; local file header signature 4 bytes (0x04034b50)
dw 0x000a ; version needed to extract 2 bytes (1.0)
dw 0 ; general purpose bit flag 2 bytes
dw 0 ; compression method 2 bytes (0 - store)
dw 0 ; last mod file time 2 bytes
dw 0 ; last mod file date 2 bytes
dd 0x9ea71e4b ; crc-32 4 bytes
dd .data_e - .data_s ; compressed size 4 bytes
dd 0x10000000 ; uncompressed size 4 bytes (XXX: quite big)
dw .name_e - .name_s ; file name length 2 bytes
dw 0 ; extra field length 2 bytes
; name
.name_s:
db "file1.txt"
.name_e:
; extra header would be here
; file data (this is stored, so plaintext)
.data_s:
db "Just enter any data here.", 0x0d, 0x0a
.data_e:
; -------------------------------------------------------------------
central_directory:
.s:
; Central directory entries
dd 0x02014b50 ; central file header signature 4 bytes (0x02014b50)
dw 0x031e ; version made by 2 bytes
dw 0x000a ; version needed to extract 2 bytes
dw 0 ; general purpose bit flag 2 bytes
dw 0 ; compression method 2 bytes
dw 0 ; last mod file time 2 bytes
dw 0 ; last mod file date 2 bytes
dd 0x9ea71e4b ; crc-32 4 bytes
dd file_1.data_e - file_1.data_s ; compressed size 4 bytes
dd file_1.data_e - file_1.data_s ; uncompressed size 4 bytes
dw file_1.name_e - file_1.name_s ; file name length 2 bytes
dw 0 ; extra field length 2 bytes
dw 0 ; file comment length 2 bytes
dw 0 ; disk number start 2 bytes
dw 0 ; internal file attributes 2 bytes
dd 0 ; external file attributes 4 bytes
dd file_1 ; relative offset of local header 4 bytes
; name
db "file1.txt"
; extra header would be here
; comment would be here
.e:
; -------------------------------------------------------------------
; End of central directory record:
dd 0x06054b50 ; end of central dir signature 4 bytes (0x06054b50)
dw 0 ; number of this disk 2 bytes
dw 0 ; number of the disk with the
; start of the central directory 2 bytes
dw 1 ; total number of entries in the
; central directory on this disk 2 bytes
dw 1 ; total number of entries in
; the central directory 2 bytes
dd central_directory.e - central_directory.s
; size of the central directory 4 bytes
dd central_directory ; offset of start of central
; directory with respect to
; the starting disk number 4 bytes
dw 0 ; .ZIP file comment length 2 bytes
; .ZIP file comment (variable size)
; -------------------------------------------------------------------
; End of file.
end_of_file:
; vim: syntax=nasm
; So... what would happen if the compressed size mismatches
; uncompressed size in a stored file? Let's find out!
; Note, there are three variants here:
; A - only Local File Header has mismatched sizes.
; B - only Central Directory has mismatched sizes.
; C - both have mismatched sizes.
;
; This is variant: B
;
; by gynvael.coldwind//vx
[bits 32]
; Let's make a ZIP! :)
; Note: how to calculate crc-32? easy! just try to unpack the file
; with commandline unzip, it shows the good crc ;p
; File #1 Local File Hedaer
file_1:
dd 0x04034b50 ; local file header signature 4 bytes (0x04034b50)
dw 0x000a ; version needed to extract 2 bytes (1.0)
dw 0 ; general purpose bit flag 2 bytes
dw 0 ; compression method 2 bytes (0 - store)
dw 0 ; last mod file time 2 bytes
dw 0 ; last mod file date 2 bytes
dd 0x9ea71e4b ; crc-32 4 bytes
dd .data_e - .data_s ; compressed size 4 bytes
dd .data_e - .data_s ; uncompressed size 4 bytes
dw .name_e - .name_s ; file name length 2 bytes
dw 0 ; extra field length 2 bytes
; name
.name_s:
db "file1.txt"
.name_e:
; extra header would be here
; file data (this is stored, so plaintext)
.data_s:
db "Just enter any data here.", 0x0d, 0x0a
.data_e:
; -------------------------------------------------------------------
central_directory:
.s:
; Central directory entries
dd 0x02014b50 ; central file header signature 4 bytes (0x02014b50)
dw 0x031e ; version made by 2 bytes
dw 0x000a ; version needed to extract 2 bytes
dw 0 ; general purpose bit flag 2 bytes
dw 0 ; compression method 2 bytes
dw 0 ; last mod file time 2 bytes
dw 0 ; last mod file date 2 bytes
dd 0x9ea71e4b ; crc-32 4 bytes
dd file_1.data_e - file_1.data_s ; compressed size 4 bytes
dd 0x10000000 ; uncompressed size 4 bytes (XXX: quite big)
dw file_1.name_e - file_1.name_s ; file name length 2 bytes
dw 0 ; extra field length 2 bytes
dw 0 ; file comment length 2 bytes
dw 0 ; disk number start 2 bytes
dw 0 ; internal file attributes 2 bytes
dd 0 ; external file attributes 4 bytes
dd file_1 ; relative offset of local header 4 bytes
; name
db "file1.txt"
; extra header would be here
; comment would be here
.e:
; -------------------------------------------------------------------
; End of central directory record:
dd 0x06054b50 ; end of central dir signature 4 bytes (0x06054b50)
dw 0 ; number of this disk 2 bytes
dw 0 ; number of the disk with the
; start of the central directory 2 bytes
dw 1 ; total number of entries in the
; central directory on this disk 2 bytes
dw 1 ; total number of entries in
; the central directory 2 bytes
dd central_directory.e - central_directory.s
; size of the central directory 4 bytes
dd central_directory ; offset of start of central
; directory with respect to
; the starting disk number 4 bytes
dw 0 ; .ZIP file comment length 2 bytes
; .ZIP file comment (variable size)
; -------------------------------------------------------------------
; End of file.
end_of_file:
; vim: syntax=nasm
; So... what would happen if the compressed size mismatches
; uncompressed size in a stored file? Let's find out!
; Note, there are three variants here:
; A - only Local File Header has mismatched sizes.
; B - only Central Directory has mismatched sizes.
; C - both have mismatched sizes.
;
; This is variant: C
;
; by gynvael.coldwind//vx
[bits 32]
; Let's make a ZIP! :)
; Note: how to calculate crc-32? easy! just try to unpack the file
; with commandline unzip, it shows the good crc ;p
; File #1 Local File Hedaer
file_1:
dd 0x04034b50 ; local file header signature 4 bytes (0x04034b50)
dw 0x000a ; version needed to extract 2 bytes (1.0)
dw 0 ; general purpose bit flag 2 bytes
dw 0 ; compression method 2 bytes (0 - store)
dw 0 ; last mod file time 2 bytes
dw 0 ; last mod file date 2 bytes
dd 0x9ea71e4b ; crc-32 4 bytes
dd .data_e - .data_s ; compressed size 4 bytes
dd 0x10000000 ; uncompressed size 4 bytes (XXX: quite big)
dw .name_e - .name_s ; file name length 2 bytes
dw 0 ; extra field length 2 bytes
; name
.name_s:
db "file1.txt"
.name_e:
; extra header would be here
; file data (this is stored, so plaintext)
.data_s:
db "Just enter any data here.", 0x0d, 0x0a
.data_e:
; -------------------------------------------------------------------
central_directory:
.s:
; Central directory entries
dd 0x02014b50 ; central file header signature 4 bytes (0x02014b50)
dw 0x031e ; version made by 2 bytes
dw 0x000a ; version needed to extract 2 bytes
dw 0 ; general purpose bit flag 2 bytes
dw 0 ; compression method 2 bytes
dw 0 ; last mod file time 2 bytes
dw 0 ; last mod file date 2 bytes
dd 0x9ea71e4b ; crc-32 4 bytes
dd file_1.data_e - file_1.data_s ; compressed size 4 bytes
dd 0x10000000 ; uncompressed size 4 bytes (XXX: quite big)
dw file_1.name_e - file_1.name_s ; file name length 2 bytes
dw 0 ; extra field length 2 bytes
dw 0 ; file comment length 2 bytes
dw 0 ; disk number start 2 bytes
dw 0 ; internal file attributes 2 bytes
dd 0 ; external file attributes 4 bytes
dd file_1 ; relative offset of local header 4 bytes
; name
db "file1.txt"
; extra header would be here
; comment would be here
.e:
; -------------------------------------------------------------------
; End of central directory record:
dd 0x06054b50 ; end of central dir signature 4 bytes (0x06054b50)
dw 0 ; number of this disk 2 bytes
dw 0 ; number of the disk with the
; start of the central directory 2 bytes
dw 1 ; total number of entries in the
; central directory on this disk 2 bytes
dw 1 ; total number of entries in
; the central directory 2 bytes
dd central_directory.e - central_directory.s
; size of the central directory 4 bytes
dd central_directory ; offset of start of central
; directory with respect to
; the starting disk number 4 bytes
dw 0 ; .ZIP file comment length 2 bytes
; .ZIP file comment (variable size)
; -------------------------------------------------------------------
; End of file.
end_of_file:
; vim: syntax=nasm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment