Using !packhdr: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
No edit summary
Line 8: Line 8:
* Pack the header (UPX) and remove the installer icon (Resource Hacker)
* Pack the header (UPX) and remove the installer icon (Resource Hacker)


== The batch files ==
== Batch files ==
Firstly you will need to download [http://upx.sourceforge.net/#download UPX] and [http://angusj.com/resourcehacker/ 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:
Firstly you will need to download [http://upx.sourceforge.net/#download UPX] and [http://angusj.com/resourcehacker/ 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:


Line 33: Line 33:
</highlight-nsis>
</highlight-nsis>
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'').
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:
<highlight-nsis>
!ifndef _Packhdr_Included
!define _Packhdr_Included
!ifndef Packhdr
  !define _Packhdr_Error
!endif
!if `${Packhdr}` != upx
  !define _Packhdr_Error
!endif
!if `${Packhdr}` != upx+noicon
  !define _Packhdr_Error
!endif
!ifdef _Packhdr_Error
  !error `Packhdr not defined correclty! Possible values: upx | upx+noicon`
!endif
!packhdr $%TEMP%\exehead.tmp `"${NSISDIR}\packhdr\${Packhdr}.bat" "$%TEMP%\exehead.tmp"`
!undef Packhdr
!endif
</highlight-nsis>


[[Category:Tutorials]]
[[Category:Tutorials]]

Revision as of 15:06, 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
 
!ifndef Packhdr
  !define _Packhdr_Error
!endif
!if `${Packhdr}` != upx
  !define _Packhdr_Error
!endif
!if `${Packhdr}` != upx+noicon
  !define _Packhdr_Error
!endif
!ifdef _Packhdr_Error
  !error `Packhdr not defined correclty! Possible values: upx | upx+noicon`
!endif
 
!packhdr $%TEMP%\exehead.tmp `"${NSISDIR}\packhdr\${Packhdr}.bat" "$%TEMP%\exehead.tmp"`
 
!undef Packhdr
 
!endif