1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498
|
; Licensed under the zlib/libpng license (same as NSIS)
!ifndef MINIZ_INCLUDED
!define MINIZ_INCLUDED
!ifndef MINIZ_BUFFER_SIZE
!define MINIZ_BUFFER_SIZE 262144
!endif
!ifndef MINIZ_COMP_FLAGS
!define MINIZ_COMP_FLAGS 1500
!endif
!define MINIZ_CRC32_INIT 0
!define MINIZ_FINISH 4
!define MINIZ_NO_FLUSH 0
!define MINIZ_HELPER_DLL miniz.dll
!searchreplace MINIZ_NAME ${MINIZ_HELPER_DLL} ".dll" ""
!ifndef MINIZ_HELPER_DIR
!error "Please define the directory containing ${MINIZ_HELPER_DLL}"
!endif
!define MINIZ_PREFIX "MINIZ_"
!define MINIZ_UNFUNC "un."
!define /math CPIO_BUFFER_SIZE ${MINIZ_BUFFER_SIZE} >>> 1
!include include\stdmacros.nsh
!include LogicLib.nsh
!include Win\WinError.nsh
!include include\cpio.nsh
!define MINIZ_FUNCDEF \
`!insertmacro STDMACROS_FUNCDEF ${MINIZ_PREFIX}`
!define MINIZ_FUNCINC \
`!insertmacro STDMACROS_FUNCINC ${MINIZ_PREFIX}`
!define MINIZ_FUNCPROLOG \
`!insertmacro STDMACROS_FUNCPROLOG ${MINIZ_PREFIX}`
; ${MINIZ_Alloc} handle
${MINIZ_FUNCDEF} Alloc
!macro MINIZ_Alloc_Call UN HANDLE
Call `${UN}${MINIZ_PREFIX}Alloc`
Pop ${HANDLE}
!macroend
; ${MINIZ_Init} flags handle
; Create and initalize compressor object
; Parameter:
; flags - compression flags
; Return value:
; Handle to compressor object
!macro MINIZ_Init UN
!define ${UN}MINIZ_Init_INCLUDED
!macroend
${MINIZ_FUNCDEF} Init
!macro MINIZ_Init_Call UN FLAGS HANDLE
!insertmacro STDMACROS_ToSystemReg ${FLAGS} ${__MACRO__}_FLAGS
!insertmacro STDMACROS_ToSystemReg ${HANDLE} ${__MACRO__}_HANDLE
System::Call "${MINIZ_NAME}::init(i ${${__MACRO__}_FLAGS}) p.${${__MACRO__}_HANDLE}"
!macroend
; ${MINIZ_CRC32} crc data len
; Compute cyclic redundancy check (CRC) value
; Parameter:
; crc - initial value of CRC
; data - buffer containing the data
; len - size of data in bytes
; Return value:
; updated CRC value
!macro MINIZ_CRC32 UN
!define ${UN}MINIZ_CRC32_INCLUDED
!macroend
${MINIZ_FUNCDEF} CRC32
!macro MINIZ_CRC32_Call UN CRC DATA LEN RESULT
!insertmacro STDMACROS_ToSystemReg ${CRC} ${__MACRO__}_CRC
!insertmacro STDMACROS_ToSystemReg ${DATA} ${__MACRO__}_DATA
!insertmacro STDMACROS_ToSystemReg ${LEN} ${__MACRO__}_LEN
!insertmacro STDMACROS_ToSystemReg ${RESUlT} ${__MACRO__}_RESUlT
System::Call "${MINIZ_NAME}::crc32(i ${${__MACRO__}_CRC}, p ${${__MACRO__}_DATA}, i ${${__MACRO__}_LEN}) i.${${__MACRO__}_RESULT}"
!macroend
; ${MINIZ_Compress} handle input inputlen output ouputlen flush result
; Compress data
; Parameters:
; handle - compressor object
; input - input data
; inputlen - size of input in bytes
; output - output buffer
; outputlen - size of output buffer in bytes
; flush - flag to perform flush operation
; Return value:
; Negative value in case of an error
!macro MINIZ_Compress UN
!define ${UN}MINIZ_Compress_INCLUDED
!macroend
${MINIZ_FUNCDEF} Compress
!macro MINIZ_Compress_Call UN HANDLE INPUT INPUTLEN OUTPUT OUTPUTLEN FLUSH RESULT
!insertmacro STDMACROS_ToSystemReg ${HANDLE} ${__MACRO__}_HANDLE
!insertmacro STDMACROS_ToSystemReg ${INPUT} ${__MACRO__}_INPUT
!insertmacro STDMACROS_ToSystemReg ${INPUTLEN} ${__MACRO__}_INPUTLEN
!insertmacro STDMACROS_ToSystemReg ${OUTPUT} ${__MACRO__}_OUTPUT
!insertmacro STDMACROS_ToSystemReg ${OUTPUTLEN} ${__MACRO__}_OUTPUTLEN
!insertmacro STDMACROS_ToSystemReg ${FLUSH} ${__MACRO__}_FLUSH
!insertmacro STDMACROS_ToSystemReg ${RESULT} ${__MACRO__}_RESULT
System::Call "${MINIZ_NAME}::compress(p ${${__MACRO__}_HANDLE}, p ${${__MACRO__}_INPUT}, *i ${${__MACRO__}_INPUTLEN}${${__MACRO__}_INPUTLEN}, p ${${__MACRO__}_OUTPUT}, *i ${${__MACRO__}_OUTPUTLEN}${${__MACRO__}_OUTPUTLEN}, i ${${__MACRO__}_FLUSH}) i.${${__MACRO__}_RESULT}"
!macroend
; ${MINIZ_Destroy} handle
; Destroy compressor object
; Parameter:
; handle - compressor object
!macro MINIZ_Destroy UN
!define ${UN}MINIZ_Destroy_INCLUDED
!macroend
${MINIZ_FUNCDEF} Destroy
!macro MINIZ_Destroy_Call UN HANDLE
!insertmacro STDMACROS_ToSystemReg ${HANDLE} ${__MACRO__}_HANDLE
System::Call "${MINIZ_NAME}::destroy(p ${${__MACRO__}_HANDLE})"
!macroend
; ${MINIZ_Free} module
; Release the loaded miniz helper module
; Parameter:
; module - handle to the loaded module
!macro MINIZ_Free UN
!define ${UN}MINIZ_Free_INCLUDED
!macroend
${MINIZ_FUNCDEF} Free
!macro MINIZ_Free_Call UN MODULE
!insertmacro STDMACROS_ToSystemReg ${MODULE} ${__MACRO__}_MODULE
System::Call "kernel32::FreeLibrary(p ${${__MACRO__}_MODULE})"
!macroend
; ${MINIZ_GZip_Header} output buffer len result
${MINIZ_FUNCDEF} GZip_Header
!macro MINIZ_GZip_Header_Call UN OUTPUT RESULT
Push ${OUTPUT}
Call `${UN}${MINIZ_PREFIX}GZip_Header`
Pop ${RESULT}
!macroend
; ${MINIZ_GZip} input output result
${MINIZ_FUNCDEF} GZip
!macro MINIZ_GZip_Call UN INPUT OUTPUT RESULT
Push ${INPUT}
Push ${OUTPUT}
Call `${UN}${MINIZ_PREFIX}GZip`
Pop ${RESULT}
!macroend
; $[MINIZ_CPIO_GZ_Open} output result
${MINIZ_FUNCDEF} CPIO_GZ_Open
!macro MINIZ_CPIO_GZ_Open_Call UN OUTPUT RESULT
Push ${OUTPUT}
Call `${UN}${MINIZ_PREFIX}CPIO_GZ_Open`
Pop ${RESULT}
!macroend
; ${MINIZ_CPIO_GZ_Filter} handle buffer len result
${MINIZ_FUNCDEF} CPIO_GZ_Filter
!macro MINIZ_CPIO_GZ_Filter_Call UN HANDLE BUFFER LEN RESULT
Push ${HANDLE}
Push ${BUFFER}
Push ${LEN}
Call `${UN}${MINIZ_PREFIX}CPIO_GZ_Filter`
Pop ${RESULT}
!macroend
; ${MINIZ_CPIO_GZ_Write} handle filename result
${MINIZ_FUNCDEF} CPIO_GZ_Write
!macro MINIZ_CPIO_GZ_Write_Call UN HANDLE FILENAME RESULT
Push ${HANDLE}
Push "${FILENAME}"
Call `${UN}${MINIZ_PREFIX}CPIO_GZ_Write`
Pop ${RESULT}
!macroend
; ${MINIZ_CPIO_GZ_Close} handle result
${MINIZ_FUNCDEF} CPIO_GZ_Close
!macro MINIZ_CPIO_GZ_Close_Call UN HANDLE RESULT
Push ${HANDLE}
Call `${UN}${MINIZ_PREFIX}CPIO_GZ_Close`
Pop ${RESULT}
!macroend
!macro MINIZ_Alloc UN
; Unpack and load miniz helper dll
; Result:
; Handle of loaded module
${MINIZ_FUNCPROLOG} "${UN}" Alloc
Push $0
Push $1
StrCpy $1 "$PLUGINSDIR\${MINIZ_HELPER_DLL}"
${IfNot} ${FileExists} "$1"
; Unpack miniz helper dll
Push $OUTDIR
SetOutPath $PLUGINSDIR
ReserveFile "${MINIZ_HELPER_DIR}\${MINIZ_HELPER_DLL}"
File "/oname=${MINIZ_HELPER_DLL}" "${MINIZ_HELPER_DIR}\${MINIZ_HELPER_DLL}"
Pop $0
SetOutPath $0
${EndIf}
System::Call "kernel32::LoadLibrary(t r1) p.r0"
Pop $1
Exch $0
FunctionEnd
!macroend ; MINIZ_Alloc
!macro MINIZ_GZip_Header UN
; Write gzip header into the provided buffer
; Parameter:
; output - writable file handle
; Return value:
; Non zero value if successful
${MINIZ_FUNCPROLOG} "${UN}" GZip_Header
Exch $0
Push $1
Push $2
; GZip header
; offset size value description
; 0 2 0x1F 0x8b identificatioon bytes
; 2 1 0x08 compression method (0x08 = deflate)
; 3 1 0x00 flags (0x00 = no flags set)
; 4 4 0x00 0x00 0x00 0x00 last modification time
; 8 1 0x02 compression flags (0x02 = max compression)
; 9 1 0x00 operationg system (0x00 = MS/DOS, NT/Win32)
System::Call "*(&l .r2, &i1 31, &i1 139, &i1 8, &i1 0, &i4 0, &i1 2, &i1 0) p.r1"
${If} $1 P<> 0
System::Call "kernel32::WriteFile(p r0, p r1, i r2, *i .r2, p 0) i.r0"
System::Free $1
${Else}
StrCpy $0 0
${EndIf}
Pop $2
Pop $1
Exch $0
FunctionEnd
!macroend ; MINIZ_GZip_Header
!macro MINIZ_GZip UN
; Read input file, compress its content and write the compressed data
; to a gzip formatted output file
; Parameters:
; input - handle of file to read from
; output - writable file handle
; Return value:
; 0 if successful otherwise error code
${MINIZ_FUNCINC} "${UN}" Alloc
${MINIZ_FUNCINC} "${UN}" Init
${MINIZ_FUNCINC} "${UN}" CRC32
${MINIZ_FUNCINC} "${UN}" GZip_Header
${MINIZ_FUNCINC} "${UN}" Compress
${MINIZ_FUNCINC} "${UN}" Destroy
${MINIZ_FUNCINC} "${UN}" Free
${MINIZ_FUNCPROLOG} "${UN}" GZip
System::Store 'S'
Pop $2
Pop $1
; input=$1, output=$2
StrCpy $0 ${ERROR_INVALID_HANDLE}
${If} $1 P<> 0
${AndIf} $2 P<> 0
!insertmacro ${MINIZ_PREFIX}Alloc_Call "${UN}" $3
${If} $3 P<> 0
!insertmacro ${MINIZ_PREFIX}Init_Call "${UN}" ${MINIZ_COMP_FLAGS} $4
${If} $4 P<> 0
; Allocate input buffer (half of output buffer size)
StrCpy $6 ${MINIZ_BUFFER_SIZE}
IntOp $6 $6 >> 1
System::Alloc $6
Pop $5
${If} $5 P<> 0
; Allocate output buffer
StrCpy $8 ${MINIZ_BUFFER_SIZE}
System::Alloc $8
Pop $7
${If} $7 P<> 0
!insertmacro ${MINIZ_PREFIX}GZip_Header_Call "${UN}" $2 $0
${If} $0 != 0
StrCpy $R1 ${MINIZ_CRC32_INIT}
StrCpy $R2 0
${DoWhile} $0 != 0
System::Call "kernel32::ReadFile(p r1, p r5, i r6, *i .r9, p 0) i.r0"
${If} $0 != 0
!insertmacro ${MINIZ_PREFIX}CRC32_Call "${UN}" $R1 $5 $9 $R1
IntOp $R2 $R2 + $9
${If} $9 < $6
; Reached end of file
!insertmacro ${MINIZ_PREFIX}Compress_Call "${UN}" $4 $5 $9 $7 $8 ${MINIZ_FINISH} $0
${If} $0 < 0
${ExitDo}
${EndIf}
System::Call "kernel32::WriteFile(p r2, p r7, i r8, *i .r9, p 0) i.r0"
${ExitDo}
${Else}
StrCpy $R0 $8 ; Reset size to size of output buffer
!insertmacro ${MINIZ_PREFIX}Compress_Call "${UN}" $4 $5 $9 $7 $R0 ${MINIZ_NO_FLUSH} $0
${If} $0 < 0
${ExitDo}
${EndIf}
System::Call "kernel32::WriteFile(p r2, p r7, i r10, *i .r9, p 0) i.r0"
${EndIf}
${Else}
${ExitDo}
${EndIf}
${Loop}
${If} $0 > 0
; Write gzip footer
System::Call "*$7(&l .r8, &i4 r11)"
System::Call "kernel32::WriteFile(p r2, p r7, i r8, *i .r8, p 0) i.r0"
${If} $0 != 0
System::Call "*$7(&i4 r12)"
System::Call "kernel32::WriteFile(p r2, p r7, i r8, *i .r8, p 0) i.r0"
${If} $0 != 0
; Indicate success
StrCpy $0 0
${EndIf}
${EndIf}
${ElseIf} $0 == 0
System::Call "kernel32::GetLastError() i.r0"
${EndIf}
${EndIf}
System::Free $7
${EndIf}
System::Free $5
${EndIf}
!insertmacro ${MINIZ_PREFIX}Destroy_Call "${UN}" $4
${EndIf}
!insertmacro ${MINIZ_PREFIX}Free_Call "${UN}" $3
${EndIf}
${EndIf}
Push $0
System::Store 'L'
FunctionEnd
!macroend ; MINIZ_GZip
!macro MINIZ_CPIO_GZ_Open UN
; Allocate and intialize handle for creating a gzip compressed cpio archive
; Parameter:
; output - writable file handle
; Return value:
; Handle for creating a gzip compressed cpio archive
${MINIZ_FUNCINC} "${UN}" Alloc
${MINIZ_FUNCINC} "${UN}" Init
${MINIZ_FUNCINC} "${UN}" GZip_Header
${MINIZ_FUNCINC} "${UN}" Destroy
${MINIZ_FUNCINC} "${UN}" Free
${MINIZ_FUNCPROLOG} "${UN}" CPIO_GZ_Open
System::Store 'S'
Pop $1
StrCpy $0 0
${If} $1 P<> 0
!insertmacro ${MINIZ_PREFIX}Alloc_Call "${UN}" $2
${If} $2 P<> 0
!insertmacro ${MINIZ_PREFIX}Init_Call "${UN}" ${MINIZ_COMP_FLAGS} $3
${If} $3 P<> 0
StrCpy $5 ${MINIZ_BUFFER_SIZE}
System::Alloc $5
Pop $4
${If} $4 P<> 0
!insertmacro ${MINIZ_PREFIX}GZip_Header_Call "${UN}" $1 $0
${If} $0 != 0
System::Call "*(p r1, p r2, p r3, p r4, &i${NSIS_PTR_SIZE} r5, &i${NSIS_PTR_SIZE} 0, &i4 ${MINIZ_CRC32_INIT}) p.r0"
${EndIf}
${EndIf}
${EndIf}
${EndIf}
${EndIf}
${If} $0 == 0
${If} $4 P<> 0
System::Free $4
${EndIf}
${If} $3 P<> 0
!insertmacro ${MINIZ_PREFIX}Destroy_Call "${UN}" §4
${EndIf}
${If} $2 P<> 0
!insertmacro ${MINIZ_PREFIX}Free_Call "${UN}" §3
${EndIf}
${EndIf}
Push $0
System::Store 'L'
FunctionEnd
!macroend ; MINIZ_CPIO_GZ_Open
!macro MINIZ_CPIO_GZ_Filter UN
; Write buffer in compressed format to file
; Parameters:
; handle - handle obtained via MINIZ_CPIO_GZ_Open
; buffer - buffer to be written
; len - size of buffer in bytes
; Return value:
; Non zero value if successful
${MINIZ_FUNCINC} "${UN}" CRC32
${MINIZ_FUNCPROLOG} "${UN}" CPIO_GZ_Filter
System::Store 'S'
Pop $R0
Pop $9
Pop $8
System::Call "*$8(p .r1, p, p .r3, p .r4, &i${NSIS_PTR_SIZE} .r5, &i${NSIS_PTR_SIZE} .r6, &i4 .r7)"
!insertmacro ${MINIZ_PREFIX}CRC32_Call "${UN}" $7 $9 $R0 $7
IntOp $6 $6 + $R0
!insertmacro ${MINIZ_PREFIX}Compress_Call "${UN}" $3 $9 $R0 $4 $5 ${MINIZ_NO_FLUSH} $0
${If} $0 >= 0
System::Call "kernel32::WriteFile(p r1, p r4, i r5, *i .r5, p 0) i.r0"
${If} $0 != 0
; Update size and CRC32 value
System::Call "*$8(p, p, p, p, &i${NSIS_PTR_SIZE}, &i${NSIS_PTR_SIZE} r6, &i4 r7)"
${EndIf}
${EndIf}
Push $0
System::Store 'L'
FunctionEnd
!macroend ; MINIZ_CPIO_GZ_Filter
!macro MINIZ_CPIO_GZ_Write UN
; Write CPIO entry of given file name to handle
; Parameters:
; handle - handle obtained via MINIZ_CPIO_GZ_Open
; filename - name of file to be added
; Return value:
; 0 if successful otherwise error code
${MINIZ_FUNCINC} "${UN}" CPIO_GZ_Filter
${CPIO_FUNCINC} "${UN}" Write_Filter
${MINIZ_FUNCPROLOG} "${UN}" CPIO_GZ_Write
Push $0
GetFunctionAddress $0 `${UN}${MINIZ_PREFIX}CPIO_GZ_Filter`
Exch $0
Call `${UN}${CPIO_PREFIX}Write_Filter`
FunctionEnd
!macroend ; MINIZ_CPIO_GZ_Write
!macro MINIZ_CPIO_GZ_Close UN
; Release handle and its associated memory
; Parameters:
; handle - handle obtained via MINIZ_CPIO_GZ_Open
; Return value:
; 0 if successful otherwise error code
${MINIZ_FUNCINC} "${UN}" Compress
${MINIZ_FUNCINC} "${UN}" Destroy
${MINIZ_FUNCINC} "${UN}" Free
${MINIZ_FUNCPROLOG} "${UN}" CPIO_GZ_Close
System::Store 'S'
Pop $8
StrCpy $0 ${ERROR_INVALID_HANDLE}
${If} $8 P<> 0
System::Call "*$8(p .r1, p .r2, p .r3, p .r4, &i${NSIS_PTR_SIZE} .r5, &i${NSIS_PTR_SIZE} .r6, &i4 .r7)"
StrCpy $9 0
!insertmacro ${MINIZ_PREFIX}Compress_Call "${UN}" $3 0 $9 $4 $5 ${MINIZ_FINISH} $0
${If} $0 >= 0
System::Call "kernel32::WriteFile(p r1, p r4, i r5, *i .r5, p 0) i.r0"
${If} $0 != 0
; Write gzip footer
System::Call "*$4(&l .r5, &i4 r7)"
System::Call "kernel32::WriteFile(p r1, p r4, i r5, *i .r5, p 0) i.r0"
${If} $0 != 0
System::Call "*$4(&i4 r6)"
System::Call "kernel32::WriteFile(p r1, p r4, i r5, *i .r5, p 0) i.r0"
${EndIf}
${EndIf}
${EndIf}
${If} $0 != 0
; Indicate success
StrCpy $0 0
${Else}
System::Call "kernel32::GetLastError() i.r0"
${EndIf}
${If} $4 P<> 0
System::Free $4
${EndIf}
${If} $3 P<> 0
!insertmacro ${MINIZ_PREFIX}Destroy_Call "${UN}" $3
${EndIf}
${If} $2 P<> 0
!insertmacro ${MINIZ_PREFIX}Free_Call "${UN}" $2
${EndIf}
System::Free $8
${EndIf}
Push $0
System::Store 'L'
FunctionEnd
!macroend ; MINIZ_CPIO_GZ_Close
!endif ; MINIZ_INCLUDED
|