From 213266164465090e17bcd4411b22e8fc7e6f2e6c Mon Sep 17 00:00:00 2001 From: anders_k Date: Tue, 6 Mar 2012 00:26:12 +0000 Subject: [PATCH] System plugin: Prefer A/W export when t type is used git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6220 212acab6-be3b-0410-9dea-997c60f758d6 --- Contrib/System/Source/System.c | 44 +++++++++++++--------------------- Contrib/System/Source/System.h | 6 +++++ 2 files changed, 23 insertions(+), 27 deletions(-) diff --git a/Contrib/System/Source/System.c b/Contrib/System/Source/System.c index 3842e6c5..8d5773b7 100644 --- a/Contrib/System/Source/System.c +++ b/Contrib/System/Source/System.c @@ -415,6 +415,7 @@ SystemProc *PrepareProc(BOOL NeedForCall) BOOL param_defined = FALSE; SystemProc *proc = NULL; TCHAR *ibuf, *ib, *sbuf, *cbuf, *cb; + unsigned int UsedTString = 0; // Retrieve proc specs cb = (cbuf = AllocString()); // Current String buffer @@ -612,7 +613,10 @@ SystemProc *PrepareProc(BOOL NeedForCall) case _T('m'): case _T('M'): temp2 = PAT_STRING; break; case _T('t'): - case _T('T'): temp2 = PAT_TSTRING; break; + case _T('T'): + temp2 = PAT_TSTRING; + ++UsedTString; + break; case _T('g'): case _T('G'): temp2 = PAT_GUID; break; case _T('w'): @@ -815,36 +819,20 @@ SystemProc *PrepareProc(BOOL NeedForCall) // Get proc address proc->Proc = NSISGetProcAddress(proc->Dll, proc->ProcName); -#ifdef _UNICODE - if ((proc->Proc != NULL) && - (proc->ProcName[0] == _T('l') && - proc->ProcName[1] == _T('s') && - proc->ProcName[2] == _T('t') && - proc->ProcName[3] == _T('r')) && - (lstrcmpi(_T("kernel32"), proc->DllName) == 0 || lstrcmpi(_T("kernel32.dll"), proc->DllName) == 0)) - { - int lastCharIdx = lstrlen(proc->ProcName) - 1; - - if (lastCharIdx > 1 && - proc->ProcName[lastCharIdx] != _T('A') && - proc->ProcName[lastCharIdx] != _T('W')) - { - proc->Proc = NULL; // force using W variant - } - } -#endif - if (proc->Proc == NULL) + if (UsedTString) { + FARPROC tproc; + TCHAR*ProcName = proc->ProcName; // This buffer has room for us to party on + unsigned int cch = lstrlen(ProcName); #ifdef _UNICODE - // automatic W discover - lstrcat(proc->ProcName, _T("W")); + STRSET2CH(ProcName+cch, _T('W'), _T('\0')); #else - // automatic A discover - lstrcat(proc->ProcName, "A"); + STRSET2CH(ProcName+cch, _T('A'), _T('\0')); #endif - if ((proc->Proc = NSISGetProcAddress(proc->Dll, proc->ProcName)) == NULL) - proc->ProcResult = PR_ERROR; - } + tproc = NSISGetProcAddress(proc->Dll, ProcName); + if (tproc) proc->Proc = tproc; + } + if (!proc->Proc) proc->ProcResult = PR_ERROR; } break; case PT_STRUCT: @@ -872,7 +860,9 @@ void ParamsIn(SystemProc *proc) int i; HGLOBAL* place; TCHAR *realbuf; +#ifndef _UNICODE LPWSTR wstr; +#endif i = (proc->ParamCount > 0)?(1):(0); while (TRUE) diff --git a/Contrib/System/Source/System.h b/Contrib/System/Source/System.h index 72656b06..a7f94ede 100644 --- a/Contrib/System/Source/System.h +++ b/Contrib/System/Source/System.h @@ -146,4 +146,10 @@ extern SystemProc *CallBack(SystemProc *proc); extern SystemProc *RealCallBack(); extern void CallStruct(SystemProc *proc); +#ifdef _UNICODE +# define STRSET2CH(str, c1, c2) ( *(DWORD*)(str) = ((c1)|(c2)<<16) ) +#else +# define STRSET2CH(str, c1, c2) ( *(WORD*)(str) = ((c1)|(c2)<<8) ) +#endif + #endif