Hi @ll,
i'm going to write a utility that calculates the crc32 from any file. I've modified the source from
marsface source to fit my needs. I read the whole file in pMem and wanna calculate the checksum from it. But somehow the checksum from marsface and mine is different :confused:
I hope you find the "error".

crc32_table dd 256 dup(?)
CRC dd ?

hFile dd 0 dup(?)
hMem dd ?
pMem dd ?
nRead dd ?

fmt_fileCRC db 'CRC: %08lx',0

mov hFile,eax
invoke GetFileSize,eax,0
mov file_size,eax

invoke GlobalAlloc, GHND, eax
mov hMem, eax
invoke GlobalLock, eax
mov pMem, eax

invoke ReadFile, hFile, pMem, file_size, ADDR nRead, 0 ;Read the whole File
invoke init_crc32
; -------------------------------------- CRC Calculation
mov eax, -1 ; start value
xor edx, edx ; clear edx
lea esi, pMem ; p = filebuf
lea edi, crc32_table ; ct = crc32_table

mov ebx, eax ; sCRC = CRC
shl eax, 8 ; CRC = CRC << 8
shr ebx, 24 ; sCRC = sCRC >> 24
mov dl, [esi] ; get Byte from Buffer
xor ebx, edx ; sCRC = sCRC ^ *ptr
lea esi, [esi + 1] ; p++
xor eax, [edi + ebx*4]; CRC = CRC^ct[sCRC]
mov CRC, eax ; save CRC
; -------------------------------------------------------------------
invoke wsprintf, ADDR strbuf, ADDR fmt_fileCRC, CRC
invoke MessageBox,hWin, ADDR strbuf, addr szDisplayName, MB_OK

invoke GlobalUnlock, pMem
invoke GlobalFree, hMem
invoke CloseHandle, hFile

init_crc32 proc
lea esi, crc32_table ; get table
xor edx, edx ; i = 0

mov eax, edx ; c = i
shl eax, 24 ; c = c << 24
mov ecx, 8 ; j = 8

add eax, eax ; c = c << 1
jnc ic2 ; [cf] has now the bit.

xor eax, CRC32_POLY ; c = c ^ CRC32_POLY

loop ic1 ; do it for 8 times

mov [esi], eax ; store final value
lea esi, [esi + 4] ; next in arry
inc dx ; i++
and dx, 0ffh ; i&=255
jne ic0 ; if ZERO, we are done


init_crc32 endp
Posted on 2001-12-08 08:23:33 by DaEagle99
you should loop your CRC calculation for the whole file
Posted on 2001-12-08 09:31:18 by savage
try to modify your code like this (not tested!):

mov eax, -1
mov ecx, file_size
xor edx, edx
lea esi, pMem
lea edi, crc32_table

mov ebx, eax
shl eax, 8
shr ebx, 24
mov dl, [esi]
xor ebx, edx
lea esi, [esi + 1]
xor eax, [edi + ebx*4]
dec ecx
or ecx, ecx ; looped through whole file?
jnz @B ; no, then continue

mov CRC, eax
Posted on 2001-12-08 09:45:22 by bazik
Sorry for my late post, its due win crashes.

i think that the POLY value is different for the
calcuation of the CRC table.

My algo uses this

CRC32_POLY equ 004c11db7h ; AUTODIN II, Ethernet, & FDDI

Maybe you are using the POLY from WinZIP.
Posted on 2001-12-09 07:13:09 by marsface