Anders
By: a guest | Jan 4th, 2010 | Syntax:
NullSoft Installer | Size: 2.25 KB | Hits: 490 | Expires: Never
#CRC32 with system plugin
!include LogicLib.nsh
!include Util.nsh
Function ZIPCRC32_Begin
push $0
push $1
push $2
push $3
push $4
System::Call '*(&i1024,&i4 0xFFFFFFFF)i.r0'
${For} $1 0 255
StrCpy $3 $1
${For} $2 0 7
IntOp $4 $3 & 1
IntOp $3 $3 >> 1
IntOp $3 $3 & 0x7FFFFFFF
${If} $4 != 0
IntOp $3 $3 ^ 0xEDB88320
${EndIf}
${Next}
System::Call *$0(&i4r3)
IntOp $0 $0 + 4
${Next}
IntOp $0 $0 - 1024
pop $4
pop $3
pop $2
pop $1
exch $0
FunctionEnd
!macro ZIPCRC32_Begin outvarSTATE
call ZIPCRC32_Begin
pop ${outvarSTATE}
!macroend
Function ZIPCRC32_End
Exch $0
System::Call *$0(&i1024,&i4.s)
System::Free $0
pop $0
IntOp $0 $0 ^ 0xFFFFFFFF
Exch $0
FunctionEnd
!macro ZIPCRC32_End varSTATE outvarCRC
push ${varSTATE}
call ZIPCRC32_End
pop ${outvarCRC}
!macroend
Function ZIPCRC32_Update
System::Store "s"
pop $2 ;cbBuf
pop $1 ;buf
pop $0 ;varSTATE
IntOp $2 $1 + $2
System::Call *$0(&i1024,&i4.r9)
loop:
System::Call *$1(&i1.r7)
IntOp $1 $1 + 1
IntOp $8 $9 & 0xFF
IntOp $8 $8 ^ $7
IntOp $8 $8 * 4
IntOp $7 $0 + $8
System::Call *$7(&i4.r8)
IntOp $9 $9 >> 8
IntOp $9 $9 & 0xFFFFFF
IntOp $9 $9 ^ $8
IntCmpU $1 $2 0 loop
System::Call *$0(&i1024,&i4r9)
System::Store "l"
FunctionEnd
!macro ZIPCRC32_Update varSTATE buf cbBuf
push ${varSTATE}
push ${buf}
push ${cbBuf}
call ZIPCRC32_Update
!macroend
!macro _ZIPCRC32_UpdateFromFileHandle
System::Store "s"
pop $1 ;filehandle
pop $0 ;varSTATE
System::Call *(&i4096)i.r2
loop:
System::Call 'kernel32::ReadFile(ir1,ir2,i4096,*i.r3,i0)i.r4'
${If} $4 <> 0
${AndIf} $3 U> 0
!insertmacro ZIPCRC32_Update $0 $2 $3
goto loop
${EndIf}
System::Free $2
System::Store "l"
!macroend
!macro ZIPCRC32_UpdateFromFileHandle varSTATE filehandle
push ${varSTATE}
push ${filehandle}
${CallArtificialFunction} _ZIPCRC32_UpdateFromFileHandle
!macroend
Section
!insertmacro ZIPCRC32_Begin $0
#System::Call '*(&m99 "ABC")i.r1'
#!insertmacro ZIPCRC32_Update $0 $1 3
FileOpen $1 "$windir\regedit.exe" r
!insertmacro ZIPCRC32_UpdateFromFileHandle $0 $1
FileClose $1
!insertmacro ZIPCRC32_End $0 $0
IntFmt $0 "0x%X" $0
DetailPrint CRC=$0
CRCCheck::GenCRC "$windir\regedit.exe"
pop $0
IntFmt $0 "0x%X" $0
DetailPrint CRC=$0
SectionEnd