Hi, i'm currently working on a app to calculate the crc32 of any filetype. I've found a routine to calculate but the result isn't that what WinZip shows :( . Maybe there's an error in the code? Do you know other routines to calculate the 32-BIT-CRC comfortable from :)? Here's the actual code:
  invoke RtlZeroMemory,addr DateiName,250
        invoke GetWindowText,hFileName,addr FileName,250
        invoke CreateFile,addr FileName,GENERIC_READ,0,0,OPEN_EXISTING,0,0
        mov hFile,eax
        invoke GetFileSize,eax,0
        mov file_size,eax
        invoke GlobalAlloc,GMEM_MOVEABLE or GMEM_ZEROINIT,eax
        mov  hMemory,eax 
        invoke GlobalLock,hMemory 
        mov  pMemory,eax 
        invoke ReadFile,hFile,pMemory,filesize,ADDR bytesread,NULL 
        invoke CloseHandle,hFile 
        invoke CRC32,pMemory,file_size
        mov ecx,eax
        invoke dwtoa,ecx,addr filebuff
        invoke MessageBox,hWin,addr filebuff,ADDR szDisplayName,0
	invoke GlobalUnlock,pMemory 
        invoke GlobalFree,hMemory 

InitCRC proc uses ebx esi edi
	lea	edi, crctab+(255*4)
	xor	edx, edx
	dec	dl
@@l2:	mov	eax, edx
	mov	ebx, 0EDB88320h		; winzip polynom
	push	8
	pop	ecx
@@l1:	shr	eax, 1
	sbb	esi, esi
	and	esi, ebx
	xor	eax, esi
	dec	ecx
	jnz	@@l1
	dec	edx
	jns	@@l2
InitCRC endp

CRC32 proc uses	ebx esi edi lpbuffer:DWORD, lsize:DWORD
	mov	esi, lpbuffer
	mov	ebx, lsize
	xor	ecx, ecx
	lea	eax, 
	mov	edi, 0EDB88320h
@@m1:	xor	edx, edx
	mov	dl, 
	xor	dl, al
@@m2:	shr	edx, 1
	jnc	@@m3
	xor	edx, edi
@@m3:	inc	ecx
	and	cl, 7
	jnz	@@m2
	shr	eax, 8
	xor	eax, edx
	inc	esi
	dec	ebx
	jg	@@m1	
	not	eax
CRC32 endp
Thanks, DaEagle99 This message was edited by DaEagle99, on 3/30/2001 7:40:24 AM
Posted on 2001-03-30 06:38:00 by DaEagle99
Are you sure that WinZip takes the CRC of the file? Could they take the CRC of the compressed file instead? It would make more sence to do that, so it means that checking the integrity of the .zip can be done by merely calulating the CRC, rather than decompressing, then CRCing. Mirno
Posted on 2001-03-30 06:45:00 by Mirno
Hi Mirno, >Are you sure that WinZip takes the CRC of the file? I think so, cause i've written a crc check in turbo pascal and it matched with the one from WinZip. WinZip calculates the crc of the file decompressed, because when it got extracted, it gets compared with the one of the orginial. So it prevents modifying the files in the zip. But my question is: Does my code calculate the crc32 of the file correct? And do you know ohter sources to do that? Or can you even send me an example doing that? thx, DaEagle99 This message was edited by DaEagle99, on 3/30/2001 9:14:26 AM
Posted on 2001-03-30 08:12:00 by DaEagle99