Hi Pabs,

I come back to your offer to figure out the scons side.

The attached patch (against nsis-2.40) implements the 
functions CallProc, RealCallBack and CallBack of the System 
plugin in pure x86 assembly. The call.asm assembly source 
file supports both the MASM and GNU assembler in one file. 
The trick lies in the "; .if 0" line which is ignored by 
MASM but evaluated by the GNU assembler.

The stack probing function _alloca_probe is equivalent
to _chkstk. GCC provides an equivalent function in
libgcc called _alloca. For details see the discussion
in:
http://gcc.gnu.org/ml/gcc/2006-11/msg00081.html

I refrained from using hardcoded offsets for the structures
SystemProc and ProcParameter but rather opted for C helper
functions for determining these offsets. As a result it is 
easier for maintenance because changes to the SystemProc 
and ProcParameter structures would not affect the assembly 
source code. As a side effect the hardcoded offset 
SYSTEM_ZERO_PARAM_VALUE_OFFSET in System.h is no longer
needed.

I changed the macros SYSTEM_LOG_ADD and SYSTEM_LOG_POST in
System.c to avoid an access violation in case call.asm was 
compiled without the SYSTEM_DEBUG_LOG define. 

DllMain is used instead of _DllMainCRTStartup to avoid an
"endless" recursion for the debug report macro _RPT0. The 
system DllMain initializes the C runtime environment. In 
particular the value for _osplatform is initialized. In the
function _get_winmajor called in the execution of the _RPT0 
macro an assertion failure is raised if _osplatform is 
not set. The assertion is reported by the same means as 
used for the _RPT0 macro. This leads to an "endless"
recursion. By default the define SYSTEM_DEBUG_LOG is not
set. So it would be ok to stick with _DllMainCRTStartup.

I used the attached test.py python script for unit 
testing the System plug-in.

For building the System plug-in I used the development
environment of Microsoft Visual Studio 8 and the
following batch script for the GNU toolchain:

@echo off
setlocal
set TOOLCHAIN_PATH="C:\mingw\bin"
rem SET DEBUG=-DSYSTEM_DEBUG_LOG
set DEFINES=-DWIN32 -DNDEBUG -D_WINDOWS -D_USERDLL %DEBUG%
set CFLAGS=-g -Os -Wall %DEFINES%

set SRCS=Buffers.c Plugin.c stdafx.c System.c
set ASM_SRCS=call.asm
set OBJS=Buffers.o call.o Plugin.o stdafx.o System.o

et AS="%TOOLCHAIN_PATH%\gcc.exe" -x assembler-with-cpp -s
set GCC="%TOOLCHAIN_PATH%\gcc.exe"

for %%F in (%SRCS%) do %GCC% %CFLAGS% -c %%F
for %%F in (%ASM_SRCS%) do %AS% %DEFINES% -c %%F

%GCC% -shared %OBJS% -mwindows -o System.dll -lole32 -Wl,--add-stdcall-alias
enlocal

So that's where scons respectively you are welcome to 
take over.

Best regards,
Thomas
diff -urN nsis-2.40-src.orig/Contrib/System/Source/call.asm nsis-2.40-src/Contrib/System/Source/call.asm
--- nsis-2.40-src.orig/Contrib/System/Source/call.asm	1970-01-01 01:00:00.000000000 +0100
+++ nsis-2.40-src/Contrib/System/Source/call.asm	2008-10-24 20:15:22.000000000 +0200
@@ -0,0 +1,954 @@
+;# Copyright (c) 2008 Thomas Gaugler <[EMAIL PROTECTED]>
+;#
+;# Permission is hereby granted, free of charge, to any person
+;# obtaining a copy of this software and associated documentation
+;# files (the "Software"), to deal in the Software without
+;# restriction, including without limitation the rights to use,
+;# copy, modify, merge, publish, distribute, sublicense, and/or sell
+;# copies of the Software, and to permit persons to whom the
+;# Software is furnished to do so, subject to the following
+;# conditions:
+;#
+;# The above copyright notice and this permission notice shall be
+;# included in all copies or substantial portions of the Software.
+;#
+;# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+;# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+;# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+;# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+;# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+;# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+;# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+;# OTHER DEALINGS IN THE SOFTWARE.
+;#
+;#
+;# Implementation of the functions CallProc, RealCallBack and
+;# CallBack of the System plugin in pure x86 assembly.
+;#
+;# This is a hybrid assembly source file supporting both the
+;# MASM as well as the GNU assembler in one file.
+;#
+;# 
+;# MASM:
+;# ml.exe /c /nologo /Fo"call.obj" /W3 /Zi /errorReport:prompt /Ta"call.asm"
+;#
+;# For enabling debug support use:
+;# ml.exe /c /nologo /D"SYSTEM_DEBUG_LOG" /Fo"call.obj" /W3 /Zi /errorReport:prompt /Ta"call.asm" 
+;#
+;# GNU toolchain:
+;# gcc -x assembler-with-cpp -s call.asm -c
+;# 
+;# For enabling debug support use:
+;# gcc -x assembler-with-cpp -DSYSTEM_DEBUG_LOG -s call.asm -c
+;#
+
+; .if 0
+;# MASM specific block
+.386
+.model flat
+OPTION casemap:none
+;# SYSCALL is identical to the C calling convention, 
+;# but does not add an underscore prefix to symbols.
+OPTION language:syscall
+
+SECTION_DATA     equ .data
+SECTION_CODE     equ .code
+
+DATA_SUFFIX      equ
+
+ASCII            equ DB
+
+TEMP_LABEL       equ @@
+TEMP_LABEL_AHEAD equ @f
+TEMP_LABEL_BACK  equ @b
+
+MACRO_DECL       equ
+
+FUNC_DECL MACRO name
+name PROC
+ENDM
+
+FUNC_END MACRO name
+name ENDP
+ENDM 
+
+;# end of MASM specific block
+IF 0
+; .else
+;# GNU toolchain specific block
+.intel_syntax noprefix
+.set __GNU__,1
+
+#ifdef SYSTEM_DEBUG_LOG
+;# Disable further proprocessing of SYSTEM_DEBUG_LOG
+;# and hand it over to the GNU assembler
+#undef SYSTEM_DEBUG_LOG
+.set SYSTEM_DEBUG_LOG,1
+#endif
+
+#define IFDEF            .ifdef
+#define ELSE             .else
+#define ENDIF            .endif
+
+#define EXTERN           .extern
+
+#define SECTION_DATA     .data
+#define SECTION_CODE     .text
+
+#define DATA_SUFFIX      :
+#define BYTE             .byte
+#define DWORD            .int
+#define ASCII            .ascii
+
+#define MACRO_DECL       .macro
+#define MACRO
+#define ENDM             .endm
+
+#define TEMP_LABEL       1
+#define TEMP_LABEL_AHEAD 1f
+#define TEMP_LABEL_BACK  1b
+
+.macro FUNC_DECL name
+.global \name
+.func   \name
+\name:
+.endm
+
+.macro FUNC_END name
+.endfunc
+.endm
+
+;# /*
+;# http://gcc.gnu.org/ml/gcc/2006-11/msg00081.html
+;# _alloca_probe <=> _chkstk <=> _alloca (in libgcc)
+;#  */
+
+#define __alloca_probe   __alloca
+
+#define END              .end
+
+;# end of GNU toolchain specific block
+ENDIF
+
+IFDEF SYSTEM_DEBUG_LOG
+  EXTERN    _WriteToLog          : PROC
+  EXTERN    _syslogbuf           : DWORD
+ENDIF
+
+EXTERN    __alloca_probe         : PROC
+
+EXTERN	  [EMAIL PROTECTED]    : PROC
+EXTERN    [EMAIL PROTECTED]  : PROC
+EXTERN    __imp__wsprintfA       : PROC
+
+EXTERN    _GlobalCopy            : PROC
+
+EXTERN    _LastStackPlace        : DWORD
+EXTERN    _LastStackReal         : DWORD
+EXTERN    _LastError             : DWORD
+EXTERN    _LastProc              : DWORD
+EXTERN    _CallbackIndex         : DWORD 
+
+EXTERN    _retexpr               : DWORD
+EXTERN    _retaddr               : PTR
+
+EXTERN    _GetNewStackSize       : PROC
+EXTERN    _GetGenStackOption     : PROC
+EXTERN    _GetCDeclOption        : PROC
+EXTERN    _GetErrorOption        : PROC
+EXTERN    _GetProcOffset         : PROC
+EXTERN    _GetCloneOffset        : PROC
+EXTERN    _GetProcNameOffset     : PROC
+EXTERN    _GetArgsSizeOffset     : PROC
+EXTERN    _GetParamCount         : PROC
+EXTERN    _GetParamsOffset       : PROC
+EXTERN    _GetSizeOfProcParam    : PROC
+EXTERN    _GetSizeOffsetParam    : PROC
+EXTERN    _GetValueOffsetParam   : PROC
+EXTERN    _Get_valueOffsetParam  : PROC
+EXTERN    _SetCloneOption        : PROC
+EXTERN    _SetProcResultOk       : PROC
+EXTERN    _SetProcResultCallback : PROC
+
+SECTION_DATA
+IFDEF SYSTEM_DEBUG_LOG
+  LogStack DATA_SUFFIX ASCII "%s  ESP = 0x%08X  Stack = 0x%08X  Real = 0x%08X"
+                 BYTE 0
+                
+  LogCall DATA_SUFFIX  BYTE 9,9
+                 ASCII "Call:"
+                 BYTE 10,0
+                 
+  LogBeforeCall DATA_SUFFIX BYTE 9,9,9
+                 ASCII "Before call        "
+                 BYTE 0
+                 
+  LogNearCall DATA_SUFFIX BYTE 10,9,9,9
+                 ASCII "Near call          "
+                 BYTE 0
+                 
+  LogBackFrom DATA_SUFFIX BYTE 9
+                 ASCII "Back from "
+                 BYTE 0
+                 
+  LogAfterCall DATA_SUFFIX BYTE 10,9,9,9
+                 ASCII "After call         "
+                 BYTE 0
+                 
+  LogReturnAfter DATA_SUFFIX BYTE 10,9,9,9
+                 ASCII "Return               0x%08X    0x%08X"
+                 BYTE 0
+                 
+  LogCalled DATA_SUFFIX ASCII "Called callback from "
+                 BYTE 0
+                 
+  LogShortAfter DATA_SUFFIX BYTE 10,9,9,9
+                 ASCII "Short-After call   "
+                 BYTE 0
+                 
+  LogReturn DATA_SUFFIX BYTE 9,9
+                 ASCII "Return from callback:"
+                 BYTE 10,0
+                 
+  LogBefore DATA_SUFFIX BYTE 9,9,9
+                 ASCII "Before call-back   "
+                 BYTE 0
+                 
+  LogShortBefore DATA_SUFFIX BYTE 10,9,9,9
+                 ASCII "Sh-Before call-back"
+                 BYTE 0
+                 
+  LogLF DATA_SUFFIX BYTE 10,0
+  
+ENDIF
+
+SECTION_CODE
+
+IFDEF SYSTEM_DEBUG_LOG
+
+;# Sets edi to address of the end of the syslog buffer (terminating zero)
+MACRO_DECL SYSTEM_LOG_INIT MACRO
+  mov         edi,offset _syslogbuf
+TEMP_LABEL:
+  ;# End loop if terminating zero of buffer was found otherwise move
+  ;# to next character and check again
+  cmp         byte ptr [edi],0
+  je          TEMP_LABEL_AHEAD
+  inc         edi
+  jmp         TEMP_LABEL_BACK
+TEMP_LABEL:
+ENDM
+
+;# Appends log information and advances edi accordingly.
+;#
+;# edi must point to the address of the log buffer where
+;# the log information should be appended.
+;#
+;# eax returns number of bytes appended to log buffer
+MACRO_DECL SYSTEM_LOG_ADD MACRO arg1,arg2
+  ;# Format string
+IFDEF __GNU__
+  push        \arg1 \arg2
+ELSE
+  push        arg1 arg2
+ENDIF
+  ;# Log buffer
+  push        edi
+  call        dword ptr [__imp__wsprintfA]
+  ;# If wsprintf succeeds then advance edi by number of bytes
+  ;# written to buffer
+  cmp         eax,0
+  jl          TEMP_LABEL_AHEAD
+  add         edi,eax
+TEMP_LABEL:
+  add         esp,8
+ENDM
+
+;# Writes stackpointer and additional information to log
+;# and advances edi accordingly (terminating zero of buffer).
+;#
+;# edi must point to the address of the log buffer where
+;# the log information should be appended.
+;#
+;# eax returns number of bytes appended to log buffer
+MACRO_DECL SYSTEM_EVENT MACRO arg1,arg2
+  ;# Save current stack pointer in eax
+  mov         eax,esp
+  ;# Stackpointer information
+  push        dword ptr [_LastStackReal]
+  push        dword ptr [_LastStackPlace]
+  push        eax
+  ;# Event information
+IFDEF __GNU__
+  push        \arg1 \arg2
+ELSE
+  push        arg1 arg2
+ENDIF
+  SYSTEM_LOG_ADD offset LogStack
+  add         esp,16
+ENDM
+
+;# Flush log information and reset log buffer.
+;#
+;# edi must point to the address of the log buffer where
+;# the log information should be appended.
+;#
+;# eax returns number of bytes appended to log buffer
+MACRO_DECL SYSTEM_LOG_POST MACRO
+  ;# Append line feed to log information
+  SYSTEM_LOG_ADD offset LogLF
+  ;# Flush log information
+  push        offset _syslogbuf
+  call        _WriteToLog
+  add         esp,4
+  ;# Reset log buffer
+  mov         byte ptr [_syslogbuf],0
+ENDM
+
+ENDIF
+
+FUNC_DECL _CallProc
+  ;# Save stack
+  push        ebp
+  mov         ebp,esp
+  ;# Stack space for local variables
+  ;# ebp-12 = High double word of result 
+  ;# ebp-8  = Low double word of result
+  ;# ebp-4  = Size of ProcParameter structure
+  sub         esp,12
+  ;# Save all usable registers to free our hands
+  push        ebx
+  push        edi
+  push        esi
+  push        ebp
+  
+  IFDEF SYSTEM_DEBUG_LOG
+    SYSTEM_LOG_INIT
+    SYSTEM_LOG_ADD offset LogCall
+    SYSTEM_EVENT offset LogBeforeCall
+  ENDIF
+  
+  ;# CallbackIndex != 0 
+  cmp         dword ptr [_CallbackIndex],0
+  je          stack_expand_done
+  
+  ;# proc->Options without POPT_GENSTACK 
+  push        dword ptr [ebp+8]
+  call        _GetGenStackOption
+  cmp         eax,0
+  pop         eax
+  jne         stack_expand_done
+  
+  ;# Save previous stack location
+  mov         dword ptr [_LastStackReal],esp
+  cmp         dword ptr [_LastStackPlace],0
+  jne         stack_adjust
+  ;# Create new stack
+  call        _GetNewStackSize
+  call        __alloca_probe
+  mov         dword ptr [_LastStackPlace],esp
+  jmp         stack_expand_done
+stack_adjust:
+  ;# Move stack pointer
+  mov         esp,dword ptr [_LastStackPlace]
+  
+stack_expand_done:
+  ;# Push arguments to stack
+  ;#
+  ;# Get number of parameters
+  push        dword ptr [ebp+8]
+  call        _GetParamCount
+  add         esp,4
+  
+  ;# Skip if there are no parameters
+  cmp         eax,0
+  jle         params_loop_done
+  
+  ;# Save number of paramters on stack
+  push        eax
+
+  ;# Get offset for element Params of SystemProc structure
+  call        _GetParamsOffset
+  add         eax,dword ptr [ebp+8]
+  push        eax
+      
+  call        _GetSizeOfProcParam
+  mov         dword ptr [ebp-4],eax
+  
+  ;# Calculate offset for the last Parameter
+  pop         ebx
+  pop         ecx
+  mul         ecx
+  add         ebx,eax
+  
+  ;# Save offset of last paramter on stack
+  push        ebx
+  ;# Save number of paramters on stack
+  push        ecx
+
+  ;# Size offset of parameter
+  call        _GetSizeOffsetParam
+  push        eax
+
+  ;# Value offset of parameter
+  call        _GetValueOffsetParam
+  push        eax
+  
+  ;# _value offset of parameter
+  call        _Get_valueOffsetParam
+  push        eax
+      
+  ;# ebx = _value offset
+  pop         ebx
+  ;# edx = Value offset
+  pop         edx
+  ;# esi = Size offset
+  pop         esi
+  ;# ecx = n-th parameter
+  pop         ecx
+  ;# eax = offset of current worked on parameter  
+  pop         eax
+  
+params_loop:
+  ;# Check Size of param
+  cmp         dword ptr [eax+esi],2
+  jne         params_default
+  
+  ;# Long type
+  push        dword ptr [eax+ebx]
+  
+params_default:  
+  ;# Default for all types
+  push        dword ptr [eax+edx]
+
+  ;# Continue with next parameter
+  sub         eax,dword ptr[ebp-4]  
+  loop        params_loop
+     
+params_loop_done:  
+  ;# Save proc
+  ;# proc->Clone
+  call        _GetCloneOffset
+  mov         ecx,dword ptr [ebp+8]
+  add         eax,ecx
+  
+  ;# proc->Clone = LastProc
+  mov         edx,dword ptr [_LastProc]
+  mov         dword ptr [eax],edx
+  
+  ;# LastProc = proc
+  mov         dword ptr [_LastProc],ecx
+  
+  IFDEF SYSTEM_DEBUG_LOG
+    SYSTEM_EVENT offset LogNearCall
+    SYSTEM_LOG_POST
+  ENDIF
+  
+  ;# Get address of procedure 
+  call        _GetProcOffset
+  mov         ecx,dword ptr [ebp+8]
+  mov         ecx,dword ptr [eax+ecx]
+    
+  ;# /*
+  ;# workaround for bug #1535007
+  ;# http://sf.net/tracker/index.php?func=detail&aid=1535007&group_id=22049&atid=373085
+  ;#
+  ;# If a function returns short and doesn't clear eax in the process,
+  ;# it will only set 2 bytes of eax, and the other 2 bytes remain
+  ;# "random". In this case, they'll be part of the proc pointer.
+  ;#
+  ;# To avoid this, eax is cleared before the function is called. This
+  ;# makes sure the value eax will contain is only what the function
+  ;# actually sets.
+  ;#  */
+  xor         eax,eax
+  
+  ;# Call
+  call        ecx
+  
+  ;# Return
+  mov         dword ptr [ebp-8],eax
+  mov         dword ptr [ebp-12],edx
+  
+  IFDEF SYSTEM_DEBUG_LOG
+    SYSTEM_LOG_INIT
+    SYSTEM_LOG_ADD offset LogBackFrom
+    ;# LastProc->ProcName	
+    call        _GetProcNameOffset
+    mov         ecx,dword ptr [_LastProc]
+    add         eax,ecx
+    SYSTEM_LOG_ADD eax
+    SYSTEM_EVENT offset LogShortAfter
+  ENDIF
+  
+  cmp         dword ptr [_CallbackIndex],0
+  je          stack_restore_done
+  mov         eax,dword ptr [_LastProc]
+  push        eax
+  call        _GetGenStackOption
+  cmp         eax,0
+  pop         eax
+  jne         stack_restore_done
+  
+  ;# Restore real stack location
+  mov         dword ptr [_LastStackPlace],esp
+  mov         esp,dword ptr [_LastStackReal]
+  pop         ebp
+  
+stack_restore_done:
+  ;# Restore proc  
+  mov         edx,dword ptr [_LastProc]
+  mov         dword ptr [ebp+8],edx
+  
+  ;# proc->Clone
+  call        _GetCloneOffset
+  add         eax,edx
+  
+  ;# LastProc = proc->Clone
+  mov         eax,dword ptr [eax]
+  mov         dword ptr [_LastProc],eax
+ 
+  ;# In case of cdecl convention we should clear stack
+  
+  ;# if ((proc->Options & POPT_CDECL) != 0)
+  push        edx
+  call        _GetCDeclOption
+  cmp         eax,0
+  pop         edx
+  je          stack_clear_done
+      
+  ;# Get number of parameters  
+  push        edx
+  call        _GetParamCount
+  add         esp,4
+  
+  ;# Skip if there are no parameters
+  cmp         eax,0 
+  jle         stack_clear_done
+  
+  ;# Save number of parameters on stack
+  push        eax
+  
+  ;# Get offset for element Params of SystemProc structure
+  call        _GetParamsOffset
+  add         eax,dword ptr [ebp+8]
+  
+  ;# Calculate offset for the Parameter 1    
+  add         eax,dword ptr [ebp-4]
+  
+  ;# Save offset for the Parameter 1 on stack
+  push        eax  
+  
+  ;# Size offset of parameter
+  call        _GetSizeOffsetParam
+  push        eax
+  
+  ;# if ((CallbackIndex > 0) && ((proc->Options & POPT_GENSTACK) == 0))
+  cmp         dword ptr [_CallbackIndex],0
+  jle         real_stack_cleanup
+  push        dword ptr [ebp+8]
+  call        _GetGenStackOption
+  cmp         eax,0
+  pop         eax
+  jne         real_stack_cleanup
+  
+  ;# In case of temporary stack
+  ;#
+  ;# esi = Size offset
+  pop         esi
+  ;# eax = offset of current worked on parameter
+  pop         eax
+  ;# ecx = n-th paramter
+  pop         ecx
+   
+temp_stack_loop:    
+  ;# LastStackPlace += 4* Size of current parameter;
+  mov         edx,dword ptr [eax+esi]
+  mov         ebx,dword ptr [_LastStackPlace]
+  lea         edx,[ebx+edx*4]
+  mov         dword ptr [_LastStackPlace],edx
+  
+  ;# Go to next
+  add         eax,dword ptr [ebp-4]
+  loop        temp_stack_loop
+  
+  ;# End of stack cleanup
+  jmp         stack_clear_done
+    
+real_stack_cleanup:
+  ;# In case of real stack 
+  ;#
+  ;# esi = Size offset
+  pop         esi
+  ;# eax = offset of current worked on parameter
+  pop         eax  
+  ;# ecx = Number of paramters
+  pop         ecx
+
+real_stack_loop:
+  ;# Size of current parameter == 2
+  cmp         dword ptr [eax+esi],2
+  jne         real_stack_default
+  ;# Long type
+  pop         edx
+  
+real_stack_default:
+  ;# Default
+  pop         edx
+  add         eax,dword ptr [ebp-4]
+  loop        real_stack_loop  
+  
+stack_clear_done:    
+  ;# In case of cleared call-proc-queue -> clear allocated stack place (more flexible)
+  cmp         dword ptr [_LastProc],0
+  jne         stack_cleanup_done
+  mov         dword ptr [_LastStackPlace],0
+  
+stack_cleanup_done:
+
+  ;# Save return
+  
+  ;# Get offset for element Params of SystemProc structure
+  call        _GetParamsOffset
+  mov         edx,dword ptr [ebp+8]
+  add         edx,eax
+      
+  ;# proc->Params[0].Value = Low double word of result
+  call        _GetValueOffsetParam
+  mov         ecx,dword ptr [ebp-8]
+  mov         dword ptr [edx+eax],ecx
+  
+  ;# proc->Params[0]._value = High double word of result
+  call        _Get_valueOffsetParam
+  mov         ecx,dword ptr [ebp-12]
+  mov         dword ptr [edx+eax],ecx
+  
+  ;# Proc result: OK
+  push        dword ptr [ebp+8]
+  call        _SetProcResultOk
+  pop         eax
+  
+  ;# In case of POPT_ERROR -> GetLastError
+  push        eax
+  call        _GetErrorOption
+  cmp         eax,0
+  pop         eax
+  je          handling_error_option_done
+  call        dword ptr [EMAIL PROTECTED]
+  mov         dword ptr [_LastError],eax
+  
+handling_error_option_done:
+  IFDEF SYSTEM_DEBUG_LOG
+    SYSTEM_EVENT offset LogAfterCall
+    
+    push        dword ptr [ebp-12]
+    push        dword ptr [ebp-8]
+    SYSTEM_LOG_ADD offset LogReturnAfter
+    add         esp,8
+  
+    SYSTEM_LOG_POST
+  ENDIF
+  
+  ;# Return
+  mov         eax,dword ptr [ebp+8]
+  ;# Restore registers
+  pop         esi
+  pop         edi
+  pop         ebx
+  ;# Restore stack pointer
+  mov         esp,ebp
+  pop         ebp
+  ret
+FUNC_END _CallProc
+
+
+
+FUNC_DECL _RealCallBack
+  ;# Save stack
+  push        ebp
+  mov         ebp,esp
+  
+  ;# Stack space for local variables
+  ;# ebp-16 = Size of ProcParameter structure
+  ;# ebp-12 = ArgsSize
+  ;# ebp-8  = Arguments pointer
+  ;# ebp-4  = proc
+  sub         esp,16
+  
+  ;# Save all usable registers to free our hands
+  push        ebx
+  push        edi
+  push        esi
+  
+  ;# Arguments pointer
+  ;# 1-st arg (4 bytes), return (4 bytes) => add 8 bytes
+  mov         dword ptr [ebp-8],ebp
+  add         dword ptr [ebp-8],8
+  
+  ;# Our callback proc
+  mov         dword ptr [ebp-4],eax
+
+  IFDEF SYSTEM_DEBUG_LOG
+    SYSTEM_LOG_INIT  
+    SYSTEM_LOG_ADD offset LogCalled
+    ;# LastProc->ProcName
+    call        _GetProcNameOffset
+    mov         ecx,dword ptr [_LastProc]
+    add         eax,ecx
+    SYSTEM_LOG_ADD eax  
+    SYSTEM_EVENT offset LogShortAfter
+    SYSTEM_LOG_POST
+  ENDIF
+  
+  call        _GetCloneOffset
+  mov         edx,eax
+  mov         ecx,dword ptr [ebp-4]
+  
+  ;# 1. Find last unused clone
+  jmp         clone_load
+clone_next:
+  mov         ecx,dword ptr [eax]
+  mov         dword ptr [ebp-4],ecx
+clone_load:
+  lea         eax,[ecx+edx]
+  cmp         dword ptr [eax],0
+  jne         clone_next
+  
+  ;# 2. Create new clone
+  push        edx
+  push        ecx
+  call        _GlobalCopy
+  pop         ecx
+  pop         edx
+  ;# proc->Clone = Result of GlobalCopy
+  mov         ecx,dword ptr [ebp-4]
+  mov         dword ptr [ecx+edx],eax
+  ;# proc = proc->Clone
+  mov         dword ptr [ebp-4],eax
+  
+  ;# 3. Set clone option
+  push        eax
+  call        _SetCloneOption
+  pop         eax
+  
+  ;# Read Arguments
+  
+  ;# Get number of parameters  
+  push        dword ptr [ebp-4]
+  call        _GetParamCount
+  add         esp,4
+  
+  ;# Skip if there are no parameters
+  cmp         eax,0 
+  jle         cb_params_loop_done
+  
+  ;# Save number of parameters on stack
+  push        eax
+
+  ;# Get size of ProcParameter structure
+  call        _GetSizeOfProcParam
+  mov         dword ptr [ebp-16],eax
+  
+  ;# Get offset for element Params of SystemProc structure
+  call        _GetParamsOffset
+  add         eax,dword ptr [ebp-4]
+  
+  ;# Calculate offset for the Parameter 1    
+  add         eax,dword ptr [ebp-16]
+  
+  ;# Save offset for the Parameter 1 on stack
+  push        eax  
+ 
+  ;# Size offset of parameter
+  call        _GetSizeOffsetParam
+  push        eax
+
+  ;# Value offset of parameter
+  call        _GetValueOffsetParam
+  push        eax
+  
+  ;# _value offset of parameter
+  call        _Get_valueOffsetParam
+  push        eax
+      
+  ;# ebx = _value offset
+  pop         ebx
+  ;# edx = Value offset
+  pop         edx
+  ;# esi = Size offset
+  pop         esi
+  ;# eax = offset of current worked on parameter  
+  pop         eax
+  ;# ecx = n-th parameter
+  pop         ecx
+
+  ;# proc->ArgsSize = 0
+  mov         dword ptr [ebp-12],0
+ 
+cb_params_loop:
+  push ecx
+  ;# Size of current parameter == 2
+  cmp         dword ptr [eax+esi],2
+  jne         cb_params_default
+  ;# Long type
+  mov         ecx,dword ptr [ebp-8]
+  mov         ecx,dword ptr [ecx]
+  mov         dword ptr [eax+ebx],ecx
+  ;# (Arguments pointer)++
+  add         dword ptr [ebp-8],4
+  ;# ArgsSize += 4
+  add         dword ptr [ebp-12],4
+  
+cb_params_default:
+  ;# Default
+  mov         ecx,dword ptr [ebp-8]
+  mov         ecx,dword ptr [ecx]
+  mov         dword ptr [eax+edx],ecx
+  ;# (Arguments pointer)++
+  add         dword ptr [ebp-8],4
+  ;# ArgsSize += 4
+  add         dword ptr [ebp-12],4
+  ;# Next parameter
+  add         eax,dword ptr [ebp-16]
+  pop         ecx
+  loop        cb_params_loop
+
+cb_params_loop_done:
+  ;# proc->ArgsSize = ArgsSize
+  call        _GetArgsSizeOffset
+  add         eax,dword ptr [ebp-4]
+  mov         ecx,dword ptr [ebp-12]
+  mov         dword ptr [eax],ecx
+  
+  push        dword ptr [ebp-4]
+  call        _SetProcResultCallback
+  pop         eax
+  
+  ;# Return
+  ;# eax = proc
+  ;# Save temporary stack info
+  push        ebp
+  ;# Push LastStackPlace
+  mov         dword ptr [_LastStackPlace],esp
+  ;# Restore real stack
+  mov         esp,dword ptr [_LastStackReal]
+  ;# Pop LastStackReal
+  pop         ebp
+  
+  ;# Fake return from System::Call
+  
+  ;# Restore registers
+  pop         esi
+  pop         edi
+  pop         ebx
+  ;# Restore stack pointer
+  mov         esp,ebp
+  pop         ebp
+  ;# Return
+  ret
+FUNC_END _RealCallBack
+
+
+
+FUNC_DECL _CallBack
+  ;# Save stack
+  push        ebp
+  mov         ebp,esp
+  
+  ;# Save all usable registers to free our hands
+  push        ebx
+  push        edi
+  push        esi
+
+  IFDEF SYSTEM_DEBUG_LOG
+    SYSTEM_LOG_INIT
+    SYSTEM_LOG_ADD offset LogReturn
+    SYSTEM_EVENT offset LogBefore
+    SYSTEM_LOG_POST
+  ENDIF
+  
+  ;# Get offset for element Params of SystemProc structure
+  call        _GetParamsOffset
+  add         eax,dword ptr [ebp+8]
+  push        eax
+  
+  ;# Value offset
+  call        _GetValueOffsetParam
+  mov         ecx,eax
+  
+  ;# _value offset
+  call        _Get_valueOffsetParam
+  mov         edx,eax
+  
+  ;# offset of Params element within SystemProc structure
+  pop         eax  
+  
+  push        dword ptr [eax+ecx]
+  push        dword ptr [eax+edx]
+  
+  ;# Adjust return statement
+  ;# if ((proc->Options & POPT_CDECL) != 0)
+  push        dword ptr [ebp+8]
+  call        _GetCDeclOption
+  cmp         eax,0
+  pop         edx
+  jne         _retexpr_stdcall
+  ;# retexpr[1] = proc->ArgsSize
+  call        _GetArgsSizeOffset	
+  mov         ecx,dword ptr [ebp+8]
+  mov         al,byte ptr [ecx+eax]
+  mov         byte ptr [_retexpr+1],al
+  jmp         set_return_addr
+_retexpr_stdcall:
+  mov         byte ptr [_retexpr+1],0
+set_return_addr:  
+  ;# Right return statement address
+  mov         dword ptr [_retaddr],offset _retexpr
+  
+  ;# Remove unneeded callback proc
+  push        dword ptr [ebp+8]
+  call        dword ptr [EMAIL PROTECTED]
+  
+  ;# Prepare return
+  ;# Callback proc result
+  pop         edx
+  pop         eax
+  
+  ;# Restore temporary stack and return
+
+  ;# Save real stack info
+  ;# Save previous stack location
+  ;# Push _LastStackReal
+  push        ebp
+  mov         dword ptr [_LastStackReal],esp
+  ;# Move stack pointer
+  mov         esp,dword ptr [_LastStackPlace]
+  ;# Pop _LastStackPlace
+  pop         ebp
+  
+  IFDEF SYSTEM_DEBUG_LOG
+    push        eax
+    push        edx
+    SYSTEM_EVENT offset LogShortBefore
+    SYSTEM_LOG_POST
+    ;# Callback proc result
+    pop         edx
+    pop         eax
+  ENDIF
+  
+  ;# Fake return from Callback
+  
+  ;# Restore registers
+  pop         esi
+  pop         edi
+  pop         ebx
+  ;# Restore stack pointer
+  mov         esp,ebp
+  pop         ebp
+  ;# Return
+  jmp         dword ptr [_retaddr]
+  
+FUNC_END _CallBack
+
+END
+
diff -urN nsis-2.40-src.orig/Contrib/System/Source/System.c nsis-2.40-src/Contrib/System/Source/System.c
--- nsis-2.40-src.orig/Contrib/System/Source/System.c	2008-08-15 20:13:21.000000000 +0200
+++ nsis-2.40-src/Contrib/System/Source/System.c	2008-08-15 20:13:21.000000000 +0200
@@ -7,6 +7,9 @@
 #include "System.h"
 #ifndef __GNUC__
 #include <crtdbg.h>
+#else
+#define _RPT0(type, msg)
+#define _CRT_WARN           0
 #endif /* __GNUC__ */
 #include <objbase.h>
 
@@ -29,7 +32,6 @@
     1, // PAT_GUID
     0}; // PAT_CALLBACK (Size will be equal to 1)
 
-int z1, z2; // I've made them static for easier use at callback procs
 int LastStackPlace;
 int LastStackReal;
 DWORD LastError;
@@ -41,8 +43,6 @@
 char retexpr[4];
 HANDLE retaddr;
 
-#ifndef __GNUC__
-
 /*
 FIXME:
 GCC cannot compile the inline assembly used by System::Call and
@@ -61,14 +61,13 @@
 
 #ifdef SYSTEM_LOG_DEBUG
 
-// System log debuggin turned on
-#define SYSTEM_EVENT(a)  { _asm { mov logespsave, esp }; LogEvent(a); }
-#define SYSTEM_LOG_ADD(a)  { lstrcat(syslogbuf, a); }
-#define SYSTEM_LOG_POST     { lstrcat(syslogbuf, "\n"); WriteToLog(syslogbuf); *syslogbuf = 0; }
+// System log debugging turned on
+#define SYSTEM_LOG_ADD(a)  { register int _len = lstrlen(syslogbuf); lstrcpyn(syslogbuf + _len, a, sizeof(syslogbuf) - _len); }
+#define SYSTEM_LOG_POST     { SYSTEM_LOG_ADD("\n"); WriteToLog(syslogbuf); *syslogbuf = 0; }
 
 HANDLE logfile = NULL;
 char syslogbuf[4096] = "";
-int logop = 0, logespsave;
+int logop = 0;
 
 void WriteToLog(char *buffer)
 {
@@ -92,14 +91,6 @@
 //    FlushFileBuffers(logfile);
 }
 
-void LogEvent(char *a)
-{
-    char buffer[1024];
-    wsprintf(buffer, "%s  ESP = 0x%08X  Stack = 0x%08X  Real = 0x%08X", a, 
-        logespsave, LastStackPlace, LastStackReal);
-    SYSTEM_LOG_ADD(buffer);
-}
-
 PLUGINFUNCTION(Debug)
 {
     char *o1;
@@ -261,8 +252,6 @@
         GlobalFree((HANDLE) proc); // No, free it
 } PLUGINFUNCTIONEND
 
-#endif /* __GNUC__ */
-
 PLUGINFUNCTIONSHORT(Int64Op)
 {
     __int64 i1, i2 = 0, i3, i4;
@@ -320,8 +309,6 @@
     return myatoi(buffer);
 }
 
-#ifndef __GNUC__
-
 SystemProc *PrepareProc(BOOL NeedForCall)
 {
     int SectionType = PST_PROC, // First section is always proc spec
@@ -916,368 +903,6 @@
     while (i >= 0);
 }
 
-void _alloca_probe();
-
-SystemProc __declspec(naked) *CallProc(SystemProc *proc)
-{
-    int z3;
-
-    _asm
-    {
-        // Save stack
-        push    ebp
-        mov     ebp, esp
-        // Stack space for local variables
-        sub     esp, __LOCAL_SIZE   
-        // Save all usable registers to free our hands
-        push    ebx
-        push    edi
-        push    esi
-    }
-
-    SYSTEM_LOG_ADD("\t\tCall:\n");
-    SYSTEM_EVENT("\t\t\tBefore call        ")
-
-    if (CallbackIndex && (!(proc->Options & POPT_GENSTACK)))
-    {
-        _asm
-        {
-            push    ebp
-            // Save previous stack location
-            mov     LastStackReal, esp
-        }
-
-        if (LastStackPlace == 0)
-        {
-            _asm
-            {
-                // Create new stack
-                mov     eax, NEW_STACK_SIZE
-                call    _alloca_probe
-                mov     LastStackPlace, esp
-            }
-        } else
-            _asm
-            {
-                // Move stack pointer
-                mov     esp, LastStackPlace
-            }
-    }
-
-    // Push arguments to stack
-    for (z1 = proc->ParamCount; z1 > 0; z1--)
-    {
-        // Long types
-        if (proc->Params[z1].Size == 2)
-        {
-            z2 = proc->Params[z1]._value;
-            _asm    push    z2;
-        }
-        // Default
-        z2 = proc->Params[z1].Value;
-        _asm    push    z2;
-    }
-
-    // Call the proc and save return
-    z1 = (int) proc->Proc;
-
-    // Save proc
-    proc->Clone = (SystemProc *) LastProc;
-    _asm 
-    {
-        mov eax, proc
-        mov LastProc, eax
-    }
-    //LastProc = proc;
-
-    SYSTEM_EVENT("\n\t\t\tNear call          ")
-    SYSTEM_LOG_POST;
-
-    // workaround for bug #1535007
-    // http://sf.net/tracker/index.php?func=detail&aid=1535007&group_id=22049&atid=373085
-    //
-    // If a function returns short and doesn't clear eax in the process,
-    // it will only set 2 bytes of eax, and the other 2 bytes remain
-    // "random". In this case, they'll be part of the proc pointer.
-    //
-    // To avoid this, eax is cleared before the function is called. This
-    // makes sure the value eax will contain is only what the function
-    // actually sets.
-    _asm xor eax, eax
-
-    _asm
-    {
-        // Call
-        call    z1
-        // Return
-        mov     z1, eax
-        mov     z2, edx
-    }
-
-    SYSTEM_LOG_ADD("Back from ");
-    SYSTEM_LOG_ADD(LastProc->ProcName);
-    SYSTEM_EVENT("\n\t\t\tShort-After call   ")
-
-    if ((CallbackIndex) && (!(LastProc->Options & POPT_GENSTACK)))
-    {
-        _asm
-        {
-            // Restore real stack location
-            mov     LastStackPlace, esp
-            mov     esp, LastStackReal
-            pop     ebp
-        }
-    }
-
-    // Restore proc
-    _asm 
-    {
-       mov eax, LastProc
-       mov proc, eax
-    }
-//    proc = LastProc;
-    LastProc = proc->Clone;
-
-    // In case of cdecl convention we should clear stack
-    if ((proc->Options & POPT_CDECL) != 0)
-    {
-        if ((CallbackIndex > 0) && ((proc->Options & POPT_GENSTACK) == 0))
-        {
-            // In case of temporary stack
-            for (z3 = 1; z3 <= proc->ParamCount; z3++)
-                LastStackPlace += 4*proc->Params[z3].Size;
-        } else
-        {
-            // in case of real stack
-            for (z3 = 1; z3 <= proc->ParamCount; z3++)
-            {   
-                if (proc->Params[z3].Size == 2) 
-                    _asm    pop    edx;
-                _asm    pop    edx;
-            }
-        }
-    }
-
-    // In case of cleared call-proc-queue -> clear allocated stack place (more flexible)
-    if (LastProc == NULL) LastStackPlace = (int) NULL;
-
-    // Save return
-    proc->Params[0].Value = z1;
-//    if (proc->Params[0].Size == 2) 
-        proc->Params[0]._value = z2;
-    // Proc result: OK
-    proc->ProcResult = PR_OK;
-
-    // In case of POPT_ERROR -> GetLastError
-    if ((proc->Options & POPT_ERROR) != 0)
-    {
-        LastError = GetLastError();
-    }
-
-    SYSTEM_EVENT("\n\t\t\tAfter call         ")
-#ifdef SYSTEM_LOG_DEBUG
-    {
-        char buf[1024];
-        wsprintf(buf, "\n\t\t\tReturn              0x%08X    0x%08X", z1, z2);
-        SYSTEM_LOG_ADD(buf);
-    }
-#endif
-    SYSTEM_LOG_POST;
-
-    _asm 
-    {
-        // Return
-        mov     eax, proc
-        // Restore registers
-        pop     esi
-        pop     edi
-        pop     ebx
-        // Restore stack pointer
-        mov     esp, ebp
-        pop     ebp
-        // Return
-        ret
-    }
-}
-
-SystemProc __declspec(naked) *RealCallBack()
-{
-    SystemProc *proc;
-    
-    _asm 
-    {
-        // Save stack
-        push    ebp
-        mov     ebp, esp
-        // Stack space for local variables
-        sub     esp, __LOCAL_SIZE   
-        // Save all usable registers to free our hands
-        push    ebx
-        push    edi
-        push    esi
-
-        // Arguments pointer
-        mov     z2, esp    // 1-st arg - 4*4 (pushes) - 4 (return) - __LOCAL_SIZE
-        add     z2, __LOCAL_SIZE
-        add     z2, 5*4
-        // Our callback proc
-        mov     proc, eax
-    }
-
-    SYSTEM_LOG_ADD("Called callback from ");
-    SYSTEM_LOG_ADD(LastProc->ProcName);
-    SYSTEM_EVENT("\n\t\t\tShort-After call   ")
-    SYSTEM_LOG_POST;
-
-    // Find last unused clone
-    while ((proc->Clone != NULL)) proc = proc->Clone;
-    // 2. Create new clone
-    proc = (proc->Clone = GlobalCopy(proc));
-    // 3. Set clone option
-    proc->Options |= POPT_CLONE;
-
-    // Read arguments
-    proc->ArgsSize = 0;
-    for (z1 = 1; z1 <= proc->ParamCount; z1++)
-    {
-        // Default
-        proc->Params[z1].Value = *(((int*)z2)++);
-        proc->ArgsSize += 4;
-        // Long only
-        if (proc->Params[z1].Size == 2)
-        {
-            proc->Params[z1]._value = *(((int*)z2)++);
-            proc->ArgsSize += 4;
-        }
-    }
-    proc->ProcResult = PR_CALLBACK;
-
-    _asm
-    {
-        // Return
-        mov     eax, proc
-
-        // Save temporary stack info
-        push    ebp
-//        push    LastStackPlace
-        mov     LastStackPlace, esp
-        // Restore real stack
-        mov     esp, LastStackReal
-        pop     ebp
-//        pop     LastStackReal
-    }
-
-    _asm
-    {
-        // Fake return from System::Call
-
-        // Restore registers
-        pop     esi
-        pop     edi
-        pop     ebx
-        // Restore stack pointer
-        mov     esp, ebp
-        pop     ebp
-        // Return
-        ret
-    }
-}
-
-
-SystemProc __declspec(naked) *CallBack(SystemProc *proc)
-{
-    _asm 
-    {
-        // Save stack
-        push    ebp
-        mov     ebp, esp
-        // Stack space for local variables
-        sub     esp, __LOCAL_SIZE
-        // Save all usable registers to free our hands
-        push    ebx
-        push    edi
-        push    esi
-    }
-
-  // MessageBox(NULL, "cool1", "Cool", MB_OK);
-
-    SYSTEM_LOG_ADD("\t\tReturn from callback:\n");
-    SYSTEM_EVENT("\t\t\tBefore call-back   ");
-    SYSTEM_LOG_POST;
-
-    //z1 = proc->Params[0].Value;
-    //z2 = proc->Params[0]._value;
-    //z1 = &(proc->Params[0].Value);
-    _asm
-    {
-        mov eax, proc
-        add eax, SYSTEM_ZERO_PARAM_VALUE_OFFSET
-        push [eax]
-        push [eax+4]
-    }
-    
-    // Adjust return statement
-    if ((proc->Options & POPT_CDECL) == 0) retexpr[1] = proc->ArgsSize;
-    else retexpr[1] = 0x0;
-
-    // Right return statement address
-    retaddr = (HANDLE) retexpr;
-
-    // Remove unneeded callback proc
-    GlobalFree((HANDLE) proc);
-
-//    MessageBox(NULL, "cool2", "Cool", MB_OK);
-
-    _asm
-    {
-        // Prepare return
-        // callback proc result
-        pop edx
-        pop eax
-
-        // Restore temporary stack and return
-
-        // Save real stack info
-        // Save previous stack location
-//        push    LastStackReal
-        push    ebp
-        mov     LastStackReal, esp
-        // Move stack pointer
-        mov     esp, LastStackPlace
-//        pop     LastStackPlace
-        pop     ebp        
-    }
-        
-#ifdef SYSTEM_LOG_DEBUG
-    _asm
-    {
-        push eax
-        push edx
-    }
-    SYSTEM_EVENT("\n\t\t\tSh-Before call-back");
-    SYSTEM_LOG_POST;        
-    _asm
-    {
-        // callback proc result
-        pop edx
-        pop eax
-    }
-#endif
-
-    // Fake return from Callback
-    _asm {
-        // Restore registers
-        pop     esi
-        pop     edi
-        pop     ebx
-        // Restore stack pointer
-        mov     esp, ebp
-        pop     ebp
-        // Return
-        jmp     retaddr
-    }
-}
-
 HANDLE CreateCallback(SystemProc *cbproc)
 {
     char *mem;
@@ -1387,9 +1012,7 @@
     proc->Params[0].Value = (int) proc->Proc;
 }
 
-#endif /* __GNUC__ */
-
-BOOL WINAPI _DllMainCRTStartup(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
+BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
 {
         g_hInstance=hInst;
         
@@ -1411,3 +1034,139 @@
         return TRUE;
 }
 
+/*
+Returns size by which the stack should be expanded
+*/
+unsigned int GetNewStackSize(void)
+{
+		return NEW_STACK_SIZE;
+}
+
+/*
+Returns non-zero value if GENSTACK option is set
+*/
+unsigned int GetGenStackOption(SystemProc *proc)
+{
+		return (proc->Options & POPT_GENSTACK);
+}
+
+/*
+Returns non-zero value if CDECL option is set
+*/
+unsigned int GetCDeclOption(SystemProc *proc)
+{
+		return (proc->Options & POPT_CDECL);
+}
+
+/*
+Returns non-zero value if Error option is set
+*/
+unsigned int GetErrorOption(SystemProc *proc)
+{
+		return (proc->Options & POPT_ERROR);
+}
+
+/*
+Returns offset for element Proc of SystemProc structure
+*/
+unsigned int GetProcOffset(void)
+{
+		return (unsigned int)(&(((SystemProc *)0)->Proc));
+}
+
+/*
+Returns offset for element Clone of SystemProc structure
+*/
+unsigned int GetCloneOffset(void)
+{
+		return (unsigned int)(&(((SystemProc *)0)->Clone));
+}
+
+/*
+Returns offset for element ProcName of SystemProc structure
+*/
+unsigned int GetProcNameOffset(void)
+{
+		return (unsigned int)(&(((SystemProc *)0)->ProcName));
+}
+
+/*
+Returns offset for element ArgsSize of SystemProc structure
+*/
+unsigned int GetArgsSizeOffset(void)
+{
+		return (unsigned int)(&(((SystemProc *)0)->ArgsSize));
+}
+
+/*
+Returns number of parameters
+*/
+unsigned int GetParamCount(SystemProc *proc)
+{
+		return proc->ParamCount;
+}
+
+/*
+Returns offset for element Params of SystemProc structure
+*/
+unsigned int GetParamsOffset(void)
+{
+		return (unsigned int)(&(((SystemProc *)0)->Params));
+}
+
+/*
+Returns size of ProcParameter structure
+*/
+unsigned int GetSizeOfProcParam(void)
+{
+		return (sizeof(ProcParameter));
+}
+
+
+/*
+Returns offset for element Size of ProcParameter structure
+*/
+unsigned int GetSizeOffsetParam(void)
+{
+		return (unsigned int)(&(((ProcParameter *)0)->Size));
+}
+
+/*
+Returns offset for element Value of ProcParameter structure
+*/
+unsigned int GetValueOffsetParam(void)
+{
+		return (unsigned int)(&(((ProcParameter *)0)->Value));
+}
+
+/*
+Returns offset for element _value of ProcParameter structure
+*/
+unsigned int Get_valueOffsetParam(void)
+{
+		return (unsigned int)(&(((ProcParameter *)0)->_value));
+}
+
+/*
+Sets "CLONE" option
+*/
+void SetCloneOption(SystemProc *proc)
+{
+	proc->Options |= POPT_CLONE;
+}
+
+/*
+Sets Result of procedure call to be "OK"
+*/
+void SetProcResultOk(SystemProc *proc)
+{
+	proc->ProcResult = PR_OK;
+}
+
+/*
+Sets Result of procedure call to be "CALLBACK"
+*/
+void SetProcResultCallback(SystemProc *proc)
+{
+	proc->ProcResult = PR_CALLBACK;
+}
diff -urN nsis-2.40-src.orig/Contrib/System/Source/System.h nsis-2.40-src/Contrib/System/Source/System.h
--- nsis-2.40-src.orig/Contrib/System/Source/System.h	2005-05-06 12:23:32.000000000 +0200
+++ nsis-2.40-src/Contrib/System/Source/System.h	2005-05-06 12:23:32.000000000 +0200
@@ -58,10 +58,6 @@
 {
 	int Type;
 	int Option; // -1 -> Pointer, 1-... -> Special+1
-
-    // if you'll change ProcParameter or SystemProc structure - update this value
-#define  SYSTEM_ZERO_PARAM_VALUE_OFFSET 0x820
-
 	int Value;	// it can hold any 4 byte value 
     int _value; // value buffer for structures > 4 bytes (I hope 8 bytes will be enough)
     int Size; // Value real size (should be either 1 or 2 (the number of pushes))
# Copyright (c) 2008 Thomas Gaugler <[EMAIL PROTECTED]>
#
# Permission is hereby granted, free of charge, to any person
# obtaining a copy of this software and associated documentation
# files (the "Software"), to deal in the Software without
# restriction, including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following
# conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
# OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.
#
#
# Unit test implementation for System plug-in 
# of Nullsoft Installer System.
#

import unittest
from ctypes import *
from ctypes.wintypes import HGLOBAL, HWND, UINT

SIZE_T = c_ulong

GPTR = 0x0040

NSIS_MAX_STRLEN = 1024
NSIS_MAX_VARS = 25

class PlugInEnv:
    class STACK_TYPE(Structure):
        pass

    STACK_TYPE._fields_ = [("next", POINTER(STACK_TYPE)), ("text", c_char * NSIS_MAX_STRLEN)]

    def getstacktype(self):
        """ Get type of internal stack structure
	"""
        return POINTER(self.STACK_TYPE)

    def getstackptr(self):
        """ Get pointer to head of stack
        """
        return pointer(self.head)

    def getvarptr(self):
        """ Get pointer to array of user variables
	"""
	return cast(self.vars, c_char_p)

    def getmaxstrlen(self):
        """ Get maximum allowed string length for stack and user variables
	"""
        return NSIS_MAX_STRLEN 

    def setuservariable(self, varnum, string):
        """ Set user variable
	"""
	if self.vars and varnum >= 0 and varnum < NSIS_MAX_VARS:
            memmove(addressof(self.vars) + (varnum * NSIS_MAX_STRLEN), string, len(string))
    
    def getuservariable(self, varnum):
        """ Get user variable
	"""
	string = None
	if self.vars and varnum >= 0 and varnum < NSIS_MAX_VARS:
            string = string_at(addressof(self.vars) + (varnum * NSIS_MAX_STRLEN))
        return string

    def pushstring(self, string):
        """ Push string on top of stack
	"""
        mem = windll.kernel32.GlobalAlloc(UINT(GPTR), SIZE_T(sizeof(self.STACK_TYPE)))
        if mem:
            elem = self.STACK_TYPE.from_address(mem)
            elem.next = self.head
            elem.text = string
            self.head = pointer(elem)

    def popstring(self):
        """ Pop topmost string from stack
	"""
        string = None
	if self.head:
             elem = self.head.contents
             string = elem.text
	     if elem.next:
                 next = addressof(elem.next.contents)
                 self.head =  pointer(self.STACK_TYPE.from_address(next))
             else:
	         self.head = cast(None, POINTER(self.STACK_TYPE))
             windll.kernel32.GlobalFree(HGLOBAL(addressof(elem)))
        return string

    def walk(self):
        """ Walk through stack
	"""
        ptr = self.head
        while ptr:
             elem = ptr.contents
             print "current:", addressof(elem)
             print "text:", elem.text
             ptr = elem.next
	     if ptr:
                 print "next:", addressof(ptr.contents)
             else:
	         print "next: NULL" 

    def __init__(self, *args, **kwds):
	""" Initialize stack and user variables
	"""
	self.head = cast(None, POINTER(self.STACK_TYPE))
	self.vars = create_string_buffer("", NSIS_MAX_VARS * NSIS_MAX_STRLEN)


class TestSystemPlugIn(unittest.TestCase):

    def setUp(self):
        """ Load System Plugin
	"""
	self.plugin = windll.kernel32.LoadLibraryA("System.dll") 
        self.env = PlugInEnv()
	self.parent = HWND(0)

	# Enable debug facility if available
	if windll.kernel32.GetProcAddress(self.plugin, "Debug"):
	    self.env.pushstring("Debug.log")
	    self.callFunc("Debug")

    def callFunc(self, function):
        """ Call the given Plugin function
	"""
	prototype = CFUNCTYPE(c_int, HWND, c_int, c_char_p, POINTER(self.env.getstacktype()))
	func = prototype(windll.kernel32.GetProcAddress(self.plugin, function))
                
        if func:
            func(self.parent, c_int(self.env.getmaxstrlen()), self.env.getvarptr(), self.env.getstackptr())

    def testWinVerReg(self):
        """ Check for Windows Version (return value in user variable)
	"""
	self.env.pushstring("kernel32::GetVersion() i.r0")
	self.callFunc("Call");
	self.env.popstring()
	self.assertEqual(int(self.env.getuservariable(0)), windll.kernel32.GetVersion(), "mismatch of Windows version retrieved via Sytem plugin and direct Win32 API call")

    def testWinVerStack(self):
        """ Check for Windows Version (return value on stack)
	"""
	self.env.pushstring("kernel32::GetVersion() i.s")
	self.callFunc("Call");
        self.assertEqual(int(self.env.popstring()), windll.kernel32.GetVersion(), "mismatch of Windows version retrieved via Sytem plugin and direct Win32 API call")

    def testEnumWindows(self):
        """ Enumerate top-level windows using callback function
	"""
        windows = list()
        self.env.pushstring("(i.r1, i) iss")
        self.callFunc("Get")
        self.env.setuservariable(2, self.env.popstring())
        self.env.pushstring("user32::EnumWindows(k r2, i) i.s")
        self.callFunc("Call");
	while self.env.popstring() == "callback1":
            # Add window handle to list
            windows.append(int(self.env.getuservariable(1)))

            # Get name and class of window
            self.env.pushstring("user32::GetWindowText(i r1, t.r3, i " + str(self.env.getmaxstrlen()) + ")")
            self.callFunc("Call")
            self.env.pushstring("user32::GetClassName(i r1, t.r4, i " + str(self.env.getmaxstrlen()) + ")")
            self.callFunc("Call")
            print self.env.getuservariable(3), "[", self.env.getuservariable(4), "]"

            # Push return value of callback function onto stack
            self.env.pushstring("1")
            self.env.pushstring(self.env.getuservariable(2))
            self.callFunc("Call")

        self.env.pushstring(self.env.getuservariable(2))
        self.callFunc("Free")

        self.failUnless(windll.user32.GetTopWindow(0) in windows, "Could not find top most window in list of windows")

    def tearDown(self):
        """ Unload System Plugin
	"""
        windll.kernel32.FreeLibrary(self.plugin)

if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(TestSystemPlugIn)
    unittest.TextTestRunner(verbosity=2).run(suite)

Reply via email to