The MASM Forum Archive 2004 to 2012

General Forums => The Laboratory => Topic started by: Vortex on January 15, 2005, 02:39:12 PM

Title: Calculating checksum value
Post by: Vortex on January 15, 2005, 02:39:12 PM
Here is an algo to calculate the MS checksum value of a PE, it was presented by f0dder at Harold's forum:

MicrosoftCheckSum2 PROC C uses esi, buf:dword, len:dword
mov ecx, [len]           
mov edx, [buf]           
shr  ecx, 1               
xor  eax, eax             
clc                                 
@@theLoop:
adc ax, [edx + (ecx * 2) - 2]
dec ecx
jnz @@theLoop
adc eax, [len]
ret
MicrosoftCheckSum2 ENDP
Title: Re: Calculating checksum value
Post by: Mirno on January 15, 2005, 05:45:03 PM
That code?
I originally wrote that on Hiro's original forum!

BTW the clc isn't needed, the XOR does it.

Mirno
Title: Re: Calculating checksum value
Post by: Vortex on January 16, 2005, 09:44:46 AM
Hi Mirno,

Yes, I checked it, you are right.

Kindly, please accept my apologies.