include "win32ax.inc"
.code
start:
call Thomas1_ct
stdcall FileToZip,"Name.txt","FileInZip.txt","Nombre_zip.zip" ,"Comment "
invoke ExitProcess,0
struct ZIP_local_file_header
PK dd 0x04034b50 ;Local file header signature
Version_needed dw ? ;Version needed to extract
flag1 dw ? ;General purpose bit flag
Compression_method dw ? ;Compression method
time_modification dw ? ;File last modification time
date_modification dw ? ;File last modification date
CRC_32 dd ? ;CRC-32
Compressed_size dd ? ;Compressed size
Uncompressed_size dd ? ;Uncompressed size
name_size dw ? ;File name length
extra_field_size dw ? ;Extra field length
;Filename
;ExtraField
ends
struct ZIP_central_directory_file_header
PK dd 0x02014b50 ;Central directory file header signature
ver_made dw ? ;Version made by
Version_needed dw ? ;Version needed to extract
flag1 dw ? ;General purpose bit flag
Compression_method dw ? ;Compression method
time_modification dw ? ;File last modification time
date_modification dw ? ;File last modification date
CRC_32 dd ? ;CRC-32
Compressed_size dd ? ;Compressed size
Uncompressed_size dd ? ;Uncompressed size
name_size dw ? ;File name length
extra_field_size dw ? ;Extra field length
comment_lenght dw ? ;File comment length
disk_number dw ? ;Disk number where file starts
internal_attributes dw ? ;Internal file attributes
external_attributes dd ? ;External file attributes
offser_file dd ? ;Relative offset of local file header
;File name
;Extra field
;File comment
ends
struct ZIP_end_of_central_directory_record
PK dd 0x06054b50 ; End of central directory signature
Number_disk dw ? ; Number of this disk
Disk1 dw ? ; Disk where central directory starts
number_central_dir dw ? ; Number of central directory records on this disk
number_central_directory_records dw ? ; Total number of central directory records
size_central_directory dd ? ; Size of central directory (bytes)
offset dd ? ; Offset of start of central directory, relative to start of archive
comment_length dw ? ; ZIP file comment length (n)
;ZIP file comment
ends
proc FileToZip uses ebx edi ecx,PathFile,NameOfFile,PathOfZip,Comment
local File dd ?
local sizeofname dd ?
local SizeOfZip dd ?
local Zip dd ?
local _crc32 dd ?
local sizeofcomment dd ?
sizeoffile equ ebx
.if [Comment] = 0
mov [sizeofcomment],0
.else
invoke lstrlen,[Comment]
mov [sizeofcomment],eax
.endif
stdcall _ReadFile,[PathFile]
mov [File],eax
invoke lstrlen,[NameOfFile]
mov [sizeofname],eax
mov ecx,sizeoffile
add ecx,sizeof.ZIP_local_file_header
add ecx,eax
add ecx,sizeof.ZIP_central_directory_file_header
add ecx,eax
add ecx,sizeof.ZIP_end_of_central_directory_record
add ecx,[sizeofcomment]
mov [SizeOfZip],ecx
invoke GlobalAlloc,GPTR,ecx
mov [Zip],eax
mov dword[eax],0x04034b50
virtual at eax
zllh ZIP_local_file_header
end virtual
mov [zllh.Version_needed],0xA
push eax
stdcall crc,[File], sizeoffile
mov [_crc32],eax
mov ecx,eax
pop eax
mov [zllh.CRC_32], ecx
mov [zllh.Compressed_size], sizeoffile
mov [zllh.Uncompressed_size], sizeoffile
mov ecx,[sizeofname]
mov [zllh.name_size], cx
add eax,sizeof.ZIP_local_file_header
mov edi,eax
invoke RtlMoveMemory,edi,[NameOfFile] ,[sizeofname]
add edi,[sizeofname]
invoke RtlMoveMemory,edi,[File] , sizeoffile
add edi,sizeoffile
virtual at edi
ZCDFH ZIP_central_directory_file_header
end virtual
mov dword[edi],0x02014b50
mov [ZCDFH.ver_made],0xA
mov [ZCDFH.Version_needed],0xA
mov ecx,[_crc32]
mov [ZCDFH.CRC_32], ecx
mov [ZCDFH.Compressed_size], sizeoffile
mov [ZCDFH.Uncompressed_size], sizeoffile
mov ecx,[sizeofname]
mov [ZCDFH.name_size],cx
add edi,sizeof.ZIP_central_directory_file_header
invoke RtlMoveMemory,edi,[NameOfFile] ,[sizeofname]
add edi, [sizeofname]
mov dword[edi],0x06054b50
virtual at edi
ZECDR ZIP_end_of_central_directory_record
end virtual
mov [ZECDR.number_central_directory_records],1h
mov [ZECDR.number_central_dir],1h
mov [ZECDR.size_central_directory],38h
mov ecx,sizeof.ZIP_local_file_header
add ecx, [sizeofname]
add ecx,sizeoffile
mov [ZECDR.offset],ecx
mov eax,[sizeofcomment]
mov [ZECDR.comment_length] ,ax
add edi, sizeof.ZIP_end_of_central_directory_record
invoke RtlMoveMemory,edi,[Comment],[sizeofcomment]
stdcall Save,[PathOfZip],[Zip],[SizeOfZip]
ret
endp
proc Save,Ruta,Datos,Tamaño
local d dd ?
invoke CreateFile,[Ruta],GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0
push eax
invoke WriteFile,eax,[Datos],[Tamaño],addr d ,NULL
pop eax
invoke CloseHandle,eax
ret
endp
proc _ReadFile,Path
locals
b dd ?
hFile dd ?
sizefile dd ?
hMap dd ?
IB dd ?
endl
invoke CreateFile, [Path], GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0
mov [hFile], eax
invoke GetFileSize, [hFile], 0
mov [sizefile], eax
invoke GlobalAlloc, GPTR, eax
mov [IB], eax
invoke ReadFile, [hFile], [IB], [sizefile], addr b, 0
invoke CloseHandle, [hFile]
mov eax, [IB]
mov ebx,[sizefile]
ret
endp
proc Thomas1_ct uses ebx esi edi
mov edi, CRCtable - 4
xor ecx, ecx
_ml:
mov eax, ecx
add edi, 4
mov esi, 8
@@:
shr eax, 1
sbb edx, edx
and edx, 0EDB88320h
xor eax, edx
dec esi
jnz @B
inc ecx
mov [edi], eax
cmp ecx, 256
jb _ml
ret
endp
; Calculate CRC
; (Uses Thomas1_ct for table generation)
proc crc uses ebx esi edi ,buf:DWORD, len:DWORD
mov esi, [buf]
mov edi, CRCtable
mov edx, [len]
shr edx, 1
or ecx, -1
xor eax, eax
@@:
mov al, [esi]
xor al, cl
shr ecx, 8
mov ebx, [edi+4*eax]
xor ecx, ebx
mov al, [esi+1]
xor al, cl
shr ecx, 8
mov ebx, [edi+4*eax]
add esi,2
xor ecx, ebx
dec edx
jnz @B
test [len], 1
jz @F
mov al, [esi]
xor al, cl
inc esi
shr ecx, 8
mov ebx, [edi+4*eax]
xor ecx, ebx
@@:
mov eax, ecx
not eax
ret
endp
.data
CRCtable dd 256 dup (?)
.end start