implemented RFE #1778973 - nsExec & ExecDos - Support DisableX64FSRedirection feature
also fixed bug #1889317 git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@5542 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
parent
efebf6bedd
commit
8fba6791ad
1 changed files with 77 additions and 53 deletions
|
@ -82,63 +82,92 @@ BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) {
|
||||||
#define CHAR4_TO_DWORD(a,b,c,d) (((DWORD)CHAR2_TO_WORD(a,b))|(CHAR2_TO_WORD(c,d)<<16))
|
#define CHAR4_TO_DWORD(a,b,c,d) (((DWORD)CHAR2_TO_WORD(a,b))|(CHAR2_TO_WORD(c,d)<<16))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
BOOL IsWOW64() {
|
||||||
|
typedef BOOL (WINAPI *LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
|
||||||
|
BOOL wow64;
|
||||||
|
LPFN_ISWOW64PROCESS fnIsWow64Process;
|
||||||
|
|
||||||
|
fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress(
|
||||||
|
GetModuleHandle("kernel32"), "IsWow64Process");
|
||||||
|
|
||||||
|
if (fnIsWow64Process != NULL) {
|
||||||
|
if (fnIsWow64Process(GetCurrentProcess(), &wow64)) {
|
||||||
|
return wow64;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
void ExecScript(int log) {
|
void ExecScript(int log) {
|
||||||
char szRet[128] = "";
|
char szRet[128] = "";
|
||||||
char *pExec;
|
|
||||||
int nComSpecSize;
|
|
||||||
char meDLLPath[MAX_PATH];
|
char meDLLPath[MAX_PATH];
|
||||||
char *p;
|
|
||||||
char *executor;
|
char *executor;
|
||||||
char *g_exec;
|
char *g_exec;
|
||||||
|
char *pExec;
|
||||||
unsigned int g_to;
|
unsigned int g_to;
|
||||||
BOOL bOEM;
|
BOOL bOEM;
|
||||||
|
|
||||||
nComSpecSize = GetModuleFileName(g_hInst, meDLLPath, MAX_PATH) + 2; // 2 chars for quotes
|
if (IsWOW64()) {
|
||||||
p = meDLLPath + nComSpecSize - 2; // point p at null char of meDLLPath
|
char *p;
|
||||||
g_exec = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+nComSpecSize+2); // 1 for space, 1 for null
|
int nComSpecSize;
|
||||||
*g_exec = '"';
|
|
||||||
executor = g_exec + 1;
|
|
||||||
|
|
||||||
do
|
nComSpecSize = GetModuleFileName(g_hInst, meDLLPath, MAX_PATH) + 2; // 2 chars for quotes
|
||||||
{
|
g_exec = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+nComSpecSize+2); // 1 for space, 1 for null
|
||||||
if (*p == '\\')
|
p = meDLLPath + nComSpecSize - 2; // point p at null char of meDLLPath
|
||||||
break;
|
*g_exec = '"';
|
||||||
p = CharPrev(meDLLPath, p);
|
executor = g_exec + 1;
|
||||||
}
|
|
||||||
while (p > meDLLPath);
|
|
||||||
if (p == meDLLPath)
|
|
||||||
{
|
|
||||||
// bad path
|
|
||||||
pushstring("error");
|
|
||||||
GlobalFree(g_exec);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
*p = 0;
|
do
|
||||||
GetTempFileName(meDLLPath, "ns", 0, executor);
|
|
||||||
*p = '\\';
|
|
||||||
if (CopyFile(meDLLPath, executor, FALSE))
|
|
||||||
{
|
|
||||||
HANDLE hFile, hMapping;
|
|
||||||
LPBYTE pMapView;
|
|
||||||
PIMAGE_NT_HEADERS pNTHeaders;
|
|
||||||
hFile = CreateFile(executor, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING,0, 0);
|
|
||||||
hMapping = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, NULL);
|
|
||||||
pMapView = MapViewOfFile(hMapping, FILE_MAP_WRITE, 0, 0, 0);
|
|
||||||
if (pMapView)
|
|
||||||
{
|
{
|
||||||
pNTHeaders = (PIMAGE_NT_HEADERS)(pMapView + ((PIMAGE_DOS_HEADER)pMapView)->e_lfanew);
|
if (*p == '\\')
|
||||||
pNTHeaders->FileHeader.Characteristics = IMAGE_FILE_32BIT_MACHINE | IMAGE_FILE_LOCAL_SYMS_STRIPPED |
|
break;
|
||||||
IMAGE_FILE_LINE_NUMS_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE;
|
p = CharPrev(meDLLPath, p);
|
||||||
pNTHeaders->OptionalHeader.Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
|
}
|
||||||
pNTHeaders->OptionalHeader.AddressOfEntryPoint = (DWORD)WinMain - (DWORD)g_hInst;
|
while (p > meDLLPath);
|
||||||
UnmapViewOfFile(pMapView);
|
if (p == meDLLPath)
|
||||||
|
{
|
||||||
|
// bad path
|
||||||
|
pushstring("error");
|
||||||
|
GlobalFree(g_exec);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
CloseHandle(hMapping);
|
|
||||||
CloseHandle(hFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
lstrcat(g_exec, "\"");
|
*p = 0;
|
||||||
|
GetTempFileName(meDLLPath, "ns", 0, executor);
|
||||||
|
*p = '\\';
|
||||||
|
if (CopyFile(meDLLPath, executor, FALSE))
|
||||||
|
{
|
||||||
|
HANDLE hFile, hMapping;
|
||||||
|
LPBYTE pMapView;
|
||||||
|
PIMAGE_NT_HEADERS pNTHeaders;
|
||||||
|
hFile = CreateFile(executor, GENERIC_READ|GENERIC_WRITE, 0, NULL, OPEN_EXISTING,0, 0);
|
||||||
|
hMapping = CreateFileMapping(hFile, NULL, PAGE_READWRITE, 0, 0, NULL);
|
||||||
|
pMapView = MapViewOfFile(hMapping, FILE_MAP_WRITE, 0, 0, 0);
|
||||||
|
if (pMapView)
|
||||||
|
{
|
||||||
|
pNTHeaders = (PIMAGE_NT_HEADERS)(pMapView + ((PIMAGE_DOS_HEADER)pMapView)->e_lfanew);
|
||||||
|
pNTHeaders->FileHeader.Characteristics = IMAGE_FILE_32BIT_MACHINE | IMAGE_FILE_LOCAL_SYMS_STRIPPED |
|
||||||
|
IMAGE_FILE_LINE_NUMS_STRIPPED | IMAGE_FILE_EXECUTABLE_IMAGE;
|
||||||
|
pNTHeaders->OptionalHeader.Subsystem = IMAGE_SUBSYSTEM_WINDOWS_CUI;
|
||||||
|
pNTHeaders->OptionalHeader.AddressOfEntryPoint = (DWORD)WinMain - (DWORD)g_hInst;
|
||||||
|
UnmapViewOfFile(pMapView);
|
||||||
|
}
|
||||||
|
CloseHandle(hMapping);
|
||||||
|
CloseHandle(hFile);
|
||||||
|
}
|
||||||
|
|
||||||
|
lstrcat(g_exec, "\"");
|
||||||
|
|
||||||
|
// add space
|
||||||
|
pExec = g_exec + lstrlen(g_exec);
|
||||||
|
*pExec = ' ';
|
||||||
|
pExec++;
|
||||||
|
} else {
|
||||||
|
executor = NULL;
|
||||||
|
g_exec = (char *)GlobalAlloc(GPTR, sizeof(char)*g_stringsize+1); // 1 for null
|
||||||
|
pExec = g_exec;
|
||||||
|
}
|
||||||
|
|
||||||
g_to = 0; // default is no timeout
|
g_to = 0; // default is no timeout
|
||||||
bOEM = FALSE; // default is no OEM->ANSI conversion
|
bOEM = FALSE; // default is no OEM->ANSI conversion
|
||||||
|
@ -147,11 +176,6 @@ void ExecScript(int log) {
|
||||||
if (g_hwndParent)
|
if (g_hwndParent)
|
||||||
g_hwndList = FindWindowEx(FindWindowEx(g_hwndParent,NULL,"#32770",NULL),NULL,"SysListView32",NULL);
|
g_hwndList = FindWindowEx(FindWindowEx(g_hwndParent,NULL,"#32770",NULL),NULL,"SysListView32",NULL);
|
||||||
|
|
||||||
// add space
|
|
||||||
pExec = g_exec + lstrlen(g_exec);
|
|
||||||
*pExec = ' ';
|
|
||||||
pExec++;
|
|
||||||
|
|
||||||
params:
|
params:
|
||||||
popstring(pExec);
|
popstring(pExec);
|
||||||
if (my_strstr(pExec, "/TIMEOUT=") == pExec) {
|
if (my_strstr(pExec, "/TIMEOUT=") == pExec) {
|
||||||
|
@ -170,7 +194,7 @@ params:
|
||||||
{
|
{
|
||||||
pushstring("error");
|
pushstring("error");
|
||||||
*(pExec-2) = '\0'; // skip space and quote
|
*(pExec-2) = '\0'; // skip space and quote
|
||||||
DeleteFile(executor);
|
if (executor) DeleteFile(executor);
|
||||||
GlobalFree(g_exec);
|
GlobalFree(g_exec);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -220,7 +244,7 @@ params:
|
||||||
GetStartupInfo(&si);
|
GetStartupInfo(&si);
|
||||||
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
|
||||||
si.wShowWindow = SW_HIDE;
|
si.wShowWindow = SW_HIDE;
|
||||||
si.hStdInput = newstdin;
|
si.hStdInput = newstdin;
|
||||||
si.hStdOutput = newstdout;
|
si.hStdOutput = newstdout;
|
||||||
si.hStdError = newstdout;
|
si.hStdError = newstdout;
|
||||||
if (!CreateProcess(NULL,g_exec,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
|
if (!CreateProcess(NULL,g_exec,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
|
||||||
|
@ -323,10 +347,10 @@ done:
|
||||||
CloseHandle(pi.hProcess);
|
CloseHandle(pi.hProcess);
|
||||||
CloseHandle(newstdout);
|
CloseHandle(newstdout);
|
||||||
CloseHandle(read_stdout);
|
CloseHandle(read_stdout);
|
||||||
CloseHandle(newstdin);
|
CloseHandle(newstdin);
|
||||||
CloseHandle(read_stdin);
|
CloseHandle(read_stdin);
|
||||||
*(pExec-2) = '\0'; // skip space and quote
|
*(pExec-2) = '\0'; // skip space and quote
|
||||||
DeleteFile(executor);
|
if (executor) DeleteFile(executor);
|
||||||
GlobalFree(g_exec);
|
GlobalFree(g_exec);
|
||||||
if (log) {
|
if (log) {
|
||||||
GlobalUnlock(hUnusedBuf);
|
GlobalUnlock(hUnusedBuf);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue