Using !packhdr: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
Line 42: Line 42:
!if `${Packhdr}` != upx
!if `${Packhdr}` != upx
   !if `${Packhdr}` != upx+noicon
   !if `${Packhdr}` != upx+noicon
     !error `Packhdr must be defined as: noicon, noicon+upx, upx`
     !error `Packhdr must be defined as: upx | upx+noicon`
   !endif
   !endif
!endif
!endif

Revision as of 15:16, 24 July 2010

Author: Afrow UK (talk, contrib)


!packhdr

!packhdr is a useful compile time directive which allows modifications to the built installer executable header before it is written to the finished installer executable file. It can be used to pack the executable header using UPX or edit resources using Resource Hacker. I have used !packhdr for many years in conjunction with some useful batch files to:

  • Pack the header (UPX)
  • Pack the header (UPX) and remove the installer icon (Resource Hacker)

Batch files

Firstly you will need to download UPX and Resource Hacker and copy upx.exe and reshacker.exe to a new NSIS\Packhdr folder. Then place the following batch files in the NSIS\Packhdr folder:

upx.bat

cd /d %~dp0

upx --best %1

upx+noicon.bat

cd /d %~dp0

ResHacker -delete %1, %1, icongroup,103,
del ResHacker.log

upx --best %1

Usage

Simply place the following at the top of your NSIS scripts:

!packhdr $%TEMP%\exehead.tmp `"${NSISDIR}\Packhdr\upx.bat" "$%TEMP%\exehead.tmp"`

You can substitute upx.bat with upx+noicon.bat depending on your requirement for the particular installer. I use upx+noicon.bat for utility executables that are written in NSIS but do not serve a purpose as an installation wizard (i.e. SilentInstall silent).

Script header

You can put this code into an NSH file and place it in your NSIS\Include folder:

!ifndef _Packhdr_Included
!define _Packhdr_Included
 
!if `${Packhdr}` != upx
  !if `${Packhdr}` != upx+noicon
    !error `Packhdr must be defined as: upx | upx+noicon`
  !endif
!endif
 
!packhdr $%TEMP%\exehead.tmp `"${NSISDIR}\packhdr\${Packhdr}.bat" "$%TEMP%\exehead.tmp"`
 
!undef Packhdr
 
!endif

Usage:

!define Packhdr upx
!include Packhdr.nsh