diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /other-licenses/nsis | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'other-licenses/nsis')
88 files changed, 9363 insertions, 0 deletions
diff --git a/other-licenses/nsis/Contrib/ApplicationID/ApplicationID.rc b/other-licenses/nsis/Contrib/ApplicationID/ApplicationID.rc new file mode 100644 index 0000000000..77a48f6a83 --- /dev/null +++ b/other-licenses/nsis/Contrib/ApplicationID/ApplicationID.rc @@ -0,0 +1,101 @@ +// Microsoft Visual C++ generated resource script.
+//
+#include "resource.h"
+
+#define APSTUDIO_READONLY_SYMBOLS
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 2 resource.
+//
+#include "afxres.h"
+
+/////////////////////////////////////////////////////////////////////////////
+#undef APSTUDIO_READONLY_SYMBOLS
+
+/////////////////////////////////////////////////////////////////////////////
+// English (U.S.) resources
+
+#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
+#ifdef _WIN32
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+#pragma code_page(1252)
+#endif //_WIN32
+
+#ifdef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// TEXTINCLUDE
+//
+
+1 TEXTINCLUDE
+BEGIN
+ "resource.h\0"
+END
+
+2 TEXTINCLUDE
+BEGIN
+ "#include ""afxres.h""\r\n"
+ "\0"
+END
+
+3 TEXTINCLUDE
+BEGIN
+ "\r\n"
+ "\0"
+END
+
+#endif // APSTUDIO_INVOKED
+
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// Version
+//
+
+VS_VERSION_INFO VERSIONINFO
+ FILEVERSION 1,0,0,0
+ PRODUCTVERSION 1,0,0,0
+ FILEFLAGSMASK 0x17L
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x2L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904b0"
+ BEGIN
+ VALUE "FileDescription", "NSIS Plug-in for managing Application Modal ID resources"
+ VALUE "FileVersion", "1, 0, 0, 0"
+ VALUE "InternalName", "ApplicationID"
+ VALUE "LegalCopyright", "Original code Copyright (c) 2009 Mike Anchor"
+ VALUE "OriginalFilename", "ApplicationID.dll"
+ VALUE "ProductName", "ApplicationID"
+ VALUE "ProductVersion", "1, 0, 0, 0"
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1200
+ END
+END
+
+#endif // English (U.S.) resources
+/////////////////////////////////////////////////////////////////////////////
+
+
+
+#ifndef APSTUDIO_INVOKED
+/////////////////////////////////////////////////////////////////////////////
+//
+// Generated from the TEXTINCLUDE 3 resource.
+//
+
+
+/////////////////////////////////////////////////////////////////////////////
+#endif // not APSTUDIO_INVOKED
+
diff --git a/other-licenses/nsis/Contrib/ApplicationID/ApplicationID.vcproj b/other-licenses/nsis/Contrib/ApplicationID/ApplicationID.vcproj new file mode 100644 index 0000000000..6df3794340 --- /dev/null +++ b/other-licenses/nsis/Contrib/ApplicationID/ApplicationID.vcproj @@ -0,0 +1,206 @@ +<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="8.00"
+ Name="ApplicationID"
+ ProjectGUID="{EBB19D89-C251-4281-BC02-04559F609530}"
+ RootNamespace="ApplicationID"
+ Keyword="Win32Proj"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;APPLICATIONID_EXPORTS"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ ATLMinimizesCRunTimeLibraryUsage="true"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;APPLICATIONID_EXPORTS"
+ RuntimeLibrary="0"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ Detect64BitPortabilityProblems="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCWebDeploymentTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\Set.cpp"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath=".\resource.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ <File
+ RelativePath=".\ApplicationID.rc"
+ >
+ </File>
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/other-licenses/nsis/Contrib/ApplicationID/Set.cpp b/other-licenses/nsis/Contrib/ApplicationID/Set.cpp new file mode 100644 index 0000000000..82cb77e16f --- /dev/null +++ b/other-licenses/nsis/Contrib/ApplicationID/Set.cpp @@ -0,0 +1,219 @@ +/* + * Module : Set.cpp + * Purpose: NSIS Plug-in for setting shortcut ApplicationID property + * Created: 27/12/2009 + * Original code Copyright (c) 2009 Mike Anchor. + */ + +/* + * Additional Mozilla contributions: + * Unicode support + * Jump list deletion on uninstall + * Pinned item removal on uninstall + * contrib: <jmathies@mozilla.com> + */ + +#define INITGUID + +#include <windows.h> +#include <shlobj.h> +#include <propvarutil.h> +#include <propkey.h> +#include <stdio.h> + +#pragma comment (lib, "shlwapi.lib") + +#define MAX_STRLEN 1024 + +typedef struct _stack_t { + struct _stack_t *next; + TCHAR text[MAX_PATH]; +} stack_t; + +stack_t **g_stacktop; +unsigned int g_stringsize; +TCHAR *g_variables; + +// Indicates that an application supports dual desktop and immersive modes. In Windows 8, this property is only applicable for web browsers. +DEFINE_PROPERTYKEY(PKEY_AppUserModel_IsDualMode, 0x9F4C2855, 0x9F79, 0x4B39, 0xA8, 0xD0, 0xE1, 0xD4, 0x2D, 0xE1, 0xD5, 0xF3, 11); + +int popstring(TCHAR *str, int len); +void pushstring(const TCHAR *str, int len); + +extern "C" void __declspec(dllexport) Set(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) +{ + g_stringsize = string_size; + g_stacktop = stacktop; + g_variables = variables; + + { + IPropertyStore *m_pps = NULL; + WCHAR wszPath[MAX_PATH]; + WCHAR wszAppID[MAX_PATH]; + TCHAR szPath[MAX_PATH]; + TCHAR szAppID[MAX_PATH]; + TCHAR szDualMode[MAX_PATH]; + bool success = false; + + ZeroMemory(wszPath, sizeof(wszPath)); + ZeroMemory(wszAppID, sizeof(wszAppID)); + ZeroMemory(szPath, sizeof(szPath)); + ZeroMemory(szAppID, sizeof(szAppID)); + ZeroMemory(szDualMode, sizeof(szDualMode)); + + popstring(szPath, MAX_PATH); + popstring(szAppID, MAX_PATH); + bool dualMode = (popstring(szDualMode, MAX_PATH) == 0); // optional +#if !defined(UNICODE) + MultiByteToWideChar(CP_ACP, 0, szPath, -1, wszPath, MAX_PATH); + MultiByteToWideChar(CP_ACP, 0, szAppID, -1, wszAppID, MAX_PATH); + if (dualMode && stricmp(szDualMode, "true") != 0) { + dualMode = false; + } +#else + wcscpy_s(wszPath, szPath); + wcscpy_s(wszAppID, szAppID); + if (dualMode && _wcsicmp(szDualMode, L"true") != 0) { + dualMode = false; + } +#endif + + CoInitialize(NULL); + + if (SUCCEEDED(SHGetPropertyStoreFromParsingName(wszPath, NULL, GPS_READWRITE, IID_PPV_ARGS(&m_pps)))) + { + PROPVARIANT propvar; + if (SUCCEEDED(InitPropVariantFromString(wszAppID, &propvar))) { + if (SUCCEEDED(m_pps->SetValue(PKEY_AppUserModel_ID, propvar))) { + if (dualMode) { + InitPropVariantFromBoolean(true, &propvar); + m_pps->SetValue(PKEY_AppUserModel_IsDualMode, propvar); + } + if (SUCCEEDED(m_pps->Commit())) { + success = true; + } + } + } + } + if (m_pps != NULL) + m_pps->Release(); + + CoUninitialize(); + + pushstring(success == true ? TEXT("0") : TEXT("-1"), MAX_PATH); + } +} + +extern "C" void __declspec(dllexport) UninstallJumpLists(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) +{ + g_stringsize = string_size; + g_stacktop = stacktop; + g_variables = variables; + + ICustomDestinationList *m_cdl = NULL; + WCHAR wszAppID[MAX_PATH]; + TCHAR szAppID[MAX_PATH]; + bool success = false; + + ZeroMemory(wszAppID, sizeof(wszAppID)); + ZeroMemory(szAppID, sizeof(szAppID)); + + popstring(szAppID, MAX_PATH); + +#if !defined(UNICODE) + MultiByteToWideChar(CP_ACP, 0, szAppID, -1, wszAppID, MAX_PATH); +#else + wcscpy_s(wszAppID, szAppID); +#endif + + CoInitialize(NULL); + + CoCreateInstance(CLSID_DestinationList, NULL, CLSCTX_INPROC_SERVER, + IID_ICustomDestinationList, (void**)&m_cdl); + + if (m_cdl) { + if (SUCCEEDED(m_cdl->DeleteList(wszAppID))) { + success = true; + } + } + + if (m_cdl) + m_cdl->Release(); + + CoUninitialize(); + + pushstring(success == true ? TEXT("0") : TEXT("-1"), MAX_PATH); +} + +extern "C" void __declspec(dllexport) UninstallPinnedItem(HWND hwndParent, int string_size, TCHAR *variables, stack_t **stacktop) +{ + g_stringsize = string_size; + g_stacktop = stacktop; + g_variables = variables; + + IShellItem *pItem = NULL; + IStartMenuPinnedList *pPinnedList = NULL; + WCHAR wszPath[MAX_PATH]; + TCHAR szPath[MAX_PATH]; + bool success = false; + + ZeroMemory(wszPath, sizeof(wszPath)); + ZeroMemory(szPath, sizeof(szPath)); + + popstring(szPath, MAX_PATH); + +#if !defined(UNICODE) + MultiByteToWideChar(CP_ACP, 0, szPath, -1, wszPath, MAX_PATH); +#else + wcscpy_s(wszPath, szPath); +#endif + + CoInitialize(NULL); + + HRESULT hr; + hr = SHCreateItemFromParsingName(wszPath, NULL, IID_PPV_ARGS(&pItem)); + + if (SUCCEEDED(hr)) { + + hr = CoCreateInstance(CLSID_StartMenuPin, + NULL, + CLSCTX_INPROC_SERVER, + IID_PPV_ARGS(&pPinnedList)); + + if (SUCCEEDED(hr)) { + hr = pPinnedList->RemoveFromList(pItem); + pPinnedList->Release(); + success = true; + } + + pItem->Release(); + } + + CoUninitialize(); + + pushstring(success == true ? TEXT("0") : TEXT("-1"), MAX_PATH); +} + +//Function: Removes the element from the top of the NSIS stack and puts it in the buffer +int popstring(TCHAR *str, int len) +{ + stack_t *th; + if (!g_stacktop || !*g_stacktop) return 1; + th=(*g_stacktop); + lstrcpyn(str,th->text, len); + *g_stacktop=th->next; + GlobalFree((HGLOBAL)th); + return 0; +} + +//Function: Adds an element to the top of the NSIS stack +void pushstring(const TCHAR *str, int len) +{ + stack_t *th; + + if (!g_stacktop) return; + th=(stack_t*)GlobalAlloc(GPTR, sizeof(stack_t) + len); + lstrcpyn(th->text, str, len); + th->next=*g_stacktop; + *g_stacktop=th; +} diff --git a/other-licenses/nsis/Contrib/ApplicationID/resource.h b/other-licenses/nsis/Contrib/ApplicationID/resource.h new file mode 100644 index 0000000000..03194f3a5b --- /dev/null +++ b/other-licenses/nsis/Contrib/ApplicationID/resource.h @@ -0,0 +1,14 @@ +//{{NO_DEPENDENCIES}}
+// Microsoft Visual C++ generated include file.
+// Used by ApplicationID.rc
+
+// Next default values for new objects
+//
+#ifdef APSTUDIO_INVOKED
+#ifndef APSTUDIO_READONLY_SYMBOLS
+#define _APS_NEXT_RESOURCE_VALUE 101
+#define _APS_NEXT_COMMAND_VALUE 40001
+#define _APS_NEXT_CONTROL_VALUE 1001
+#define _APS_NEXT_SYMED_VALUE 101
+#endif
+#endif
diff --git a/other-licenses/nsis/Contrib/BitsUtils/BitsUtils.cpp b/other-licenses/nsis/Contrib/BitsUtils/BitsUtils.cpp new file mode 100644 index 0000000000..aea1f270ea --- /dev/null +++ b/other-licenses/nsis/Contrib/BitsUtils/BitsUtils.cpp @@ -0,0 +1,317 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include <windows.h> +#include <bits.h> +#include <utility> + +// Avoid conversions, we will only build Unicode anyway. +#if !(defined(UNICODE) && defined(_UNICODE)) +# error "Unicode required" +#endif + +static HINSTANCE gHInst; + +// ***** Section: ScopeExit +// Derived from mfbt mozilla::ScopeExit, I have removed the use of +// GuardObjectNotifier and the MOZ_* annotations. +template <typename ExitFunction> +class ScopeExit { + ExitFunction mExitFunction; + bool mExecuteOnDestruction; + + public: + explicit ScopeExit(ExitFunction &&cleanup) + : mExitFunction(cleanup), mExecuteOnDestruction(true) {} + + ScopeExit(ScopeExit &&rhs) + : mExitFunction(std::move(rhs.mExitFunction)), + mExecuteOnDestruction(rhs.mExecuteOnDestruction) { + rhs.release(); + } + + ~ScopeExit() { + if (mExecuteOnDestruction) { + mExitFunction(); + } + } + + void release() { mExecuteOnDestruction = false; } + + private: + explicit ScopeExit(const ScopeExit &) = delete; + ScopeExit &operator=(const ScopeExit &) = delete; + ScopeExit &operator=(ScopeExit &&) = delete; +}; + +template <typename ExitFunction> +ScopeExit<ExitFunction> MakeScopeExit(ExitFunction &&exitFunction) { + return ScopeExit<ExitFunction>(std::move(exitFunction)); +} + +// ***** Section: NSIS stack +typedef struct _stack_t { + struct _stack_t *next; + WCHAR text[1]; // this should be the length of g_stringsize when allocating +} stack_t; + +static unsigned int g_stringsize; +static stack_t **g_stacktop; + +static int popstringn(LPWSTR str, int maxlen) { + stack_t *th; + if (!g_stacktop || !*g_stacktop) return 1; + th = (*g_stacktop); + if (str) lstrcpynW(str, th->text, maxlen ? maxlen : g_stringsize); + *g_stacktop = th->next; + GlobalFree((HGLOBAL)th); + return 0; +} + +static void pushstring(LPCWSTR str) { + stack_t *th; + if (!g_stacktop) return; + th = (stack_t *)GlobalAlloc( + GPTR, (sizeof(stack_t) + (g_stringsize) * sizeof(*str))); + lstrcpynW(th->text, str, g_stringsize); + th->next = *g_stacktop; + *g_stacktop = th; +} + +// ***** Section: NSIS Plug-In API (from NSIS api.h) +// NSIS Plug-In Callback Messages +enum NSPIM { + NSPIM_UNLOAD, // This is the last message a plugin gets, do final cleanup + NSPIM_GUIUNLOAD, // Called after .onGUIEnd +}; + +// Prototype for callbacks registered with +// extra_parameters->RegisterPluginCallback() Return NULL for unknown messages +// Should always be __cdecl for future expansion possibilities +typedef UINT_PTR (*NSISPLUGINCALLBACK)(enum NSPIM); + +#define NSISCALL __stdcall + +typedef struct { + LPVOID exec_flags; + int(NSISCALL *ExecuteCodeSegment)(int, HWND); + void(NSISCALL *validate_filename)(LPWSTR); + int(NSISCALL *RegisterPluginCallback)( + HMODULE, NSISPLUGINCALLBACK); // returns 0 on success, 1 if already + // registered and < 0 on errors +} extra_parameters; + +// ***** Section: StartBitsThread +UINT_PTR __cdecl NSISPluginCallback(NSPIM msg); + +static struct { + HANDLE thread; + bool shutdown_requested; + CRITICAL_SECTION cs; + CONDITION_VARIABLE cv; +} gStartBitsThread = {nullptr, false, 0, 0}; + +// This thread connects to the BackgroundCopyManager, which may take some time +// if the BITS service is not already running. It also holds open the connection +// until gStartBitsThread.shutdown_requested becomes true. +DWORD WINAPI StartBitsThreadProc(LPVOID) { + EnterCriticalSection(&gStartBitsThread.cs); + auto leaveCS = + MakeScopeExit([] { LeaveCriticalSection(&gStartBitsThread.cs); }); + + if (FAILED(CoInitializeEx(nullptr, COINIT_MULTITHREADED))) { + return 0; + } + auto coUninit = MakeScopeExit([] { CoUninitialize(); }); + + IBackgroundCopyManager *bcm = nullptr; + if (FAILED(CoCreateInstance( + __uuidof(BackgroundCopyManager), nullptr, CLSCTX_LOCAL_SERVER, + __uuidof(IBackgroundCopyManager), (LPVOID *)&bcm)) || + !bcm) { + return 0; + } + + do { + SleepConditionVariableCS(&gStartBitsThread.cv, &gStartBitsThread.cs, + INFINITE); + } while (!gStartBitsThread.shutdown_requested); + + bcm->Release(); + return 1; +} + +// Start up the thread +// returns true on success +bool StartBitsServiceBackgroundThreadImpl(extra_parameters *extra_params) { + EnterCriticalSection(&gStartBitsThread.cs); + auto leaveCS = + MakeScopeExit([] { LeaveCriticalSection(&gStartBitsThread.cs); }); + + if (gStartBitsThread.thread) { + // Thread is already started, assumed to be still running. + return true; + } + + // Ensure the callback is registered so the thread can be stopped, and also so + // NSIS doesn't unload this DLL. + extra_params->RegisterPluginCallback(gHInst, NSISPluginCallback); + + gStartBitsThread.shutdown_requested = false; + + gStartBitsThread.thread = + CreateThread(nullptr, 0, StartBitsThreadProc, nullptr, 0, 0); + if (!gStartBitsThread.thread) { + return false; + } + + return true; +} + +// Shut down the Start BITS thread, if it was started. +void ShutdownStartBitsThread() { + EnterCriticalSection(&gStartBitsThread.cs); + if (gStartBitsThread.thread) { + gStartBitsThread.shutdown_requested = true; + WakeAllConditionVariable(&gStartBitsThread.cv); + LeaveCriticalSection(&gStartBitsThread.cs); + + // Give the thread a little time to clean up. + if (WaitForSingleObject(gStartBitsThread.thread, 1000) == WAIT_OBJECT_0) { + EnterCriticalSection(&gStartBitsThread.cs); + gStartBitsThread.thread = nullptr; + LeaveCriticalSection(&gStartBitsThread.cs); + } else { + // Don't attempt to recover if we didn't see the thread end, + // the process will be exiting soon anyway. + } + + } else { + LeaveCriticalSection(&gStartBitsThread.cs); + } +} + +// ***** Section: CancelBitsJobsByName +#define MAX_JOB_NAME 256 + +bool CancelBitsJobsByNameImpl(LPWSTR matchJobName) { + if (FAILED(CoInitialize(nullptr))) { + return false; + } + auto coUninit = MakeScopeExit([] { CoUninitialize(); }); + + IBackgroundCopyManager *bcm = nullptr; + if (FAILED(CoCreateInstance( + __uuidof(BackgroundCopyManager), nullptr, CLSCTX_LOCAL_SERVER, + __uuidof(IBackgroundCopyManager), (LPVOID *)&bcm)) || + !bcm) { + return false; + } + auto bcmRelease = MakeScopeExit([bcm] { bcm->Release(); }); + + IEnumBackgroundCopyJobs *enumerator = nullptr; + // Attempt to enumerate jobs for all users. If that fails, + // try for only the current user. + if (FAILED(bcm->EnumJobs(BG_JOB_ENUM_ALL_USERS, &enumerator))) { + enumerator = nullptr; + if (FAILED(bcm->EnumJobs(0, &enumerator))) { + return false; + } + } + if (!enumerator) { + return false; + } + auto enumeratorRelease = + MakeScopeExit([enumerator] { enumerator->Release(); }); + + bool success = true; + + IBackgroundCopyJob *job = nullptr; + HRESULT nextResult; + while ((nextResult = enumerator->Next(1, &job, nullptr), + SUCCEEDED(nextResult))) { + if (nextResult == S_FALSE) { + break; + } + if (!job) { + success = false; + break; + } + + LPWSTR curJobName = nullptr; + + if (SUCCEEDED(job->GetDisplayName(&curJobName)) && curJobName) { + if (lstrcmpW(curJobName, matchJobName) == 0) { + if (!SUCCEEDED(job->Cancel())) { + // If we can't cancel we can still try the other jobs. + success = false; + } + } + CoTaskMemFree((LPVOID)curJobName); + curJobName = nullptr; + } else { + // We may not be able to access certain jobs, keep trying the rest. + success = false; + } + + job->Release(); + job = nullptr; + } + + if (!SUCCEEDED(nextResult)) { + success = false; + } + + return success; +} + +// ***** Section: DLL entry points +extern "C" { +// Cancel all BITS jobs with the given name. +void __declspec(dllexport) + CancelBitsJobsByName(HWND hwndParent, int string_size, char *variables, + stack_t **stacktop, extra_parameters *) { + g_stacktop = stacktop; + g_stringsize = string_size; + + WCHAR matchJobName[MAX_JOB_NAME + 1]; + matchJobName[0] = L'\0'; + + if (!popstringn(matchJobName, sizeof(matchJobName) / sizeof(WCHAR))) { + if (CancelBitsJobsByNameImpl(matchJobName)) { + pushstring(L"ok"); + return; + } + } + + pushstring(L"error"); +} + +// Start the BITS service in the background, and hold a reference to it until +// the (un)installer exits. +// Does not provide any feedback or touch the stack. +void __declspec(dllexport) + StartBitsServiceBackground(HWND, int, char *, stack_t **, + extra_parameters *extra_params) { + StartBitsServiceBackgroundThreadImpl(extra_params); +} +} + +// Handle messages from NSIS +UINT_PTR __cdecl NSISPluginCallback(NSPIM msg) { + if (msg == NSPIM_UNLOAD) { + ShutdownStartBitsThread(); + } + return 0; +} + +BOOL APIENTRY DllMain(HINSTANCE instance, DWORD reason, LPVOID) { + if (reason == DLL_PROCESS_ATTACH) { + gHInst = instance; + InitializeConditionVariable(&gStartBitsThread.cv); + InitializeCriticalSection(&gStartBitsThread.cs); + } + return TRUE; +} diff --git a/other-licenses/nsis/Contrib/BitsUtils/BitsUtils.sln b/other-licenses/nsis/Contrib/BitsUtils/BitsUtils.sln new file mode 100644 index 0000000000..5e0311a9b2 --- /dev/null +++ b/other-licenses/nsis/Contrib/BitsUtils/BitsUtils.sln @@ -0,0 +1,22 @@ +
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.28307.271
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "BitsUtils", "BitsUtils.vcxproj", "{5058AAED-D02A-4F86-B011-31516AB5CD63}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {5058AAED-D02A-4F86-B011-31516AB5CD63}.Release|x86.ActiveCfg = Release|Win32
+ {5058AAED-D02A-4F86-B011-31516AB5CD63}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {53DD94C2-CC74-40B7-B9B7-08AD945C28F3}
+ EndGlobalSection
+EndGlobal
diff --git a/other-licenses/nsis/Contrib/BitsUtils/BitsUtils.vcxproj b/other-licenses/nsis/Contrib/BitsUtils/BitsUtils.vcxproj new file mode 100644 index 0000000000..71520de97e --- /dev/null +++ b/other-licenses/nsis/Contrib/BitsUtils/BitsUtils.vcxproj @@ -0,0 +1,62 @@ +<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <VCProjectVersion>15.0</VCProjectVersion>
+ <ProjectGuid>{5058AAED-D02A-4F86-B011-31516AB5CD63}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ <RootNamespace>BitsUtils</RootNamespace>
+ <WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="Shared">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>false</SDLCheck>
+ <PreprocessorDefinitions>WINVER=0x601;_WIN32_WINNT=0x601;WIN32;NDEBUG;CANCELBITSJOBS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <OmitDefaultLibName>true</OmitDefaultLibName>
+ <ExceptionHandling>false</ExceptionHandling>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <GenerateDebugInformation>false</GenerateDebugInformation>
+ <EntryPointSymbol>DllMain</EntryPointSymbol>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="BitsUtils.cpp" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
diff --git a/other-licenses/nsis/Contrib/CertCheck/CertCheck.cpp b/other-licenses/nsis/Contrib/CertCheck/CertCheck.cpp new file mode 100644 index 0000000000..e79f19a615 --- /dev/null +++ b/other-licenses/nsis/Contrib/CertCheck/CertCheck.cpp @@ -0,0 +1,411 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include <stdio.h> +#include <stdlib.h> +#include <windows.h> +#include <softpub.h> +#include <wintrust.h> + +#pragma comment(lib, "wintrust.lib") +#pragma comment(lib, "crypt32.lib") + +#ifndef UNICODE +#error "This file only supports building in Unicode mode" +#endif + +static const int ENCODING = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING; + +// The definitions for NSPIM, the callback typedef, and +// extra_parameters all come from the NSIS plugin API source. +enum NSPIM +{ + NSPIM_UNLOAD, + NSPIM_GUIUNLOAD, +}; + +typedef UINT_PTR(*NSISPLUGINCALLBACK)(enum NSPIM); + +struct extra_parameters +{ + // The real type of exec_flags is exec_flags_t*, which is a large struct + // whose definition is omitted here because this plugin doesn't need it. + void* exec_flags; + int (__stdcall *ExecuteCodeSegment)(int, HWND); + void (__stdcall *validate_filename)(TCHAR*); + int (__stdcall *RegisterPluginCallback)(HMODULE, NSISPLUGINCALLBACK); +}; + +typedef struct _stack_t { + struct _stack_t *next; + TCHAR text[MAX_PATH]; +} stack_t; + +int popstring(stack_t **stacktop, LPTSTR str, int len); +void pushstring(stack_t **stacktop, LPCTSTR str, int len); + +struct CertificateCheckInfo +{ + wchar_t filePath[MAX_PATH]; + wchar_t name[MAX_PATH]; + wchar_t issuer[MAX_PATH]; +}; + +static HINSTANCE gHInst; +static HANDLE gCheckThread; +static HANDLE gCheckEvent; +static bool gCheckTrustPassed; +static bool gCheckAttributesPassed; + +// We need a plugin callback not only to clean up our thread, but also +// because registering a callback prevents NSIS from unloading the DLL +// after each call from the script. +UINT_PTR __cdecl +NSISPluginCallback(NSPIM event) +{ + if (event == NSPIM_UNLOAD){ + if (gCheckThread != NULL && + WaitForSingleObject(gCheckThread, 0) != WAIT_OBJECT_0) { + TerminateThread(gCheckThread, ERROR_OPERATION_ABORTED); + } + CloseHandle(gCheckThread); + gCheckThread = NULL; + CloseHandle(gCheckEvent); + gCheckEvent = NULL; + } + return NULL; +} + +/** + * Checks to see if a file stored at filePath matches the specified info. This + * only supports the name and issuer attributes currently. + * + * @param certContext The certificate context of the file + * @param infoToMatch The acceptable information to match + * @return FALSE if the info does not match or if any error occurs in the check + */ +BOOL +DoCertificateAttributesMatch(PCCERT_CONTEXT certContext, + CertificateCheckInfo* infoToMatch) +{ + DWORD dwData; + LPTSTR szName = NULL; + + // Pass in NULL to get the needed size of the issuer buffer. + dwData = CertGetNameString(certContext, + CERT_NAME_SIMPLE_DISPLAY_TYPE, + CERT_NAME_ISSUER_FLAG, NULL, + NULL, 0); + + if (!dwData) { + return FALSE; + } + + // Allocate memory for Issuer name buffer. + szName = (LPTSTR)LocalAlloc(LPTR, dwData * sizeof(WCHAR)); + if (!szName) { + return FALSE; + } + + // Get Issuer name. + if (!CertGetNameString(certContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, + CERT_NAME_ISSUER_FLAG, NULL, szName, dwData)) { + LocalFree(szName); + return FALSE; + } + + // If the issuer does not match, return a failure. + if (!infoToMatch->issuer || + wcscmp(szName, infoToMatch->issuer)) { + LocalFree(szName); + return FALSE; + } + + LocalFree(szName); + szName = NULL; + + // Pass in NULL to get the needed size of the name buffer. + dwData = CertGetNameString(certContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, + 0, NULL, NULL, 0); + if (!dwData) { + return FALSE; + } + + // Allocate memory for the name buffer. + szName = (LPTSTR)LocalAlloc(LPTR, dwData * sizeof(WCHAR)); + if (!szName) { + return FALSE; + } + + // Obtain the name. + if (!(CertGetNameString(certContext, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, + NULL, szName, dwData))) { + LocalFree(szName); + return FALSE; + } + + // If the issuer does not match, return a failure. + if (!infoToMatch->name || + wcscmp(szName, infoToMatch->name)) { + LocalFree(szName); + return FALSE; + } + + // We have a match! + LocalFree(szName); + + // If there were any errors we would have aborted by now. + return TRUE; +} + +/** + * Checks to see if a file's signing cert matches the specified info. This + * only supports the name and issuer attributes currently. + * + * @param info The acceptable information to match + * @return ERROR_SUCCESS if successful, ERROR_NOT_FOUND if the info + * does not match, or the last error otherwise. + */ +DWORD +CheckCertificateInfoForPEFile(CertificateCheckInfo* info) +{ + HCERTSTORE certStore = NULL; + HCRYPTMSG cryptMsg = NULL; + PCCERT_CONTEXT certContext = NULL; + PCMSG_SIGNER_INFO signerInfo = NULL; + DWORD lastError = ERROR_SUCCESS; + + // Get the HCERTSTORE and HCRYPTMSG from the signed file. + DWORD encoding, contentType, formatType; + BOOL result = CryptQueryObject(CERT_QUERY_OBJECT_FILE, + info->filePath, + CERT_QUERY_CONTENT_FLAG_PKCS7_SIGNED_EMBED, + CERT_QUERY_CONTENT_FLAG_ALL, + 0, &encoding, &contentType, + &formatType, &certStore, &cryptMsg, NULL); + if (!result) { + lastError = GetLastError(); + goto cleanup; + } + + // Pass in NULL to get the needed signer information size. + DWORD signerInfoSize; + result = CryptMsgGetParam(cryptMsg, CMSG_SIGNER_INFO_PARAM, 0, + NULL, &signerInfoSize); + if (!result) { + lastError = GetLastError(); + goto cleanup; + } + + // Allocate the needed size for the signer information. + signerInfo = (PCMSG_SIGNER_INFO)LocalAlloc(LPTR, signerInfoSize); + if (!signerInfo) { + lastError = GetLastError(); + goto cleanup; + } + + // Get the signer information (PCMSG_SIGNER_INFO). + // In particular we want the issuer and serial number. + result = CryptMsgGetParam(cryptMsg, CMSG_SIGNER_INFO_PARAM, 0, + (PVOID)signerInfo, &signerInfoSize); + if (!result) { + lastError = GetLastError(); + goto cleanup; + } + + // Search for the signer certificate in the certificate store. + CERT_INFO certInfo; + certInfo.Issuer = signerInfo->Issuer; + certInfo.SerialNumber = signerInfo->SerialNumber; + certContext = CertFindCertificateInStore(certStore, ENCODING, 0, + CERT_FIND_SUBJECT_CERT, + (PVOID)&certInfo, NULL); + if (!certContext) { + lastError = GetLastError(); + goto cleanup; + } + + if (!DoCertificateAttributesMatch(certContext, info)) { + lastError = ERROR_NOT_FOUND; + goto cleanup; + } + +cleanup: + if (signerInfo) { + LocalFree(signerInfo); + } + if (certContext) { + CertFreeCertificateContext(certContext); + } + if (certStore) { + CertCloseStore(certStore, 0); + } + if (cryptMsg) { + CryptMsgClose(cryptMsg); + } + return lastError; +} + +/** + * Verifies the trust of a signed file's certificate. + * + * @param filePath The file path to check. + * @return ERROR_SUCCESS if successful, or the last error code otherwise. + */ +DWORD +VerifyCertificateTrustForFile(LPCWSTR filePath) +{ + // Setup the file to check. + WINTRUST_FILE_INFO fileToCheck; + ZeroMemory(&fileToCheck, sizeof(fileToCheck)); + fileToCheck.cbStruct = sizeof(WINTRUST_FILE_INFO); + fileToCheck.pcwszFilePath = filePath; + + // Setup what to check, we want to check it is signed and trusted. + WINTRUST_DATA trustData; + // ZeroMemory should be fine here, but the compiler converts that into a + // call to memset, and we're avoiding the C runtime to keep file size down. + SecureZeroMemory(&trustData, sizeof(trustData)); + trustData.cbStruct = sizeof(trustData); + trustData.dwUIChoice = WTD_UI_NONE; + trustData.dwUnionChoice = WTD_CHOICE_FILE; + trustData.pFile = &fileToCheck; + + GUID policyGUID = WINTRUST_ACTION_GENERIC_VERIFY_V2; + // Check if the file is signed by something that is trusted. + LONG ret = WinVerifyTrust(NULL, &policyGUID, &trustData); + return ret; +} + +/** + * Synchronously verifies the trust and attributes of a signed PE file. + * Meant to be invoked as a thread entry point from CheckPETrustAndInfoAsync. + */ +DWORD WINAPI +VerifyCertThreadProc(void* info) +{ + CertificateCheckInfo* certInfo = (CertificateCheckInfo*)info; + + if (VerifyCertificateTrustForFile(certInfo->filePath) == ERROR_SUCCESS) { + gCheckTrustPassed = true; + } + + if (CheckCertificateInfoForPEFile(certInfo) == ERROR_SUCCESS) { + gCheckAttributesPassed = true; + } + + LocalFree(info); + SetEvent(gCheckEvent); + return 0; +} + +/** + * Verifies the trust and the attributes of a signed PE file's certificate on +* a separate thread. Returns immediately upon starting that thread. + * Call GetStatus (repeatedly if necessary) to get the result of the checks. + * + * @param stacktop A pointer to the NSIS stack. + * From the top down, the stack should contain: + * 1) the path to the file that will have its trust verified + * 2) the expected certificate subject common name + * 3) the expected certificate issuer common name + */ +extern "C" void __declspec(dllexport) +CheckPETrustAndInfoAsync(HWND, int, TCHAR*, stack_t **stacktop, extra_parameters* pX) +{ + pX->RegisterPluginCallback(gHInst, NSISPluginCallback); + + gCheckTrustPassed = false; + gCheckAttributesPassed = false; + gCheckThread = nullptr; + + CertificateCheckInfo* certInfo = + (CertificateCheckInfo*)LocalAlloc(0, sizeof(CertificateCheckInfo)); + if (certInfo) { + popstring(stacktop, certInfo->filePath, MAX_PATH); + popstring(stacktop, certInfo->name, MAX_PATH); + popstring(stacktop, certInfo->issuer, MAX_PATH); + + gCheckThread = CreateThread(nullptr, 0, VerifyCertThreadProc, + (void*)certInfo, 0, nullptr); + } + if (!gCheckThread) { + LocalFree(certInfo); + SetEvent(gCheckEvent); + } +} + +/** + * Returns the result of a certificate check on the NSIS stack. + * + * If the check is not yet finished, will push "0" to the stack. + * If the check is finished, the top of the stack will be "1", followed by: + * "1" if the certificate is trusted by the system, "0" if not. Then: + * "1" if the certificate attributes matched those provided, "0" if not. + */ +extern "C" void __declspec(dllexport) +GetStatus(HWND, int, TCHAR*, stack_t **stacktop, void*) +{ + if (WaitForSingleObject(gCheckEvent, 0) == WAIT_OBJECT_0) { + pushstring(stacktop, gCheckAttributesPassed ? L"1" : L"0", 2); + pushstring(stacktop, gCheckTrustPassed ? L"1" : L"0", 2); + pushstring(stacktop, L"1", 2); + } else { + pushstring(stacktop, L"0", 2); + } +} + +BOOL WINAPI +DllMain(HINSTANCE hInst, DWORD fdwReason, LPVOID) +{ + if (fdwReason == DLL_PROCESS_ATTACH) { + gHInst = hInst; + gCheckEvent = CreateEvent(NULL, FALSE, FALSE, NULL); + } + return TRUE; +} + +/** + * Removes an element from the top of the NSIS stack + * + * @param stacktop A pointer to the top of the stack + * @param str The string to pop to + * @param len The max length + * @return 0 on success +*/ +int popstring(stack_t **stacktop, LPTSTR str, int len) +{ + // Removes the element from the top of the stack and puts it in the buffer + stack_t *th; + if (!stacktop || !*stacktop) { + return 1; + } + + th = (*stacktop); + lstrcpyn(str,th->text, len); + *stacktop = th->next; + GlobalFree((HGLOBAL)th); + return 0; +} + +/** + * Adds an element to the top of the NSIS stack + * + * @param stacktop A pointer to the top of the stack + * @param str The string to push on the stack + * @param len The length of the string to push on the stack + * @return 0 on success +*/ +void pushstring(stack_t **stacktop, LPCTSTR str, int len) +{ + stack_t *th; + if (!stacktop) { + return; + } + + th = (stack_t*)GlobalAlloc(GPTR, sizeof(stack_t) + len); + lstrcpyn(th->text, str, len); + th->next = *stacktop; + *stacktop = th; +} diff --git a/other-licenses/nsis/Contrib/CertCheck/CertCheck.sln b/other-licenses/nsis/Contrib/CertCheck/CertCheck.sln new file mode 100644 index 0000000000..5a92a248c4 --- /dev/null +++ b/other-licenses/nsis/Contrib/CertCheck/CertCheck.sln @@ -0,0 +1,31 @@ +
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.27428.2015
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{D94576A7-B8CF-4E2C-AAF3-89213C9F3F4C}") = "CertCheck", "CertCheck.vcxproj", "{83D56BCB-B9D1-44AB-BC96-9EA8A645CB0D}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {83D56BCB-B9D1-44AB-BC96-9EA8A645CB0D}.Debug|x64.ActiveCfg = Debug|x64
+ {83D56BCB-B9D1-44AB-BC96-9EA8A645CB0D}.Debug|x64.Build.0 = Debug|x64
+ {83D56BCB-B9D1-44AB-BC96-9EA8A645CB0D}.Debug|x86.ActiveCfg = Debug|Win32
+ {83D56BCB-B9D1-44AB-BC96-9EA8A645CB0D}.Debug|x86.Build.0 = Debug|Win32
+ {83D56BCB-B9D1-44AB-BC96-9EA8A645CB0D}.Release|x64.ActiveCfg = Release|x64
+ {83D56BCB-B9D1-44AB-BC96-9EA8A645CB0D}.Release|x64.Build.0 = Release|x64
+ {83D56BCB-B9D1-44AB-BC96-9EA8A645CB0D}.Release|x86.ActiveCfg = Release|Win32
+ {83D56BCB-B9D1-44AB-BC96-9EA8A645CB0D}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {182ECAA2-6C57-480C-B5B7-9FFF56875051}
+ EndGlobalSection
+EndGlobal
diff --git a/other-licenses/nsis/Contrib/CertCheck/CertCheck.vcxproj b/other-licenses/nsis/Contrib/CertCheck/CertCheck.vcxproj new file mode 100644 index 0000000000..9062b38a40 --- /dev/null +++ b/other-licenses/nsis/Contrib/CertCheck/CertCheck.vcxproj @@ -0,0 +1,169 @@ +<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <VCProjectVersion>15.0</VCProjectVersion>
+ <ProjectGuid>{83D56BCB-B9D1-44AB-BC96-9EA8A645CB0D}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ <RootNamespace>CertCheck</RootNamespace>
+ <WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="Shared">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LinkIncremental>false</LinkIncremental>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <LinkIncremental>false</LinkIncremental>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>false</SDLCheck>
+ <PreprocessorDefinitions>WIN32;_DEBUG;CERTCHECK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <BasicRuntimeChecks>Default</BasicRuntimeChecks>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EntryPointSymbol>DllMain</EntryPointSymbol>
+ <LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>false</SDLCheck>
+ <PreprocessorDefinitions>_DEBUG;CERTCHECK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <BasicRuntimeChecks>Default</BasicRuntimeChecks>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EntryPointSymbol>DllMain</EntryPointSymbol>
+ <LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>false</SDLCheck>
+ <PreprocessorDefinitions>WIN32;NDEBUG;CERTCHECK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <OmitDefaultLibName>true</OmitDefaultLibName>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <EntryPointSymbol>DllMain</EntryPointSymbol>
+ <LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
+ <GenerateDebugInformation>false</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>false</SDLCheck>
+ <PreprocessorDefinitions>NDEBUG;CERTCHECK_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <OmitDefaultLibName>true</OmitDefaultLibName>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <EntryPointSymbol>DllMain</EntryPointSymbol>
+ <LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
+ <GenerateDebugInformation>false</GenerateDebugInformation>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="CertCheck.cpp" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file diff --git a/other-licenses/nsis/Contrib/CityHash/CityHash.cpp b/other-licenses/nsis/Contrib/CityHash/CityHash.cpp new file mode 100644 index 0000000000..9998fb627d --- /dev/null +++ b/other-licenses/nsis/Contrib/CityHash/CityHash.cpp @@ -0,0 +1,82 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include "CityHash.h" +#include "cityhash/city.h" +#include <tchar.h> + +#define MAX_STRLEN 1024 + +typedef struct _stack_t { + struct _stack_t *next; + TCHAR text[MAX_STRLEN]; +} stack_t; + +stack_t **g_stacktop; +char *g_variables; + +BOOL APIENTRY DllMain(HMODULE hModule, + DWORD ul_reason_for_call, + LPVOID lpReserved) +{ + switch (ul_reason_for_call) + { + case DLL_PROCESS_ATTACH: + case DLL_THREAD_ATTACH: + case DLL_THREAD_DETACH: + case DLL_PROCESS_DETACH: + break; + } + return TRUE; +} + +bool popString(TCHAR *result) +{ + stack_t *th; + if (!g_stacktop || !*g_stacktop) return false; + th = (*g_stacktop); + lstrcpyn(result, th->text, MAX_STRLEN); + *g_stacktop = th->next; + GlobalFree((HGLOBAL)th); + return true; +} + +void pushString(const TCHAR *str) +{ + stack_t *th; + int strLen = wcslen(str)+1; + if (!g_stacktop) return; + th = (stack_t*)GlobalAlloc(GPTR, sizeof(stack_t) + (MAX_STRLEN*sizeof(TCHAR))); + lstrcpyn(th->text, str, strLen); + th->next = *g_stacktop; + *g_stacktop = th; +} + +extern "C" +{ + +void GetCityHash64(HWND hwndParent, int string_size, char *variables, stack_t **stacktop) +{ + TCHAR hashString[MAX_STRLEN]; + TCHAR hexResult[18] = { _T('\0') }; + + g_stacktop = stacktop; + g_variables = variables; + + memset(hashString, 0, sizeof(hashString)); + memset(hexResult, 0, sizeof(hexResult)); + + if (!popString(hashString)) { + pushString(L"error"); + return; + } + uint64 result = CityHash64((const char*)&hashString[0], wcslen(hashString)*sizeof(TCHAR)); + // If the hash happens to work out to less than 16 hash digits it will just + // use less of the buffer. + swprintf(hexResult, L"%I64X", result); + pushString(hexResult); +} + +} diff --git a/other-licenses/nsis/Contrib/CityHash/CityHash.def b/other-licenses/nsis/Contrib/CityHash/CityHash.def new file mode 100644 index 0000000000..61acb6e427 --- /dev/null +++ b/other-licenses/nsis/Contrib/CityHash/CityHash.def @@ -0,0 +1,3 @@ +LIBRARY CityHash
+EXPORTS
+ GetCityHash64 @1
diff --git a/other-licenses/nsis/Contrib/CityHash/CityHash.dsp b/other-licenses/nsis/Contrib/CityHash/CityHash.dsp new file mode 100644 index 0000000000..2113913549 --- /dev/null +++ b/other-licenses/nsis/Contrib/CityHash/CityHash.dsp @@ -0,0 +1,159 @@ +# Microsoft Developer Studio Project File - Name="CityHash" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=CityHash - Win32 Debug Unicode
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "CityHash.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "CityHash.mak" CFG="CityHash - Win32 Debug Unicode"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "CityHash - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "CityHash - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "CityHash - Win32 Release Unicode" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "CityHash - Win32 Debug Unicode" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "CityHash - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CityHash_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CityHash_EXPORTS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comctl32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /entry:"DllMain" /dll /machine:I386 /nodefaultlib /out:"../../Plugins/CityHash.dll" /opt:nowin98
+# SUBTRACT LINK32 /pdb:none
+
+!ELSEIF "$(CFG)" == "CityHash - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CityHash_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CityHash_EXPORTS" /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+
+!ELSEIF "$(CFG)" == "CityHash - Win32 Release Unicode"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "CityHash___Win32_Release_Unicode"
+# PROP BASE Intermediate_Dir "CityHash___Win32_Release_Unicode"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release_Unicode"
+# PROP Intermediate_Dir "Release_Unicode"
+# PROP Ignore_Export_Lib 1
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CityHash_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O1 /D "UNICODE" /D "_UNICODE" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CityHash_EXPORTS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comctl32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /entry:"DllMain" /dll /machine:I386 /nodefaultlib /out:"../../Plugins/CityHash.dll" /opt:nowin98
+# SUBTRACT BASE LINK32 /pdb:none
+# ADD LINK32 wininet.lib kernel32.lib user32.lib gdi32.lib winspool.lib comctl32.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /entry:"DllMain" /dll /machine:I386 /out:"./Unicode/CityHash.dll" /opt:nowin98
+# SUBTRACT LINK32 /pdb:none /nodefaultlib
+
+!ELSEIF "$(CFG)" == "CityHash - Win32 Debug Unicode"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "CityHash___Win32_Debug_Unicode"
+# PROP BASE Intermediate_Dir "CityHash___Win32_Debug_Unicode"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug_Unicode"
+# PROP Intermediate_Dir "Debug_Unicode"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CityHash_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "UNICODE" /D "_UNICODE" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "CityHash_EXPORTS" /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "CityHash - Win32 Release"
+# Name "CityHash - Win32 Debug"
+# Name "CityHash - Win32 Release Unicode"
+# Name "CityHash - Win32 Debug Unicode"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\CityHash.cpp
+# End Source File
+# End Group
+# End Target
+# End Project
diff --git a/other-licenses/nsis/Contrib/CityHash/CityHash.dsw b/other-licenses/nsis/Contrib/CityHash/CityHash.dsw new file mode 100644 index 0000000000..5a77a3c94b --- /dev/null +++ b/other-licenses/nsis/Contrib/CityHash/CityHash.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "CityHash"=.\CityHash.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/other-licenses/nsis/Contrib/CityHash/CityHash.h b/other-licenses/nsis/Contrib/CityHash/CityHash.h new file mode 100755 index 0000000000..4daa91d294 --- /dev/null +++ b/other-licenses/nsis/Contrib/CityHash/CityHash.h @@ -0,0 +1,31 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#ifndef WINVER +#define WINVER 0x0600 +#endif + +#ifndef _WIN32_WINNT +#define _WIN32_WINNT 0x0600 +#endif + +#ifndef _WIN32_WINDOWS +#define _WIN32_WINDOWS 0x0410 +#endif + +#ifndef _WIN32_IE +#define _WIN32_IE 0x0700 +#endif + +#ifndef WIN32_LEAN_AND_MEAN +#define WIN32_LEAN_AND_MEAN +#endif +#include <windows.h> + +#ifdef CITYHASH_EXPORTS +#define CITYHASH_API __declspec(dllexport) +#else +#define CITYHASH_API __declspec(dllimport) +#endif diff --git a/other-licenses/nsis/Contrib/CityHash/CityHash.vcproj b/other-licenses/nsis/Contrib/CityHash/CityHash.vcproj new file mode 100644 index 0000000000..21f4533aca --- /dev/null +++ b/other-licenses/nsis/Contrib/CityHash/CityHash.vcproj @@ -0,0 +1,223 @@ +<?xml version="1.0" encoding="Windows-1252"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="CityHash"
+ ProjectGUID="{D98B80BB-829B-4739-9F93-EFF7D01C69CC}"
+ RootNamespace="CityHash"
+ Keyword="Win32Proj"
+ TargetFrameworkVersion="196613"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;CITYHASH_EXPORTS"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="3"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="2"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory="$(SolutionDir)$(ConfigurationName)"
+ IntermediateDirectory="$(ConfigurationName)"
+ ConfigurationType="2"
+ CharacterSet="1"
+ WholeProgramOptimization="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="2"
+ EnableIntrinsicFunctions="true"
+ PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;CITYHASH_EXPORTS"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ UsePrecompiledHeader="0"
+ WarningLevel="3"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ LinkIncremental="1"
+ GenerateDebugInformation="true"
+ SubSystem="2"
+ OptimizeReferences="2"
+ EnableCOMDATFolding="2"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <Filter
+ Name="Source Files"
+ Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx"
+ UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
+ >
+ <File
+ RelativePath=".\cityhash\city.cpp"
+ >
+ </File>
+ <File
+ RelativePath=".\CityHash.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="0"
+ CompileAsManaged="0"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ UsePrecompiledHeader="0"
+ CompileAsManaged="0"
+ />
+ </FileConfiguration>
+ </File>
+ </Filter>
+ <Filter
+ Name="Header Files"
+ Filter="h;hpp;hxx;hm;inl;inc;xsd"
+ UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
+ >
+ <File
+ RelativePath=".\cityhash\city.h"
+ >
+ </File>
+ <File
+ RelativePath=".\CityHash.h"
+ >
+ </File>
+ </Filter>
+ <Filter
+ Name="Resource Files"
+ Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
+ UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
+ >
+ </Filter>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/other-licenses/nsis/Contrib/CityHash/cityhash/city.cpp b/other-licenses/nsis/Contrib/CityHash/cityhash/city.cpp new file mode 100755 index 0000000000..f34777eb84 --- /dev/null +++ b/other-licenses/nsis/Contrib/CityHash/cityhash/city.cpp @@ -0,0 +1,322 @@ +// Copyright (c) 2011 Google, Inc. +// +// 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. +// +// CityHash Version 1, by Geoff Pike and Jyrki Alakuijala +// +// This file provides CityHash64() and related functions. +// +// It's probably possible to create even faster hash functions by +// writing a program that systematically explores some of the space of +// possible hash functions, by using SIMD instructions, or by +// compromising on hash quality. + +#include "city.h" + +#include <algorithm> + +using namespace std; + +#if __sparc__ +#include <string.h> +static inline uint64 UNALIGNED_LOAD64(const char *p) { + uint64 val; + memcpy(&val, p, sizeof(uint64)); + return val; +} + +static inline uint32 UNALIGNED_LOAD32(const char *p) { + uint32 val; + memcpy(&val, p, sizeof(uint32)); + return val; +} +#else +#define UNALIGNED_LOAD64(p) (*(const uint64*)(p)) +#define UNALIGNED_LOAD32(p) (*(const uint32*)(p)) +#endif + +#if !defined(LIKELY) +#if defined(__GNUC__) +#define LIKELY(x) (__builtin_expect(!!(x), 1)) +#else +#define LIKELY(x) (x) +#endif +#endif + +// Some primes between 2^63 and 2^64 for various uses. +static const uint64 k0 = 0xc3a5c85c97cb3127; +static const uint64 k1 = 0xb492b66fbe98f273; +static const uint64 k2 = 0x9ae16a3b2f90404f; +static const uint64 k3 = 0xc949d7c7509e6557; + +// Bitwise right rotate. Normally this will compile to a single +// instruction, especially if the shift is a manifest constant. +static uint64 Rotate(uint64 val, int shift) { + // Avoid shifting by 64: doing so yields an undefined result. + return shift == 0 ? val : ((val >> shift) | (val << (64 - shift))); +} + +// Equivalent to Rotate(), but requires the second arg to be non-zero. +// On x86-64, and probably others, it's possible for this to compile +// to a single instruction if both args are already in registers. +static uint64 RotateByAtLeast1(uint64 val, int shift) { + return (val >> shift) | (val << (64 - shift)); +} + +static uint64 ShiftMix(uint64 val) { + return val ^ (val >> 47); +} + +static uint64 HashLen16(uint64 u, uint64 v) { + return Hash128to64(uint128(u, v)); +} + +static uint64 HashLen0to16(const char *s, size_t len) { + if (len > 8) { + uint64 a = UNALIGNED_LOAD64(s); + uint64 b = UNALIGNED_LOAD64(s + len - 8); + return HashLen16(a, RotateByAtLeast1(b + len, len)) ^ b; + } + if (len >= 4) { + uint64 a = UNALIGNED_LOAD32(s); + return HashLen16(len + (a << 3), UNALIGNED_LOAD32(s + len - 4)); + } + if (len > 0) { + uint8 a = s[0]; + uint8 b = s[len >> 1]; + uint8 c = s[len - 1]; + uint32 y = static_cast<uint32>(a) + (static_cast<uint32>(b) << 8); + uint32 z = len + (static_cast<uint32>(c) << 2); + return ShiftMix(y * k2 ^ z * k3) * k2; + } + return k2; +} + +// This probably works well for 16-byte strings as well, but it may be overkill +// in that case. +static uint64 HashLen17to32(const char *s, size_t len) { + uint64 a = UNALIGNED_LOAD64(s) * k1; + uint64 b = UNALIGNED_LOAD64(s + 8); + uint64 c = UNALIGNED_LOAD64(s + len - 8) * k2; + uint64 d = UNALIGNED_LOAD64(s + len - 16) * k0; + return HashLen16(Rotate(a - b, 43) + Rotate(c, 30) + d, + a + Rotate(b ^ k3, 20) - c + len); +} + +// Return a 16-byte hash for 48 bytes. Quick and dirty. +// Callers do best to use "random-looking" values for a and b. +static pair<uint64, uint64> WeakHashLen32WithSeeds( + uint64 w, uint64 x, uint64 y, uint64 z, uint64 a, uint64 b) { + a += w; + b = Rotate(b + a + z, 21); + uint64 c = a; + a += x; + a += y; + b += Rotate(a, 44); + return make_pair(a + z, b + c); +} + +// Return a 16-byte hash for s[0] ... s[31], a, and b. Quick and dirty. +static pair<uint64, uint64> WeakHashLen32WithSeeds( + const char* s, uint64 a, uint64 b) { + return WeakHashLen32WithSeeds(UNALIGNED_LOAD64(s), + UNALIGNED_LOAD64(s + 8), + UNALIGNED_LOAD64(s + 16), + UNALIGNED_LOAD64(s + 24), + a, + b); +} + +// Return an 8-byte hash for 33 to 64 bytes. +static uint64 HashLen33to64(const char *s, size_t len) { + uint64 z = UNALIGNED_LOAD64(s + 24); + uint64 a = UNALIGNED_LOAD64(s) + (len + UNALIGNED_LOAD64(s + len - 16)) * k0; + uint64 b = Rotate(a + z, 52); + uint64 c = Rotate(a, 37); + a += UNALIGNED_LOAD64(s + 8); + c += Rotate(a, 7); + a += UNALIGNED_LOAD64(s + 16); + uint64 vf = a + z; + uint64 vs = b + Rotate(a, 31) + c; + a = UNALIGNED_LOAD64(s + 16) + UNALIGNED_LOAD64(s + len - 32); + z = UNALIGNED_LOAD64(s + len - 8); + b = Rotate(a + z, 52); + c = Rotate(a, 37); + a += UNALIGNED_LOAD64(s + len - 24); + c += Rotate(a, 7); + a += UNALIGNED_LOAD64(s + len - 16); + uint64 wf = a + z; + uint64 ws = b + Rotate(a, 31) + c; + uint64 r = ShiftMix((vf + ws) * k2 + (wf + vs) * k0); + return ShiftMix(r * k0 + vs) * k2; +} + +uint64 CityHash64(const char *s, size_t len) { + if (len <= 32) { + if (len <= 16) { + return HashLen0to16(s, len); + } else { + return HashLen17to32(s, len); + } + } else if (len <= 64) { + return HashLen33to64(s, len); + } + + // For strings over 64 bytes we hash the end first, and then as we + // loop we keep 56 bytes of state: v, w, x, y, and z. + uint64 x = UNALIGNED_LOAD64(s); + uint64 y = UNALIGNED_LOAD64(s + len - 16) ^ k1; + uint64 z = UNALIGNED_LOAD64(s + len - 56) ^ k0; + pair<uint64, uint64> v = WeakHashLen32WithSeeds(s + len - 64, len, y); + pair<uint64, uint64> w = WeakHashLen32WithSeeds(s + len - 32, len * k1, k0); + z += ShiftMix(v.second) * k1; + x = Rotate(z + x, 39) * k1; + y = Rotate(y, 33) * k1; + + // Decrease len to the nearest multiple of 64, and operate on 64-byte chunks. + len = (len - 1) & ~static_cast<size_t>(63); + do { + x = Rotate(x + y + v.first + UNALIGNED_LOAD64(s + 16), 37) * k1; + y = Rotate(y + v.second + UNALIGNED_LOAD64(s + 48), 42) * k1; + x ^= w.second; + y ^= v.first; + z = Rotate(z ^ w.first, 33); + v = WeakHashLen32WithSeeds(s, v.second * k1, x + w.first); + w = WeakHashLen32WithSeeds(s + 32, z + w.second, y); + std::swap(z, x); + s += 64; + len -= 64; + } while (len != 0); + return HashLen16(HashLen16(v.first, w.first) + ShiftMix(y) * k1 + z, + HashLen16(v.second, w.second) + x); +} + +uint64 CityHash64WithSeed(const char *s, size_t len, uint64 seed) { + return CityHash64WithSeeds(s, len, k2, seed); +} + +uint64 CityHash64WithSeeds(const char *s, size_t len, + uint64 seed0, uint64 seed1) { + return HashLen16(CityHash64(s, len) - seed0, seed1); +} + +// A subroutine for CityHash128(). Returns a decent 128-bit hash for strings +// of any length representable in an int. Based on City and Murmur. +static uint128 CityMurmur(const char *s, size_t len, uint128 seed) { + uint64 a = Uint128Low64(seed); + uint64 b = Uint128High64(seed); + uint64 c = 0; + uint64 d = 0; + int l = len - 16; + if (l <= 0) { // len <= 16 + c = b * k1 + HashLen0to16(s, len); + d = Rotate(a + (len >= 8 ? UNALIGNED_LOAD64(s) : c), 32); + } else { // len > 16 + c = HashLen16(UNALIGNED_LOAD64(s + len - 8) + k1, a); + d = HashLen16(b + len, c + UNALIGNED_LOAD64(s + len - 16)); + a += d; + do { + a ^= ShiftMix(UNALIGNED_LOAD64(s) * k1) * k1; + a *= k1; + b ^= a; + c ^= ShiftMix(UNALIGNED_LOAD64(s + 8) * k1) * k1; + c *= k1; + d ^= c; + s += 16; + l -= 16; + } while (l > 0); + } + a = HashLen16(a, c); + b = HashLen16(d, b); + return uint128(a ^ b, HashLen16(b, a)); +} + +uint128 CityHash128WithSeed(const char *s, size_t len, uint128 seed) { + if (len < 128) { + return CityMurmur(s, len, seed); + } + + // We expect len >= 128 to be the common case. Keep 56 bytes of state: + // v, w, x, y, and z. + pair<uint64, uint64> v, w; + uint64 x = Uint128Low64(seed); + uint64 y = Uint128High64(seed); + uint64 z = len * k1; + v.first = Rotate(y ^ k1, 49) * k1 + UNALIGNED_LOAD64(s); + v.second = Rotate(v.first, 42) * k1 + UNALIGNED_LOAD64(s + 8); + w.first = Rotate(y + z, 35) * k1 + x; + w.second = Rotate(x + UNALIGNED_LOAD64(s + 88), 53) * k1; + + // This is the same inner loop as CityHash64(), manually unrolled. + do { + x = Rotate(x + y + v.first + UNALIGNED_LOAD64(s + 16), 37) * k1; + y = Rotate(y + v.second + UNALIGNED_LOAD64(s + 48), 42) * k1; + x ^= w.second; + y ^= v.first; + z = Rotate(z ^ w.first, 33); + v = WeakHashLen32WithSeeds(s, v.second * k1, x + w.first); + w = WeakHashLen32WithSeeds(s + 32, z + w.second, y); + std::swap(z, x); + s += 64; + x = Rotate(x + y + v.first + UNALIGNED_LOAD64(s + 16), 37) * k1; + y = Rotate(y + v.second + UNALIGNED_LOAD64(s + 48), 42) * k1; + x ^= w.second; + y ^= v.first; + z = Rotate(z ^ w.first, 33); + v = WeakHashLen32WithSeeds(s, v.second * k1, x + w.first); + w = WeakHashLen32WithSeeds(s + 32, z + w.second, y); + std::swap(z, x); + s += 64; + len -= 128; + } while (LIKELY(len >= 128)); + y += Rotate(w.first, 37) * k0 + z; + x += Rotate(v.first + z, 49) * k0; + // If 0 < len < 128, hash up to 4 chunks of 32 bytes each from the end of s. + for (size_t tail_done = 0; tail_done < len; ) { + tail_done += 32; + y = Rotate(y - x, 42) * k0 + v.second; + w.first += UNALIGNED_LOAD64(s + len - tail_done + 16); + x = Rotate(x, 49) * k0 + w.first; + w.first += v.first; + v = WeakHashLen32WithSeeds(s + len - tail_done, v.first, v.second); + } + // At this point our 48 bytes of state should contain more than + // enough information for a strong 128-bit hash. We use two + // different 48-byte-to-8-byte hashes to get a 16-byte final result. + x = HashLen16(x, v.first); + y = HashLen16(y, w.first); + return uint128(HashLen16(x + v.second, w.second) + y, + HashLen16(x + w.second, y + v.second)); +} + +uint128 CityHash128(const char *s, size_t len) { + if (len >= 16) { + return CityHash128WithSeed(s + 16, + len - 16, + uint128(UNALIGNED_LOAD64(s) ^ k3, + UNALIGNED_LOAD64(s + 8))); + } else if (len >= 8) { + return CityHash128WithSeed(NULL, + 0, + uint128(UNALIGNED_LOAD64(s) ^ (len * k0), + UNALIGNED_LOAD64(s + len - 8) ^ k1)); + } else { + return CityHash128WithSeed(s, len, uint128(k0, k1)); + } +} diff --git a/other-licenses/nsis/Contrib/CityHash/cityhash/city.h b/other-licenses/nsis/Contrib/CityHash/cityhash/city.h new file mode 100644 index 0000000000..01d47e4c1f --- /dev/null +++ b/other-licenses/nsis/Contrib/CityHash/cityhash/city.h @@ -0,0 +1,98 @@ +// Copyright (c) 2011 Google, Inc. +// +// 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. +// +// CityHash Version 1, by Geoff Pike and Jyrki Alakuijala +// +// This file provides a few functions for hashing strings. On x86-64 +// hardware in 2011, CityHash64() is faster than other high-quality +// hash functions, such as Murmur. This is largely due to higher +// instruction-level parallelism. CityHash64() and CityHash128() also perform +// well on hash-quality tests. +// +// CityHash128() is optimized for relatively long strings and returns +// a 128-bit hash. For strings more than about 2000 bytes it can be +// faster than CityHash64(). +// +// Functions in the CityHash family are not suitable for cryptography. +// +// WARNING: This code has not been tested on big-endian platforms! +// It is known to work well on little-endian platforms that have a small penalty +// for unaligned reads, such as current Intel and AMD moderate-to-high-end CPUs. +// +// By the way, for some hash functions, given strings a and b, the hash +// of a+b is easily derived from the hashes of a and b. This property +// doesn't hold for any hash functions in this file. + +#ifndef CITY_HASH_H_ +#define CITY_HASH_H_ + +#include <stdlib.h> // for size_t. +#include <stdint.h> + +typedef uint8_t uint8; +typedef uint32_t uint32; +typedef uint64_t uint64; + +#ifdef __cplusplus + +#include <utility> +typedef std::pair<uint64, uint64> uint128; +inline uint64 Uint128Low64(const uint128& x) { return x.first; } +inline uint64 Uint128High64(const uint128& x) { return x.second; } + +extern "C" { +#endif + +// Hash function for a byte array. +uint64 CityHash64(const char *buf, size_t len); + +// Hash function for a byte array. For convenience, a 64-bit seed is also +// hashed into the result. +uint64 CityHash64WithSeed(const char *buf, size_t len, uint64 seed); + +// Hash function for a byte array. For convenience, two seeds are also +// hashed into the result. +uint64 CityHash64WithSeeds(const char *buf, size_t len, + uint64 seed0, uint64 seed1); + +#ifdef __cplusplus +} +// Hash function for a byte array. +uint128 CityHash128(const char *s, size_t len); + +// Hash function for a byte array. For convenience, a 128-bit seed is also +// hashed into the result. +uint128 CityHash128WithSeed(const char *s, size_t len, uint128 seed); + +// Hash 128 input bits down to 64 bits of output. +// This is intended to be a reasonably good hash function. +inline uint64 Hash128to64(const uint128& x) { + // Murmur-inspired hashing. + const uint64 kMul = 0x9ddfea08eb382d69; + uint64 a = (Uint128Low64(x) ^ Uint128High64(x)) * kMul; + a ^= (a >> 47); + uint64 b = (Uint128High64(x) ^ a) * kMul; + b ^= (b >> 47); + b *= kMul; + return b; +} +#endif + +#endif // CITY_HASH_H_ diff --git a/other-licenses/nsis/Contrib/ExDLL/SConscript b/other-licenses/nsis/Contrib/ExDLL/SConscript new file mode 100644 index 0000000000..2c6308545f --- /dev/null +++ b/other-licenses/nsis/Contrib/ExDLL/SConscript @@ -0,0 +1,25 @@ +# FIXME: install assembly and pascal includes into the correct locations
+
+c_devel = Split("""
+ exdll.h
+""")
+
+example = Split("""
+ exdll.c
+ exdll.dpr
+ exdll.dsp
+ exdll.dsw
+ exdll_with_unit.dpr
+ nsis.pas
+ extdll.inc
+""")
+
+Import('defenv')
+
+if defenv['PLATFORM'] == 'win32':
+ example += c_devel
+else:
+ defenv.DistributeIncC(c_devel)
+
+defenv.DistributeExamples(example, path='Plugin')
+
diff --git a/other-licenses/nsis/Contrib/ExDLL/exdll.c b/other-licenses/nsis/Contrib/ExDLL/exdll.c new file mode 100644 index 0000000000..c46e621a03 --- /dev/null +++ b/other-licenses/nsis/Contrib/ExDLL/exdll.c @@ -0,0 +1,44 @@ +// Unicode support by Jim Park -- 08/02/2007
+
+#include <windows.h>
+#include "tchar.h"
+#include "exdll.h"
+
+HINSTANCE g_hInstance;
+
+HWND g_hwndParent;
+
+// To work with Unicode version of NSIS, please use TCHAR-type
+// functions for accessing the variables and the stack.
+
+void __declspec(dllexport) myFunction(HWND hwndParent, int string_size,
+ TCHAR *variables, stack_t **stacktop,
+ extra_parameters *extra)
+{
+ g_hwndParent=hwndParent;
+
+ EXDLL_INIT();
+
+
+ // note if you want parameters from the stack, pop them off in order.
+ // i.e. if you are called via exdll::myFunction file.dat poop.dat
+ // calling popstring() the first time would give you file.dat,
+ // and the second time would give you poop.dat.
+ // you should empty the stack of your parameters, and ONLY your
+ // parameters.
+
+ // do your stuff here
+ {
+ TCHAR buf[1024];
+ wsprintf(buf,_T("$0=%s\n"),getuservariable(INST_0));
+ MessageBox(g_hwndParent,buf,0,MB_OK);
+ }
+}
+
+
+
+BOOL WINAPI DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved)
+{
+ g_hInstance=hInst;
+ return TRUE;
+}
diff --git a/other-licenses/nsis/Contrib/ExDLL/exdll.dpr b/other-licenses/nsis/Contrib/ExDLL/exdll.dpr new file mode 100644 index 0000000000..ab3f03d3dd --- /dev/null +++ b/other-licenses/nsis/Contrib/ExDLL/exdll.dpr @@ -0,0 +1,118 @@ +{
+ NSIS ExDLL example
+ (C) 2001 - Peter Windridge
+
+ Fixed and formatted by Brett Dever
+ http://editor.nfscheats.com/
+
+ Tested in Delphi 7.0
+}
+
+library exdll;
+
+uses Windows;
+
+type
+ VarConstants = (
+ INST_0,
+ INST_1, // $1
+ INST_2, // $2
+ INST_3, // $3
+ INST_4, // $4
+ INST_5, // $5
+ INST_6, // $6
+ INST_7, // $7
+ INST_8, // $8
+ INST_9, // $9
+ INST_R0, // $R0
+ INST_R1, // $R1
+ INST_R2, // $R2
+ INST_R3, // $R3
+ INST_R4, // $R4
+ INST_R5, // $R5
+ INST_R6, // $R6
+ INST_R7, // $R7
+ INST_R8, // $R8
+ INST_R9, // $R9
+ INST_CMDLINE, // $CMDLINE
+ INST_INSTDIR, // $INSTDIR
+ INST_OUTDIR, // $OUTDIR
+ INST_EXEDIR, // $EXEDIR
+ INST_LANG, // $LANGUAGE
+ __INST_LAST
+ );
+ TVariableList = INST_0..__INST_LAST;
+ pstack_t = ^stack_t;
+ stack_t = record
+ next: pstack_t;
+ text: PChar;
+ end;
+
+var
+ g_stringsize: integer;
+ g_stacktop: ^pstack_t;
+ g_variables: PChar;
+ g_hwndParent: HWND;
+
+function PopString(): string;
+var
+ th: pstack_t;
+begin
+ if integer(g_stacktop^) <> 0 then begin
+ th := g_stacktop^;
+ Result := PChar(@th.text);
+ g_stacktop^ := th.next;
+ GlobalFree(HGLOBAL(th));
+ end;
+end;
+
+procedure PushString(const str: string='');
+var
+ th: pstack_t;
+begin
+ if integer(g_stacktop) <> 0 then begin
+ th := pstack_t(GlobalAlloc(GPTR, SizeOf(stack_t) + g_stringsize));
+ lstrcpyn(@th.text, PChar(str), g_stringsize);
+ th.next := g_stacktop^;
+ g_stacktop^ := th;
+ end;
+end;
+
+function GetUserVariable(const varnum: TVariableList): string;
+begin
+ if (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then
+ Result := g_variables + integer(varnum) * g_stringsize
+ else
+ Result := '';
+end;
+
+procedure SetUserVariable(const varnum: TVariableList; const value: string);
+begin
+ if (value <> '') and (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then
+ lstrcpy(g_variables + integer(varnum) * g_stringsize, PChar(value))
+end;
+
+procedure NSISDialog(const text, caption: string; const buttons: integer);
+begin
+ MessageBox(g_hwndParent, PChar(text), PChar(caption), buttons);
+end;
+
+procedure ex_dll(const hwndParent: HWND; const string_size: integer; const variables: PChar; const stacktop: pointer); cdecl;
+begin
+ // setup global variables
+ g_stringsize := string_size;
+ g_hwndParent := hwndParent;
+ g_stacktop := stacktop;
+ g_variables := variables;
+ // end global variable setup
+
+ NSISDialog(GetUserVariable(INST_0), 'The value of $0', MB_OK);
+ NSISDialog(PopString, 'pop', MB_OK);
+ PushString('Hello, this is a push');
+ SetUserVariable(INST_0, 'This is user var $0');
+end;
+
+exports ex_dll;
+
+begin
+end.
diff --git a/other-licenses/nsis/Contrib/ExDLL/exdll.dsp b/other-licenses/nsis/Contrib/ExDLL/exdll.dsp new file mode 100644 index 0000000000..9888726515 --- /dev/null +++ b/other-licenses/nsis/Contrib/ExDLL/exdll.dsp @@ -0,0 +1,111 @@ +# Microsoft Developer Studio Project File - Name="exdll" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=exdll - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "exdll.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "exdll.mak" CFG="exdll - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "exdll - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "exdll - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "exdll - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXDLL_EXPORTS" /YX /FD /c
+# ADD CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXDLL_EXPORTS" /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /entry:"DllMain" /dll /machine:I386 /nodefaultlib /out:"../../Plugins/exdll.dll" /opt:nowin98
+# SUBTRACT LINK32 /pdb:none
+
+!ELSEIF "$(CFG)" == "exdll - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXDLL_EXPORTS" /YX /FD /GZ /c
+# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXDLL_EXPORTS" /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+
+!ENDIF
+
+# Begin Target
+
+# Name "exdll - Win32 Release"
+# Name "exdll - Win32 Debug"
+# Begin Group "Source Files"
+
+# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat"
+# Begin Source File
+
+SOURCE=.\exdll.c
+# End Source File
+# End Group
+# Begin Group "Header Files"
+
+# PROP Default_Filter "h;hpp;hxx;hm;inl"
+# Begin Source File
+
+SOURCE=.\exdll.h
+# End Source File
+# End Group
+# Begin Group "Resource Files"
+
+# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe"
+# End Group
+# End Target
+# End Project
diff --git a/other-licenses/nsis/Contrib/ExDLL/exdll.dsw b/other-licenses/nsis/Contrib/ExDLL/exdll.dsw new file mode 100644 index 0000000000..f40ce32de8 --- /dev/null +++ b/other-licenses/nsis/Contrib/ExDLL/exdll.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "exdll"=.\exdll.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/other-licenses/nsis/Contrib/ExDLL/exdll.h b/other-licenses/nsis/Contrib/ExDLL/exdll.h new file mode 100644 index 0000000000..c923c5197d --- /dev/null +++ b/other-licenses/nsis/Contrib/ExDLL/exdll.h @@ -0,0 +1,234 @@ +// Unicode support added by Jim Park -- 07/27/2007
+// Unicode support requires that all plugins take TCHARs instead as well. This
+// means existing plugins will not work for the Unicode version of NSIS unless
+// recompiled. You have been warned.
+
+#ifndef _EXDLL_H_
+#define _EXDLL_H_
+
+#include <windows.h>
+#include "tchar.h"
+
+#if defined(__GNUC__)
+#define UNUSED __attribute__((unused))
+#else
+#define UNUSED
+#endif
+
+// only include this file from one place in your DLL.
+// (it is all static, if you use it in two places it will fail)
+
+#define EXDLL_INIT() { \
+ g_stringsize=string_size; \
+ g_stacktop=stacktop; \
+ g_variables=variables; }
+
+// For page showing plug-ins
+#define WM_NOTIFY_OUTER_NEXT (WM_USER+0x8)
+#define WM_NOTIFY_CUSTOM_READY (WM_USER+0xd)
+
+/* Jim Park: This char is compared as an int value and therefore
+ it's fine as an ASCII. Do not need to change to wchar_t since
+ it will get the same integer value. */
+#define NOTIFY_BYE_BYE _T('x')
+
+typedef struct _stack_t {
+ struct _stack_t *next;
+ TCHAR text[1]; // this should be the length of string_size
+} stack_t;
+
+
+static unsigned int g_stringsize;
+static stack_t **g_stacktop;
+static TCHAR *g_variables;
+
+static int __stdcall popstring(TCHAR *str) UNUSED; // 0 on success, 1 on empty stack
+static void __stdcall pushstring(const TCHAR *str) UNUSED;
+static TCHAR * __stdcall getuservariable(const int varnum) UNUSED;
+static void __stdcall setuservariable(const int varnum, const TCHAR *var) UNUSED;
+
+enum
+{
+INST_0, // $0
+INST_1, // $1
+INST_2, // $2
+INST_3, // $3
+INST_4, // $4
+INST_5, // $5
+INST_6, // $6
+INST_7, // $7
+INST_8, // $8
+INST_9, // $9
+INST_R0, // $R0
+INST_R1, // $R1
+INST_R2, // $R2
+INST_R3, // $R3
+INST_R4, // $R4
+INST_R5, // $R5
+INST_R6, // $R6
+INST_R7, // $R7
+INST_R8, // $R8
+INST_R9, // $R9
+INST_CMDLINE, // $CMDLINE
+INST_INSTDIR, // $INSTDIR
+INST_OUTDIR, // $OUTDIR
+INST_EXEDIR, // $EXEDIR
+INST_LANG, // $LANGUAGE
+__INST_LAST
+};
+
+typedef struct {
+ int autoclose;
+ int all_user_var;
+ int exec_error;
+ int abort;
+ int exec_reboot;
+ int reboot_called;
+ int XXX_cur_insttype; // deprecated
+ int XXX_insttype_changed; // deprecated
+ int silent;
+ int instdir_error;
+ int rtl;
+ int errlvl;
+ int alter_reg_view;
+ int status_update;
+} exec_flags_type;
+
+typedef struct {
+ exec_flags_type *exec_flags;
+ int (__stdcall *ExecuteCodeSegment)(int, HWND);
+ void (__stdcall *validate_filename)(TCHAR *);
+} extra_parameters;
+
+// utility functions (not required but often useful)
+static int __stdcall popstring(TCHAR *str)
+{
+ stack_t *th;
+ if (!g_stacktop || !*g_stacktop) return 1;
+ th=(*g_stacktop);
+ lstrcpy(str,th->text);
+ *g_stacktop = th->next;
+ GlobalFree((HGLOBAL)th);
+ return 0;
+}
+
+static void __stdcall pushstring(const TCHAR *str)
+{
+ stack_t *th;
+ if (!g_stacktop) return;
+ th=(stack_t*)GlobalAlloc(GPTR,(sizeof(stack_t)+(g_stringsize)*sizeof(TCHAR)));
+ lstrcpyn(th->text,str,g_stringsize);
+ th->next=*g_stacktop;
+ *g_stacktop=th;
+}
+
+static TCHAR * __stdcall getuservariable(const int varnum)
+{
+ if (varnum < 0 || varnum >= __INST_LAST) return NULL;
+ return g_variables+varnum*g_stringsize;
+}
+
+static void __stdcall setuservariable(const int varnum, const TCHAR *var)
+{
+ if (var != NULL && varnum >= 0 && varnum < __INST_LAST)
+ lstrcpy(g_variables + varnum*g_stringsize, var);
+}
+
+#ifdef _UNICODE
+#define PopStringW(x) popstring(x)
+#define PushStringW(x) pushstring(x)
+#define SetUserVariableW(x,y) setuservariable(x,y)
+
+static int __stdcall PopStringA(char* ansiStr)
+{
+ wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, g_stringsize*sizeof(wchar_t));
+ int rval = popstring(wideStr);
+ WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL);
+ GlobalFree((HGLOBAL)wideStr);
+ return rval;
+}
+
+static void __stdcall PushStringA(const char* ansiStr)
+{
+ wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, g_stringsize*sizeof(wchar_t));
+ MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize);
+ pushstring(wideStr);
+ GlobalFree((HGLOBAL)wideStr);
+ return;
+}
+
+static void __stdcall GetUserVariableW(const int varnum, wchar_t* wideStr)
+{
+ lstrcpyW(wideStr, getuservariable(varnum));
+}
+
+static void __stdcall GetUserVariableA(const int varnum, char* ansiStr)
+{
+ wchar_t* wideStr = getuservariable(varnum);
+ WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL);
+}
+
+static void __stdcall SetUserVariableA(const int varnum, const char* ansiStr)
+{
+ if (ansiStr != NULL && varnum >= 0 && varnum < __INST_LAST)
+ {
+ wchar_t* wideStr = g_variables + varnum * g_stringsize;
+ MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize);
+ }
+}
+
+#else
+// ANSI defs
+
+#define PopStringA(x) popstring(x)
+#define PushStringA(x) pushstring(x)
+#define SetUserVariableA(x,y) setuservariable(x,y)
+
+static int __stdcall PopStringW(wchar_t* wideStr)
+{
+ char* ansiStr = (char*) GlobalAlloc(GPTR, g_stringsize);
+ int rval = popstring(ansiStr);
+ MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize);
+ GlobalFree((HGLOBAL)ansiStr);
+ return rval;
+}
+
+static void __stdcall PushStringW(wchar_t* wideStr)
+{
+ char* ansiStr = (char*) GlobalAlloc(GPTR, g_stringsize);
+ WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL);
+ pushstring(ansiStr);
+ GlobalFree((HGLOBAL)ansiStr);
+}
+
+static void __stdcall GetUserVariableW(const int varnum, wchar_t* wideStr)
+{
+ char* ansiStr = getuservariable(varnum);
+ MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize);
+}
+
+static void __stdcall GetUserVariableA(const int varnum, char* ansiStr)
+{
+ lstrcpyA(ansiStr, getuservariable(varnum));
+}
+
+static void __stdcall SetUserVariableW(const int varnum, const wchar_t* wideStr)
+{
+ if (wideStr != NULL && varnum >= 0 && varnum < __INST_LAST)
+ {
+ char* ansiStr = g_variables + varnum * g_stringsize;
+ WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL);
+ }
+}
+#endif
+
+static BOOL __stdcall IsUnicode(void)
+{
+#ifdef _UNICODE
+ return TRUE;
+#else
+ return FALSE;
+#endif
+}
+
+#endif//_EXDLL_H_
diff --git a/other-licenses/nsis/Contrib/ExDLL/exdll_with_unit.dpr b/other-licenses/nsis/Contrib/ExDLL/exdll_with_unit.dpr new file mode 100644 index 0000000000..007e350dc0 --- /dev/null +++ b/other-licenses/nsis/Contrib/ExDLL/exdll_with_unit.dpr @@ -0,0 +1,31 @@ +{
+ NSIS ExDLL2 example
+ Original is ExDLL
+ (C) 2001 - Peter Windridge
+
+ Changed with delphi unit nsis.pas
+ by bernhard mayer
+
+ Tested in Delphi 7.0
+}
+
+library exdll;
+
+uses
+ nsis, windows;
+
+procedure ex_dll(const hwndParent: HWND; const string_size: integer; const variables: PChar; const stacktop: pointer); cdecl;
+begin
+ // set up global variables
+ Init(hwndParent, string_size, variables, stacktop);
+
+ NSISDialog(GetUserVariable(INST_0), 'The value of $0', MB_OK);
+ NSISDialog(PopString, 'pop', MB_OK);
+ PushString('Hello, this is a push');
+ SetUserVariable(INST_0, 'This is user var $0');
+end;
+
+exports ex_dll;
+
+begin
+end.
diff --git a/other-licenses/nsis/Contrib/ExDLL/exdllutil.cpp b/other-licenses/nsis/Contrib/ExDLL/exdllutil.cpp new file mode 100644 index 0000000000..f1413767aa --- /dev/null +++ b/other-licenses/nsis/Contrib/ExDLL/exdllutil.cpp @@ -0,0 +1,131 @@ +// Unicode support by Jim Park -- 08/23/2007
+
+#include <windows.h>
+#include "exdllutil.h"
+
+// utility functions (not required but often useful)
+static int __stdcall popstring(TCHAR *str)
+{
+ stack_t *th;
+ if (!g_stacktop || !*g_stacktop) return 1;
+ th=(*g_stacktop);
+ lstrcpy(str,th->text);
+ *g_stacktop = th->next;
+ GlobalFree((HGLOBAL)th);
+ return 0;
+}
+
+static void __stdcall pushstring(const TCHAR *str)
+{
+ stack_t *th;
+ if (!g_stacktop) return;
+ th=(stack_t*)GlobalAlloc(GPTR,(sizeof(stack_t)+(g_stringsize)*sizeof(TCHAR)));
+ lstrcpyn(th->text,str,g_stringsize);
+ th->next=*g_stacktop;
+ *g_stacktop=th;
+}
+
+static TCHAR * __stdcall getuservariable(const int varnum)
+{
+ if (varnum < 0 || varnum >= __INST_LAST) return NULL;
+ return g_variables+varnum*g_stringsize;
+}
+
+static void __stdcall setuservariable(const int varnum, const TCHAR *var)
+{
+ if (var != NULL && varnum >= 0 && varnum < __INST_LAST)
+ lstrcpy(g_variables + varnum*g_stringsize, var);
+}
+
+#ifdef _UNICODE
+static int __stdcall PopStringA(char* ansiStr)
+{
+ wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, g_stringsize*sizeof(wchar_t));
+ int rval = popstring(wideStr);
+ WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL);
+ GlobalFree((HGLOBAL)wideStr);
+ return rval;
+}
+
+static void __stdcall PushStringA(const char* ansiStr)
+{
+ wchar_t* wideStr = (wchar_t*) GlobalAlloc(GPTR, g_stringsize*sizeof(wchar_t));
+ MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize);
+ pushtring(wideStr);
+ GlobalFree((HGLOBAL)wideStr);
+ return;
+}
+
+static void __stdcall GetUserVariableW(const int varnum, wchar_t* wideStr)
+{
+ lstrcpyW(wideStr, getuservariable(varnum));
+}
+
+static void __stdcall GetUserVariableA(const int varnum, char* ansiStr)
+{
+ wchar_t* wideStr = getuservariable(varnum);
+ WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL);
+}
+
+static void __stdcall SetUserVariableA(const int varnum, const char* ansiStr)
+{
+ if (ansiStr != NULL && varnum >= 0 && varnum < __INST_LAST)
+ {
+ wchar_t* wideStr = g_variables + varnum * g_stringsize;
+ MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize);
+ }
+}
+
+#else
+// ANSI defs
+static int __stdcall PopStringW(wchar_t* wideStr)
+{
+ char* ansiStr = (char*) GlobalAlloc(GPTR, g_stringsize);
+ int rval = popstring(ansiStr);
+ MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize);
+ GlobalFree((HGLOBAL)ansiStr);
+ return rval;
+}
+
+static void __stdcall PushStringW(wchar_t* wideStr)
+{
+ char* ansiStr = (char*) GlobalAlloc(GPTR, g_stringsize);
+ WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL);
+ pushstring(ansiStr);
+ GlobalFree((HGLOBAL)ansiStr);
+}
+
+static void __stdcall GetUserVariableW(const int varnum, wchar_t* wideStr)
+{
+ char* ansiStr = getuservariable(varnum);
+ MultiByteToWideChar(CP_ACP, 0, ansiStr, -1, wideStr, g_stringsize);
+}
+
+static void __stdcall GetUserVariableA(const int varnum, char* ansiStr)
+{
+ lstrcpyA(ansiStr, getuservariable(varnum));
+}
+
+static void __stdcall SetUserVariableW(const int varnum, const wchar_t* wideStr)
+{
+ if (wideStr != NULL && varnum >= 0 && varnum < __INST_LAST)
+ {
+ char* ansiStr = g_variables + varnum * g_stringsize;
+ WideCharToMultiByte(CP_ACP, 0, wideStr, -1, ansiStr, g_stringsize, NULL, NULL);
+ }
+}
+#endif
+
+static BOOL __stdcall IsUnicode(void)
+{
+#ifdef _UNICODE
+ return TRUE;
+#else
+ return FALSE;
+#endif
+}
+
+static TCHAR* __stdcall AllocString()
+{
+ return (TCHAR*) GlobalAlloc(GPTR, g_stringsize*sizeof(TCHAR));
+}
diff --git a/other-licenses/nsis/Contrib/ExDLL/exdllutil.h b/other-licenses/nsis/Contrib/ExDLL/exdllutil.h new file mode 100644 index 0000000000..51897fc643 --- /dev/null +++ b/other-licenses/nsis/Contrib/ExDLL/exdllutil.h @@ -0,0 +1,119 @@ +// Unicode support by Jim Park -- 08/23/2007
+// Jim Park: Should probably turn this into a nice class for C++ programs.
+
+#pragma once
+#include <windows.h>
+#include <tchar.h>
+// only include this file from one place in your DLL.
+// (it is all static, if you use it in two places it will fail)
+
+#define EXDLL_INIT() { \
+ g_stringsize=string_size; \
+ g_stacktop=stacktop; \
+ g_variables=variables; }
+
+// For page showing plug-ins
+#define WM_NOTIFY_OUTER_NEXT (WM_USER+0x8)
+#define WM_NOTIFY_CUSTOM_READY (WM_USER+0xd)
+
+/* Jim Park: This char is compared as an int value and therefore
+ it's fine as an ASCII. Do not need to change to wchar_t since
+ it will get the same integer value. */
+#define NOTIFY_BYE_BYE _T('x')
+
+typedef struct _stack_t {
+ struct _stack_t *next;
+ TCHAR text[1]; // this should be the length of string_size
+} stack_t;
+
+static unsigned int g_stringsize;
+static stack_t **g_stacktop;
+static TCHAR *g_variables;
+
+
+enum
+{
+INST_0, // $0
+INST_1, // $1
+INST_2, // $2
+INST_3, // $3
+INST_4, // $4
+INST_5, // $5
+INST_6, // $6
+INST_7, // $7
+INST_8, // $8
+INST_9, // $9
+INST_R0, // $R0
+INST_R1, // $R1
+INST_R2, // $R2
+INST_R3, // $R3
+INST_R4, // $R4
+INST_R5, // $R5
+INST_R6, // $R6
+INST_R7, // $R7
+INST_R8, // $R8
+INST_R9, // $R9
+INST_CMDLINE, // $CMDLINE
+INST_INSTDIR, // $INSTDIR
+INST_OUTDIR, // $OUTDIR
+INST_EXEDIR, // $EXEDIR
+INST_LANG, // $LANGUAGE
+__INST_LAST
+};
+
+typedef struct {
+ int autoclose;
+ int all_user_var;
+ int exec_error;
+ int abort;
+ int exec_reboot;
+ int reboot_called;
+ int XXX_cur_insttype; // deprecated
+ int XXX_insttype_changed; // deprecated
+ int silent;
+ int instdir_error;
+ int rtl;
+ int errlvl;
+ int alter_reg_view;
+} exec_flags_type;
+
+typedef struct {
+ exec_flags_type *exec_flags;
+ int (__stdcall *ExecuteCodeSegment)(int, HWND);
+ void (__stdcall *validate_filename)(TCHAR *);
+} extra_parameters;
+
+static int __stdcall popstring(TCHAR *str); // 0 on success, 1 on empty stack
+static void __stdcall pushstring(const TCHAR *str);
+static char * __stdcall getuservariable(const int varnum);
+static void __stdcall setuservariable(const int varnum, const TCHAR *var);
+
+#ifdef _UNICODE
+#define PopStringW(x) popstring(x)
+#define PushStringW(x) pushstring(x)
+#define SetUserVariableW(x,y) setuservariable(x,y)
+
+static int __stdcall PopStringA(char* ansiStr);
+static void __stdcall PushStringA(const char* ansiStr);
+static void __stdcall GetUserVariableW(const int varnum, wchar_t* wideStr);
+static void __stdcall GetUserVariableA(const int varnum, char* ansiStr);
+static void __stdcall SetUserVariableA(const int varnum, const char* ansiStr);
+
+#else
+// ANSI defs
+
+#define PopStringA(x) popstring(x)
+#define PushStringA(x) pushstring(x)
+#define SetUserVariableA(x,y) setuservariable(x,y)
+
+static int __stdcall PopStringW(wchar_t* wideStr);
+static void __stdcall PushStringW(wchar_t* wideStr);
+static void __stdcall GetUserVariableW(const int varnum, wchar_t* wideStr);
+static void __stdcall GetUserVariableA(const int varnum, char* ansiStr);
+static void __stdcall SetUserVariableW(const int varnum, const wchar_t* wideStr);
+
+#endif
+
+static BOOL __stdcall IsUnicode(void)
+static TCHAR* __stdcall AllocString();
+
diff --git a/other-licenses/nsis/Contrib/ExDLL/extdll.inc b/other-licenses/nsis/Contrib/ExDLL/extdll.inc new file mode 100644 index 0000000000..4c48ae5ce5 --- /dev/null +++ b/other-licenses/nsis/Contrib/ExDLL/extdll.inc @@ -0,0 +1,145 @@ +;################################################################
+; ExtDLL header for MASM32
+;
+; Author: Ramon
+;
+; Obs: This header must be included after windows.inc and kernel32.inc
+; because it need the prototypes for lstrcpy, lstrcpyn,
+; GlobalAlloc and GlobalFree
+;
+;################################################################
+stack_t struct
+ next dd ?
+ text dd ? ; 1 DUP(?) ; this should be the length of string_size
+stack_t ends
+
+.const
+; For page showing plug-ins
+WM_NOTIFY_OUTER_NEXT equ (WM_USER+0x8)
+WM_NOTIFY_CUSTOM_READY equ (WM_USER+0xd)
+NOTIFY_BYE_BYE equ 'x'
+
+INST_0 EQU 0 ; $0
+INST_1 EQU 1 ; $1
+INST_2 EQU 2 ; $2
+INST_3 EQU 3 ; $3
+INST_4 EQU 4 ; $4
+INST_5 EQU 5 ; $5
+INST_6 EQU 6 ; $6
+INST_7 EQU 7 ; $7
+INST_8 EQU 8 ; $8
+INST_9 EQU 9 ; $9
+INST_R0 EQU 10 ; $R0
+INST_R1 EQU 11 ; $R1
+INST_R2 EQU 12 ; $R2
+INST_R3 EQU 13 ; $R3
+INST_R4 EQU 14 ; $R4
+INST_R5 EQU 15 ; $R5
+INST_R6 EQU 16 ; $R6
+INST_R7 EQU 17 ; $R7
+INST_R8 EQU 18 ; $R8
+INST_R9 EQU 19 ; $R9
+INST_CMDLINE EQU 20 ; $CMDLINE
+INST_INSTDIR EQU 21 ; $INSTDIR
+INST_OUTDIR EQU 22 ; $OUTDIR
+INST_EXEDIR EQU 23 ; $EXEDIR
+INST_LANG EQU 24 ; $LANGUAGE
+__INST_LAST EQU 25
+
+.data?
+g_stringsize dd ?
+g_stacktop dd ?
+g_variables dd ?
+
+m2m MACRO M1, M2
+ push M2
+ pop M1
+ENDM
+
+EXDLL_INIT MACRO
+ m2m g_stringsize, string_size
+ m2m g_stacktop, stacktop
+ m2m g_variables, variables
+ENDM
+
+.code
+
+; utility functions (not required but often useful)
+popstring proc uses edi pStr:DWORD
+
+ LOCAL th:DWORD
+
+ mov edi, g_stacktop
+ cmp edi, 0
+ jz STACK_ERR
+ mov edi, [edi]
+ cmp edi, 0
+ jz STACK_ERR
+
+ ASSUME edi:PTR stack_t
+ invoke lstrcpy, pStr, ADDR [edi].text
+ mov th , edi
+ mov edi, [edi].next
+ mov eax, g_stacktop
+ mov [eax], edi
+ invoke GlobalFree, th
+ ASSUME edi:PTR NOTHING
+ mov eax, 0
+ ret
+
+STACK_ERR:
+ mov eax, 1
+ ret
+
+popstring endp
+
+pushstring proc uses edi pStr:DWORD
+
+ cmp g_stacktop, 0
+ jz STACK_ERR
+
+ mov eax, sizeof stack_t
+ add eax, g_stringsize
+ invoke GlobalAlloc, GPTR, eax
+
+ mov edi, eax
+ assume edi:PTR stack_t
+
+ invoke lstrcpyn, ADDR [edi].text, pStr, g_stringsize
+ mov eax, g_stacktop
+ push DWORD PTR[eax]
+ mov [eax], edi
+ pop eax
+ ;lea edi, [edi].next ; Not needed [edi].next == edi
+ mov DWORD PTR[edi], eax
+ ASSUME edi:PTR NOTHING
+
+STACK_ERR:
+ ret
+
+pushstring endp
+
+getuservariable proc varnum:DWORD
+
+ .if varnum < 0 || varnum >= __INST_LAST
+ xor eax, eax
+ .else
+ mov eax, varnum
+ imul eax, g_stringsize
+ add eax, g_variables
+ .endif
+ ret
+
+getuservariable endp
+
+setuservariable proc varnum:DWORD, var:DWORD
+
+ .if (var != NULL && varnum >= 0 && varnum < __INST_LAST)
+ mov eax, varnum
+ imul eax, g_stringsize
+ add eax, g_variables
+ invoke lstrcpy, eax, var
+ .endif
+ ret
+
+setuservariable endp
diff --git a/other-licenses/nsis/Contrib/ExDLL/nsis.pas b/other-licenses/nsis/Contrib/ExDLL/nsis.pas new file mode 100644 index 0000000000..356d26cbde --- /dev/null +++ b/other-licenses/nsis/Contrib/ExDLL/nsis.pas @@ -0,0 +1,126 @@ +{
+ Original Code from
+ (C) 2001 - Peter Windridge
+
+ Code in seperate unit and some changes
+ 2003 by Bernhard Mayer
+
+ Fixed and formatted by Brett Dever
+ http://editor.nfscheats.com/
+
+ simply include this unit in your plugin project and export
+ functions as needed
+}
+
+
+unit nsis;
+
+interface
+
+uses
+ windows;
+
+type
+ VarConstants = (
+ INST_0, // $0
+ INST_1, // $1
+ INST_2, // $2
+ INST_3, // $3
+ INST_4, // $4
+ INST_5, // $5
+ INST_6, // $6
+ INST_7, // $7
+ INST_8, // $8
+ INST_9, // $9
+ INST_R0, // $R0
+ INST_R1, // $R1
+ INST_R2, // $R2
+ INST_R3, // $R3
+ INST_R4, // $R4
+ INST_R5, // $R5
+ INST_R6, // $R6
+ INST_R7, // $R7
+ INST_R8, // $R8
+ INST_R9, // $R9
+ INST_CMDLINE, // $CMDLINE
+ INST_INSTDIR, // $INSTDIR
+ INST_OUTDIR, // $OUTDIR
+ INST_EXEDIR, // $EXEDIR
+ INST_LANG, // $LANGUAGE
+ __INST_LAST
+ );
+ TVariableList = INST_0..__INST_LAST;
+ pstack_t = ^stack_t;
+ stack_t = record
+ next: pstack_t;
+ text: PChar;
+ end;
+
+var
+ g_stringsize: integer;
+ g_stacktop: ^pstack_t;
+ g_variables: PChar;
+ g_hwndParent: HWND;
+
+procedure Init(const hwndParent: HWND; const string_size: integer; const variables: PChar; const stacktop: pointer);
+function PopString(): string;
+procedure PushString(const str: string='');
+function GetUserVariable(const varnum: TVariableList): string;
+procedure SetUserVariable(const varnum: TVariableList; const value: string);
+procedure NSISDialog(const text, caption: string; const buttons: integer);
+
+implementation
+
+procedure Init(const hwndParent: HWND; const string_size: integer; const variables: PChar; const stacktop: pointer);
+begin
+ g_stringsize := string_size;
+ g_hwndParent := hwndParent;
+ g_stacktop := stacktop;
+ g_variables := variables;
+end;
+
+function PopString(): string;
+var
+ th: pstack_t;
+begin
+ if integer(g_stacktop^) <> 0 then begin
+ th := g_stacktop^;
+ Result := PChar(@th.text);
+ g_stacktop^ := th.next;
+ GlobalFree(HGLOBAL(th));
+ end;
+end;
+
+procedure PushString(const str: string='');
+var
+ th: pstack_t;
+begin
+ if integer(g_stacktop) <> 0 then begin
+ th := pstack_t(GlobalAlloc(GPTR, SizeOf(stack_t) + g_stringsize));
+ lstrcpyn(@th.text, PChar(str), g_stringsize);
+ th.next := g_stacktop^;
+ g_stacktop^ := th;
+ end;
+end;
+
+function GetUserVariable(const varnum: TVariableList): string;
+begin
+ if (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then
+ Result := g_variables + integer(varnum) * g_stringsize
+ else
+ Result := '';
+end;
+
+procedure SetUserVariable(const varnum: TVariableList; const value: string);
+begin
+ if (value <> '') and (integer(varnum) >= 0) and (integer(varnum) < integer(__INST_LAST)) then
+ lstrcpy(g_variables + integer(varnum) * g_stringsize, PChar(value))
+end;
+
+procedure NSISDialog(const text, caption: string; const buttons: integer);
+begin
+ MessageBox(g_hwndParent, PChar(text), PChar(caption), buttons);
+end;
+
+begin
+end.
diff --git a/other-licenses/nsis/Contrib/ExDLL/tchar.h b/other-licenses/nsis/Contrib/ExDLL/tchar.h new file mode 100644 index 0000000000..5c18ffb778 --- /dev/null +++ b/other-licenses/nsis/Contrib/ExDLL/tchar.h @@ -0,0 +1,210 @@ +/*
+ * tchar.h
+ *
+ * This file is a part of NSIS.
+ *
+ * Copyright (C) 1999-2007 Nullsoft and Contributors
+ *
+ * This software is provided 'as-is', without any express or implied
+ * warranty.
+ *
+ * For Unicode support by Jim Park -- 08/30/2007
+ */
+
+// Jim Park: Only those we use are listed here.
+
+#pragma once
+
+#ifdef _UNICODE
+
+#ifndef _T
+#define __T(x) L ## x
+#define _T(x) __T(x)
+#define _TEXT(x) __T(x)
+#endif
+typedef wchar_t TCHAR;
+typedef wchar_t _TUCHAR;
+
+// program
+#define _tmain wmain
+#define _tWinMain wWinMain
+#define _tenviron _wenviron
+#define __targv __wargv
+
+// printfs
+#define _ftprintf fwprintf
+#define _sntprintf _snwprintf
+#define _stprintf _swprintf
+#define _tprintf wprintf
+#define _vftprintf vfwprintf
+#define _vsntprintf _vsnwprintf
+#define _vstprintf _vswprintf
+
+// scanfs
+#define _tscanf wscanf
+#define _stscanf swscanf
+
+// string manipulations
+#define _tcscat wcscat
+#define _tcschr wcschr
+#define _tcsclen wcslen
+#define _tcscpy wcscpy
+#define _tcsdup _wcsdup
+#define _tcslen wcslen
+#define _tcsnccpy wcsncpy
+#define _tcsncpy wcsncpy
+#define _tcsrchr wcsrchr
+#define _tcsstr wcsstr
+#define _tcstok wcstok
+
+// string comparisons
+#define _tcscmp wcscmp
+#define _tcsicmp _wcsicmp
+#define _tcsncicmp _wcsnicmp
+#define _tcsncmp wcsncmp
+#define _tcsnicmp _wcsnicmp
+
+// upper / lower
+#define _tcslwr _wcslwr
+#define _tcsupr _wcsupr
+#define _totlower towlower
+#define _totupper towupper
+
+// conversions to numbers
+#define _tcstoi64 _wcstoi64
+#define _tcstol wcstol
+#define _tcstoul wcstoul
+#define _tstof _wtof
+#define _tstoi _wtoi
+#define _tstoi64 _wtoi64
+#define _ttoi _wtoi
+#define _ttoi64 _wtoi64
+#define _ttol _wtol
+
+// conversion from numbers to strings
+#define _itot _itow
+#define _ltot _ltow
+#define _i64tot _i64tow
+#define _ui64tot _ui64tow
+
+// file manipulations
+#define _tfopen _wfopen
+#define _topen _wopen
+#define _tremove _wremove
+#define _tunlink _wunlink
+
+// reading and writing to i/o
+#define _fgettc fgetwc
+#define _fgetts fgetws
+#define _fputts fputws
+#define _gettchar getwchar
+
+// directory
+#define _tchdir _wchdir
+
+// environment
+#define _tgetenv _wgetenv
+#define _tsystem _wsystem
+
+// time
+#define _tcsftime wcsftime
+
+#else // ANSI
+
+#ifndef _T
+#define _T(x) x
+#define _TEXT(x) x
+#endif
+typedef char TCHAR;
+typedef unsigned char _TUCHAR;
+
+// program
+#define _tmain main
+#define _tWinMain WinMain
+#define _tenviron environ
+#define __targv __argv
+
+// printfs
+#define _ftprintf fprintf
+#define _sntprintf _snprintf
+#define _stprintf sprintf
+#define _tprintf printf
+#define _vftprintf vfprintf
+#define _vsntprintf _vsnprintf
+#define _vstprintf vsprintf
+
+// scanfs
+#define _tscanf scanf
+#define _stscanf sscanf
+
+// string manipulations
+#define _tcscat strcat
+#define _tcschr strchr
+#define _tcsclen strlen
+#define _tcscnlen strnlen
+#define _tcscpy strcpy
+#define _tcsdup _strdup
+#define _tcslen strlen
+#define _tcsnccpy strncpy
+#define _tcsrchr strrchr
+#define _tcsstr strstr
+#define _tcstok strtok
+
+// string comparisons
+#define _tcscmp strcmp
+#define _tcsicmp _stricmp
+#define _tcsncmp strncmp
+#define _tcsncicmp _strnicmp
+#define _tcsnicmp _strnicmp
+
+// upper / lower
+#define _tcslwr _strlwr
+#define _tcsupr _strupr
+
+#define _totupper toupper
+#define _totlower tolower
+
+// conversions to numbers
+#define _tcstol strtol
+#define _tcstoul strtoul
+#define _tstof atof
+#define _tstoi atoi
+#define _tstoi64 _atoi64
+#define _tstoi64 _atoi64
+#define _ttoi atoi
+#define _ttoi64 _atoi64
+#define _ttol atol
+
+// conversion from numbers to strings
+#define _i64tot _i64toa
+#define _itot _itoa
+#define _ltot _ltoa
+#define _ui64tot _ui64toa
+
+// file manipulations
+#define _tfopen fopen
+#define _topen _open
+#define _tremove remove
+#define _tunlink _unlink
+
+// reading and writing to i/o
+#define _fgettc fgetc
+#define _fgetts fgets
+#define _fputts fputs
+#define _gettchar getchar
+
+// directory
+#define _tchdir _chdir
+
+// environment
+#define _tgetenv getenv
+#define _tsystem system
+
+// time
+#define _tcsftime strftime
+
+#endif
+
+// is functions (the same in Unicode / ANSI)
+#define _istgraph isgraph
+#define _istascii __isascii
diff --git a/other-licenses/nsis/Contrib/ExecInExplorer/ExecInExplorer.cpp b/other-licenses/nsis/Contrib/ExecInExplorer/ExecInExplorer.cpp new file mode 100644 index 0000000000..05e0ed5e92 --- /dev/null +++ b/other-licenses/nsis/Contrib/ExecInExplorer/ExecInExplorer.cpp @@ -0,0 +1,212 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, you can obtain one at http://mozilla.org/MPL/2.0/. */ + +// This file is an NSIS plugin which exports a function that starts a process +// from a provided path by using the shell automation API to have explorer.exe +// invoke ShellExecute. This roundabout method of starting a process is useful +// because it means the new process will use the integrity level and security +// token of the shell, so it allows starting an unelevated process from inside +// an elevated one. The method is based on +// https://blogs.msdn.microsoft.com/oldnewthing/20131118-00/?p=2643 +// but the code has been rewritten to remove the need for ATL or the C runtime. + +// Normally an NSIS installer would use the UAC plugin, which itself uses both +// an unelevated and an elevated process, and the elevated process can invoke +// functions in the unelevated one, so this plugin wouldn't be needed. +// But uninstallers are often directly run elevated because that's just how +// the Windows UI launches them, so there is no unelevated process. This +// plugin allows starting a needed unelevated process in that situation. + +#include <windows.h> +#include <shlobj.h> + +#pragma comment(lib, "shlwapi.lib") + +static IShellView* +GetDesktopWindowShellView() +{ + IShellView* view = nullptr; + IShellWindows* shell = nullptr; + CoCreateInstance(CLSID_ShellWindows, NULL, CLSCTX_LOCAL_SERVER, + IID_PPV_ARGS(&shell)); + if (shell) { + VARIANT empty; + VariantInit(&empty); + + VARIANT loc; + loc.vt = VT_VARIANT | VT_BYREF; + PIDLIST_ABSOLUTE locList; + SHGetFolderLocation(nullptr, CSIDL_DESKTOP, nullptr, 0, &locList); + loc.byref = locList; + + HWND windowHandle = 0; + IDispatch* dispatch = nullptr; + + shell->FindWindowSW(&loc, &empty, SWC_DESKTOP, (long*)&windowHandle, + SWFO_NEEDDISPATCH, &dispatch); + if (dispatch) { + IServiceProvider* provider = nullptr; + dispatch->QueryInterface(IID_PPV_ARGS(&provider)); + if (provider) { + IShellBrowser* browser = nullptr; + provider->QueryService(SID_STopLevelBrowser, IID_PPV_ARGS(&browser)); + if (browser) { + browser->QueryActiveShellView(&view); + browser->Release(); + } + provider->Release(); + } + dispatch->Release(); + } + shell->Release(); + } + + return view; +} + +static IShellDispatch2* +GetApplicationFromShellView(IShellView* view) +{ + IShellDispatch2* shellDispatch = nullptr; + IDispatch* viewDisp = nullptr; + HRESULT hr = view->GetItemObject(SVGIO_BACKGROUND, IID_PPV_ARGS(&viewDisp)); + if (SUCCEEDED(hr)) { + IShellFolderViewDual* shellViewFolder = nullptr; + viewDisp->QueryInterface(IID_PPV_ARGS(&shellViewFolder)); + if (shellViewFolder) { + IDispatch* dispatch = nullptr; + shellViewFolder->get_Application(&dispatch); + if (dispatch) { + dispatch->QueryInterface(IID_PPV_ARGS(&shellDispatch)); + dispatch->Release(); + } + shellViewFolder->Release(); + } + viewDisp->Release(); + } + return shellDispatch; +} + +static bool +ShellExecInExplorerProcess(wchar_t* path, wchar_t* args = nullptr) +{ + bool rv = false; + if (SUCCEEDED(CoInitialize(nullptr))) { + IShellView *desktopView = GetDesktopWindowShellView(); + if (desktopView) { + IShellDispatch2 *shellDispatch = GetApplicationFromShellView(desktopView); + if (shellDispatch) { + BSTR bstrPath = SysAllocString(path); + VARIANT vArgs; + VariantInit(&vArgs); + if (args) { + vArgs.vt = VT_BSTR; + vArgs.bstrVal = SysAllocString(args); + } + rv = SUCCEEDED(shellDispatch->ShellExecuteW(bstrPath, vArgs, VARIANT{}, + VARIANT{}, VARIANT{})); + VariantClear(&vArgs); + SysFreeString(bstrPath); + shellDispatch->Release(); + } + desktopView->Release(); + } + CoUninitialize(); + } + return rv; +} + +struct stack_t { + stack_t* next; + TCHAR text[MAX_PATH]; +}; + +/** + * Removes an element from the top of the NSIS stack + * + * @param stacktop A pointer to the top of the stack + * @param str The string to pop to + * @param len The max length + * @return 0 on success + */ +int +popstring(stack_t **stacktop, TCHAR *str, int len) +{ + // Removes the element from the top of the stack and puts it in the buffer + stack_t *th; + if (!stacktop || !*stacktop) { + return 1; + } + + th = (*stacktop); + lstrcpyn(str, th->text, len); + *stacktop = th->next; + HeapFree(GetProcessHeap(), 0, th); + return 0; +} + +/** + * Adds an element to the top of the NSIS stack + * + * @param stacktop A pointer to the top of the stack + * @param str The string to push on the stack + * @param len The length of the string to push on the stack + * @return 0 on success + */ +void +pushstring(stack_t **stacktop, const TCHAR *str, int len) +{ + stack_t *th; + if (!stacktop) { + return; + } + th = (stack_t*)HeapAlloc(GetProcessHeap(), 0, sizeof(stack_t) + len); + lstrcpyn(th->text, str, len); + th->next = *stacktop; + *stacktop = th; +} + +/** +* Starts an executable or URL from the shell process. +* +* @param stacktop Pointer to the top of the stack, AKA the first parameter to + the plugin call. Should contain the file or URL to execute. +* @return 1 if the file/URL was executed successfully, 0 if it was not +*/ +extern "C" void __declspec(dllexport) +Exec(HWND, int, TCHAR *, stack_t **stacktop, void *) +{ + wchar_t path[MAX_PATH + 1]; + wchar_t args[MAX_PATH + 1]; + bool rv = false; + bool restoreArgString = false; + // We're skipping building the C runtime to keep the file size low, so we + // can't use a normal string initialization because that would call memset. + path[0] = L'\0'; + args[0] = L'\0'; + popstring(stacktop, path, MAX_PATH); + if (popstring(stacktop, args, MAX_PATH) == 0) { + // This stack item may not be for us, but we don't know yet. + restoreArgString = true; + } + + if (lstrcmpW(args, L"/cmdargs") == 0) { + popstring(stacktop, args, MAX_PATH); + rv = ShellExecInExplorerProcess(path, args); + } else { + // If the stack wasn't empty, then we popped something that wasn't for us. + if (restoreArgString) { + pushstring(stacktop, args, lstrlenW(args)); + } + rv = ShellExecInExplorerProcess(path); + } + + pushstring(stacktop, rv ? L"1" : L"0", 2); +} + +BOOL APIENTRY +DllMain(HMODULE, DWORD, LPVOID) +{ + return TRUE; +} diff --git a/other-licenses/nsis/Contrib/ExecInExplorer/ExecInExplorer.sln b/other-licenses/nsis/Contrib/ExecInExplorer/ExecInExplorer.sln new file mode 100644 index 0000000000..cbd2ea4bf0 --- /dev/null +++ b/other-licenses/nsis/Contrib/ExecInExplorer/ExecInExplorer.sln @@ -0,0 +1,31 @@ +
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio 15
+VisualStudioVersion = 15.0.27428.2015
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ExecInExplorer", "ExecInExplorer.vcxproj", "{B5DBA89B-37EE-425C-A375-4E04E69731FA}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x64 = Debug|x64
+ Debug|x86 = Debug|x86
+ Release|x64 = Release|x64
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {B5DBA89B-37EE-425C-A375-4E04E69731FA}.Debug|x64.ActiveCfg = Debug|x64
+ {B5DBA89B-37EE-425C-A375-4E04E69731FA}.Debug|x64.Build.0 = Debug|x64
+ {B5DBA89B-37EE-425C-A375-4E04E69731FA}.Debug|x86.ActiveCfg = Debug|Win32
+ {B5DBA89B-37EE-425C-A375-4E04E69731FA}.Debug|x86.Build.0 = Debug|Win32
+ {B5DBA89B-37EE-425C-A375-4E04E69731FA}.Release|x64.ActiveCfg = Release|x64
+ {B5DBA89B-37EE-425C-A375-4E04E69731FA}.Release|x64.Build.0 = Release|x64
+ {B5DBA89B-37EE-425C-A375-4E04E69731FA}.Release|x86.ActiveCfg = Release|Win32
+ {B5DBA89B-37EE-425C-A375-4E04E69731FA}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {69740CF4-5E42-4A56-AFF5-2D17D42CFB75}
+ EndGlobalSection
+EndGlobal
diff --git a/other-licenses/nsis/Contrib/ExecInExplorer/ExecInExplorer.vcxproj b/other-licenses/nsis/Contrib/ExecInExplorer/ExecInExplorer.vcxproj new file mode 100644 index 0000000000..fcb217d87c --- /dev/null +++ b/other-licenses/nsis/Contrib/ExecInExplorer/ExecInExplorer.vcxproj @@ -0,0 +1,175 @@ +<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Debug|x64">
+ <Configuration>Debug</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|x64">
+ <Configuration>Release</Configuration>
+ <Platform>x64</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <VCProjectVersion>15.0</VCProjectVersion>
+ <ProjectGuid>{B5DBA89B-37EE-425C-A375-4E04E69731FA}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ <RootNamespace>ExecInExplorer</RootNamespace>
+ <WindowsTargetPlatformVersion>10.0.15063.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v141</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="Shared">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <LinkIncremental>false</LinkIncremental>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <LinkIncremental>false</LinkIncremental>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LinkIncremental>false</LinkIncremental>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <LinkIncremental>false</LinkIncremental>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>false</SDLCheck>
+ <PreprocessorDefinitions>WIN32;_DEBUG;EXECINEXPLORER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ <OmitDefaultLibName>true</OmitDefaultLibName>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <BasicRuntimeChecks>Default</BasicRuntimeChecks>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EntryPointSymbol>DllMain</EntryPointSymbol>
+ <LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
+ <ClCompile>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>false</SDLCheck>
+ <PreprocessorDefinitions>_DEBUG;EXECINEXPLORER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ <OmitDefaultLibName>true</OmitDefaultLibName>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <BasicRuntimeChecks>Default</BasicRuntimeChecks>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EntryPointSymbol>DllMain</EntryPointSymbol>
+ <LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>false</SDLCheck>
+ <PreprocessorDefinitions>WIN32;NDEBUG;EXECINEXPLORER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <OmitDefaultLibName>true</OmitDefaultLibName>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <GenerateDebugInformation>false</GenerateDebugInformation>
+ <EntryPointSymbol>DllMain</EntryPointSymbol>
+ <LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
+ <ClCompile>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MaxSpeed</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>false</SDLCheck>
+ <PreprocessorDefinitions>NDEBUG;EXECINEXPLORER_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <OmitDefaultLibName>true</OmitDefaultLibName>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <WholeProgramOptimization>false</WholeProgramOptimization>
+ </ClCompile>
+ <Link>
+ <SubSystem>Windows</SubSystem>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <GenerateDebugInformation>false</GenerateDebugInformation>
+ <EntryPointSymbol>DllMain</EntryPointSymbol>
+ <LinkTimeCodeGeneration>Default</LinkTimeCodeGeneration>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="ExecInExplorer.cpp" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file diff --git a/other-licenses/nsis/Contrib/HttpPostFile/HttpPostFile.cpp b/other-licenses/nsis/Contrib/HttpPostFile/HttpPostFile.cpp new file mode 100644 index 0000000000..7b55493829 --- /dev/null +++ b/other-licenses/nsis/Contrib/HttpPostFile/HttpPostFile.cpp @@ -0,0 +1,304 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// To explain some of the oddities:
+// This plugin avoids linking against a runtime that might not be present, thus
+// it avoids standard library functions.
+// NSIS requires GlobalAlloc/GlobalFree for its interfaces, and I use them for
+// other allocations (vs e.g. HeapAlloc) for the sake of consistency.
+
+#include <Windows.h>
+#include <Wininet.h>
+
+#define AGENT_NAME L"HttpPostFile plugin"
+
+PBYTE LoadFileData(LPWSTR fileName, DWORD& cbData);
+bool HttpPost(LPURL_COMPONENTS pUrl, LPWSTR contentTypeHeader, PBYTE data,
+ DWORD cbData);
+
+// NSIS API
+typedef struct _stack_t {
+ struct _stack_t* next;
+ WCHAR text[1];
+} stack_t;
+
+// Unlink and return the topmost element of the stack, if any.
+static stack_t* popstack(stack_t** stacktop) {
+ if (!stacktop || !*stacktop) return nullptr;
+ stack_t* element = *stacktop;
+ *stacktop = element->next;
+ element->next = nullptr;
+ return element;
+}
+
+// Allocate a new stack element (with space for `stringsize`), copy the string,
+// add to the top of the stack.
+static void pushstring(LPCWSTR str, stack_t** stacktop,
+ unsigned int stringsize) {
+ stack_t* element;
+ if (!stacktop) return;
+
+ // The allocation here has space for stringsize+1 WCHARs, because stack_t.text
+ // is 1 element long. This is consistent with the NSIS ExDLL example, though
+ // inconsistent with the comment that says the array "should be the length of
+ // g_stringsize when allocating". I'm sticking to consistency with
+ // the code, and erring towards having a larger buffer than necessary.
+
+ element = (stack_t*)GlobalAlloc(
+ GPTR, (sizeof(stack_t) + stringsize * sizeof(*str)));
+ lstrcpynW(element->text, str, stringsize);
+ element->next = *stacktop;
+ *stacktop = element;
+}
+
+BOOL APIENTRY DllMain(HINSTANCE instance, DWORD reason, LPVOID) {
+ // No initialization or cleanup is needed.
+ return TRUE;
+}
+
+extern "C" {
+
+// HttpPostFile::Post <File> <Content-Type header with \r\n> <URL>
+//
+// e.g. HttpPostFile "C:\blah.json" "Content-Type: application/json$\r$\n"
+// "https://example.com"
+//
+// Leaves a result string on the stack, "success" if the POST was successful, an
+// error message otherwise.
+// The status code from the server is not checked, as long as we got some
+// response the result will be "success". The response is read, but discarded.
+void __declspec(dllexport)
+ Post(HWND hwndParent, int string_size, char* /* variables */,
+ stack_t** stacktop, void* /* extra_parameters */) {
+ static const URL_COMPONENTS kZeroComponents = {0};
+ const WCHAR* errorMsg = L"error";
+
+ DWORD cbData = INVALID_FILE_SIZE;
+ PBYTE data = nullptr;
+
+ // Copy a constant, because initializing an automatic variable with {0} ends
+ // up linking to memset, which isn't available.
+ URL_COMPONENTS components = kZeroComponents;
+
+ // Get args, taking ownership of the strings from the stack, to avoid
+ // allocating and copying strings.
+ stack_t* postFileName = popstack(stacktop);
+ stack_t* contentTypeHeader = popstack(stacktop);
+ stack_t* url = popstack(stacktop);
+
+ if (!postFileName || !contentTypeHeader || !url) {
+ errorMsg = L"error getting arguments";
+ goto finish;
+ }
+
+ data = LoadFileData(postFileName->text, cbData);
+ if (!data || cbData == INVALID_FILE_SIZE) {
+ errorMsg = L"error reading file";
+ goto finish;
+ }
+
+ {
+ // This length is used to allocate for the host name and path components,
+ // which should be no longer than the source URL.
+ int urlBufLen = lstrlenW(url->text) + 1;
+
+ components.dwStructSize = sizeof(components);
+ components.dwHostNameLength = urlBufLen;
+ components.dwUrlPathLength = urlBufLen;
+ components.lpszHostName =
+ (LPWSTR)GlobalAlloc(GPTR, urlBufLen * sizeof(WCHAR));
+ components.lpszUrlPath =
+ (LPWSTR)GlobalAlloc(GPTR, urlBufLen * sizeof(WCHAR));
+ }
+
+ errorMsg = L"error parsing URL";
+ if (components.lpszHostName && components.lpszUrlPath &&
+ InternetCrackUrl(url->text, 0, 0, &components) &&
+ (components.nScheme == INTERNET_SCHEME_HTTP ||
+ components.nScheme == INTERNET_SCHEME_HTTPS)) {
+ errorMsg = L"error sending HTTP request";
+ if (HttpPost(&components, contentTypeHeader->text, data, cbData)) {
+ // success!
+ errorMsg = nullptr;
+ }
+ }
+
+finish:
+ if (components.lpszUrlPath) {
+ GlobalFree(components.lpszUrlPath);
+ }
+ if (components.lpszHostName) {
+ GlobalFree(components.lpszHostName);
+ }
+ if (data) {
+ GlobalFree(data);
+ }
+
+ // Free args taken from the NSIS stack
+ if (url) {
+ GlobalFree(url);
+ }
+ if (contentTypeHeader) {
+ GlobalFree(contentTypeHeader);
+ }
+ if (postFileName) {
+ GlobalFree(postFileName);
+ }
+
+ if (errorMsg) {
+ pushstring(errorMsg, stacktop, string_size);
+ } else {
+ pushstring(L"success", stacktop, string_size);
+ }
+}
+}
+
+// Returns buffer with file contents on success, placing the size in cbData.
+// Returns nullptr on failure.
+// Caller must use GlobalFree() on the returned buffer if non-null.
+PBYTE LoadFileData(LPWSTR fileName, DWORD& cbData) {
+ bool success = false;
+
+ HANDLE hPostFile = INVALID_HANDLE_VALUE;
+
+ PBYTE data = nullptr;
+
+ DWORD bytesRead;
+ DWORD bytesReadTotal;
+
+ hPostFile = CreateFile(fileName, GENERIC_READ, FILE_SHARE_READ, nullptr,
+ OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr);
+ if (hPostFile == INVALID_HANDLE_VALUE) {
+ goto finish;
+ }
+
+ cbData = GetFileSize(hPostFile, NULL);
+ if (cbData == INVALID_FILE_SIZE) {
+ goto finish;
+ }
+
+ data = (PBYTE)GlobalAlloc(GPTR, cbData);
+ if (!data) {
+ goto finish;
+ }
+
+ bytesReadTotal = 0;
+ do {
+ if (!ReadFile(hPostFile, data + bytesReadTotal, cbData - bytesReadTotal,
+ &bytesRead, nullptr /* overlapped */)) {
+ goto finish;
+ }
+ bytesReadTotal += bytesRead;
+ } while (bytesReadTotal < cbData && bytesRead > 0);
+
+ if (bytesReadTotal == cbData) {
+ success = true;
+ }
+
+finish:
+ if (!success) {
+ if (data) {
+ GlobalFree(data);
+ data = nullptr;
+ }
+ cbData = INVALID_FILE_SIZE;
+ }
+ if (hPostFile != INVALID_HANDLE_VALUE) {
+ CloseHandle(hPostFile);
+ hPostFile = INVALID_HANDLE_VALUE;
+ }
+
+ return data;
+}
+
+// Returns true on success
+bool HttpPost(LPURL_COMPONENTS pUrl, LPWSTR contentTypeHeader, PBYTE data,
+ DWORD cbData) {
+ bool success = false;
+
+ HINTERNET hInternet = nullptr;
+ HINTERNET hConnect = nullptr;
+ HINTERNET hRequest = nullptr;
+
+ hInternet = InternetOpen(AGENT_NAME, INTERNET_OPEN_TYPE_PRECONFIG,
+ nullptr, // proxy
+ nullptr, // proxy bypass
+ 0 // flags
+ );
+ if (!hInternet) {
+ goto finish;
+ }
+
+ hConnect = InternetConnect(hInternet, pUrl->lpszHostName, pUrl->nPort,
+ nullptr, // userName,
+ nullptr, // password
+ INTERNET_SERVICE_HTTP,
+ 0, // flags
+ 0 // context
+ );
+ if (!hConnect) {
+ goto finish;
+ }
+
+ {
+ // NOTE: Some of these settings are perhaps unnecessary for a POST.
+ DWORD httpFlags = INTERNET_FLAG_NO_CACHE_WRITE | INTERNET_FLAG_NO_COOKIES |
+ INTERNET_FLAG_NO_UI | INTERNET_FLAG_RELOAD;
+ if (pUrl->nScheme == INTERNET_SCHEME_HTTPS) {
+ // NOTE: nsJSON sets flags to allow redirecting HTTPS to HTTP, or HTTP to
+ // HTTPS I left those out because it seemed undesirable for our use case.
+ httpFlags |= INTERNET_FLAG_SECURE;
+ }
+ hRequest = HttpOpenRequest(hConnect, L"POST", pUrl->lpszUrlPath,
+ nullptr, // version,
+ nullptr, // referrer
+ nullptr, // accept types
+ httpFlags,
+ 0 // context
+ );
+ if (!hRequest) {
+ goto finish;
+ }
+ }
+
+ if (contentTypeHeader) {
+ if (!HttpAddRequestHeaders(hRequest, contentTypeHeader,
+ -1L, // headers length (count string length)
+ HTTP_ADDREQ_FLAG_ADD)) {
+ goto finish;
+ }
+ }
+
+ if (!HttpSendRequestW(hRequest,
+ nullptr, // additional headers
+ 0, // headers length
+ data, cbData)) {
+ goto finish;
+ }
+
+ BYTE readBuffer[1024];
+ DWORD bytesRead;
+ do {
+ if (!InternetReadFile(hRequest, readBuffer, sizeof(readBuffer),
+ &bytesRead)) {
+ goto finish;
+ }
+ // read data is thrown away
+ } while (bytesRead > 0);
+
+ success = true;
+
+finish:
+ if (hRequest) {
+ InternetCloseHandle(hRequest);
+ }
+ if (hConnect) {
+ InternetCloseHandle(hConnect);
+ }
+ if (hInternet) {
+ InternetCloseHandle(hInternet);
+ }
+
+ return success;
+}
\ No newline at end of file diff --git a/other-licenses/nsis/Contrib/HttpPostFile/HttpPostFile.sln b/other-licenses/nsis/Contrib/HttpPostFile/HttpPostFile.sln new file mode 100644 index 0000000000..c6fd9ca5e5 --- /dev/null +++ b/other-licenses/nsis/Contrib/HttpPostFile/HttpPostFile.sln @@ -0,0 +1,22 @@ +
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.30128.74
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "HttpPostFile", "HttpPostFile.vcxproj", "{A8BF99FD-8603-4137-862A-1D14268D7812}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {A8BF99FD-8603-4137-862A-1D14268D7812}.Release|x86.ActiveCfg = Release|Win32
+ {A8BF99FD-8603-4137-862A-1D14268D7812}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {5EF33D14-5BB9-4E44-A347-9FF33E86D9DC}
+ EndGlobalSection
+EndGlobal
diff --git a/other-licenses/nsis/Contrib/HttpPostFile/HttpPostFile.vcxproj b/other-licenses/nsis/Contrib/HttpPostFile/HttpPostFile.vcxproj new file mode 100644 index 0000000000..32ca342ea2 --- /dev/null +++ b/other-licenses/nsis/Contrib/HttpPostFile/HttpPostFile.vcxproj @@ -0,0 +1,63 @@ +<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <VCProjectVersion>16.0</VCProjectVersion>
+ <Keyword>Win32Proj</Keyword>
+ <ProjectGuid>{a8bf99fd-8603-4137-862a-1d14268d7812}</ProjectGuid>
+ <RootNamespace>HttpPostFile</RootNamespace>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v142</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="Shared">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LinkIncremental>false</LinkIncremental>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <WarningLevel>Level3</WarningLevel>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <PreprocessorDefinitions>WINVER=0x601;_WIN32_WINNT=0x601;WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <ConformanceMode>true</ConformanceMode>
+ <OmitDefaultLibName>true</OmitDefaultLibName>
+ <ExceptionHandling>false</ExceptionHandling>
+ <SDLCheck>false</SDLCheck>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <AdditionalDependencies>wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <EntryPointSymbol>DllMain</EntryPointSymbol>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="HttpPostFile.cpp" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file diff --git a/other-licenses/nsis/Contrib/HttpPostFile/test/postdriver.nsi b/other-licenses/nsis/Contrib/HttpPostFile/test/postdriver.nsi new file mode 100644 index 0000000000..6a54bf3ca3 --- /dev/null +++ b/other-licenses/nsis/Contrib/HttpPostFile/test/postdriver.nsi @@ -0,0 +1,63 @@ +; Any copyright is dedicated to the Public Domain. +; http://creativecommons.org/publicdomain/zero/1.0/ + +; Simple driver for HttpPostFile, passes command line args to HttpPostFile::Post and +; writes the result string to a file for automated checking. +; Always specifies Content-Type: application/json +; +; Usage: posttest /postfile=postfile.json /url=http://example.com /resultfile=result.txt + +!include LogicLib.nsh +!include FileFunc.nsh + +OutFile "postdriver.exe" +RequestExecutionLevel user +ShowInstDetails show +Unicode true + +!addplugindir ..\..\..\Plugins + +Var PostFileArg +Var UrlArg +Var ResultFileArg +Var ResultString + +Section + +StrCpy $ResultString "error getting command line arguments" + +ClearErrors +${GetParameters} $0 +IfErrors done + +ClearErrors +${GetOptions} " $0" " /postfile=" $PostFileArg +IfErrors done + +${GetOptions} " $0" " /url=" $UrlArg +IfErrors done + +${GetOptions} " $0" " /resultfile=" $ResultFileArg +IfErrors done + +DetailPrint "POST File = $PostFileArg" +DetailPrint "URL = $UrlArg" +DetailPrint "Result File = $ResultFileArg" + +StrCpy $ResultString "error running plugin" +HttpPostFile::Post $PostFileArg "Content-Type: application/json$\r$\n" $UrlArg +Pop $ResultString + +done: +${If} $ResultString != "success" +DetailPrint $ResultString +${EndIf} + +ClearErrors +FileOpen $0 $ResultFileArg "w" +${Unless} ${Errors} +FileWrite $0 $ResultString +FileClose $0 +${EndUnless} + +SectionEnd diff --git a/other-licenses/nsis/Contrib/HttpPostFile/test/unittest.py b/other-licenses/nsis/Contrib/HttpPostFile/test/unittest.py new file mode 100644 index 0000000000..2d5cd94d26 --- /dev/null +++ b/other-licenses/nsis/Contrib/HttpPostFile/test/unittest.py @@ -0,0 +1,247 @@ +# Any copyright is dedicated to the Public Domain. +# http://creativecommons.org/publicdomain/zero/1.0/ + +# Unit test for the HttpPostFile plugin, using a server on localhost. +# +# This test has not been set up to run in continuous integration. It is +# intended to be run manually, and only on Windows. +# +# Requires postdriver.exe, which can be built from postdriver.nsi with makensis +# from MozillaBuild: +# +# makensis-3.01.exe postdriver.nsi +# +# It can then be run from this directory as: +# +# python3 test.py + +import os +import subprocess +import http.server +import socketserver +import threading + +DRIVER_EXE_FILE_NAME = "postdriver.exe" +JSON_FILE_NAME = "test1.json" +RESULT_FILE_NAME = "result.txt" +BIND_HOST = "127.0.0.1" +BIND_PORT = 8080 +COMMON_URL = f"http://{BIND_HOST}:{BIND_PORT}/submit" +COMMON_JSON_BYTES = '{"yes": "indeed",\n"and": "ij"}'.encode('utf-8') + +DRIVER_TIMEOUT_SECS = 60 +SERVER_TIMEOUT_SECS = 120 + + +class PostHandler(http.server.BaseHTTPRequestHandler): + """BaseHTTPRequestHandler, basically just here to have a configurable do_POST handler""" + + +last_submission = None +last_content_type = None +server_response = 'Hello, plugin'.encode('utf-8') + + +def server_accept_submit(handler): + """Plugs into PostHandler.do_POST, accepts a POST on /submit and saves it into + the globals""" + + global last_submission + global last_content_type + global server_response + + last_submission = None + last_content_type = None + + if handler.path == "/submit": + handler.send_response(200, 'Ok') + content_length = int(handler.headers['Content-Length']) + last_submission = handler.rfile.read(content_length) + last_content_type = handler.headers['Content-Type'] + else: + handler.send_response(404, 'Not found') + handler.end_headers() + + handler.wfile.write(server_response) + handler.wfile.flush() + + handler.log_message("sent response") + + +server_hang_event = None + + +def server_hang(handler): + """Plugs into PostHandler.do_POST, waits on server_hang_event or until timeout""" + server_hang_event.wait(SERVER_TIMEOUT_SECS) + + +def run_and_assert_result(handle_request, post_file, url, expected_result): + """Sets up the server on another thread, runs the NSIS driver, and checks the result""" + global last_submission + global server_hang_event + + try: + os.remove(RESULT_FILE_NAME) + except FileNotFoundError: + pass + + PostHandler.do_POST = handle_request + last_submission = None + + def handler_thread(): + with socketserver.TCPServer((BIND_HOST, BIND_PORT), PostHandler) as httpd: + httpd.timeout = SERVER_TIMEOUT_SECS + httpd.handle_request() + + if handle_request: + server_thread = threading.Thread(target=handler_thread) + server_thread.start() + + try: + subprocess.call([DRIVER_EXE_FILE_NAME, f'/postfile={post_file}', f'/url={url}', + f'/resultfile={RESULT_FILE_NAME}', '/S'], timeout=DRIVER_TIMEOUT_SECS) + + with open(RESULT_FILE_NAME, "r") as result_file: + result = result_file.read() + + if result != expected_result: + raise AssertionError(f'{result} != {expected_result}') + + finally: + if server_hang_event: + server_hang_event.set() + + if handle_request: + server_thread.join() + os.remove(RESULT_FILE_NAME) + + +def create_json_file(json_bytes=COMMON_JSON_BYTES): + with open(JSON_FILE_NAME, "wb") as outfile: + outfile.write(json_bytes) + + +def check_submission(json_bytes=COMMON_JSON_BYTES): + if last_submission != json_bytes: + raise AssertionError(f'{last_submission.hex()} != {COMMON_JSON_BYTES}') + + +def cleanup_json_file(): + os.remove(JSON_FILE_NAME) + + +# Tests begin here + +try: + cleanup_json_file() +except FileNotFoundError: + pass + +# Basic test + +create_json_file() +run_and_assert_result(server_accept_submit, JSON_FILE_NAME, COMMON_URL, "success") +check_submission() +assert last_content_type == 'application/json' +cleanup_json_file() + +print("Basic test OK\n") + +# Test with missing file + +try: + cleanup_json_file() +except FileNotFoundError: + pass + +run_and_assert_result(None, JSON_FILE_NAME, COMMON_URL, "error reading file") + +print("Missing file test OK\n") + +# Test with empty file + +create_json_file(bytes()) +run_and_assert_result(server_accept_submit, JSON_FILE_NAME, COMMON_URL, "success") +check_submission(bytes()) +cleanup_json_file() + +print("Empty file test OK\n") + +# Test with large file + +# NOTE: Not actually JSON, but nothing here should care +four_mbytes = bytes([x & 255 for x in range(4*1024*1024)]) +create_json_file(four_mbytes) +run_and_assert_result(server_accept_submit, JSON_FILE_NAME, COMMON_URL, "success") +if last_submission != four_mbytes: + raise AssertionError("large file mismatch") +cleanup_json_file() + +print("Large file test OK\n") + +# Test with long file name + +# Test with bad URL + +bogus_url = "notAUrl" +create_json_file() +run_and_assert_result(None, JSON_FILE_NAME, bogus_url, "error parsing URL") +cleanup_json_file() + +print("Bad URL test OK\n") + +# Test with empty response + +server_response = bytes() +create_json_file() +run_and_assert_result(server_accept_submit, JSON_FILE_NAME, COMMON_URL, "success") +check_submission() +cleanup_json_file() + +print("Empty response test OK\n") + +# Test with large response + +server_response = four_mbytes +create_json_file() +run_and_assert_result(server_accept_submit, JSON_FILE_NAME, COMMON_URL, "success") +check_submission() +cleanup_json_file() + +print("Large response test OK\n") + +# Test with 404 +# NOTE: This succeeds since the client doesn't check the status code + +create_json_file() +nonexistent_url = f"http://{BIND_HOST}:{BIND_PORT}/bad" +run_and_assert_result(server_accept_submit, JSON_FILE_NAME, nonexistent_url, "success") +cleanup_json_file() + +print("404 response test OK\n") + +# Test with no server on the port +# NOTE: I'm assuming nothing else has been able to bind to the port + +print("Running no server test, this will take a few seconds...") + +create_json_file() +run_and_assert_result(None, JSON_FILE_NAME, COMMON_URL, "error sending HTTP request") +cleanup_json_file() + +print("No server test OK\n") + +# Test with server that hangs on response +# NOTE: HttpPostFile doesn't currently set the timeouts. Defaults seem to be around 30 seconds, +# but if they end up being longer than the 60 second driver timeout then this will fail. + +print("Running server hang test, this will take up to a minute...") + +server_hang_event = threading.Event() +create_json_file() +run_and_assert_result(server_hang, JSON_FILE_NAME, COMMON_URL, "error sending HTTP request") +cleanup_json_file() +server_hang_event = None + +print("Server hang test OK\n") diff --git a/other-licenses/nsis/Contrib/InetBgDL/InetBgDL.cpp b/other-licenses/nsis/Contrib/InetBgDL/InetBgDL.cpp new file mode 100644 index 0000000000..0d248be60d --- /dev/null +++ b/other-licenses/nsis/Contrib/InetBgDL/InetBgDL.cpp @@ -0,0 +1,739 @@ +// +// Copyright (C) Anders Kjersem. Licensed under the zlib/libpng license +// + +// This file is intended to be compiled with MSVC's Omit Default Library Name (/Zl) +// option enabled, in order to keep the file size low for bundling this DLL with +// the stub installer. That means that any code requiring the C runtime will fail +// to link. You'll see a couple of odd-looking things here for this reason; they +// should all be called out with comments. + +#include "InetBgDL.h" + +#define USERAGENT _T("NSIS InetBgDL (Mozilla)") + +#define STATUS_COMPLETEDALL 0 +#define STATUS_INITIAL 202 +#define STATUS_CONNECTING STATUS_INITIAL //102 +#define STATUS_DOWNLOADING STATUS_INITIAL +#define STATUS_ERR_GETLASTERROR 418 //HTTP: I'm a teapot: Win32 error code in $3 +#define STATUS_ERR_LOCALFILEWRITEERROR 450 //HTTP: MS parental control extension +#define STATUS_ERR_CANCELLED 499 +#define STATUS_ERR_CONNECTION_LOST 1000 + +typedef DWORD FILESIZE_T; // Limit to 4GB for now... +#define FILESIZE_UNKNOWN (-1) + +#define MAX_STRLEN 1024 + +HINSTANCE g_hInst; +NSIS::stack_t*g_pLocations = NULL; +HANDLE g_hThread = NULL; +HANDLE g_hGETStartedEvent = NULL; +HINTERNET g_hInetSes = NULL; +HINTERNET g_hInetFile = NULL; +volatile UINT g_FilesTotal = 0; +volatile UINT g_FilesCompleted = 0; +volatile UINT g_Status = STATUS_INITIAL; +volatile FILESIZE_T g_cbCurrXF; +volatile FILESIZE_T g_cbCurrTot = FILESIZE_UNKNOWN; +CRITICAL_SECTION g_CritLock; +UINT g_N_CCH; +PTSTR g_N_Vars; +TCHAR g_ServerIP[128] = { _T('\0') }; + +DWORD g_ConnectTimeout = 0; +DWORD g_ReceiveTimeout = 0; + +// Setup a buffer of size 256KiB to store the downloaded data. +constexpr UINT g_cbBufXF = 262144; +// This buffer is only needed inside TaskThreadProc(), but declaring it on +// the stack there triggers a runtime stack size check, which is implemented +// by a C runtime library function, so we have to avoid the compiler wanting +// to build that check by not having any large stack buffers. +BYTE g_bufXF[g_cbBufXF]; + +#define NSISPI_INITGLOBALS(N_CCH, N_Vars) do { \ + g_N_CCH = N_CCH; \ + g_N_Vars = N_Vars; \ + } while(0) + +#define ONELOCKTORULETHEMALL +#ifdef ONELOCKTORULETHEMALL +#define TaskLock_AcquireExclusive() EnterCriticalSection(&g_CritLock) +#define TaskLock_ReleaseExclusive() LeaveCriticalSection(&g_CritLock) +#define StatsLock_AcquireExclusive() TaskLock_AcquireExclusive() +#define StatsLock_ReleaseExclusive() TaskLock_ReleaseExclusive() +#define StatsLock_AcquireShared() StatsLock_AcquireExclusive() +#define StatsLock_ReleaseShared() StatsLock_ReleaseExclusive() +#endif + +// Normally we would just call the C library wcstol, but since we can't use the +// C runtime, we'll supply our own function as an understudy. +static DWORD +MyTStrToL(TCHAR const* str) +{ + if (!str) { + return 0; + } + + int len = lstrlen(str); + DWORD place = 1; + DWORD rv = 0; + for (int i = len - 1; i >= 0; --i) { + int digit = str[i] - 0x30; + rv += digit * place; + place *= 10; + } + return rv; +} + +PTSTR NSIS_SetRegStr(UINT Reg, LPCTSTR Value) +{ + PTSTR s = g_N_Vars + (Reg * g_N_CCH); + lstrcpy(s, Value); + return s; +} +#define NSIS_SetRegStrEmpty(r) NSIS_SetRegStr(r, _T("")) +void NSIS_SetRegUINT(UINT Reg, UINT Value) +{ + TCHAR buf[32]; + wsprintf(buf, _T("%u"), Value); + NSIS_SetRegStr(Reg, buf); +} +#define StackFreeItem(pI) GlobalFree(pI) +NSIS::stack_t* StackPopItem(NSIS::stack_t**ppST) +{ + if (*ppST) + { + NSIS::stack_t*pItem = *ppST; + *ppST = pItem->next; + return pItem; + } + return NULL; +} + +void Reset() +{ + // The g_hGETStartedEvent event is used to make sure that the Get() call will + // acquire the lock before the Reset() call acquires the lock. + if (g_hGETStartedEvent) { + TRACE(_T("InetBgDl: waiting on g_hGETStartedEvent\n")); + WaitForSingleObject(g_hGETStartedEvent, INFINITE); + CloseHandle(g_hGETStartedEvent); + g_hGETStartedEvent = NULL; + } + + TaskLock_AcquireExclusive(); +#ifndef ONELOCKTORULETHEMALL + StatsLock_AcquireExclusive(); +#endif + g_FilesTotal = 0; // This causes the Task thread to exit the transfer loop + if (g_hThread) + { + TRACE(_T("InetBgDl: waiting on g_hThread\n")); + if (WAIT_OBJECT_0 != WaitForSingleObject(g_hThread, 5 * 1000)) + { + TRACE(_T("InetBgDl: terminating g_hThread\n")); + // Suspend the thread so that it's not still trying to use these handles + // that we're about to close out from under it. + SuspendThread(g_hThread); + if (g_hInetFile) { + InternetCloseHandle(g_hInetFile); + g_hInetFile = nullptr; + } + if (g_hInetSes) { + InternetCloseHandle(g_hInetSes); + g_hInetSes = nullptr; + } + TerminateThread(g_hThread, ERROR_OPERATION_ABORTED); + } + CloseHandle(g_hThread); + g_hThread = NULL; + } + g_FilesTotal = 0; + g_FilesCompleted = 0; + g_Status = STATUS_INITIAL; +#ifndef ONELOCKTORULETHEMALL + StatsLock_ReleaseExclusive(); +#endif + for (NSIS::stack_t*pTmpTast,*pTask = g_pLocations; pTask ;) + { + pTmpTast = pTask; + pTask = pTask->next; + StackFreeItem(pTmpTast); + } + g_pLocations = NULL; + TaskLock_ReleaseExclusive(); +} + +UINT_PTR __cdecl NSISPluginCallback(UINT Event) +{ + switch(Event) + { + case NSPIM_UNLOAD: + Reset(); + break; + } + return NULL; +} + +void __stdcall InetStatusCallback(HINTERNET hInternet, DWORD_PTR dwContext, + DWORD dwInternetStatus, + LPVOID lpvStatusInformation, + DWORD dwStatusInformationLength) +{ + if (dwInternetStatus == INTERNET_STATUS_NAME_RESOLVED) { + // If we're in the process of being reset, don't try to update g_ServerIP; + // there's no need for it, and Reset() will be holding the StatsLock, so + // we'll hang here and block the reset if we try to acquire it. + if (g_FilesTotal != 0) { + // The documentation states the IP address is a PCTSTR but it is usually a + // PCSTR and only sometimes a PCTSTR. + StatsLock_AcquireExclusive(); + wsprintf(g_ServerIP, _T("%S"), lpvStatusInformation); + if (lstrlen(g_ServerIP) == 1) + { + wsprintf(g_ServerIP, _T("%s"), lpvStatusInformation); + } + StatsLock_ReleaseExclusive(); + } + } + +#if defined(PLUGIN_DEBUG) + switch (dwInternetStatus) + { + case INTERNET_STATUS_RESOLVING_NAME: + TRACE(_T("InetBgDl: INTERNET_STATUS_RESOLVING_NAME (%d), name=%s\n"), + dwStatusInformationLength, lpvStatusInformation); + break; + case INTERNET_STATUS_NAME_RESOLVED: + TRACE(_T("InetBgDl: INTERNET_STATUS_NAME_RESOLVED (%d), resolved name=%s\n"), + dwStatusInformationLength, g_ServerIP); + break; + case INTERNET_STATUS_CONNECTING_TO_SERVER: + TRACE(_T("InetBgDl: INTERNET_STATUS_CONNECTING_TO_SERVER (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_CONNECTED_TO_SERVER: + TRACE(_T("InetBgDl: INTERNET_STATUS_CONNECTED_TO_SERVER (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_SENDING_REQUEST: + TRACE(_T("InetBgDl: INTERNET_STATUS_SENDING_REQUEST (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_REQUEST_SENT: + TRACE(_T("InetBgDl: INTERNET_STATUS_REQUEST_SENT (%d), bytes sent=%d\n"), + dwStatusInformationLength, lpvStatusInformation); + break; + case INTERNET_STATUS_RECEIVING_RESPONSE: + TRACE(_T("InetBgDl: INTERNET_STATUS_RECEIVING_RESPONSE (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_RESPONSE_RECEIVED: + TRACE(_T("InetBgDl: INTERNET_STATUS_RESPONSE_RECEIVED (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_CTL_RESPONSE_RECEIVED: + TRACE(_T("InetBgDl: INTERNET_STATUS_CTL_RESPONSE_RECEIVED (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_PREFETCH: + TRACE(_T("InetBgDl: INTERNET_STATUS_PREFETCH (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_CLOSING_CONNECTION: + TRACE(_T("InetBgDl: INTERNET_STATUS_CLOSING_CONNECTION (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_CONNECTION_CLOSED: + TRACE(_T("InetBgDl: INTERNET_STATUS_CONNECTION_CLOSED (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_HANDLE_CREATED: + TRACE(_T("InetBgDl: INTERNET_STATUS_HANDLE_CREATED (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_HANDLE_CLOSING: + TRACE(_T("InetBgDl: INTERNET_STATUS_HANDLE_CLOSING (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_DETECTING_PROXY: + TRACE(_T("InetBgDl: INTERNET_STATUS_DETECTING_PROXY (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_REQUEST_COMPLETE: + TRACE(_T("InetBgDl: INTERNET_STATUS_REQUEST_COMPLETE (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_REDIRECT: + TRACE(_T("InetBgDl: INTERNET_STATUS_REDIRECT (%d), new url=%s\n"), + dwStatusInformationLength, lpvStatusInformation); + break; + case INTERNET_STATUS_INTERMEDIATE_RESPONSE: + TRACE(_T("InetBgDl: INTERNET_STATUS_INTERMEDIATE_RESPONSE (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_USER_INPUT_REQUIRED: + TRACE(_T("InetBgDl: INTERNET_STATUS_USER_INPUT_REQUIRED (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_STATE_CHANGE: + TRACE(_T("InetBgDl: INTERNET_STATUS_STATE_CHANGE (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_COOKIE_SENT: + TRACE(_T("InetBgDl: INTERNET_STATUS_COOKIE_SENT (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_COOKIE_RECEIVED: + TRACE(_T("InetBgDl: INTERNET_STATUS_COOKIE_RECEIVED (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_PRIVACY_IMPACTED: + TRACE(_T("InetBgDl: INTERNET_STATUS_PRIVACY_IMPACTED (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_P3P_HEADER: + TRACE(_T("InetBgDl: INTERNET_STATUS_P3P_HEADER (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_P3P_POLICYREF: + TRACE(_T("InetBgDl: INTERNET_STATUS_P3P_POLICYREF (%d)\n"), + dwStatusInformationLength); + break; + case INTERNET_STATUS_COOKIE_HISTORY: + TRACE(_T("InetBgDl: INTERNET_STATUS_COOKIE_HISTORY (%d)\n"), + dwStatusInformationLength); + break; + default: + TRACE(_T("InetBgDl: Unknown Status %d\n"), dwInternetStatus); + break; + } +#endif +} + +DWORD CALLBACK TaskThreadProc(LPVOID ThreadParam) +{ + NSIS::stack_t *pURL,*pFile; + DWORD cbio = sizeof(DWORD); + DWORD previouslyWritten = 0, writtenThisSession = 0; + HANDLE hLocalFile; + bool completedFile = false; +startnexttask: + hLocalFile = INVALID_HANDLE_VALUE; + pFile = NULL; + TaskLock_AcquireExclusive(); + // Now that we've acquired the lock, we can set the event to indicate this. + // SetEvent will likely never fail, but if it does we should set it to NULL + // to avoid anyone waiting on it. + if (!SetEvent(g_hGETStartedEvent)) { + CloseHandle(g_hGETStartedEvent); + g_hGETStartedEvent = NULL; + } + pURL = g_pLocations; + if (pURL) + { + pFile = pURL->next; + g_pLocations = pFile->next; + } +#ifndef ONELOCKTORULETHEMALL + StatsLock_AcquireExclusive(); +#endif + if (completedFile) + { + ++g_FilesCompleted; + } + completedFile = false; + g_cbCurrXF = 0; + g_cbCurrTot = FILESIZE_UNKNOWN; + if (!pURL) + { + if (g_FilesTotal) + { + if (g_FilesTotal == g_FilesCompleted) + { + g_Status = STATUS_COMPLETEDALL; + } + } + g_hThread = NULL; + } +#ifndef ONELOCKTORULETHEMALL + StatsLock_ReleaseExclusive(); +#endif + TaskLock_ReleaseExclusive(); + + if (!pURL) + { + if (0) + { +diegle: + DWORD gle = GetLastError(); + //TODO? if (ERROR_INTERNET_EXTENDED_ERROR==gle) InternetGetLastResponseInfo(...) + g_Status = STATUS_ERR_GETLASTERROR; + } +die: + if (g_hInetSes) + { + InternetCloseHandle(g_hInetSes); + g_hInetSes = nullptr; + } + if (INVALID_HANDLE_VALUE != hLocalFile) + { + CloseHandle(hLocalFile); + } + StackFreeItem(pURL); + StackFreeItem(pFile); + return 0; + } + + if (!g_hInetSes) + { + g_hInetSes = InternetOpen(USERAGENT, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); + if (!g_hInetSes) + { + TRACE(_T("InetBgDl: InternetOpen failed with gle=%u\n"), + GetLastError()); + goto diegle; + } + InternetSetStatusCallback(g_hInetSes, (INTERNET_STATUS_CALLBACK)InetStatusCallback); + + //msdn.microsoft.com/library/default.asp?url=/workshop/components/offline/offline.asp#Supporting Offline Browsing in Applications and Components + ULONG longOpt; + DWORD cbio = sizeof(ULONG); + if (InternetQueryOption(g_hInetSes, INTERNET_OPTION_CONNECTED_STATE, &longOpt, &cbio)) + { + if (INTERNET_STATE_DISCONNECTED_BY_USER&longOpt) + { + INTERNET_CONNECTED_INFO ci = {INTERNET_STATE_CONNECTED, 0}; + InternetSetOption(g_hInetSes, INTERNET_OPTION_CONNECTED_STATE, &ci, sizeof(ci)); + } + } + + // Change the default connect timeout if specified. + if(g_ConnectTimeout > 0) + { + InternetSetOption(g_hInetSes, INTERNET_OPTION_CONNECT_TIMEOUT, + &g_ConnectTimeout, sizeof(g_ConnectTimeout)); + } + + // Change the default receive timeout if specified. + if (g_ReceiveTimeout) + { + InternetSetOption(g_hInetSes, INTERNET_OPTION_RECEIVE_TIMEOUT, + &g_ReceiveTimeout, sizeof(DWORD)); + } + } + + DWORD ec = ERROR_SUCCESS; + hLocalFile = CreateFile(pFile->text, GENERIC_READ | GENERIC_WRITE, + FILE_SHARE_READ | FILE_SHARE_DELETE, + NULL, OPEN_ALWAYS, 0, NULL); + if (INVALID_HANDLE_VALUE == hLocalFile) + { + TRACE(_T("InetBgDl: CreateFile file handle invalid\n")); + goto diegle; + } + if (GetLastError() == ERROR_ALREADY_EXISTS) { + // Resuming a download that was started earlier and then aborted. + previouslyWritten = GetFileSize(hLocalFile, NULL); + g_cbCurrXF = previouslyWritten; + SetFilePointer(hLocalFile, previouslyWritten, NULL, FILE_BEGIN); + } + + const DWORD IOURedirFlags = INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTP | + INTERNET_FLAG_IGNORE_REDIRECT_TO_HTTPS; + const DWORD IOUCacheFlags = INTERNET_FLAG_RESYNCHRONIZE | + INTERNET_FLAG_NO_CACHE_WRITE | + INTERNET_FLAG_PRAGMA_NOCACHE | + INTERNET_FLAG_RELOAD; + const DWORD IOUCookieFlags = INTERNET_FLAG_NO_COOKIES; + DWORD IOUFlags = IOURedirFlags | IOUCacheFlags | IOUCookieFlags | + INTERNET_FLAG_NO_UI | INTERNET_FLAG_EXISTING_CONNECT; + + TCHAR *hostname = (TCHAR*) GlobalAlloc(GPTR, MAX_STRLEN * sizeof(TCHAR)), + *urlpath = (TCHAR*) GlobalAlloc(GPTR, MAX_STRLEN * sizeof(TCHAR)), + *extrainfo = (TCHAR*) GlobalAlloc(GPTR, MAX_STRLEN * sizeof(TCHAR)); + + URL_COMPONENTS uc = { sizeof(URL_COMPONENTS), NULL, 0, (INTERNET_SCHEME)0, + hostname, MAX_STRLEN, (INTERNET_PORT)0, NULL, 0, + NULL, 0, urlpath, MAX_STRLEN, extrainfo, MAX_STRLEN}; + uc.dwHostNameLength = uc.dwUrlPathLength = uc.dwExtraInfoLength = MAX_STRLEN; + + if (!InternetCrackUrl(pURL->text, 0, ICU_ESCAPE, &uc)) + { + // Bad url or param passed in + TRACE(_T("InetBgDl: InternetCrackUrl false with url=%s, gle=%u\n"), + pURL->text, GetLastError()); + goto diegle; + } + + TRACE(_T("InetBgDl: scheme_id=%d, hostname=%s, port=%d, urlpath=%s, extrainfo=%s\n"), + uc.nScheme, hostname, uc.nPort, urlpath, extrainfo); + + // Only http and https are supported + if (uc.nScheme != INTERNET_SCHEME_HTTP && + uc.nScheme != INTERNET_SCHEME_HTTPS) + { + TRACE(_T("InetBgDl: only http and https is supported, aborting...\n")); + goto diegle; + } + + // Tell the server to pick up wherever we left off. + TCHAR headers[32]; + // We're skipping building the C runtime to keep the file size low, so we + // can't use a normal string initialization because that would call memset. + headers[0] = _T('\0'); + wsprintf(headers, _T("Range: bytes=%d-\r\n"), previouslyWritten); + + TRACE(_T("InetBgDl: calling InternetOpenUrl with url=%s\n"), pURL->text); + g_hInetFile = InternetOpenUrl(g_hInetSes, pURL->text, + headers, -1, IOUFlags | + (uc.nScheme == INTERNET_SCHEME_HTTPS ? + INTERNET_FLAG_SECURE : 0), 1); + if (!g_hInetFile) + { + TRACE(_T("InetBgDl: InternetOpenUrl failed with gle=%u\n"), + GetLastError()); + goto diegle; + } + + // Get the file length via the Content-Length header + FILESIZE_T cbThisFile; + cbio = sizeof(cbThisFile); + if (!HttpQueryInfo(g_hInetFile, + HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, + &cbThisFile, &cbio, NULL)) + { + cbThisFile = FILESIZE_UNKNOWN; + } + TRACE(_T("InetBgDl: file size=%d bytes\n"), cbThisFile); + + // Use a 4MiB read buffer for the connection. + // Bigger buffers will be faster. + // cbReadBufXF should be a multiple of g_cbBufXF. + const UINT cbReadBufXF = 4194304; + + // Up the default internal buffer size from 4096 to internalReadBufferSize. + DWORD internalReadBufferSize = cbReadBufXF; + if (!InternetSetOption(g_hInetFile, INTERNET_OPTION_READ_BUFFER_SIZE, + &internalReadBufferSize, sizeof(DWORD))) + { + TRACE(_T("InetBgDl: InternetSetOption failed to set read buffer size to %u bytes, gle=%u\n"), + internalReadBufferSize, GetLastError()); + + // Maybe it's too big, try half of the optimal value. If that fails just + // use the default. + internalReadBufferSize /= 2; + if (!InternetSetOption(g_hInetFile, INTERNET_OPTION_READ_BUFFER_SIZE, + &internalReadBufferSize, sizeof(DWORD))) + { + TRACE(_T("InetBgDl: InternetSetOption failed to set read buffer size ") \ + _T("to %u bytes (using default read buffer size), gle=%u\n"), + internalReadBufferSize, GetLastError()); + } + } + + for(;;) + { + DWORD cbio = 0, cbXF = 0; + BOOL retXF = InternetReadFile(g_hInetFile, g_bufXF, g_cbBufXF, &cbio); + if (!retXF) + { + ec = GetLastError(); + TRACE(_T("InetBgDl: InternetReadFile failed, gle=%u\n"), ec); + if (ERROR_INTERNET_CONNECTION_ABORTED == ec || + ERROR_INTERNET_CONNECTION_RESET == ec) + { + ec = ERROR_BROKEN_PIPE; + } + break; + } + + if (0 == cbio) + { + ASSERT(ERROR_SUCCESS == ec); + // EOF or broken connection? + // TODO: Can InternetQueryDataAvailable detect this? + + TRACE(_T("InetBgDl: InternetReadFile true with 0 cbio, cbThisFile=%d, gle=%u\n"), + cbThisFile, GetLastError()); + // If we haven't transferred all of the file, and we know how big the file + // is, and we have no more data to read from the HTTP request, then set a + // broken pipe error. Reading without StatsLock is ok in this thread. + if (FILESIZE_UNKNOWN != cbThisFile && writtenThisSession != cbThisFile) + { + TRACE(_T("InetBgDl: expected Content-Length of %d bytes, ") + _T("but transferred %d bytes\n"), + cbThisFile, writtenThisSession); + ec = ERROR_BROKEN_PIPE; + } + break; + } + + // Check if we canceled the download + if (0 == g_FilesTotal) + { + TRACE(_T("InetBgDl: 0 == g_FilesTotal, aborting transfer loop...\n")); + ec = ERROR_CANCELLED; + break; + } + + cbXF = cbio; + if (cbXF) + { + retXF = WriteFile(hLocalFile, g_bufXF, cbXF, &cbio, NULL); + if (!retXF || cbXF != cbio) + { + ec = GetLastError(); + break; + } + + StatsLock_AcquireExclusive(); + if (FILESIZE_UNKNOWN != cbThisFile) { + g_cbCurrTot = cbThisFile; + } + writtenThisSession += cbXF; + g_cbCurrXF += cbXF; + StatsLock_ReleaseExclusive(); + } + } + + TRACE(_T("InetBgDl: TaskThreadProc completed %s, ec=%u\n"), pURL->text, ec); + InternetCloseHandle(g_hInetFile); + g_hInetFile = nullptr; + if (ERROR_SUCCESS == ec) + { + if (INVALID_HANDLE_VALUE != hLocalFile) + { + CloseHandle(hLocalFile); + hLocalFile = INVALID_HANDLE_VALUE; + } + StackFreeItem(pURL); + StackFreeItem(pFile); + ++completedFile; + } + else if (ERROR_BROKEN_PIPE == ec) + { + g_Status = STATUS_ERR_CONNECTION_LOST; + goto die; + } + else + { + TRACE(_T("InetBgDl: failed with ec=%u\n"), ec); + SetLastError(ec); + goto diegle; + } + goto startnexttask; +} + +NSISPIEXPORTFUNC Get(HWND hwndNSIS, UINT N_CCH, TCHAR*N_Vars, NSIS::stack_t**ppST, NSIS::xparams_t*pX) +{ + pX->RegisterPluginCallback(g_hInst, NSISPluginCallback); + for (;;) + { + NSIS::stack_t*pURL = StackPopItem(ppST); + if (!pURL) + { + break; + } + + if (lstrcmpi(pURL->text, _T("/connecttimeout")) == 0) + { + NSIS::stack_t*pConnectTimeout = StackPopItem(ppST); + g_ConnectTimeout = MyTStrToL(pConnectTimeout->text) * 1000; + continue; + } + else if (lstrcmpi(pURL->text, _T("/receivetimeout")) == 0) + { + NSIS::stack_t*pReceiveTimeout = StackPopItem(ppST); + g_ReceiveTimeout = MyTStrToL(pReceiveTimeout->text) * 1000; + continue; + } + else if (lstrcmpi(pURL->text, _T("/reset")) == 0) + { + StackFreeItem(pURL); + Reset(); + continue; + } + else if (lstrcmpi(pURL->text, _T("/end")) == 0) + { +freeurlandexit: + StackFreeItem(pURL); + break; + } + + NSIS::stack_t*pFile = StackPopItem(ppST); + if (!pFile) + { + goto freeurlandexit; + } + + TaskLock_AcquireExclusive(); + + pFile->next = NULL; + pURL->next = pFile; + NSIS::stack_t*pTasksTail = g_pLocations; + while(pTasksTail && pTasksTail->next) pTasksTail = pTasksTail->next; + if (pTasksTail) + { + pTasksTail->next = pURL; + } + else + { + g_pLocations = pURL; + } + + if (!g_hThread) + { + DWORD tid; + if (g_hGETStartedEvent) { + CloseHandle(g_hGETStartedEvent); + } + g_hGETStartedEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + g_hThread = CreateThread(NULL, 0, TaskThreadProc, NULL, 0, &tid); + } + + if (!g_hThread) + { + goto freeurlandexit; + } + +#ifndef ONELOCKTORULETHEMALL + StatsLock_AcquireExclusive(); +#endif + ++g_FilesTotal; +#ifndef ONELOCKTORULETHEMALL + StatsLock_ReleaseExclusive(); +#endif + TaskLock_ReleaseExclusive(); + } +} + +NSISPIEXPORTFUNC GetStats(HWND hwndNSIS, UINT N_CCH, TCHAR*N_Vars, NSIS::stack_t**ppST, NSIS::xparams_t*pX) +{ + NSISPI_INITGLOBALS(N_CCH, N_Vars); + StatsLock_AcquireShared(); + NSIS_SetRegUINT(0, g_Status); + NSIS_SetRegUINT(1, g_FilesCompleted); + NSIS_SetRegUINT(2, g_FilesTotal - g_FilesCompleted); + NSIS_SetRegUINT(3, g_cbCurrXF); + NSIS_SetRegStrEmpty(4); + if (FILESIZE_UNKNOWN != g_cbCurrTot) + { + NSIS_SetRegUINT(4, g_cbCurrTot); + } + NSIS_SetRegStr(5, g_ServerIP); + StatsLock_ReleaseShared(); +} + +BOOL WINAPI DllMain(HINSTANCE hInst, ULONG Reason, LPVOID pCtx) +{ + if (DLL_PROCESS_ATTACH==Reason) + { + g_hInst=hInst; + InitializeCriticalSection(&g_CritLock); + } + return TRUE; +} diff --git a/other-licenses/nsis/Contrib/InetBgDL/InetBgDL.h b/other-licenses/nsis/Contrib/InetBgDL/InetBgDL.h new file mode 100644 index 0000000000..b0397ab7a0 --- /dev/null +++ b/other-licenses/nsis/Contrib/InetBgDL/InetBgDL.h @@ -0,0 +1,59 @@ +// +// Copyright (C) Anders Kjersem. Licensed under the zlib/libpng license +// + +#ifdef UNICODE +# ifndef _UNICODE +# define _UNICODE +# endif +#endif + +#define _WIN32_WINNT 0x0400 +#include <windows.h> +#include <tchar.h> +#include <wininet.h> + +#if defined(_DEBUG) || 0 +# define PLUGIN_DEBUG 1 +void MYTRACE(LPCTSTR fmt, ...) +{ + va_list argptr; + va_start(argptr, fmt); + TCHAR buffer[2048] = { _T('\0') }; + wvsprintf(buffer, fmt, argptr); + buffer[(sizeof(buffer)/sizeof(*buffer)) - 1] = _T('\0'); + OutputDebugString(buffer); + va_end(argptr); +} +#else +void MYTRACE(...) { } +#endif +# define TRACE MYTRACE + +#ifndef ASSERT +# define ASSERT(x) +#endif + +#define NSISPIEXPORTFUNC EXTERN_C void __declspec(dllexport) __cdecl + +namespace NSIS { + +#define NSISCALL __stdcall +typedef struct _xparams_t { + LPVOID xx1;//exec_flags_type *exec_flags; + int (NSISCALL *ExecuteCodeSegment)(int, HWND); + void (NSISCALL *validate_filename)(TCHAR*); + int (NSISCALL *RegisterPluginCallback)(HMODULE,LPVOID); +} xparams_t; +typedef struct _stack_t { + struct _stack_t *next; + TCHAR text[1]; +} stack_t; + +} // namespace NSIS + +enum NSPIM +{ + NSPIM_UNLOAD, + NSPIM_GUIUNLOAD, +}; diff --git a/other-licenses/nsis/Contrib/InetBgDL/InetBgDl.sln b/other-licenses/nsis/Contrib/InetBgDL/InetBgDl.sln new file mode 100644 index 0000000000..0e84c0f982 --- /dev/null +++ b/other-licenses/nsis/Contrib/InetBgDL/InetBgDl.sln @@ -0,0 +1,25 @@ +
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.28922.388
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "InetBgDl", "InetBgDl.vcxproj", "{B9B76BC4-5C6C-4808-AC23-2C10126CDFC0}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x86 = Debug|x86
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {B9B76BC4-5C6C-4808-AC23-2C10126CDFC0}.Debug|x86.ActiveCfg = Debug|Win32
+ {B9B76BC4-5C6C-4808-AC23-2C10126CDFC0}.Debug|x86.Build.0 = Debug|Win32
+ {B9B76BC4-5C6C-4808-AC23-2C10126CDFC0}.Release|x86.ActiveCfg = Release|Win32
+ {B9B76BC4-5C6C-4808-AC23-2C10126CDFC0}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {58385AF6-83F5-4D76-903D-2CFEDAFFCDC6}
+ EndGlobalSection
+EndGlobal
diff --git a/other-licenses/nsis/Contrib/InetBgDL/InetBgDl.vcxproj b/other-licenses/nsis/Contrib/InetBgDL/InetBgDl.vcxproj new file mode 100644 index 0000000000..99b7684797 --- /dev/null +++ b/other-licenses/nsis/Contrib/InetBgDL/InetBgDl.vcxproj @@ -0,0 +1,108 @@ +<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <ItemGroup>
+ <ClCompile Include="InetBgDL.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="InetBgDL.h" />
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <VCProjectVersion>16.0</VCProjectVersion>
+ <ProjectGuid>{B9B76BC4-5C6C-4808-AC23-2C10126CDFC0}</ProjectGuid>
+ <Keyword>Win32Proj</Keyword>
+ <RootNamespace>InetBgDl</RootNamespace>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>true</UseDebugLibraries>
+ <PlatformToolset>v142</PlatformToolset>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <UseDebugLibraries>false</UseDebugLibraries>
+ <PlatformToolset>v142</PlatformToolset>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <CharacterSet>Unicode</CharacterSet>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Label="Shared">
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <LinkIncremental>true</LinkIncremental>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <LinkIncremental>false</LinkIncremental>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>Disabled</Optimization>
+ <SDLCheck>false</SDLCheck>
+ <PreprocessorDefinitions>WINVER=0x601;_WIN32_WINNT=0x601;WIN32;_DEBUG;INETBGDL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <ConformanceMode>true</ConformanceMode>
+ <PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
+ <ExceptionHandling>false</ExceptionHandling>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <EnableUAC>false</EnableUAC>
+ <AdditionalDependencies>wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
+ <ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <PrecompiledHeader>NotUsing</PrecompiledHeader>
+ <WarningLevel>Level3</WarningLevel>
+ <Optimization>MinSpace</Optimization>
+ <FunctionLevelLinking>true</FunctionLevelLinking>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ <SDLCheck>false</SDLCheck>
+ <PreprocessorDefinitions>WINVER=0x601;_WIN32_WINNT=0x601;WIN32;NDEBUG;INETBGDL_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <ExceptionHandling>false</ExceptionHandling>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <OmitDefaultLibName>true</OmitDefaultLibName>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
+ </ClCompile>
+ <Link>
+ <SubSystem>Console</SubSystem>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <OptimizeReferences>true</OptimizeReferences>
+ <GenerateDebugInformation>false</GenerateDebugInformation>
+ <EnableUAC>false</EnableUAC>
+ <AdditionalDependencies>wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
+ <ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
+ <EntryPointSymbol>DllMain</EntryPointSymbol>
+ </Link>
+ </ItemDefinitionGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file diff --git a/other-licenses/nsis/Contrib/README b/other-licenses/nsis/Contrib/README new file mode 100644 index 0000000000..8301fe26c4 --- /dev/null +++ b/other-licenses/nsis/Contrib/README @@ -0,0 +1,34 @@ +These directories contain modified source code to the NSIS Plugins used by the +Windows installers. + +NSIS project page: http://nsis.sourceforge.net/ +NSIS Unicode port project page: http://www.scratchpaper.com/ + +APPLICABLE LICENSES +------------------- +* All NSIS source code, plug-ins, documentation, examples, header files and + graphics, with the exception of the compression modules and where otherwise + noted, are licensed under the zlib/libpng license. + +* The zlib compression module for NSIS is licensed under the zlib/libpng + license. + +* The bzip2 compression module for NSIS is licensed under the bzip2 license. + +* The LZMA compression module for NSIS is licensed under the Common Public + License version 1.0. + +------------------------------------------------------------------------------- + +ExDLL NSIS Unicode source 2.38.1 for plugin projects +http://www.scratchpaper.com/ +These files are required to compile the nsProcess and ShellLink plugins. No +changes were made to these files. + +------------------------------------------------------------------------------- + +ApplicationID v1.0 +http://nsis.sourceforge.net/ApplicationID_plug-in +Unicode support and taskbar resource deleteion was added for this plugin. A diff +of the changes to the source is available at: +https://bugzilla.mozilla.org/show_bug.cgi?id=521141 diff --git a/other-licenses/nsis/Contrib/ServicesHelper/Services.cpp b/other-licenses/nsis/Contrib/ServicesHelper/Services.cpp new file mode 100644 index 0000000000..5c3d2fe59f --- /dev/null +++ b/other-licenses/nsis/Contrib/ServicesHelper/Services.cpp @@ -0,0 +1,241 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +#include <windows.h> +#include "../../../../toolkit/mozapps/update/common/pathhash.h" + +#pragma comment(lib, "advapi32.lib") + +typedef struct _stack_t { + struct _stack_t *next; + TCHAR text[MAX_PATH]; +} stack_t; + +int popstring(stack_t **stacktop, LPTSTR str, int len); +void pushstring(stack_t **stacktop, LPCTSTR str, int len); + +/** + * Determines if the specified service exists or not + * + * @param serviceName The name of the service to check + * @param exists Whether or not the service exists + * @return TRUE if there were no errors + */ +static BOOL +IsServiceInstalled(LPCWSTR serviceName, BOOL &exists) +{ + exists = FALSE; + + // Get a handle to the local computer SCM database with full access rights. + SC_HANDLE serviceManager = OpenSCManager(NULL, NULL, + SC_MANAGER_ENUMERATE_SERVICE); + if (!serviceManager) { + return FALSE; + } + + SC_HANDLE serviceHandle = OpenServiceW(serviceManager, + serviceName, + SERVICE_QUERY_CONFIG); + if (!serviceHandle && GetLastError() != ERROR_SERVICE_DOES_NOT_EXIST) { + CloseServiceHandle(serviceManager); + return FALSE; + } + + if (serviceHandle) { + CloseServiceHandle(serviceHandle); + exists = TRUE; + } + + CloseServiceHandle(serviceManager); + return TRUE; +} + +/** + * Determines if the specified service is installed or not + * + * @param stacktop A pointer to the top of the stack + * @param variables A pointer to the NSIS variables + * @return 0 if the service does not exist + * 1 if the service does exist + * -1 if there was an error. + */ +extern "C" void __declspec(dllexport) +IsInstalled(HWND hwndParent, int string_size, + TCHAR *variables, stack_t **stacktop, void *extra) +{ + TCHAR tmp[MAX_PATH] = { L'\0' }; + WCHAR serviceName[MAX_PATH] = { '\0' }; + popstring(stacktop, tmp, MAX_PATH); + +#if !defined(UNICODE) + MultiByteToWideChar(CP_ACP, 0, tmp, -1, serviceName, MAX_PATH); +#else + wcscpy(serviceName, tmp); +#endif + + BOOL serviceInstalled; + if (!IsServiceInstalled(serviceName, serviceInstalled)) { + pushstring(stacktop, TEXT("-1"), 3); + } else { + pushstring(stacktop, serviceInstalled ? TEXT("1") : TEXT("0"), 2); + } +} + +/** + * Stops the specified service. + * + * @param serviceName The name of the service to stop + * @return TRUE if the operation was successful + */ +static BOOL +StopService(LPCWSTR serviceName) +{ + // Get a handle to the local computer SCM database with full access rights. + SC_HANDLE serviceManager = OpenSCManager(NULL, NULL, + SC_MANAGER_ENUMERATE_SERVICE); + if (!serviceManager) { + return FALSE; + } + + SC_HANDLE serviceHandle = OpenServiceW(serviceManager, + serviceName, + SERVICE_STOP); + if (!serviceHandle) { + CloseServiceHandle(serviceManager); + return FALSE; + } + + //Stop the service so it deletes faster and so the uninstaller + // can actually delete its EXE. + DWORD totalWaitTime = 0; + SERVICE_STATUS status; + static const int maxWaitTime = 1000 * 60; // Never wait more than a minute + BOOL stopped = FALSE; + if (ControlService(serviceHandle, SERVICE_CONTROL_STOP, &status)) { + do { + Sleep(status.dwWaitHint); + // + 10 milliseconds to make sure we always approach maxWaitTime + totalWaitTime += (status.dwWaitHint + 10); + if (status.dwCurrentState == SERVICE_STOPPED) { + stopped = true; + break; + } else if (totalWaitTime > maxWaitTime) { + break; + } + } while (QueryServiceStatus(serviceHandle, &status)); + } + + CloseServiceHandle(serviceHandle); + CloseServiceHandle(serviceManager); + return stopped; +} + +/** + * Stops the specified service + * + * @param stacktop A pointer to the top of the stack + * @param variables A pointer to the NSIS variables + * @return 1 if the service was stopped, 0 on error + */ +extern "C" void __declspec(dllexport) +Stop(HWND hwndParent, int string_size, + TCHAR *variables, stack_t **stacktop, void *extra) +{ + TCHAR tmp[MAX_PATH] = { L'\0' }; + WCHAR serviceName[MAX_PATH] = { '\0' }; + + popstring(stacktop, tmp, MAX_PATH); + +#if !defined(UNICODE) + MultiByteToWideChar(CP_ACP, 0, tmp, -1, serviceName, MAX_PATH); +#else + wcscpy(serviceName, tmp); +#endif + + if (StopService(serviceName)) { + pushstring(stacktop, TEXT("1"), 2); + } else { + pushstring(stacktop, TEXT("0"), 2); + } +} + +/** + * Determines a unique registry path from a file or directory path + * + * @param stacktop A pointer to the top of the stack + * @param variables A pointer to the NSIS variables + * @return The unique registry path or an empty string on error + */ +extern "C" void __declspec(dllexport) +PathToUniqueRegistryPath(HWND hwndParent, int string_size, + TCHAR *variables, stack_t **stacktop, + void *extra) +{ + TCHAR tmp[MAX_PATH] = { L'\0' }; + WCHAR installBasePath[MAX_PATH] = { '\0' }; + popstring(stacktop, tmp, MAX_PATH); + +#if !defined(UNICODE) + MultiByteToWideChar(CP_ACP, 0, tmp, -1, installBasePath, MAX_PATH); +#else + wcscpy(installBasePath, tmp); +#endif + + WCHAR registryPath[MAX_PATH + 1] = { '\0' }; + if (CalculateRegistryPathFromFilePath(installBasePath, registryPath)) { + pushstring(stacktop, registryPath, wcslen(registryPath) + 1); + } else { + pushstring(stacktop, TEXT(""), 1); + } +} + +BOOL WINAPI +DllMain(HANDLE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) +{ + return TRUE; +} + +/** + * Removes an element from the top of the NSIS stack + * + * @param stacktop A pointer to the top of the stack + * @param str The string to pop to + * @param len The max length + * @return 0 on success +*/ +int popstring(stack_t **stacktop, TCHAR *str, int len) +{ + // Removes the element from the top of the stack and puts it in the buffer + stack_t *th; + if (!stacktop || !*stacktop) { + return 1; + } + + th = (*stacktop); + lstrcpyn(str,th->text, len); + *stacktop = th->next; + GlobalFree((HGLOBAL)th); + return 0; +} + +/** + * Adds an element to the top of the NSIS stack + * + * @param stacktop A pointer to the top of the stack + * @param str The string to push on the stack + * @param len The length of the string to push on the stack + * @return 0 on success +*/ +void pushstring(stack_t **stacktop, const TCHAR *str, int len) +{ + stack_t *th; + if (!stacktop) { + return; + } + + th = (stack_t*)GlobalAlloc(GPTR, sizeof(stack_t) + len); + lstrcpyn(th->text, str, len); + th->next = *stacktop; + *stacktop = th; +} diff --git a/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.dsp b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.dsp new file mode 100644 index 0000000000..8c9577c516 --- /dev/null +++ b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.dsp @@ -0,0 +1,115 @@ +# Microsoft Developer Studio Project File - Name="ServicesHelper" - Package Owner=<4> +# Microsoft Developer Studio Generated Build File, Format Version 6.00 +# ** DO NOT EDIT ** + +# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 + +CFG=ServicesHelper - Win32 Debug +!MESSAGE This is not a valid makefile. To build this project using NMAKE, +!MESSAGE use the Export Makefile command and run +!MESSAGE +!MESSAGE NMAKE /f "ServicesHelper.mak". +!MESSAGE +!MESSAGE You can specify a configuration when running NMAKE +!MESSAGE by defining the macro CFG on the command line. For example: +!MESSAGE +!MESSAGE NMAKE /f "ServicesHelper.mak" CFG="ServicesHelper - Win32 Debug" +!MESSAGE +!MESSAGE Possible choices for configuration are: +!MESSAGE +!MESSAGE "ServicesHelper - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE "ServicesHelper - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") +!MESSAGE + +# Begin Project +# PROP AllowPerConfigDependencies 0 +# PROP Scc_ProjName "" +# PROP Scc_LocalPath "" +CPP=cl.exe +MTL=midl.exe +RSC=rc.exe + +!IF "$(CFG)" == "ServicesHelper - Win32 Release" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 0 +# PROP BASE Output_Dir "Release" +# PROP BASE Intermediate_Dir "Release" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 0 +# PROP Output_Dir "Release" +# PROP Intermediate_Dir "Release" +# PROP Ignore_Export_Lib 0 +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXDLL_EXPORTS" /YX /FD /c +# ADD CPP /nologo /MT /W3 /GX /O1 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /D "_USRDLL" /D "EXDLL_EXPORTS" /D _WIN32_WINNT=0x0400 /FR /YX /FD /c +# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "NDEBUG" +# ADD RSC /l 0x409 /d "NDEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib MSVCRT.LIB /nologo /entry:"DllMain" /dll /machine:I386 /nodefaultlib /out:"../../Plugins/ServicesHelper.dll" /opt:nowin98 +# SUBTRACT LINK32 /pdb:none + +!ELSEIF "$(CFG)" == "ServicesHelper - Win32 Debug" + +# PROP BASE Use_MFC 0 +# PROP BASE Use_Debug_Libraries 1 +# PROP BASE Output_Dir "Debug" +# PROP BASE Intermediate_Dir "Debug" +# PROP BASE Target_Dir "" +# PROP Use_MFC 0 +# PROP Use_Debug_Libraries 1 +# PROP Output_Dir "Debug" +# PROP Intermediate_Dir "Debug" +# PROP Target_Dir "" +# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXDLL_EXPORTS" /YX /FD /GZ /c +# ADD CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "EXDLL_EXPORTS" /YX /FD /GZ /c +# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 +# ADD BASE RSC /l 0x409 /d "_DEBUG" +# ADD RSC /l 0x409 /d "_DEBUG" +BSC32=bscmake.exe +# ADD BASE BSC32 /nologo +# ADD BSC32 /nologo +LINK32=link.exe +# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept +# ADD LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept + +!ENDIF + +# Begin Target + +# Name "ServicesHelper - Win32 Release" +# Name "ServicesHelper - Win32 Debug" +# Begin Group "Source Files" + +# PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" +# Begin Source File + +SOURCE=\toolkit\mozapps\update\common\pathhash.cpp +# End Source File +# Begin Source File + +SOURCE=\toolkit\mozapps\update\common\pathhash.h +# End Source File +# Begin Source File + +SOURCE=.\Services.cpp +# End Source File +# End Group +# Begin Group "Header Files" + +# PROP Default_Filter "h;hpp;hxx;hm;inl" +# End Group +# Begin Group "Resource Files" + +# PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" +# End Group +# End Target +# End Project diff --git a/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.dsw b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.dsw new file mode 100644 index 0000000000..c144217016 --- /dev/null +++ b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00 +# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! + +############################################################################### + +Project: "ServicesHelper"=.\ServicesHelper.dsp - Package Owner=<4> + +Package=<5> +{{{ +}}} + +Package=<4> +{{{ +}}} + +############################################################################### + +Global: + +Package=<5> +{{{ +}}} + +Package=<3> +{{{ +}}} + +############################################################################### + diff --git a/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.rc b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.rc new file mode 100644 index 0000000000..3e64f62c44 --- /dev/null +++ b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.rc @@ -0,0 +1,99 @@ +// Microsoft Visual C++ generated resource script. +// +#include "resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include "afxres.h" + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include ""afxres.h""\r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED + + +///////////////////////////////////////////////////////////////////////////// +// +// Version +// + +VS_VERSION_INFO VERSIONINFO + FILEVERSION 1,0,0,0 + PRODUCTVERSION 1,0,0,0 + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x2L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "040904b0" + BEGIN + VALUE "FileDescription", "NSIS Plug-in for managing Windows services" + VALUE "FileVersion", "1, 0, 0, 0" + VALUE "InternalName", "ServicesHelper" + VALUE "LegalCopyright", "MPL 1.1+/GPL 2.0+/LGPL 2.1+" + VALUE "OriginalFilename", "ServicesHelper.dll" + VALUE "ProductName", "ServicesHelper" + VALUE "ProductVersion", "1, 0, 0, 0" + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x409, 1200 + END +END + +#endif // English (United States) resources +///////////////////////////////////////////////////////////////////////////// + + + +#ifndef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 3 resource. +// + + +///////////////////////////////////////////////////////////////////////////// +#endif // not APSTUDIO_INVOKED + diff --git a/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.sln b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.sln new file mode 100644 index 0000000000..348a8e3003 --- /dev/null +++ b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.sln @@ -0,0 +1,20 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ServicesHelper", "ServicesHelper.vcproj", "{A0D0AD52-1D8B-402E-92EF-81AE0C320BD7}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A0D0AD52-1D8B-402E-92EF-81AE0C320BD7}.Debug|Win32.ActiveCfg = Debug|Win32 + {A0D0AD52-1D8B-402E-92EF-81AE0C320BD7}.Debug|Win32.Build.0 = Debug|Win32 + {A0D0AD52-1D8B-402E-92EF-81AE0C320BD7}.Release|Win32.ActiveCfg = Release|Win32 + {A0D0AD52-1D8B-402E-92EF-81AE0C320BD7}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.vcproj b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.vcproj new file mode 100644 index 0000000000..637fa5110f --- /dev/null +++ b/other-licenses/nsis/Contrib/ServicesHelper/ServicesHelper.vcproj @@ -0,0 +1,212 @@ +<?xml version="1.0" encoding="Windows-1252"?> +<VisualStudioProject + ProjectType="Visual C++" + Version="8.00" + Name="ServicesHelper" + ProjectGUID="{A0D0AD52-1D8B-402E-92EF-81AE0C320BD7}" + RootNamespace="ServicesHelper" + Keyword="Win32Proj" + > + <Platforms> + <Platform + Name="Win32" + /> + </Platforms> + <ToolFiles> + </ToolFiles> + <Configurations> + <Configuration + Name="Debug|Win32" + OutputDirectory="../../Plugins" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="2" + CharacterSet="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + Optimization="0" + AdditionalIncludeDirectories="../../../../toolkit/components/maintenanceservice/" + PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;_USRDLL;APPLICATIONID_EXPORTS" + MinimalRebuild="true" + BasicRuntimeChecks="3" + RuntimeLibrary="3" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="4" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="2" + GenerateDebugInformation="true" + SubSystem="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + <Configuration + Name="Release|Win32" + OutputDirectory="../../Plugins" + IntermediateDirectory="$(ConfigurationName)" + ConfigurationType="2" + ATLMinimizesCRunTimeLibraryUsage="true" + CharacterSet="1" + WholeProgramOptimization="1" + > + <Tool + Name="VCPreBuildEventTool" + /> + <Tool + Name="VCCustomBuildTool" + /> + <Tool + Name="VCXMLDataGeneratorTool" + /> + <Tool + Name="VCWebServiceProxyGeneratorTool" + /> + <Tool + Name="VCMIDLTool" + /> + <Tool + Name="VCCLCompilerTool" + AdditionalIncludeDirectories="../../../../toolkit/components/maintenanceservice/" + PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;_USRDLL;APPLICATIONID_EXPORTS" + RuntimeLibrary="0" + UsePrecompiledHeader="0" + WarningLevel="3" + Detect64BitPortabilityProblems="true" + DebugInformationFormat="3" + /> + <Tool + Name="VCManagedResourceCompilerTool" + /> + <Tool + Name="VCResourceCompilerTool" + /> + <Tool + Name="VCPreLinkEventTool" + /> + <Tool + Name="VCLinkerTool" + LinkIncremental="1" + GenerateDebugInformation="true" + SubSystem="2" + OptimizeReferences="2" + EnableCOMDATFolding="2" + TargetMachine="1" + /> + <Tool + Name="VCALinkTool" + /> + <Tool + Name="VCManifestTool" + /> + <Tool + Name="VCXDCMakeTool" + /> + <Tool + Name="VCBscMakeTool" + /> + <Tool + Name="VCFxCopTool" + /> + <Tool + Name="VCAppVerifierTool" + /> + <Tool + Name="VCWebDeploymentTool" + /> + <Tool + Name="VCPostBuildEventTool" + /> + </Configuration> + </Configurations> + <References> + </References> + <Files> + <Filter + Name="Source Files" + Filter="cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx" + UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}" + > + <File + RelativePath="..\..\..\..\toolkit\mozapps\update\common\pathhash.cpp" + > + </File> + <File + RelativePath=".\Services.cpp" + > + </File> + </Filter> + <Filter + Name="Header Files" + Filter="h;hpp;hxx;hm;inl;inc;xsd" + UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}" + > + <File + RelativePath=".\resource.h" + > + </File> + </Filter> + <Filter + Name="Resource Files" + Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav" + UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}" + > + <File + RelativePath=".\ServicesHelper.rc" + > + </File> + </Filter> + </Files> + <Globals> + </Globals> +</VisualStudioProject> diff --git a/other-licenses/nsis/Contrib/ServicesHelper/resource.h b/other-licenses/nsis/Contrib/ServicesHelper/resource.h new file mode 100644 index 0000000000..5b0a02ad34 --- /dev/null +++ b/other-licenses/nsis/Contrib/ServicesHelper/resource.h @@ -0,0 +1,14 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Visual C++ generated include file. +// Used by ServicesHelper.rc + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NEXT_RESOURCE_VALUE 101 +#define _APS_NEXT_COMMAND_VALUE 40001 +#define _APS_NEXT_CONTROL_VALUE 1001 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/other-licenses/nsis/Contrib/WebBrowser/CustomFunctions.cpp b/other-licenses/nsis/Contrib/WebBrowser/CustomFunctions.cpp new file mode 100644 index 0000000000..4ad004b841 --- /dev/null +++ b/other-licenses/nsis/Contrib/WebBrowser/CustomFunctions.cpp @@ -0,0 +1,75 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0.If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "WebBrowser.h" +#include "exdll.h" + +extern WebBrowser* gBrowser; +void Init(HWND hWndParent, int string_size, TCHAR* variables, + stack_t** stacktop, extra_parameters* extra); + +static void CustomFunctionWrapper(void* NSISFunctionAddr, VARIANT jsArg, + VARIANT* retVal) { + // Marshal the argument passed to the JavaScript function onto the NSIS stack. + switch (jsArg.vt) { + case VT_BSTR: + pushstring(jsArg.bstrVal); + break; + case VT_I4: { + TCHAR intArgStr[32] = _T(""); + _itot_s(jsArg.intVal, intArgStr, 10); + pushstring(intArgStr); + break; + } + case VT_BOOL: + pushstring(jsArg.boolVal == VARIANT_TRUE ? _T("1") : _T("0")); + break; + default: + // No other argument types supported. + pushstring(_T("")); + break; + } + + // Call the NSIS function. + int rv = g_executeCodeSegment((int)NSISFunctionAddr, nullptr); + + // Retrieve the return value from the NSIS stack. + TCHAR* nsisRetval = + (TCHAR*)HeapAlloc(GetProcessHeap(), 0, g_stringsize * sizeof(TCHAR)); + popstring(nsisRetval); + + // Pass the return value back to JavaScript, if it asked for one. + if (retVal) { + VariantInit(retVal); + retVal->vt = VT_BSTR; + retVal->bstrVal = SysAllocString(nsisRetval); + } + + HeapFree(GetProcessHeap(), 0, nsisRetval); +} + +PLUGINFUNCTION(RegisterCustomFunction) { + if (!gBrowser) { + Init(hWndParent, string_size, variables, stacktop, extra); + } + + TCHAR* funcAddrStr = + (TCHAR*)HeapAlloc(GetProcessHeap(), 0, g_stringsize * sizeof(TCHAR)); + popstring(funcAddrStr); + + TCHAR* funcName = + (TCHAR*)HeapAlloc(GetProcessHeap(), 0, g_stringsize * sizeof(TCHAR)); + popstring(funcName); + + if (gBrowser && funcAddrStr && funcName) { + // Apparently GetFunctionAddress returnes a 1-indexed offset, but + // ExecuteCodeSegment expects a 0-indexed one. Or something. + uintptr_t funcAddr = static_cast<uintptr_t>(_ttoi64(funcAddrStr)) - 1; + gBrowser->AddCustomFunction(funcName, CustomFunctionWrapper, + (void*)funcAddr); + } + + HeapFree(GetProcessHeap(), 0, funcName); + HeapFree(GetProcessHeap(), 0, funcAddrStr); +} diff --git a/other-licenses/nsis/Contrib/WebBrowser/Timers.cpp b/other-licenses/nsis/Contrib/WebBrowser/Timers.cpp new file mode 100644 index 0000000000..00844b7091 --- /dev/null +++ b/other-licenses/nsis/Contrib/WebBrowser/Timers.cpp @@ -0,0 +1,59 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0.If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include <windows.h> +#include "exdll.h" + +static void APIENTRY TimerCallback(LPVOID NSISFunctionAddr, DWORD, DWORD) { + g_executeCodeSegment((int)NSISFunctionAddr, nullptr); +} + +PLUGINFUNCTION(CreateTimer) { + EXDLL_INIT(); + extra->RegisterPluginCallback(gHInst, NSISPluginCallback); + + TCHAR* funcAddrStr = + (TCHAR*)HeapAlloc(GetProcessHeap(), 0, g_stringsize * sizeof(TCHAR)); + popstring(funcAddrStr); + // Apparently GetFunctionAddress returnes a 1-indexed offset, but + // ExecuteCodeSegment expects a 0-indexed one. Or something. + uintptr_t funcAddr = static_cast<uintptr_t>(_ttoi64(funcAddrStr)) - 1; + HeapFree(GetProcessHeap(), 0, funcAddrStr); + + TCHAR* intervalStr = + (TCHAR*)HeapAlloc(GetProcessHeap(), 0, g_stringsize * sizeof(TCHAR)); + popstring(intervalStr); + long interval = _ttol(intervalStr); + HeapFree(GetProcessHeap(), 0, intervalStr); + + HANDLE timer = CreateWaitableTimer(nullptr, FALSE, nullptr); + if (!timer) { + return; + } + + // The interval we were passed is in milliseconds, so we need to convert it + // to the 100-nanosecond units that SetWaitableTimer expects. We also need to + // make it negative, because that's what signifies a relative offset from now + // instead of an epoch-based time stamp. + LARGE_INTEGER dueTime; + dueTime.QuadPart = -(interval * 10000); + + SetWaitableTimer(timer, &dueTime, interval, TimerCallback, (void*)funcAddr, + FALSE); + + TCHAR timerStr[32] = _T(""); + _ltot_s((long)timer, timerStr, 10); + pushstring(timerStr); +} + +PLUGINFUNCTION(CancelTimer) { + TCHAR* timerStr = + (TCHAR*)HeapAlloc(GetProcessHeap(), 0, g_stringsize * sizeof(TCHAR)); + popstring(timerStr); + HANDLE timer = reinterpret_cast<HANDLE>(_ttoi(timerStr)); + HeapFree(GetProcessHeap(), 0, timerStr); + + CancelWaitableTimer(timer); + CloseHandle(timer); +} diff --git a/other-licenses/nsis/Contrib/WebBrowser/WebBrowser.cpp b/other-licenses/nsis/Contrib/WebBrowser/WebBrowser.cpp new file mode 100644 index 0000000000..59e0a1d881 --- /dev/null +++ b/other-licenses/nsis/Contrib/WebBrowser/WebBrowser.cpp @@ -0,0 +1,604 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0.If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "WebBrowser.h" +#include <mshtmdid.h> + +WebBrowser::WebBrowser(HWND _hWndParent) : mHwndParent(_hWndParent) { + // Whatever executed this constructor owns our first reference. + AddRef(); + + HRESULT hr = ::OleCreate(CLSID_WebBrowser, IID_IOleObject, OLERENDER_DRAW, 0, + this, this, (void**)&mOleObject); + if (FAILED(hr)) { + return; + } + + RECT posRect; + ::GetClientRect(mHwndParent, &posRect); + + hr = mOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, nullptr, this, 0, + mHwndParent, &posRect); + if (FAILED(hr)) { + mOleObject->Release(); + mOleObject = nullptr; + return; + } + + SetRect(posRect); + + hr = mOleObject->QueryInterface(&mWebBrowser2); + if (FAILED(hr)) { + mOleObject->Release(); + mOleObject = nullptr; + return; + } + + mWebBrowser2->put_Silent(VARIANT_TRUE); +} + +WebBrowser::~WebBrowser() { + if (mWebBrowser2) { + mWebBrowser2->Release(); + mWebBrowser2 = nullptr; + } + if (mOleInPlaceActiveObject) { + mOleInPlaceActiveObject->Release(); + mOleInPlaceActiveObject = nullptr; + } + if (mOleInPlaceObject) { + mOleInPlaceObject->Release(); + mOleInPlaceObject = nullptr; + } + if (mOleObject) { + mOleObject->Release(); + mOleObject = nullptr; + } +} + +void WebBrowser::Shutdown() { + if (mOleObject) { + mOleObject->Close(OLECLOSE_NOSAVE); + mOleObject->SetClientSite(nullptr); + } +} + +bool WebBrowser::IsInitialized() { return mOleObject != nullptr; } + +HRESULT WebBrowser::ActiveObjectTranslateAccelerator(bool tab, LPMSG lpmsg) { + if (IsInitialized() && mOleInPlaceActiveObject) { + HRESULT hr = mOleInPlaceActiveObject->TranslateAcceleratorW(lpmsg); + if (hr == S_FALSE && tab) { + // The browser control will give up focus, but it is the only control so + // it would get focus again via IsDialogMessage. This does not result in + // the focus returning to the web page, though, so instead let the + // control process the tab again. + hr = mOleInPlaceActiveObject->TranslateAcceleratorW(lpmsg); + } + return hr; + } else { + return S_FALSE; + } +} + +void WebBrowser::SetRect(const RECT& _rc) { + mRect = _rc; + + if (mOleInPlaceObject) { + mOleInPlaceObject->SetObjectRects(&mRect, &mRect); + } +} + +void WebBrowser::Resize(DWORD width, DWORD height) { + RECT r = mRect; + r.bottom = r.top + height; + r.right = r.left + width; + SetRect(r); +} + +void WebBrowser::Navigate(wchar_t* url) { + if (!IsInitialized()) { + return; + } + + VARIANT flags; + VariantInit(&flags); + flags.vt = VT_I4; + flags.intVal = navNoHistory | navEnforceRestricted | navUntrustedForDownload | + navBlockRedirectsXDomain; + + mWebBrowser2->Navigate(url, &flags, nullptr, nullptr, nullptr); +} + +void WebBrowser::AddCustomFunction(wchar_t* name, CustomFunction function, + void* arg) { + CustomFunctionRecord record = {name, function, arg}; + +// We've disabled exceptions but push_back can throw on an allocation +// failure, so we need to suppress a warning trying to tell us that +// that combination doesn't make any sense. +#pragma warning(suppress : 4530) + mCustomFunctions.push_back(record); +} + +////////////////////////////////////////////////////////////////////////////// +// IUnknown +////////////////////////////////////////////////////////////////////////////// +// This is a standard IUnknown implementation, we don't need anything special. + +HRESULT STDMETHODCALLTYPE WebBrowser::QueryInterface(REFIID riid, + void** ppvObject) { + if (riid == __uuidof(IUnknown)) { + *ppvObject = static_cast<IOleClientSite*>(this); + } else if (riid == __uuidof(IOleClientSite)) { + *ppvObject = static_cast<IOleClientSite*>(this); + } else if (riid == __uuidof(IOleInPlaceSite)) { + *ppvObject = static_cast<IOleInPlaceSite*>(this); + } else if (riid == __uuidof(IDropTarget)) { + *ppvObject = static_cast<IDropTarget*>(this); + } else if (riid == __uuidof(IStorage)) { + *ppvObject = static_cast<IStorage*>(this); + } else if (riid == __uuidof(IDocHostUIHandler)) { + *ppvObject = static_cast<IDocHostUIHandler*>(this); + } else if (riid == __uuidof(IDocHostShowUI)) { + *ppvObject = static_cast<IDocHostShowUI*>(this); + } else if (riid == __uuidof(IDispatch)) { + *ppvObject = static_cast<IDispatch*>(this); + } else { + *ppvObject = nullptr; + return E_NOINTERFACE; + } + + AddRef(); + return S_OK; +} + +ULONG STDMETHODCALLTYPE WebBrowser::AddRef() { + return InterlockedIncrement(&mComRefCount); +} + +ULONG STDMETHODCALLTYPE WebBrowser::Release() { + ULONG refCount = InterlockedDecrement(&mComRefCount); + if (refCount == 0) { + delete this; + } + return refCount; +} + +////////////////////////////////////////////////////////////////////////////// +// IOleWindow +////////////////////////////////////////////////////////////////////////////// + +HRESULT STDMETHODCALLTYPE +WebBrowser::GetWindow(__RPC__deref_out_opt HWND* phwnd) { + *phwnd = mHwndParent; + return S_OK; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::ContextSensitiveHelp(BOOL fEnterMode) { + // We don't provide context-sensitive help. + return E_NOTIMPL; +} + +////////////////////////////////////////////////////////////////////////////// +// IOleInPlaceSite +////////////////////////////////////////////////////////////////////////////// + +HRESULT STDMETHODCALLTYPE WebBrowser::CanInPlaceActivate() { + // We always support in-place activation. + return S_OK; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::OnInPlaceActivate() { + OleLockRunning(mOleObject, TRUE, FALSE); + mOleObject->QueryInterface(&mOleInPlaceObject); + mOleInPlaceObject->QueryInterface(&mOleInPlaceActiveObject); + mOleInPlaceObject->SetObjectRects(&mRect, &mRect); + + return S_OK; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::OnUIActivate() { + // Nothing to do before activating the control's UI. + return S_OK; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::GetWindowContext( + __RPC__deref_out_opt IOleInPlaceFrame** ppFrame, + __RPC__deref_out_opt IOleInPlaceUIWindow** ppDoc, + __RPC__out LPRECT lprcPosRect, __RPC__out LPRECT lprcClipRect, + __RPC__inout LPOLEINPLACEFRAMEINFO lpFrameInfo) { + *ppFrame = nullptr; + *ppDoc = nullptr; + *lprcPosRect = mRect; + *lprcClipRect = mRect; + + lpFrameInfo->fMDIApp = false; + lpFrameInfo->hwndFrame = mHwndParent; + lpFrameInfo->haccel = nullptr; + lpFrameInfo->cAccelEntries = 0; + + return S_OK; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::Scroll(SIZE scrollExtant) { + // We should have disabled all scrollbars. + return E_NOTIMPL; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::OnUIDeactivate(BOOL fUndoable) { + // Nothing to do after deactivating the control's UI. + return S_OK; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::OnInPlaceDeactivate() { + if (mOleInPlaceObject) { + mOleInPlaceObject->Release(); + mOleInPlaceObject = nullptr; + } + + return S_OK; +} + +// We don't support the concept of undo. +HRESULT STDMETHODCALLTYPE WebBrowser::DiscardUndoState() { return E_NOTIMPL; } + +HRESULT STDMETHODCALLTYPE WebBrowser::DeactivateAndUndo() { return E_NOTIMPL; } + +// We don't support moving or resizing the control. +HRESULT STDMETHODCALLTYPE +WebBrowser::OnPosRectChange(__RPC__in LPCRECT lprcPosRect) { + return E_NOTIMPL; +} + +////////////////////////////////////////////////////////////////////////////// +// IOleClientSite +////////////////////////////////////////////////////////////////////////////// +// We don't need anything that IOleClientSite does, because we're doing OLE +// only in the most basic sense and we don't support linking (or, indeed, +// embedding), but some implementation of this interface is required for +// OleCreate to work, so we have to have a stub version. + +HRESULT STDMETHODCALLTYPE WebBrowser::SaveObject() { return E_NOTIMPL; } + +HRESULT STDMETHODCALLTYPE +WebBrowser::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, + __RPC__deref_out_opt IMoniker** ppmk) { + return E_NOTIMPL; +} + +HRESULT STDMETHODCALLTYPE +WebBrowser::GetContainer(__RPC__deref_out_opt IOleContainer** ppContainer) { + *ppContainer = nullptr; + return E_NOINTERFACE; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::ShowObject() { return S_OK; } + +HRESULT STDMETHODCALLTYPE WebBrowser::OnShowWindow(BOOL fShow) { return S_OK; } + +HRESULT STDMETHODCALLTYPE WebBrowser::RequestNewObjectLayout() { + return E_NOTIMPL; +} + +////////////////////////////////////////////////////////////////////////////// +// IDropTarget +////////////////////////////////////////////////////////////////////////////// +// This is a stub implementation which blocks all dropping. The main reason we +// want to do that is prevent accidentally dropping something on the control +// and having it navigate, because there's no recovering from that except to +// restart the app, and also it would look ridiculous. There could also be +// security implications though, which we'd rather just avoid engaging with +// altogether if we can. + +HRESULT STDMETHODCALLTYPE +WebBrowser::DragEnter(__RPC__in_opt IDataObject* pDataObj, DWORD grfKeyState, + POINTL pt, __RPC__inout DWORD* pdwEffect) { + *pdwEffect = DROPEFFECT_NONE; + return S_OK; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::DragOver(DWORD grfKeyState, POINTL pt, + __RPC__inout DWORD* pdwEffect) { + *pdwEffect = DROPEFFECT_NONE; + return S_OK; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::DragLeave() { return S_OK; } + +HRESULT STDMETHODCALLTYPE WebBrowser::Drop(__RPC__in_opt IDataObject* pDataObj, + DWORD grfKeyState, POINTL pt, + __RPC__inout DWORD* pdwEffect) { + *pdwEffect = DROPEFFECT_NONE; + return S_OK; +} + +////////////////////////////////////////////////////////////////////////////// +// IStorage +////////////////////////////////////////////////////////////////////////////// +// We don't need anything that IStorage does, but we have to pass some +// implementation of it to OleCreate, so we need to have a stub version. + +HRESULT STDMETHODCALLTYPE WebBrowser::CreateStream( + __RPC__in_string const OLECHAR* pwcsName, DWORD grfMode, DWORD reserved1, + DWORD reserved2, __RPC__deref_out_opt IStream** ppstm) { + *ppstm = nullptr; + return E_NOTIMPL; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::OpenStream(const OLECHAR* pwcsName, + void* reserved1, DWORD grfMode, + DWORD reserved2, + IStream** ppstm) { + *ppstm = nullptr; + return E_NOTIMPL; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::CreateStorage( + __RPC__in_string const OLECHAR* pwcsName, DWORD grfMode, DWORD reserved1, + DWORD reserved2, __RPC__deref_out_opt IStorage** ppstg) { + *ppstg = nullptr; + return E_NOTIMPL; +} + +HRESULT STDMETHODCALLTYPE +WebBrowser::OpenStorage(__RPC__in_opt_string const OLECHAR* pwcsName, + __RPC__in_opt IStorage* pstgPriority, DWORD grfMode, + __RPC__deref_opt_in_opt SNB snbExclude, DWORD reserved, + __RPC__deref_out_opt IStorage** ppstg) { + return E_NOTIMPL; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::CopyTo(DWORD ciidExclude, + const IID* rgiidExclude, + __RPC__in_opt SNB snbExclude, + IStorage* pstgDest) { + return E_NOTIMPL; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::MoveElementTo( + __RPC__in_string const OLECHAR* pwcsName, __RPC__in_opt IStorage* pstgDest, + __RPC__in_string const OLECHAR* pwcsNewName, DWORD grfFlags) { + return E_NOTIMPL; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::Commit(DWORD grfCommitFlags) { + return E_NOTIMPL; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::Revert() { return E_NOTIMPL; } + +HRESULT STDMETHODCALLTYPE WebBrowser::EnumElements(DWORD reserved1, + void* reserved2, + DWORD reserved3, + IEnumSTATSTG** ppenum) { + return E_NOTIMPL; +} + +HRESULT STDMETHODCALLTYPE +WebBrowser::DestroyElement(__RPC__in_string const OLECHAR* pwcsName) { + return E_NOTIMPL; +} + +HRESULT STDMETHODCALLTYPE +WebBrowser::RenameElement(__RPC__in_string const OLECHAR* pwcsOldName, + __RPC__in_string const OLECHAR* pwcsNewName) { + return E_NOTIMPL; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::SetElementTimes( + __RPC__in_opt_string const OLECHAR* pwcsName, + __RPC__in_opt const FILETIME* pctime, __RPC__in_opt const FILETIME* patime, + __RPC__in_opt const FILETIME* pmtime) { + return E_NOTIMPL; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::SetClass(__RPC__in REFCLSID clsid) { + return S_OK; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::SetStateBits(DWORD grfStateBits, + DWORD grfMask) { + return E_NOTIMPL; +} + +HRESULT STDMETHODCALLTYPE WebBrowser::Stat(__RPC__out STATSTG* pstatstg, + DWORD grfStatFlag) { + return E_NOTIMPL; +} + +////////////////////////////////////////////////////////////////////////////// +// IDocHostUIHandler +////////////////////////////////////////////////////////////////////////////// +// Our implementation for this interface is basically all about disabling +// things that we don't want/need. + +HRESULT __stdcall WebBrowser::ShowContextMenu(DWORD dwID, POINT* ppt, + IUnknown* pcmdtReserved, + IDispatch* pdispReserved) { + // Returning S_OK signals that we've handled the request for a context menu + // (which we did, by doing nothing), so the control won't try to open one. + return S_OK; +} + +HRESULT __stdcall WebBrowser::GetHostInfo(DOCHOSTUIINFO* pInfo) { + pInfo->cbSize = sizeof(DOCHOSTUIINFO); + pInfo->dwFlags = + DOCHOSTUIFLAG_DIALOG | DOCHOSTUIFLAG_DISABLE_HELP_MENU | + DOCHOSTUIFLAG_NO3DBORDER | DOCHOSTUIFLAG_SCROLL_NO | + DOCHOSTUIFLAG_OPENNEWWIN | DOCHOSTUIFLAG_OVERRIDEBEHAVIORFACTORY | + DOCHOSTUIFLAG_THEME | DOCHOSTUIFLAG_LOCAL_MACHINE_ACCESS_CHECK | + DOCHOSTUIFLAG_DISABLE_UNTRUSTEDPROTOCOL | DOCHOSTUIFLAG_DPI_AWARE; + pInfo->dwDoubleClick = DOCHOSTUIDBLCLK_DEFAULT; + pInfo->pchHostCss = nullptr; + pInfo->pchHostNS = nullptr; + return S_OK; +} + +HRESULT __stdcall WebBrowser::ShowUI(DWORD dwID, + IOleInPlaceActiveObject* pActiveObject, + IOleCommandTarget* pCommandTarget, + IOleInPlaceFrame* pFrame, + IOleInPlaceUIWindow* pDoc) { + return E_NOTIMPL; +} + +HRESULT __stdcall WebBrowser::HideUI() { return E_NOTIMPL; } + +HRESULT __stdcall WebBrowser::UpdateUI() { return E_NOTIMPL; } + +HRESULT __stdcall WebBrowser::EnableModeless(BOOL fEnable) { return E_NOTIMPL; } + +HRESULT __stdcall WebBrowser::OnDocWindowActivate(BOOL fActivate) { + return E_NOTIMPL; +} + +HRESULT __stdcall WebBrowser::OnFrameWindowActivate(BOOL fActivate) { + return E_NOTIMPL; +} + +HRESULT __stdcall WebBrowser::ResizeBorder(LPCRECT prcBorder, + IOleInPlaceUIWindow* pUIWindow, + BOOL fRameWindow) { + return E_NOTIMPL; +} + +HRESULT __stdcall WebBrowser::TranslateAccelerator(LPMSG lpMsg, + const GUID* pguidCmdGroup, + DWORD nCmdID) { + return S_FALSE; +} + +HRESULT __stdcall WebBrowser::GetOptionKeyPath(LPOLESTR* pchKey, DWORD dw) { + return E_NOTIMPL; +} + +HRESULT __stdcall WebBrowser::GetDropTarget(IDropTarget* pDropTarget, + IDropTarget** ppDropTarget) { + // The IDropTarget implementation that we need is an empty stub, so we'll do + // the easy and convenient thing and just use this object. + return QueryInterface(IID_PPV_ARGS(ppDropTarget)); +} + +HRESULT __stdcall WebBrowser::GetExternal(IDispatch** ppDispatch) { + // This object has to implement IDispatch anyway so that we can use + // DISPID_AMBIENT_DLCONTROL, so we'll make this the external handler also. + return QueryInterface(IID_PPV_ARGS(ppDispatch)); +} + +HRESULT __stdcall WebBrowser::TranslateUrl(DWORD dwTranslate, LPWSTR pchURLIn, + LPWSTR* ppchURLOut) { + *ppchURLOut = nullptr; + return E_NOTIMPL; +} + +HRESULT __stdcall WebBrowser::FilterDataObject(IDataObject* pDO, + IDataObject** ppDORet) { + *ppDORet = nullptr; + return E_NOTIMPL; +} + +////////////////////////////////////////////////////////////////////////////// +// IDocHostShowUI +////////////////////////////////////////////////////////////////////////////// + +HRESULT __stdcall WebBrowser::ShowMessage(HWND hwnd, LPOLESTR lpstrText, + LPOLESTR lpstrCaption, DWORD dwType, + LPOLESTR lpstrHelpFile, + DWORD dwHelpContext, + LRESULT* plResult) { + // Don't allow MSHTML to generate message boxes. + return S_OK; +} + +HRESULT __stdcall WebBrowser::ShowHelp(HWND hwnd, LPOLESTR pszHelpFile, + UINT uCommand, DWORD dwData, + POINT ptMouse, + IDispatch* pDispatchObjectHit) { + // Don't allow MSHTML to show any help. + return S_OK; +} + +////////////////////////////////////////////////////////////////////////////// +// IDispatch +////////////////////////////////////////////////////////////////////////////// + +// We're not using a type library. +HRESULT __stdcall WebBrowser::GetTypeInfoCount(UINT* pctinfo) { + if (pctinfo) { + *pctinfo = 0; + } + return S_OK; +} + +HRESULT __stdcall WebBrowser::GetTypeInfo(UINT iTInfo, LCID lcid, + ITypeInfo** ppTInfo) { + return E_NOTIMPL; +} + +HRESULT __stdcall WebBrowser::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, + UINT cNames, LCID lcid, + DISPID* rgDispId) { + if (cNames != 1) { + return E_NOTIMPL; + } + + for (size_t i = 0; i < mCustomFunctions.size(); ++i) { + if (mCustomFunctions[i].mName == rgszNames[0]) { + // DISPID values need to be 1-indexed because 0 is reserved + // (DISPID_VALUE). + *rgDispId = i + 1; + return S_OK; + } + } + + *rgDispId = DISPID_UNKNOWN; + return DISP_E_UNKNOWNNAME; +} + +HRESULT __stdcall WebBrowser::Invoke(DISPID dispIdMember, REFIID riid, + LCID lcid, WORD wFlags, + DISPPARAMS* pDispParams, + VARIANT* pVarResult, EXCEPINFO* pExcepInfo, + UINT* puArgErr) { + if (dispIdMember == DISPID_AMBIENT_DLCONTROL && pVarResult) { + VariantClear(pVarResult); + pVarResult->vt = VT_I4; + // As a light security measure, disable a bunch of stuff we don't want + // to be able to run in the web control. + pVarResult->intVal = DLCTL_NO_JAVA | DLCTL_NO_DLACTIVEXCTLS | + DLCTL_NO_RUNACTIVEXCTLS | DLCTL_NO_FRAMEDOWNLOAD | + DLCTL_NO_BEHAVIORS | DLCTL_NO_CLIENTPULL | + DLCTL_NOFRAMES | DLCTL_FORCEOFFLINE | DLCTL_SILENT | + DLCTL_OFFLINE | DLCTL_DLIMAGES; + return S_OK; + } + + // Otherwise this should be one of our custom functions. + // We only support invoking these as methods, not property access. + if ((wFlags & DISPATCH_METHOD) == 0) { + return DISP_E_TYPEMISMATCH; + } + + // Make sure this DISPID is valid in our custom functions list. + // DISPID values are 1-indexed because 0 is reserved (DISPID_VALUE). + DISPID customFunctionIndex = dispIdMember - 1; + if (customFunctionIndex < 0 || + customFunctionIndex >= (DISPID)mCustomFunctions.size()) { + return DISP_E_MEMBERNOTFOUND; + } + + // If the caller passed an argument to this custom function, use it. + // If not, make an empty VARIANT we can pass to it instead. + VARIANT argument; + VariantInit(&argument); + if (pDispParams->cArgs > 0) { + argument = pDispParams->rgvarg[0]; + } + + CustomFunctionRecord foundFunction = mCustomFunctions[customFunctionIndex]; + foundFunction.mFunction(foundFunction.mArg, argument, pVarResult); + + return S_OK; +} diff --git a/other-licenses/nsis/Contrib/WebBrowser/WebBrowser.h b/other-licenses/nsis/Contrib/WebBrowser/WebBrowser.h new file mode 100644 index 0000000000..8bc4800a2e --- /dev/null +++ b/other-licenses/nsis/Contrib/WebBrowser/WebBrowser.h @@ -0,0 +1,250 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0.If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include <exdisp.h> +#include <mshtmhst.h> + +#include <vector> +#include <string> + +class WebBrowser final : + /* public IUnknown, */ + /* public IOleWindow, */ + public IOleInPlaceSite, + public IOleClientSite, + public IDropTarget, + public IStorage, + public IDocHostUIHandler, + public IDocHostShowUI, + public IDispatch { + public: + ///////////////////////////////////////////////////////////////////////////// + // Our own methods + ///////////////////////////////////////////////////////////////////////////// + WebBrowser(HWND hWndParent); + ~WebBrowser(); + + WebBrowser(const WebBrowser&) = delete; + WebBrowser& operator=(const WebBrowser&) = delete; + + void Shutdown(); + + bool IsInitialized(); + + HRESULT ActiveObjectTranslateAccelerator(bool tab, LPMSG lpmsg); + void SetRect(const RECT& _rc); + void Resize(DWORD width, DWORD height); + void Navigate(wchar_t* szUrl); + + using CustomFunction = void (*)(void* context, VARIANT parameter, + VARIANT* retVal); + void AddCustomFunction(wchar_t* name, CustomFunction function, void* arg); + + ///////////////////////////////////////////////////////////////////////////// + // Data members + ///////////////////////////////////////////////////////////////////////////// + private: + IOleObject* mOleObject = nullptr; + IOleInPlaceObject* mOleInPlaceObject = nullptr; + IOleInPlaceActiveObject* mOleInPlaceActiveObject = nullptr; + IWebBrowser2* mWebBrowser2 = nullptr; + + LONG mComRefCount = 0; + + RECT mRect = {0, 0, 0, 0}; + + HWND mHwndParent = nullptr; + + struct CustomFunctionRecord { + std::wstring mName; + CustomFunction mFunction; + void* mArg; + }; + std::vector<CustomFunctionRecord> mCustomFunctions; + + ////////////////////////////////////////////////////////////////////////////// + // COM interface methods + ////////////////////////////////////////////////////////////////////////////// + public: + // IUnknown + HRESULT STDMETHODCALLTYPE QueryInterface(REFIID riid, + void** ppvObject) override; + ULONG STDMETHODCALLTYPE AddRef() override; + ULONG STDMETHODCALLTYPE Release() override; + + // IOleWindow + HRESULT STDMETHODCALLTYPE + GetWindow(__RPC__deref_out_opt HWND* phwnd) override; + HRESULT STDMETHODCALLTYPE ContextSensitiveHelp(BOOL fEnterMode) override; + + // IOleInPlaceSite + HRESULT STDMETHODCALLTYPE CanInPlaceActivate() override; + HRESULT STDMETHODCALLTYPE OnInPlaceActivate() override; + HRESULT STDMETHODCALLTYPE OnUIActivate() override; + HRESULT STDMETHODCALLTYPE GetWindowContext( + __RPC__deref_out_opt IOleInPlaceFrame** ppFrame, + __RPC__deref_out_opt IOleInPlaceUIWindow** ppDoc, + __RPC__out LPRECT lprcPosRect, __RPC__out LPRECT lprcClipRect, + __RPC__inout LPOLEINPLACEFRAMEINFO lpFrameInfo) override; + HRESULT STDMETHODCALLTYPE Scroll(SIZE scrollExtant) override; + HRESULT STDMETHODCALLTYPE OnUIDeactivate(BOOL fUndoable) override; + HRESULT STDMETHODCALLTYPE OnInPlaceDeactivate() override; + HRESULT STDMETHODCALLTYPE DiscardUndoState() override; + HRESULT STDMETHODCALLTYPE DeactivateAndUndo() override; + HRESULT STDMETHODCALLTYPE + OnPosRectChange(__RPC__in LPCRECT lprcPosRect) override; + + // IOleClientSite + HRESULT STDMETHODCALLTYPE SaveObject() override; + HRESULT STDMETHODCALLTYPE + GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, + __RPC__deref_out_opt IMoniker** ppmk) override; + HRESULT STDMETHODCALLTYPE + GetContainer(__RPC__deref_out_opt IOleContainer** ppContainer) override; + HRESULT STDMETHODCALLTYPE ShowObject() override; + HRESULT STDMETHODCALLTYPE OnShowWindow(BOOL fShow) override; + HRESULT STDMETHODCALLTYPE RequestNewObjectLayout() override; + + // IDropTarget + HRESULT STDMETHODCALLTYPE DragEnter(__RPC__in_opt IDataObject* pDataObj, + DWORD grfKeyState, POINTL pt, + __RPC__inout DWORD* pdwEffect) override; + HRESULT STDMETHODCALLTYPE DragOver(DWORD grfKeyState, POINTL pt, + __RPC__inout DWORD* pdwEffect) override; + HRESULT STDMETHODCALLTYPE DragLeave() override; + HRESULT STDMETHODCALLTYPE Drop(__RPC__in_opt IDataObject* pDataObj, + DWORD grfKeyState, POINTL pt, + __RPC__inout DWORD* pdwEffect) override; + + // IStorage + HRESULT STDMETHODCALLTYPE CreateStream( + __RPC__in_string const OLECHAR* pwcsName, DWORD grfMode, DWORD reserved1, + DWORD reserved2, __RPC__deref_out_opt IStream** ppstm) override; + HRESULT STDMETHODCALLTYPE OpenStream(const OLECHAR* pwcsName, void* reserved1, + DWORD grfMode, DWORD reserved2, + IStream** ppstm) override; + HRESULT STDMETHODCALLTYPE CreateStorage( + __RPC__in_string const OLECHAR* pwcsName, DWORD grfMode, DWORD reserved1, + DWORD reserved2, __RPC__deref_out_opt IStorage** ppstg) override; + HRESULT STDMETHODCALLTYPE + OpenStorage(__RPC__in_opt_string const OLECHAR* pwcsName, + __RPC__in_opt IStorage* pstgPriority, DWORD grfMode, + __RPC__deref_opt_in_opt SNB snbExclude, DWORD reserved, + __RPC__deref_out_opt IStorage** ppstg) override; + HRESULT STDMETHODCALLTYPE CopyTo(DWORD ciidExclude, const IID* rgiidExclude, + __RPC__in_opt SNB snbExclude, + IStorage* pstgDest) override; + HRESULT STDMETHODCALLTYPE MoveElementTo( + __RPC__in_string const OLECHAR* pwcsName, + __RPC__in_opt IStorage* pstgDest, + __RPC__in_string const OLECHAR* pwcsNewName, DWORD grfFlags) override; + HRESULT STDMETHODCALLTYPE Commit(DWORD grfCommitFlags) override; + HRESULT STDMETHODCALLTYPE Revert(void) override; + HRESULT STDMETHODCALLTYPE EnumElements(DWORD reserved1, void* reserved2, + DWORD reserved3, + IEnumSTATSTG** ppenum) override; + HRESULT STDMETHODCALLTYPE + DestroyElement(__RPC__in_string const OLECHAR* pwcsName) override; + HRESULT STDMETHODCALLTYPE + RenameElement(__RPC__in_string const OLECHAR* pwcsOldName, + __RPC__in_string const OLECHAR* pwcsNewName) override; + HRESULT STDMETHODCALLTYPE + SetElementTimes(__RPC__in_opt_string const OLECHAR* pwcsName, + __RPC__in_opt const FILETIME* pctime, + __RPC__in_opt const FILETIME* patime, + __RPC__in_opt const FILETIME* pmtime) override; + HRESULT STDMETHODCALLTYPE SetClass(__RPC__in REFCLSID clsid) override; + HRESULT STDMETHODCALLTYPE SetStateBits(DWORD grfStateBits, + DWORD grfMask) override; + HRESULT STDMETHODCALLTYPE Stat(__RPC__out STATSTG* pstatstg, + DWORD grfStatFlag) override; + + // IDocHostUIHandler + HRESULT STDMETHODCALLTYPE ShowContextMenu( + _In_ DWORD dwID, _In_ POINT* ppt, _In_ IUnknown* pcmdtReserved, + _In_ IDispatch* pdispReserved) override; + HRESULT STDMETHODCALLTYPE GetHostInfo(_Inout_ DOCHOSTUIINFO* pInfo) override; + HRESULT STDMETHODCALLTYPE ShowUI(_In_ DWORD dwID, + _In_ IOleInPlaceActiveObject* pActiveObject, + _In_ IOleCommandTarget* pCommandTarget, + _In_ IOleInPlaceFrame* pFrame, + _In_ IOleInPlaceUIWindow* pDoc) override; + HRESULT STDMETHODCALLTYPE HideUI() override; + HRESULT STDMETHODCALLTYPE UpdateUI() override; + HRESULT STDMETHODCALLTYPE EnableModeless(BOOL fEnable) override; + HRESULT STDMETHODCALLTYPE OnDocWindowActivate(BOOL fActivate) override; + HRESULT STDMETHODCALLTYPE OnFrameWindowActivate(BOOL fActivate) override; + HRESULT STDMETHODCALLTYPE ResizeBorder(_In_ LPCRECT prcBorder, + _In_ IOleInPlaceUIWindow* pUIWindow, + _In_ BOOL fRameWindow) override; + HRESULT STDMETHODCALLTYPE TranslateAccelerator(LPMSG lpMsg, + const GUID* pguidCmdGroup, + DWORD nCmdID) override; + HRESULT STDMETHODCALLTYPE GetOptionKeyPath(_Out_ LPOLESTR* pchKey, + DWORD dw) override; + HRESULT STDMETHODCALLTYPE + GetDropTarget(_In_ IDropTarget* pDropTarget, + _Outptr_ IDropTarget** ppDropTarget) override; + HRESULT STDMETHODCALLTYPE + GetExternal(_Outptr_result_maybenull_ IDispatch** ppDispatch) override; + HRESULT STDMETHODCALLTYPE TranslateUrl(DWORD dwTranslate, + _In_ LPWSTR pchURLIn, + _Outptr_ LPWSTR* ppchURLOut) override; + HRESULT STDMETHODCALLTYPE + FilterDataObject(_In_ IDataObject* pDO, + _Outptr_result_maybenull_ IDataObject** ppDORet) override; + + // IDocHostShowUI + HRESULT STDMETHODCALLTYPE ShowMessage( + /* [in] */ HWND hwnd, + /* [annotation][in] */ + _In_ LPOLESTR lpstrText, + /* [annotation][in] */ + _In_ LPOLESTR lpstrCaption, + /* [in] */ DWORD dwType, + /* [annotation][in] */ + _In_ LPOLESTR lpstrHelpFile, + /* [in] */ DWORD dwHelpContext, + /* [out] */ LRESULT* plResult) override; + HRESULT STDMETHODCALLTYPE ShowHelp( + /* [in] */ HWND hwnd, + /* [annotation][in] */ + _In_ LPOLESTR pszHelpFile, + /* [in] */ UINT uCommand, + /* [in] */ DWORD dwData, + /* [in] */ POINT ptMouse, + /* [out] */ IDispatch* pDispatchObjectHit) override; + + // IDispatch + HRESULT STDMETHODCALLTYPE GetTypeInfoCount( + /* [out] */ __RPC__out UINT* pctinfo) override; + HRESULT STDMETHODCALLTYPE GetTypeInfo( + /* [in] */ UINT iTInfo, + /* [in] */ LCID lcid, + /* [out] */ __RPC__deref_out_opt ITypeInfo** ppTInfo) override; + HRESULT STDMETHODCALLTYPE GetIDsOfNames( + /* [in] */ __RPC__in REFIID riid, + /* [size_is][in] */ __RPC__in_ecount_full(cNames) LPOLESTR* rgszNames, + /* [range][in] */ __RPC__in_range(0, 16384) UINT cNames, + /* [in] */ LCID lcid, + /* [size_is][out] */ __RPC__out_ecount_full(cNames) DISPID* rgDispId) + override; + /* [local] */ HRESULT STDMETHODCALLTYPE Invoke( + /* [annotation][in] */ + _In_ DISPID dispIdMember, + /* [annotation][in] */ + _In_ REFIID riid, + /* [annotation][in] */ + _In_ LCID lcid, + /* [annotation][in] */ + _In_ WORD wFlags, + /* [annotation][out][in] */ + _In_ DISPPARAMS* pDispParams, + /* [annotation][out] */ + _Out_opt_ VARIANT* pVarResult, + /* [annotation][out] */ + _Out_opt_ EXCEPINFO* pExcepInfo, + /* [annotation][out] */ + _Out_opt_ UINT* puArgErr) override; +};
\ No newline at end of file diff --git a/other-licenses/nsis/Contrib/WebBrowser/WebBrowser.sln b/other-licenses/nsis/Contrib/WebBrowser/WebBrowser.sln new file mode 100644 index 0000000000..8e12b98f5e --- /dev/null +++ b/other-licenses/nsis/Contrib/WebBrowser/WebBrowser.sln @@ -0,0 +1,25 @@ +
+Microsoft Visual Studio Solution File, Format Version 12.00
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.28803.452
+MinimumVisualStudioVersion = 10.0.40219.1
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "WebBrowser", "WebBrowser.vcxproj", "{EF903B79-AD97-45E0-BC6E-4FF846D6A2ED}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|x86 = Debug|x86
+ Release|x86 = Release|x86
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {EF903B79-AD97-45E0-BC6E-4FF846D6A2ED}.Debug|x86.ActiveCfg = Debug|Win32
+ {EF903B79-AD97-45E0-BC6E-4FF846D6A2ED}.Debug|x86.Build.0 = Debug|Win32
+ {EF903B79-AD97-45E0-BC6E-4FF846D6A2ED}.Release|x86.ActiveCfg = Release|Win32
+ {EF903B79-AD97-45E0-BC6E-4FF846D6A2ED}.Release|x86.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {3A087FCC-55DC-4C48-8A22-A6FFB3247674}
+ EndGlobalSection
+EndGlobal
diff --git a/other-licenses/nsis/Contrib/WebBrowser/WebBrowser.vcxproj b/other-licenses/nsis/Contrib/WebBrowser/WebBrowser.vcxproj new file mode 100644 index 0000000000..8d13e050b6 --- /dev/null +++ b/other-licenses/nsis/Contrib/WebBrowser/WebBrowser.vcxproj @@ -0,0 +1,160 @@ +<?xml version="1.0" encoding="utf-8"?>
+<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+ <ItemGroup Label="ProjectConfigurations">
+ <ProjectConfiguration Include="Debug|Win32">
+ <Configuration>Debug</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ <ProjectConfiguration Include="Release|Win32">
+ <Configuration>Release</Configuration>
+ <Platform>Win32</Platform>
+ </ProjectConfiguration>
+ </ItemGroup>
+ <PropertyGroup Label="Globals">
+ <SccProjectName />
+ <SccLocalPath />
+ <ProjectGuid>{EF903B79-AD97-45E0-BC6E-4FF846D6A2ED}</ProjectGuid>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <PlatformToolset>v142</PlatformToolset>
+ <UseOfMfc>false</UseOfMfc>
+ <CharacterSet>Unicode</CharacterSet>
+ <SpectreMitigation>false</SpectreMitigation>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
+ <ConfigurationType>DynamicLibrary</ConfigurationType>
+ <PlatformToolset>v142</PlatformToolset>
+ <UseOfMfc>false</UseOfMfc>
+ <CharacterSet>Unicode</CharacterSet>
+ <WholeProgramOptimization>true</WholeProgramOptimization>
+ <SpectreMitigation>false</SpectreMitigation>
+ </PropertyGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
+ <ImportGroup Label="ExtensionSettings">
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="$(VCTargetsPath)Microsoft.Cpp.UpgradeFromVC60.props" />
+ </ImportGroup>
+ <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
+ <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
+ <Import Project="$(VCTargetsPath)Microsoft.Cpp.UpgradeFromVC60.props" />
+ </ImportGroup>
+ <PropertyGroup Label="UserMacros" />
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <OutDir>.\Release\</OutDir>
+ <IntDir>.\Release\</IntDir>
+ <LinkIncremental>false</LinkIncremental>
+ </PropertyGroup>
+ <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <OutDir>.\Debug\</OutDir>
+ <IntDir>.\Debug\</IntDir>
+ <LinkIncremental>true</LinkIncremental>
+ </PropertyGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
+ <ClCompile>
+ <RuntimeLibrary>MultiThreaded</RuntimeLibrary>
+ <StringPooling>true</StringPooling>
+ <Optimization>MinSpace</Optimization>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ <WarningLevel>Level3</WarningLevel>
+ <PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
+ <DebugInformationFormat>None</DebugInformationFormat>
+ <ExceptionHandling>false</ExceptionHandling>
+ <BufferSecurityCheck>false</BufferSecurityCheck>
+ <RuntimeTypeInfo>false</RuntimeTypeInfo>
+ <IntrinsicFunctions>true</IntrinsicFunctions>
+ </ClCompile>
+ <Midl>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <TypeLibraryName>.\Release\WebBrowser.tlb</TypeLibraryName>
+ <MkTypLibCompatible>true</MkTypLibCompatible>
+ <TargetEnvironment>Win32</TargetEnvironment>
+ </Midl>
+ <ResourceCompile>
+ <Culture>0x080a</Culture>
+ <PreprocessorDefinitions>NDEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ResourceCompile>
+ <Bscmake>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ <OutputFile>.\Release\WebBrowser.bsc</OutputFile>
+ </Bscmake>
+ <Link>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ <LinkDLL>true</LinkDLL>
+ <SubSystem>Windows</SubSystem>
+ <OutputFile>.\Release\WebBrowser.dll</OutputFile>
+ <ImportLibrary>.\Release\WebBrowser.lib</ImportLibrary>
+ <AdditionalDependencies>odbc32.lib;odbccp32.lib;urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <GenerateDebugInformation>false</GenerateDebugInformation>
+ <OptimizeReferences>true</OptimizeReferences>
+ <LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
+ <EnableCOMDATFolding>true</EnableCOMDATFolding>
+ <EntryPointSymbol>
+ </EntryPointSymbol>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
+ <ClCompile>
+ <RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
+ <InlineFunctionExpansion>Default</InlineFunctionExpansion>
+ <Optimization>Disabled</Optimization>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ <WarningLevel>Level3</WarningLevel>
+ <DebugInformationFormat>EditAndContinue</DebugInformationFormat>
+ <PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
+ <ExceptionHandling>false</ExceptionHandling>
+ <LanguageStandard>Default</LanguageStandard>
+ </ClCompile>
+ <Midl>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ <TypeLibraryName>.\Debug\WebBrowser.tlb</TypeLibraryName>
+ <MkTypLibCompatible>true</MkTypLibCompatible>
+ <TargetEnvironment>Win32</TargetEnvironment>
+ </Midl>
+ <ResourceCompile>
+ <Culture>0x080a</Culture>
+ <PreprocessorDefinitions>_DEBUG;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+ </ResourceCompile>
+ <Bscmake>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ <OutputFile>.\Debug\WebBrowser.bsc</OutputFile>
+ </Bscmake>
+ <Link>
+ <SuppressStartupBanner>true</SuppressStartupBanner>
+ <LinkDLL>true</LinkDLL>
+ <GenerateDebugInformation>true</GenerateDebugInformation>
+ <SubSystem>Windows</SubSystem>
+ <OutputFile>.\Debug\WebBrowser.dll</OutputFile>
+ <ImportLibrary>.\Debug\WebBrowser.lib</ImportLibrary>
+ <AdditionalDependencies>odbc32.lib;odbccp32.lib;urlmon.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <OptimizeReferences>false</OptimizeReferences>
+ <ImageHasSafeExceptionHandlers>false</ImageHasSafeExceptionHandlers>
+ </Link>
+ </ItemDefinitionGroup>
+ <ItemGroup>
+ <ClCompile Include="CustomFunctions.cpp" />
+ <ClCompile Include="exdll.cpp" />
+ <ClCompile Include="main.cpp" />
+ <ClCompile Include="Timers.cpp" />
+ <ClCompile Include="WebBrowser.cpp" />
+ </ItemGroup>
+ <ItemGroup>
+ <ClInclude Include="exdll.h" />
+ <ClInclude Include="resource.h" />
+ <ClInclude Include="WebBrowser.h" />
+ </ItemGroup>
+ <ItemGroup>
+ <ResourceCompile Include="resource.rc" />
+ </ItemGroup>
+ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
+ <ImportGroup Label="ExtensionTargets">
+ </ImportGroup>
+</Project>
\ No newline at end of file diff --git a/other-licenses/nsis/Contrib/WebBrowser/exdll.cpp b/other-licenses/nsis/Contrib/WebBrowser/exdll.cpp new file mode 100644 index 0000000000..3cad7307ee --- /dev/null +++ b/other-licenses/nsis/Contrib/WebBrowser/exdll.cpp @@ -0,0 +1,30 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0.If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "exdll.h" + +unsigned int g_stringsize; +stack_t** g_stacktop; +int(__stdcall* g_executeCodeSegment)(int pos, HWND hwndProgress); +HWND g_hwndParent; + +int popstring(TCHAR* str) { + stack_t* th; + if (!g_stacktop || !*g_stacktop) return 1; + th = (*g_stacktop); + lstrcpy(str, th->text); + *g_stacktop = th->next; + GlobalFree((HGLOBAL)th); + return 0; +} + +void pushstring(const TCHAR* str) { + stack_t* th; + if (!g_stacktop) return; + th = (stack_t*)GlobalAlloc(GPTR, + sizeof(stack_t) + (g_stringsize * sizeof(TCHAR))); + lstrcpyn(th->text, str, g_stringsize); + th->next = *g_stacktop; + *g_stacktop = th; +} diff --git a/other-licenses/nsis/Contrib/WebBrowser/exdll.h b/other-licenses/nsis/Contrib/WebBrowser/exdll.h new file mode 100644 index 0000000000..1fa5659641 --- /dev/null +++ b/other-licenses/nsis/Contrib/WebBrowser/exdll.h @@ -0,0 +1,76 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0.If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#ifndef _EXDLL_H_ +#define _EXDLL_H_ + +#include <windows.h> +#include <tchar.h> + +#define PLUGINFUNCTION(name) \ + extern "C" void __declspec(dllexport) \ + name(HWND hWndParent, int string_size, TCHAR* variables, \ + stack_t** stacktop, extra_parameters* extra) + +#define EXDLL_INIT() \ + { \ + g_stringsize = string_size; \ + g_stacktop = stacktop; \ + g_executeCodeSegment = extra->ExecuteCodeSegment; \ + g_hwndParent = hWndParent; \ + } + +#define WM_NOTIFY_OUTER_NEXT (WM_USER + 0x8) +#define WM_NOTIFY_CUSTOM_READY (WM_USER + 0xd) + +typedef struct _stack_t { + struct _stack_t* next; + TCHAR text[1]; // the real length of this buffer should be string_size +} stack_t; + +extern unsigned int g_stringsize; +extern stack_t** g_stacktop; +extern int(__stdcall* g_executeCodeSegment)(int pos, HWND hwndProgress); +extern HWND g_hwndParent; +extern HINSTANCE gHInst; + +typedef struct { + int autoclose; + int all_user_var; + int exec_error; + int abort; + int exec_reboot; + int reboot_called; + int XXX_cur_insttype; // deprecated + int XXX_insttype_changed; // deprecated + int silent; + int instdir_error; + int rtl; + int errlvl; +} exec_flags; + +// NSIS Plug-In Callback Messages +enum NSPIM { + NSPIM_UNLOAD, // This is the last message a plugin gets, do final cleanup + NSPIM_GUIUNLOAD, // Called after .onGUIEnd +}; + +typedef UINT_PTR (*NSISPLUGINCALLBACK)(enum NSPIM); + +typedef struct { + exec_flags* exec_flags; + int(__stdcall* ExecuteCodeSegment)(int pos, HWND hwndProgress); + void(__stdcall* validate_filename)(LPWSTR); + int(__stdcall* RegisterPluginCallback)( + HMODULE, + NSISPLUGINCALLBACK); // returns 0 on success, 1 if already + // registered and < 0 on errors +} extra_parameters; + +int popstring(TCHAR* str); +void pushstring(const TCHAR* str); + +UINT_PTR __cdecl NSISPluginCallback(NSPIM msg); + +#endif //_EXDLL_H_ diff --git a/other-licenses/nsis/Contrib/WebBrowser/main.cpp b/other-licenses/nsis/Contrib/WebBrowser/main.cpp new file mode 100644 index 0000000000..e0589531ee --- /dev/null +++ b/other-licenses/nsis/Contrib/WebBrowser/main.cpp @@ -0,0 +1,199 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0.If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include <windows.h> +#include "resource.h" +#include "WebBrowser.h" +#include "exdll.h" + +// These variables are global because they're needed by more than one of +// our plugin methods. The expectation is that these are safe because the +// NSIS framework doesn't really support more than one dialog or thread +// at a time, and that means we don't have to either. + +// Instance handle for this DLL +HINSTANCE gHInst = nullptr; +// Parent window proc which we'll need to override and then restore +WNDPROC gWndProcOld = nullptr; +// Handle to the dialog we'll create +HWND gHwnd = nullptr; +// Set to true when our dialog should be destroyed +bool gDone = false; +// Web browser OLE site +WebBrowser* gBrowser = nullptr; + +// Set web browser control feature flags that are configured on a per-process +// basis, not for individual instances of the control. This mainly means +// disabling things that could turn into security holes. +static void ConfigurePerProcessBrowserFeatures() { + // For most of the features we're configuring, setting them to TRUE means + // we're disabling something, but for a few setting them to FALSE disables the + // thing. We don't necessarily care about *every* feature that's in the + // INTERNETFEATURELIST enum, but it seems safer to set them all anyway, to + // make sure we don't miss anything we *do* care about. + struct Feature { + INTERNETFEATURELIST id; + BOOL value; + } features[] = {{FEATURE_OBJECT_CACHING, TRUE}, + {FEATURE_ZONE_ELEVATION, TRUE}, + {FEATURE_MIME_HANDLING, TRUE}, + {FEATURE_MIME_SNIFFING, FALSE}, + {FEATURE_WINDOW_RESTRICTIONS, TRUE}, + {FEATURE_WEBOC_POPUPMANAGEMENT, TRUE}, + {FEATURE_BEHAVIORS, TRUE}, + {FEATURE_DISABLE_MK_PROTOCOL, TRUE}, + // It isn't possible to set FEATURE_LOCALMACHINE_LOCKDOWN + // using the SET_FEATURE_ON_PROCESS mode; see the MSDN page + // on CoInternetSetFeatureEnabled for the explanation. + //{FEATURE_LOCALMACHINE_LOCKDOWN, TRUE}, + {FEATURE_SECURITYBAND, FALSE}, + {FEATURE_RESTRICT_ACTIVEXINSTALL, TRUE}, + {FEATURE_VALIDATE_NAVIGATE_URL, TRUE}, + {FEATURE_RESTRICT_FILEDOWNLOAD, TRUE}, + {FEATURE_ADDON_MANAGEMENT, TRUE}, + {FEATURE_PROTOCOL_LOCKDOWN, TRUE}, + {FEATURE_HTTP_USERNAME_PASSWORD_DISABLE, TRUE}, + {FEATURE_SAFE_BINDTOOBJECT, TRUE}, + {FEATURE_UNC_SAVEDFILECHECK, TRUE}, + {FEATURE_GET_URL_DOM_FILEPATH_UNENCODED, FALSE}, + {FEATURE_TABBED_BROWSING, FALSE}, + {FEATURE_SSLUX, FALSE}, + {FEATURE_DISABLE_NAVIGATION_SOUNDS, TRUE}, + {FEATURE_DISABLE_LEGACY_COMPRESSION, TRUE}, + {FEATURE_FORCE_ADDR_AND_STATUS, FALSE}, + {FEATURE_XMLHTTP, FALSE}, + {FEATURE_DISABLE_TELNET_PROTOCOL, TRUE}, + {FEATURE_FEEDS, FALSE}, + {FEATURE_BLOCK_INPUT_PROMPTS, TRUE}}; + + for (Feature feature : features) { + CoInternetSetFeatureEnabled(feature.id, SET_FEATURE_ON_PROCESS, + feature.value); + } +} + +BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID) { + if (reason == DLL_PROCESS_ATTACH) { + gHInst = instance; + (void)OleInitialize(nullptr); + ConfigurePerProcessBrowserFeatures(); + } + return TRUE; +} + +UINT_PTR __cdecl NSISPluginCallback(NSPIM msg) { + if (msg == NSPIM_UNLOAD) { + OleUninitialize(); + } + return 0; +} + +BOOL CALLBACK ParentWndProc(HWND hwnd, UINT message, WPARAM wParam, + LPARAM lParam) { + BOOL bRes = + CallWindowProc((WNDPROC)gWndProcOld, hwnd, message, wParam, lParam); + if (!bRes && message == WM_NOTIFY_OUTER_NEXT) { + gDone = true; + PostMessage(gHwnd, WM_CLOSE, 0, 0); + } + return bRes; +} + +BOOL CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { + return FALSE; +} + +void Init(HWND hWndParent, int string_size, TCHAR* variables, + stack_t** stacktop, extra_parameters* extra) { + EXDLL_INIT(); + extra->RegisterPluginCallback(gHInst, NSISPluginCallback); + + HWND hwndChild = GetDlgItem(hWndParent, 1018); + if (!hwndChild) { + return; + } + + HWND hwnd = + CreateDialog(gHInst, MAKEINTRESOURCE(IDD_DIALOG1), hWndParent, DlgProc); + if (!hwnd) { + gDone = true; + } else { + gDone = false; + gWndProcOld = + (WNDPROC)SetWindowLong(hWndParent, DWL_DLGPROC, (LONG)ParentWndProc); + + // Tell NSIS to replace its inner dialog with ours. + SendMessage(hWndParent, WM_NOTIFY_CUSTOM_READY, (WPARAM)hwnd, 0); + + // Initialize the browser control. + if (gBrowser) { + gBrowser->Shutdown(); + gBrowser->Release(); + } + gBrowser = new WebBrowser(hwnd); + + if (!gBrowser || !gBrowser->IsInitialized()) { + return; + } + + gHwnd = hwnd; + + // Move our dialog to match the size of the parent. + RECT r; + GetClientRect(hwndChild, &r); + MoveWindow(hwnd, r.left, r.top, r.right - r.left, r.bottom - r.top, FALSE); + gBrowser->SetRect(r); + } +} + +PLUGINFUNCTION(ShowPage) { + if (!gBrowser) { + Init(hWndParent, string_size, variables, stacktop, extra); + } + + if (!gBrowser->IsInitialized()) { + return; + } + + TCHAR* sUrl = + (TCHAR*)HeapAlloc(GetProcessHeap(), 0, g_stringsize * sizeof(TCHAR)); + popstring(sUrl); + + if (gBrowser) { + gBrowser->Navigate(sUrl); + + ShowWindow(gHwnd, SW_SHOWNA); + UpdateWindow(gHwnd); + + while (!gDone) { + // This explicit wait call is needed rather than just a blocking + // GetMessage because we need this thread to be alertable so that our + // timers can wake it up and run their callbacks. + MsgWaitForMultipleObjectsEx(0, nullptr, 100, QS_ALLINPUT, + MWMO_ALERTABLE | MWMO_INPUTAVAILABLE); + MSG msg; + if (PeekMessage(&msg, nullptr, 0, 0, PM_REMOVE)) { + bool tab = msg.message == WM_KEYDOWN && msg.wParam == VK_TAB; + + if (gBrowser->ActiveObjectTranslateAccelerator(tab, &msg) != S_OK && + !IsDialogMessage(gHwnd, &msg) && + !IsDialogMessage(g_hwndParent, &msg)) { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + } + } + + SetWindowLong(g_hwndParent, DWL_DLGPROC, (LONG)gWndProcOld); + if (gHwnd) { + DestroyWindow(gHwnd); + } + + gBrowser->Shutdown(); + gBrowser->Release(); + gBrowser = nullptr; + } + + HeapFree(GetProcessHeap(), 0, (char*)sUrl); +} diff --git a/other-licenses/nsis/Contrib/WebBrowser/resource.h b/other-licenses/nsis/Contrib/WebBrowser/resource.h new file mode 100644 index 0000000000..6fdee73b5f --- /dev/null +++ b/other-licenses/nsis/Contrib/WebBrowser/resource.h @@ -0,0 +1,5 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0.If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#define IDD_DIALOG1 101 diff --git a/other-licenses/nsis/Contrib/WebBrowser/resource.rc b/other-licenses/nsis/Contrib/WebBrowser/resource.rc new file mode 100644 index 0000000000..0bc4fcc11f --- /dev/null +++ b/other-licenses/nsis/Contrib/WebBrowser/resource.rc @@ -0,0 +1,14 @@ +// This Source Code Form is subject to the terms of the Mozilla Public +// License, v. 2.0.If a copy of the MPL was not distributed with this +// file, You can obtain one at http://mozilla.org/MPL/2.0/. + +#include "resource.h" +#include "afxres.h" + +// The size of this dialog is a placeholder; +// it's going to get resized to fit its parent. +IDD_DIALOG1 DIALOGEX 0, 0, 1, 1 +STYLE DS_CONTROL | WS_CHILD | WS_CLIPSIBLINGS +FONT 8, "MS Shell Dlg" +BEGIN +END diff --git a/other-licenses/nsis/Contrib/liteFirewall/License.txt b/other-licenses/nsis/Contrib/liteFirewall/License.txt new file mode 100644 index 0000000000..5e9673682f --- /dev/null +++ b/other-licenses/nsis/Contrib/liteFirewall/License.txt @@ -0,0 +1,17 @@ +liteFirewall is based on nsisFirewall.
+
+nsisFirewall -- Small NSIS plugin for simple tasks with Windows Firewall
+Web site: http://wiz0u.free.fr/prog/nsisFirewall
+
+Copyright (c) 2007-2009 Olivier Marcoux
+
+This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source distribution.
+
diff --git a/other-licenses/nsis/Contrib/liteFirewall/ReadMe.txt b/other-licenses/nsis/Contrib/liteFirewall/ReadMe.txt new file mode 100644 index 0000000000..42560ae0c0 --- /dev/null +++ b/other-licenses/nsis/Contrib/liteFirewall/ReadMe.txt @@ -0,0 +1,39 @@ +liteFirewall 1.0 -- based on nsisFirewall 1.2
+
+http://liangsun.info/portfolio/nsis-plugin-litefirewall/
+http://nsis.sourceforge.net/LiteFirewall_Plugin
+
+---------------------------------------------------------
+liteFirewall resolved the issue nsisFirewall exists on Vista/Windows 7 platforms.
+It support the profiles (private, domain, public) of firewall rules.
+It support Unicode NSIS, while another firewall plugin SimpleFC not.
+------------------------------------------------------------
+
+Usage
+----------------------------------------------------------
+liteFirewall::AddRule "<application path>" "<rule name>"
+liteFirewall::RemoveRule "<application path>" "<rule name>"
+
+<application path> is the full path to the application you want to be authorized to
+ access the network (or accept incoming connections)
+
+<rule name> is the title that will be given to this exception entry in the firewall
+ control panel list
+
+
+Notes
+-----
+1) Your installer must be run with administrator rights for liteFirewall to work
+2) When compiling with more recent compiler than VC60, you need to choose the compilation
+option to use static MFC library.
+
+Sample scripts
+--------------
+
+ ; Add NOTEPAD to the authorized list
+ liteFirewall::AddRule "$WINDIR\Notepad.exe" "liteFirewall Test"
+ Pop $0
+
+ ; Remove NOTEPAD from the authorized list
+ liteFirewall::RemoveRule "$WINDIR\Notepad.exe" "liteFirewall Test"
+ Pop $0
\ No newline at end of file diff --git a/other-licenses/nsis/Contrib/liteFirewall/Sample.nsi b/other-licenses/nsis/Contrib/liteFirewall/Sample.nsi new file mode 100644 index 0000000000..20b0be47ca --- /dev/null +++ b/other-licenses/nsis/Contrib/liteFirewall/Sample.nsi @@ -0,0 +1,25 @@ +; liteFirewall - Sample script
+
+!ifdef TARGETDIR
+!addplugindir "${TARGETDIR}"
+!else
+!addplugindir "..\bin"
+!endif
+
+Name "Sample liteFirewall"
+OutFile "Sample.exe"
+ShowInstDetails show
+
+Section "Main program"
+ ; Add NOTEPAD to the authorized list
+ liteFirewallW::AddRule "$WINDIR\Notepad.exe" "liteFirewall Test"
+ Pop $0
+ Exec "rundll32.exe shell32.dll,Control_RunDLL firewall.cpl"
+ MessageBox MB_OK "Program added to Firewall exception list.$\r$\n(close the control panel before clicking OK)"
+
+ ; Remove NOTEPAD from the authorized list
+ liteFirewallW::RemoveRule "$WINDIR\Notepad.exe" "liteFirewall Test"
+ Pop $0
+ Exec "rundll32.exe shell32.dll,Control_RunDLL firewall.cpl"
+ MessageBox MB_OK "Program removed to Firewall exception list"
+SectionEnd
diff --git a/other-licenses/nsis/Contrib/liteFirewall/exdll.h b/other-licenses/nsis/Contrib/liteFirewall/exdll.h new file mode 100644 index 0000000000..feca246b5a --- /dev/null +++ b/other-licenses/nsis/Contrib/liteFirewall/exdll.h @@ -0,0 +1,97 @@ +#ifndef _EXDLL_H_
+#define _EXDLL_H_
+
+// only include this file from one place in your DLL.
+// (it is all static, if you use it in two places it will fail)
+
+#define EXDLL_INIT() { \
+ g_stringsize=string_size; \
+ g_stacktop=stacktop; \
+ g_variables=variables; }
+
+// For page showing plug-ins
+#define WM_NOTIFY_OUTER_NEXT (WM_USER+0x8)
+#define WM_NOTIFY_CUSTOM_READY (WM_USER+0xd)
+#define NOTIFY_BYE_BYE 'x'
+
+typedef struct _stack_t {
+ struct _stack_t *next;
+ TCHAR text[1]; // this should be the length of string_size
+} stack_t;
+
+
+static unsigned int g_stringsize;
+static stack_t **g_stacktop;
+static TCHAR *g_variables;
+
+static int __stdcall popstring(TCHAR *str); // 0 on success, 1 on empty stack
+static void __stdcall pushstring(const TCHAR *str);
+
+enum
+{
+INST_0, // $0
+INST_1, // $1
+INST_2, // $2
+INST_3, // $3
+INST_4, // $4
+INST_5, // $5
+INST_6, // $6
+INST_7, // $7
+INST_8, // $8
+INST_9, // $9
+INST_R0, // $R0
+INST_R1, // $R1
+INST_R2, // $R2
+INST_R3, // $R3
+INST_R4, // $R4
+INST_R5, // $R5
+INST_R6, // $R6
+INST_R7, // $R7
+INST_R8, // $R8
+INST_R9, // $R9
+INST_CMDLINE, // $CMDLINE
+INST_INSTDIR, // $INSTDIR
+INST_OUTDIR, // $OUTDIR
+INST_EXEDIR, // $EXEDIR
+INST_LANG, // $LANGUAGE
+__INST_LAST
+};
+
+
+// utility functions (not required but often useful)
+static int __stdcall popstring(TCHAR *str)
+{
+ stack_t *th;
+ if (!g_stacktop || !*g_stacktop) return 1;
+ th=(*g_stacktop);
+ lstrcpy(str,th->text);
+ *g_stacktop = th->next;
+ GlobalFree((HGLOBAL)th);
+ return 0;
+}
+
+static void __stdcall pushstring(const TCHAR *str)
+{
+ stack_t *th;
+ if (!g_stacktop) return;
+ th=(stack_t*)GlobalAlloc(GPTR,sizeof(stack_t)+g_stringsize*sizeof(TCHAR));
+ lstrcpyn(th->text,str,g_stringsize);
+ th->next=*g_stacktop;
+ *g_stacktop=th;
+}
+
+static TCHAR * __stdcall getuservariable(int varnum)
+{
+ if (varnum < 0 || varnum >= __INST_LAST) return NULL;
+ return g_variables+varnum*g_stringsize;
+}
+
+static void __stdcall setuservariable(int varnum, const TCHAR *var)
+{
+ if (var != NULL && varnum >= 0 && varnum < __INST_LAST)
+ lstrcpy(g_variables + varnum*g_stringsize, var);
+}
+
+
+
+#endif//_EXDLL_H_
\ No newline at end of file diff --git a/other-licenses/nsis/Contrib/liteFirewall/liteFirewall.cpp b/other-licenses/nsis/Contrib/liteFirewall/liteFirewall.cpp new file mode 100644 index 0000000000..5319938a04 --- /dev/null +++ b/other-licenses/nsis/Contrib/liteFirewall/liteFirewall.cpp @@ -0,0 +1,408 @@ +/*
+liteFirewall is based on nsisFirewall.
+Modified by Liang Sun on 19, July, 2011
+http://liangsun.info/portfolio/nsis-plugin-litefirewall/
+http://nsis.sourceforge.net/LiteFirewall_Plugin
+http://www.msnlite.org
+*/
+
+/*
+nsisFirewall -- Small NSIS plugin for simple tasks with Windows Firewall
+Web site: http://wiz0u.free.fr/prog/nsisFirewall
+
+Copyright (c) 2007-2009 Olivier Marcoux
+
+This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software.
+
+Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions:
+
+ 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source distribution.
+*/
+#include <windows.h>
+#include <tchar.h>
+#include <shlwapi.h>
+//#include <stdio.h>
+
+#ifdef NSIS
+#include "exdll.h"
+#endif
+
+//#import "libid:58FBCF7C-E7A9-467C-80B3-FC65E8FCCA08"
+#import "netfw.tlb"
+#include <netfw.h>
+using namespace NetFwTypeLib;
+
+
+#pragma comment( lib, "ole32.lib" )
+#pragma comment( lib, "oleaut32.lib" )
+// Forward declarations
+
+#ifdef NSIS
+HINSTANCE g_hInstance;
+#endif
+
+HRESULT WFCOMInitialize(INetFwPolicy2** ppNetFwPolicy2);
+
+HRESULT AddRule(LPCTSTR ExceptionName, LPCTSTR ProcessPath)
+{
+ HRESULT result = CoInitialize(NULL);
+ if (FAILED(result))
+ return result;
+ result = REGDB_E_CLASSNOTREG;
+
+ HRESULT hrComInit = S_OK;
+ HRESULT hr = S_OK;
+
+ INetFwPolicy2 *pNetFwPolicy2 = NULL;
+ INetFwRules *pFwRules = NULL;
+ INetFwRule *pFwRule = NULL;
+/* Start Mozilla modification */
+ INetFwRule *pFwRuleExisting = NULL;
+
+// long CurrentProfilesBitMask = 0;
+/* End Mozilla modification */
+
+ BSTR bstrRuleName = SysAllocString(ExceptionName);
+ BSTR bstrApplicationName = SysAllocString(ProcessPath);
+ BSTR bstrRuleInterfaceType = SysAllocString(L"All");
+
+ // Initialize COM.
+ hrComInit = CoInitializeEx(
+ 0,
+ COINIT_APARTMENTTHREADED
+ );
+
+ // Ignore RPC_E_CHANGED_MODE; this just means that COM has already been
+ // initialized with a different mode. Since we don't care what the mode is,
+ // we'll just use the existing mode.
+ if (hrComInit != RPC_E_CHANGED_MODE)
+ {
+ if (FAILED(hrComInit))
+ {
+ printf("CoInitializeEx failed: 0x%08lx\n", hrComInit);
+ goto Cleanup;
+ }
+ }
+
+ // Retrieve INetFwPolicy2
+ hr = WFCOMInitialize(&pNetFwPolicy2);
+ if (FAILED(hr))
+ {
+ try
+ {
+ INetFwMgrPtr fwMgr(L"HNetCfg.FwMgr");
+ if (fwMgr)
+ {
+ INetFwAuthorizedApplicationPtr app(L"HNetCfg.FwAuthorizedApplication");
+ if (app)
+ {
+ app->ProcessImageFileName = ProcessPath;
+ app->Name = ExceptionName;
+ app->Scope = NetFwTypeLib::NET_FW_SCOPE_ALL;
+ app->IpVersion = NetFwTypeLib::NET_FW_IP_VERSION_ANY;
+ app->Enabled = VARIANT_TRUE;
+ fwMgr->LocalPolicy->CurrentProfile->AuthorizedApplications->Add(app);
+ }
+ }
+ }
+ catch (_com_error& e)
+ {
+ printf("%s", e.Error());
+ }
+ goto Cleanup;
+ }
+
+ // Retrieve INetFwRules
+ hr = pNetFwPolicy2->get_Rules(&pFwRules);
+ if (FAILED(hr))
+ {
+ printf("get_Rules failed: 0x%08lx\n", hr);
+ goto Cleanup;
+ }
+
+/* Start Mozilla modification */
+ // Don't add a new rule if there is an existing rule with the same name.
+ hr = pFwRules->Item(bstrRuleName, &pFwRuleExisting);
+ // Release the INetFwRule object
+ if (pFwRuleExisting != NULL)
+ {
+ pFwRuleExisting->Release();
+ }
+ if (SUCCEEDED(hr))
+ {
+ printf("Firewall profile already exists\n");
+ goto Cleanup;
+ }
+
+ // Retrieve Current Profiles bitmask
+// hr = pNetFwPolicy2->get_CurrentProfileTypes(&CurrentProfilesBitMask);
+// if (FAILED(hr))
+// {
+// printf("get_CurrentProfileTypes failed: 0x%08lx\n", hr);
+// goto Cleanup;
+// }
+
+ // When possible we avoid adding firewall rules to the \ profile.
+ // If Public is currently active and it is not the only active profile, we remove it from the bitmask
+// if ((CurrentProfilesBitMask & NET_FW_PROFILE2_PUBLIC) &&
+// (CurrentProfilesBitMask != NET_FW_PROFILE2_PUBLIC))
+// {
+// CurrentProfilesBitMask ^= NET_FW_PROFILE2_PUBLIC;
+// }
+
+ // Create a new Firewall Rule object.
+ hr = CoCreateInstance(
+ __uuidof(NetFwRule),
+ NULL,
+ CLSCTX_INPROC_SERVER,
+ __uuidof(INetFwRule),
+ (void**)&pFwRule);
+ if (FAILED(hr))
+ {
+ printf("CoCreateInstance for Firewall Rule failed: 0x%08lx\n", hr);
+ goto Cleanup;
+ }
+
+ // Populate the Firewall Rule object
+ pFwRule->put_Name(bstrRuleName);
+ pFwRule->put_Protocol(NetFwTypeLib::NET_FW_IP_PROTOCOL_TCP);
+ pFwRule->put_InterfaceTypes(bstrRuleInterfaceType);
+ pFwRule->put_Profiles(NET_FW_PROFILE2_PRIVATE);
+ pFwRule->put_Action(NET_FW_ACTION_ALLOW);
+ pFwRule->put_Enabled(VARIANT_TRUE);
+
+ pFwRule->put_ApplicationName(bstrApplicationName);
+ // Add the Firewall Rule
+ hr = pFwRules->Add(pFwRule);
+ if (FAILED(hr))
+ {
+ printf("Firewall Rule Add failed: 0x%08lx\n", hr);
+ goto Cleanup;
+ }
+
+ pFwRule->Release();
+/* End Mozilla modification */
+
+ // Create a new Firewall Rule object.
+ hr = CoCreateInstance(
+ __uuidof(NetFwRule),
+ NULL,
+ CLSCTX_INPROC_SERVER,
+ __uuidof(INetFwRule),
+ (void**)&pFwRule);
+ if (FAILED(hr))
+ {
+ printf("CoCreateInstance for Firewall Rule failed: 0x%08lx\n", hr);
+ goto Cleanup;
+ }
+
+ // Populate the Firewall Rule object
+ pFwRule->put_Name(bstrRuleName);
+/* Start Mozilla modification */
+// pFwRule->put_Protocol(NET_FW_IP_PROTOCOL_ANY);
+ pFwRule->put_Protocol(NetFwTypeLib::NET_FW_IP_PROTOCOL_UDP);
+/* End Mozilla modification */
+ pFwRule->put_InterfaceTypes(bstrRuleInterfaceType);
+/* Start Mozilla modification */
+// pFwRule->put_Profiles(CurrentProfilesBitMask);
+ pFwRule->put_Profiles(NET_FW_PROFILE2_PRIVATE);
+/* End Mozilla modification */
+ pFwRule->put_Action(NET_FW_ACTION_ALLOW);
+ pFwRule->put_Enabled(VARIANT_TRUE);
+
+ pFwRule->put_ApplicationName(bstrApplicationName);
+ // Add the Firewall Rule
+ hr = pFwRules->Add(pFwRule);
+ if (FAILED(hr))
+ {
+ printf("Firewall Rule Add failed: 0x%08lx\n", hr);
+ goto Cleanup;
+ }
+
+Cleanup:
+
+ // Free BSTR's
+ SysFreeString(bstrRuleName);
+ SysFreeString(bstrApplicationName);
+ SysFreeString(bstrRuleInterfaceType);
+
+ // Release the INetFwRule object
+ if (pFwRule != NULL)
+ {
+ pFwRule->Release();
+ }
+
+ // Release the INetFwRules object
+ if (pFwRules != NULL)
+ {
+ pFwRules->Release();
+ }
+
+ // Release the INetFwPolicy2 object
+ if (pNetFwPolicy2 != NULL)
+ {
+ pNetFwPolicy2->Release();
+ }
+
+ CoUninitialize();
+ return 0;
+}
+
+HRESULT RemoveRule(LPCTSTR ExceptionName, LPCTSTR ProcessPath)
+{
+ HRESULT result = CoInitialize(NULL);
+ if (FAILED(result))
+ return result;
+ try
+ {
+ INetFwMgrPtr fwMgr(L"HNetCfg.FwMgr");
+ if (fwMgr)
+ {
+ fwMgr->LocalPolicy->CurrentProfile->AuthorizedApplications->Remove(ProcessPath);
+ result = S_OK;
+ }
+ }
+ catch (_com_error& e)
+ {
+ e;
+ }
+ HRESULT hrComInit = S_OK;
+ HRESULT hr = S_OK;
+
+ INetFwPolicy2 *pNetFwPolicy2 = NULL;
+ INetFwRules *pFwRules = NULL;
+
+/* Start Mozilla modification */
+// long CurrentProfilesBitMask = 0;
+/* End Mozilla modification */
+
+ BSTR bstrRuleName = SysAllocString(ExceptionName);
+
+ // Retrieve INetFwPolicy2
+ hr = WFCOMInitialize(&pNetFwPolicy2);
+ if (FAILED(hr))
+ {
+ goto Cleanup;
+ }
+
+ // Retrieve INetFwRules
+ hr = pNetFwPolicy2->get_Rules(&pFwRules);
+ if (FAILED(hr))
+ {
+ printf("get_Rules failed: 0x%08lx\n", hr);
+ goto Cleanup;
+ }
+
+/* Start Mozilla modification */
+ // Retrieve Current Profiles bitmask
+// hr = pNetFwPolicy2->get_CurrentProfileTypes(&CurrentProfilesBitMask);
+// if (FAILED(hr))
+// {
+// printf("get_CurrentProfileTypes failed: 0x%08lx\n", hr);
+// goto Cleanup;
+// }
+
+ // When possible we avoid adding firewall rules to the Public profile.
+ // If Public is currently active and it is not the only active profile, we remove it from the bitmask
+// if ((CurrentProfilesBitMask & NET_FW_PROFILE2_PUBLIC) &&
+// (CurrentProfilesBitMask != NET_FW_PROFILE2_PUBLIC))
+// {
+// CurrentProfilesBitMask ^= NET_FW_PROFILE2_PUBLIC;
+// }
+/* End Mozilla modification */
+
+ // Remove the Firewall Rule
+ hr = pFwRules->Remove(bstrRuleName);
+ if (FAILED(hr))
+ {
+ printf("Firewall Rule Remove failed: 0x%08lx\n", hr);
+ goto Cleanup;
+ }
+
+Cleanup:
+
+ // Free BSTR's
+ SysFreeString(bstrRuleName);
+
+ // Release the INetFwRules object
+ if (pFwRules != NULL)
+ {
+ pFwRules->Release();
+ }
+
+ // Release the INetFwPolicy2 object
+ if (pNetFwPolicy2 != NULL)
+ {
+ pNetFwPolicy2->Release();
+ }
+
+ CoUninitialize();
+ return 0;
+}
+
+
+#ifdef NSIS
+extern "C" void __declspec(dllexport) AddRule(HWND hwndParent, int string_size,
+ TCHAR *variables, stack_t **stacktop)
+{
+ EXDLL_INIT();
+
+ TCHAR ExceptionName[256], ProcessPath[MAX_PATH];
+ popstring(ProcessPath);
+ popstring(ExceptionName);
+ HRESULT result = AddRule(ExceptionName, ProcessPath);
+ // push the result back to NSIS
+ TCHAR intBuffer[16];
+ wsprintf(intBuffer, _T("%d"), result);
+ pushstring(intBuffer);
+}
+
+extern "C" void __declspec(dllexport) RemoveRule(HWND hwndParent, int string_size,
+ TCHAR *variables, stack_t **stacktop)
+{
+ EXDLL_INIT();
+
+ TCHAR ExceptionName[256], ProcessPath[MAX_PATH];
+ popstring(ProcessPath);
+ popstring(ExceptionName);
+ HRESULT result = RemoveRule(ExceptionName, ProcessPath);
+ // push the result back to NSIS
+ TCHAR intBuffer[16];
+ wsprintf(intBuffer, _T("%d"), result);
+ pushstring(intBuffer);
+}
+
+extern "C" BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD, LPVOID)
+{
+ g_hInstance = hInstance;
+ return TRUE;
+}
+#endif
+
+
+// Instantiate INetFwPolicy2
+
+HRESULT WFCOMInitialize(INetFwPolicy2** ppNetFwPolicy2)
+{
+ HRESULT hr = S_OK;
+
+ hr = CoCreateInstance(
+ __uuidof(NetFwPolicy2),
+ NULL,
+ CLSCTX_INPROC_SERVER,
+ __uuidof(INetFwPolicy2),
+ (void**)ppNetFwPolicy2);
+
+ if (FAILED(hr))
+ {
+ printf("CoCreateInstance for INetFwPolicy2 failed: 0x%08lx\n", hr);
+ goto Cleanup;
+ }
+
+Cleanup:
+ return hr;
+}
diff --git a/other-licenses/nsis/Contrib/liteFirewall/liteFirewall.dsp b/other-licenses/nsis/Contrib/liteFirewall/liteFirewall.dsp new file mode 100644 index 0000000000..cae606b4cb --- /dev/null +++ b/other-licenses/nsis/Contrib/liteFirewall/liteFirewall.dsp @@ -0,0 +1,204 @@ +# Microsoft Developer Studio Project File - Name="liteFirewall" - Package Owner=<4>
+# Microsoft Developer Studio Generated Build File, Format Version 6.00
+# ** DO NOT EDIT **
+
+# TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102
+
+CFG=liteFirewall - Win32 Debug
+!MESSAGE This is not a valid makefile. To build this project using NMAKE,
+!MESSAGE use the Export Makefile command and run
+!MESSAGE
+!MESSAGE NMAKE /f "liteFirewall.mak".
+!MESSAGE
+!MESSAGE You can specify a configuration when running NMAKE
+!MESSAGE by defining the macro CFG on the command line. For example:
+!MESSAGE
+!MESSAGE NMAKE /f "liteFirewall.mak" CFG="liteFirewall - Win32 Debug"
+!MESSAGE
+!MESSAGE Possible choices for configuration are:
+!MESSAGE
+!MESSAGE "liteFirewall - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "liteFirewall - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE "liteFirewall - Win32 Release UNICODE" (based on "Win32 (x86) Dynamic-Link Library")
+!MESSAGE
+
+# Begin Project
+# PROP AllowPerConfigDependencies 0
+# PROP Scc_ProjName ""
+# PROP Scc_LocalPath ""
+CPP=cl.exe
+MTL=midl.exe
+RSC=rc.exe
+
+!IF "$(CFG)" == "liteFirewall - Win32 Release"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release"
+# PROP BASE Intermediate_Dir "Release"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release"
+# PROP Intermediate_Dir "Release"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MD /W3 /GX /Zi /O1 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /Zi /O1 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "NSIS" /FR /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386
+# ADD LINK32 kernel32.lib user32.lib shlwapi.lib /nologo /dll /machine:I386 /out:"../bin/liteFirewall.dll" /OPT:REF /OPT:NOWIN98
+# SUBTRACT LINK32 /pdb:none /debug /nodefaultlib
+# Begin Special Build Tool
+IntDir=.\Release
+ProjDir=.
+TargetDir=\Prog\shared\bin
+SOURCE="$(InputPath)"
+PostBuild_Desc=Building Sample Installer...
+PostBuild_Cmds="%ProgramFiles%\NSIS\makensis" /V2 "/DTARGETDIR=$(TargetDir)" "/DINTDIR=$(IntDir)" "$(ProjDir)\Sample.nsi"
+# End Special Build Tool
+
+!ELSEIF "$(CFG)" == "liteFirewall - Win32 Debug"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 1
+# PROP BASE Output_Dir "Debug"
+# PROP BASE Intermediate_Dir "Debug"
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 1
+# PROP Output_Dir "Debug"
+# PROP Intermediate_Dir "Debug"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /YX /FD /GZ /c
+# ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /D "_DEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /D "NSIS" /FR /YX /FD /GZ /c
+# ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "_DEBUG"
+# ADD RSC /l 0x409 /d "_DEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# ADD LINK32 kernel32.lib user32.lib shlwapi.lib /nologo /dll /debug /machine:I386 /pdbtype:sept
+# SUBTRACT LINK32 /nodefaultlib
+# Begin Special Build Tool
+IntDir=.\Debug
+ProjDir=.
+TargetDir=.\Debug
+SOURCE="$(InputPath)"
+PostBuild_Desc=Building Sample Installer...
+PostBuild_Cmds="%ProgramFiles%\NSIS\makensis" /V4 /DTARGETDIR=$(TargetDir) /DINTDIR=$(IntDir) $(ProjDir)\Sample.nsi
+# End Special Build Tool
+
+!ELSEIF "$(CFG)" == "liteFirewall - Win32 Release UNICODE"
+
+# PROP BASE Use_MFC 0
+# PROP BASE Use_Debug_Libraries 0
+# PROP BASE Output_Dir "Release_UNICODE"
+# PROP BASE Intermediate_Dir "Release_UNICODE"
+# PROP BASE Ignore_Export_Lib 0
+# PROP BASE Target_Dir ""
+# PROP Use_MFC 0
+# PROP Use_Debug_Libraries 0
+# PROP Output_Dir "Release_UNICODE"
+# PROP Intermediate_Dir "Release_UNICODE"
+# PROP Ignore_Export_Lib 0
+# PROP Target_Dir ""
+# ADD BASE CPP /nologo /MD /W3 /GX /Zi /O1 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "NSIS" /FR /YX /FD /c
+# ADD CPP /nologo /MD /W3 /GX /Zi /O1 /D "NDEBUG" /D "WIN32" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /D "NSIS" /FR /YX /FD /c
+# ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32
+# ADD BASE RSC /l 0x409 /d "NDEBUG"
+# ADD RSC /l 0x409 /d "NDEBUG"
+BSC32=bscmake.exe
+# ADD BASE BSC32 /nologo
+# ADD BSC32 /nologo
+LINK32=link.exe
+# ADD BASE LINK32 kernel32.lib user32.lib shlwapi.lib /nologo /dll /machine:I386 /out:"../bin/liteFirewall.dll" /OPT:REF /OPT:NOWIN98
+# SUBTRACT BASE LINK32 /pdb:none /debug /nodefaultlib
+# ADD LINK32 kernel32.lib user32.lib shlwapi.lib /nologo /dll /machine:I386 /out:"../bin/liteFirewallW.dll" /OPT:REF /OPT:NOWIN98
+# SUBTRACT LINK32 /pdb:none /debug /nodefaultlib
+# Begin Special Build Tool
+IntDir=.\Release_UNICODE
+ProjDir=.
+TargetDir=\Prog\shared\bin
+SOURCE="$(InputPath)"
+PostBuild_Desc=Building Sample Installer...
+PostBuild_Cmds="%ProgramFiles%\NSIS\makensis" /V2 "/DTARGETDIR=$(TargetDir)" "/DINTDIR=$(IntDir)" "$(ProjDir)\Sample.nsi"
+# End Special Build Tool
+
+!ENDIF
+
+# Begin Target
+
+# Name "liteFirewall - Win32 Release"
+# Name "liteFirewall - Win32 Debug"
+# Name "liteFirewall - Win32 Release UNICODE"
+# Begin Source File
+
+SOURCE=.\exdll.h
+# End Source File
+# Begin Source File
+
+SOURCE=.\License.txt
+# End Source File
+# Begin Source File
+
+SOURCE=.\liteFirewall.cpp
+# End Source File
+# Begin Source File
+
+SOURCE=.\ReadMe.txt
+# End Source File
+# Begin Source File
+
+SOURCE=.\Sample.nsi
+
+!IF "$(CFG)" == "liteFirewall - Win32 Release"
+
+# Begin Custom Build
+ProjDir=.
+InputPath=.\Sample.nsi
+
+"$(ProjDir)\Sample.exe" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ rem Force Post-Build Step
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "liteFirewall - Win32 Debug"
+
+# Begin Custom Build
+ProjDir=.
+InputPath=.\Sample.nsi
+
+"$(ProjDir)\Sample.exe" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ rem Force Post-Build Step
+
+# End Custom Build
+
+!ELSEIF "$(CFG)" == "liteFirewall - Win32 Release UNICODE"
+
+# Begin Custom Build
+ProjDir=.
+InputPath=.\Sample.nsi
+
+"$(ProjDir)\Sample.exe" : $(SOURCE) "$(INTDIR)" "$(OUTDIR)"
+ rem Force Post-Build Step
+
+# End Custom Build
+
+!ENDIF
+
+# End Source File
+# End Target
+# End Project
diff --git a/other-licenses/nsis/Contrib/liteFirewall/liteFirewall.dsw b/other-licenses/nsis/Contrib/liteFirewall/liteFirewall.dsw new file mode 100644 index 0000000000..d4ca962de0 --- /dev/null +++ b/other-licenses/nsis/Contrib/liteFirewall/liteFirewall.dsw @@ -0,0 +1,29 @@ +Microsoft Developer Studio Workspace File, Format Version 6.00
+# WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE!
+
+###############################################################################
+
+Project: "liteFirewall"=.\liteFirewall.dsp - Package Owner=<4>
+
+Package=<5>
+{{{
+}}}
+
+Package=<4>
+{{{
+}}}
+
+###############################################################################
+
+Global:
+
+Package=<5>
+{{{
+}}}
+
+Package=<3>
+{{{
+}}}
+
+###############################################################################
+
diff --git a/other-licenses/nsis/Contrib/liteFirewall/liteFirewall.sln b/other-licenses/nsis/Contrib/liteFirewall/liteFirewall.sln new file mode 100644 index 0000000000..e62a48e344 --- /dev/null +++ b/other-licenses/nsis/Contrib/liteFirewall/liteFirewall.sln @@ -0,0 +1,23 @@ +
+Microsoft Visual Studio Solution File, Format Version 10.00
+# Visual Studio 2008
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "liteFirewall", "liteFirewall.vcproj", "{F7462DF9-A430-4185-9AFC-8FAEA0FB98EA}"
+EndProject
+Global
+ GlobalSection(SolutionConfigurationPlatforms) = preSolution
+ Debug|Win32 = Debug|Win32
+ Release UNICODE|Win32 = Release UNICODE|Win32
+ Release|Win32 = Release|Win32
+ EndGlobalSection
+ GlobalSection(ProjectConfigurationPlatforms) = postSolution
+ {F7462DF9-A430-4185-9AFC-8FAEA0FB98EA}.Debug|Win32.ActiveCfg = Debug|Win32
+ {F7462DF9-A430-4185-9AFC-8FAEA0FB98EA}.Debug|Win32.Build.0 = Debug|Win32
+ {F7462DF9-A430-4185-9AFC-8FAEA0FB98EA}.Release UNICODE|Win32.ActiveCfg = Release UNICODE|Win32
+ {F7462DF9-A430-4185-9AFC-8FAEA0FB98EA}.Release UNICODE|Win32.Build.0 = Release UNICODE|Win32
+ {F7462DF9-A430-4185-9AFC-8FAEA0FB98EA}.Release|Win32.ActiveCfg = Release|Win32
+ {F7462DF9-A430-4185-9AFC-8FAEA0FB98EA}.Release|Win32.Build.0 = Release|Win32
+ EndGlobalSection
+ GlobalSection(SolutionProperties) = preSolution
+ HideSolutionNode = FALSE
+ EndGlobalSection
+EndGlobal
diff --git a/other-licenses/nsis/Contrib/liteFirewall/liteFirewall.vcproj b/other-licenses/nsis/Contrib/liteFirewall/liteFirewall.vcproj new file mode 100644 index 0000000000..e1832b7ce6 --- /dev/null +++ b/other-licenses/nsis/Contrib/liteFirewall/liteFirewall.vcproj @@ -0,0 +1,390 @@ +<?xml version="1.0" encoding="gb2312"?>
+<VisualStudioProject
+ ProjectType="Visual C++"
+ Version="9.00"
+ Name="liteFirewall"
+ ProjectGUID="{F7462DF9-A430-4185-9AFC-8FAEA0FB98EA}"
+ TargetFrameworkVersion="0"
+ >
+ <Platforms>
+ <Platform
+ Name="Win32"
+ />
+ </Platforms>
+ <ToolFiles>
+ </ToolFiles>
+ <Configurations>
+ <Configuration
+ Name="Debug|Win32"
+ OutputDirectory=".\Debug"
+ IntermediateDirectory=".\Debug"
+ ConfigurationType="2"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
+ UseOfMFC="1"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ PreprocessorDefinitions="_DEBUG"
+ MkTypLibCompatible="true"
+ SuppressStartupBanner="true"
+ TargetEnvironment="1"
+ TypeLibraryName=".\Debug/liteFirewall.tlb"
+ HeaderFileName=""
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="0"
+ PreprocessorDefinitions="_DEBUG;WIN32;_WINDOWS;UNICODE;NSIS"
+ MinimalRebuild="true"
+ BasicRuntimeChecks="3"
+ RuntimeLibrary="1"
+ PrecompiledHeaderFile=".\Debug/liteFirewall.pch"
+ AssemblerListingLocation=".\Debug/"
+ ObjectFile=".\Debug/"
+ ProgramDataBaseFileName=".\Debug/"
+ BrowseInformation="1"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="4"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="_DEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="shlwapi.lib"
+ OutputFile=".\Debug/liteFirewall.dll"
+ LinkIncremental="2"
+ SuppressStartupBanner="true"
+ GenerateDebugInformation="true"
+ ProgramDatabaseFile=".\Debug/liteFirewall.pdb"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
+ ImportLibrary=".\Debug/liteFirewall.lib"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ SuppressStartupBanner="true"
+ OutputFile=".\Debug/liteFirewall.bsc"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ Description="Building Sample Installer..."
+ CommandLine=""E:\Program Files (x86)\NSIS\Unicode\makensis" /V4 /DTARGETDIR=$(TargetDir) /DINTDIR=$(IntDir) $(ProjectDir)Sample.nsi"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release UNICODE|Win32"
+ OutputDirectory=".\Release_UNICODE"
+ IntermediateDirectory=".\Release_UNICODE"
+ ConfigurationType="2"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
+ UseOfMFC="1"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="1"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ PreprocessorDefinitions="NDEBUG"
+ MkTypLibCompatible="true"
+ SuppressStartupBanner="true"
+ TargetEnvironment="1"
+ TypeLibraryName=".\Release_UNICODE/liteFirewall.tlb"
+ HeaderFileName=""
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="1"
+ InlineFunctionExpansion="1"
+ PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;UNICODE;NSIS"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ PrecompiledHeaderFile=".\Release_UNICODE/liteFirewall.pch"
+ AssemblerListingLocation=".\Release_UNICODE/"
+ ObjectFile=".\Release_UNICODE/"
+ ProgramDataBaseFileName=".\Release_UNICODE/"
+ BrowseInformation="1"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="shlwapi.lib"
+ OutputFile="../bin/liteFirewallW.dll"
+ LinkIncremental="1"
+ SuppressStartupBanner="true"
+ ProgramDatabaseFile=".\Release_UNICODE/liteFirewallW.pdb"
+ OptimizeReferences="2"
+ OptimizeForWindows98="1"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
+ ImportLibrary=".\Release_UNICODE/liteFirewallW.lib"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ SuppressStartupBanner="true"
+ OutputFile=".\Release_UNICODE/liteFirewall.bsc"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ Description="Building Sample Installer..."
+ CommandLine=""E:\Program Files (x86)\NSIS\Unicode\makensis" /V2 /DTARGETDIR=$(TargetDir) /DINTDIR=$(IntDir) $(ProjectDir)Sample.nsi"
+ />
+ </Configuration>
+ <Configuration
+ Name="Release|Win32"
+ OutputDirectory=".\Release"
+ IntermediateDirectory=".\Release"
+ ConfigurationType="2"
+ InheritedPropertySheets="$(VCInstallDir)VCProjectDefaults\UpgradeFromVC60.vsprops"
+ UseOfMFC="1"
+ ATLMinimizesCRunTimeLibraryUsage="false"
+ CharacterSet="2"
+ >
+ <Tool
+ Name="VCPreBuildEventTool"
+ />
+ <Tool
+ Name="VCCustomBuildTool"
+ />
+ <Tool
+ Name="VCXMLDataGeneratorTool"
+ />
+ <Tool
+ Name="VCWebServiceProxyGeneratorTool"
+ />
+ <Tool
+ Name="VCMIDLTool"
+ PreprocessorDefinitions="NDEBUG"
+ MkTypLibCompatible="true"
+ SuppressStartupBanner="true"
+ TargetEnvironment="1"
+ TypeLibraryName=".\Release/liteFirewall.tlb"
+ HeaderFileName=""
+ />
+ <Tool
+ Name="VCCLCompilerTool"
+ Optimization="1"
+ InlineFunctionExpansion="1"
+ PreprocessorDefinitions="NDEBUG;WIN32;_WINDOWS;NSIS"
+ StringPooling="true"
+ RuntimeLibrary="0"
+ EnableFunctionLevelLinking="true"
+ PrecompiledHeaderFile=".\Release/liteFirewall.pch"
+ AssemblerListingLocation=".\Release/"
+ ObjectFile=".\Release/"
+ ProgramDataBaseFileName=".\Release/"
+ BrowseInformation="1"
+ WarningLevel="3"
+ SuppressStartupBanner="true"
+ DebugInformationFormat="3"
+ />
+ <Tool
+ Name="VCManagedResourceCompilerTool"
+ />
+ <Tool
+ Name="VCResourceCompilerTool"
+ PreprocessorDefinitions="NDEBUG"
+ Culture="1033"
+ />
+ <Tool
+ Name="VCPreLinkEventTool"
+ />
+ <Tool
+ Name="VCLinkerTool"
+ AdditionalDependencies="shlwapi.lib"
+ OutputFile="../bin/liteFirewall.dll"
+ LinkIncremental="1"
+ SuppressStartupBanner="true"
+ ProgramDatabaseFile=".\Release/liteFirewall.pdb"
+ OptimizeReferences="2"
+ OptimizeForWindows98="1"
+ RandomizedBaseAddress="1"
+ DataExecutionPrevention="0"
+ ImportLibrary=".\Release/liteFirewall.lib"
+ TargetMachine="1"
+ />
+ <Tool
+ Name="VCALinkTool"
+ />
+ <Tool
+ Name="VCManifestTool"
+ />
+ <Tool
+ Name="VCXDCMakeTool"
+ />
+ <Tool
+ Name="VCBscMakeTool"
+ SuppressStartupBanner="true"
+ OutputFile=".\Release/liteFirewall.bsc"
+ />
+ <Tool
+ Name="VCFxCopTool"
+ />
+ <Tool
+ Name="VCAppVerifierTool"
+ />
+ <Tool
+ Name="VCPostBuildEventTool"
+ Description="Building Sample Installer..."
+ CommandLine=""E:\Program Files (x86)\NSIS\Unicode\makensis" /V2 /DTARGETDIR=$(TargetDir) /DINTDIR=$(IntDir) $(ProjectDir)Sample.nsi"
+ />
+ </Configuration>
+ </Configurations>
+ <References>
+ </References>
+ <Files>
+ <File
+ RelativePath="exdll.h"
+ >
+ </File>
+ <File
+ RelativePath="License.txt"
+ >
+ </File>
+ <File
+ RelativePath="liteFirewall.cpp"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release UNICODE|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCLCompilerTool"
+ PreprocessorDefinitions=""
+ />
+ </FileConfiguration>
+ </File>
+ <File
+ RelativePath="ReadMe.txt"
+ >
+ </File>
+ <File
+ RelativePath="Sample.nsi"
+ >
+ <FileConfiguration
+ Name="Debug|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ CommandLine="rem Force Post-Build Step
"
+ Outputs="$(ProjectDir)Sample.exe"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release UNICODE|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ CommandLine="rem Force Post-Build Step
"
+ Outputs="$(ProjectDir)Sample.exe"
+ />
+ </FileConfiguration>
+ <FileConfiguration
+ Name="Release|Win32"
+ >
+ <Tool
+ Name="VCCustomBuildTool"
+ CommandLine="rem Force Post-Build Step
"
+ Outputs="$(ProjectDir)Sample.exe"
+ />
+ </FileConfiguration>
+ </File>
+ </Files>
+ <Globals>
+ </Globals>
+</VisualStudioProject>
diff --git a/other-licenses/nsis/Contrib/liteFirewall/netfw.tlb b/other-licenses/nsis/Contrib/liteFirewall/netfw.tlb Binary files differnew file mode 100644 index 0000000000..18ff3481a6 --- /dev/null +++ b/other-licenses/nsis/Contrib/liteFirewall/netfw.tlb diff --git a/other-licenses/nsis/Plugins/AccessControl.dll b/other-licenses/nsis/Plugins/AccessControl.dll Binary files differnew file mode 100644 index 0000000000..d9642d4e86 --- /dev/null +++ b/other-licenses/nsis/Plugins/AccessControl.dll diff --git a/other-licenses/nsis/Plugins/AppAssocReg.dll b/other-licenses/nsis/Plugins/AppAssocReg.dll Binary files differnew file mode 100644 index 0000000000..b0d7f23bc1 --- /dev/null +++ b/other-licenses/nsis/Plugins/AppAssocReg.dll diff --git a/other-licenses/nsis/Plugins/ApplicationID.dll b/other-licenses/nsis/Plugins/ApplicationID.dll Binary files differnew file mode 100644 index 0000000000..78c9995d0b --- /dev/null +++ b/other-licenses/nsis/Plugins/ApplicationID.dll diff --git a/other-licenses/nsis/Plugins/BitsUtils.dll b/other-licenses/nsis/Plugins/BitsUtils.dll Binary files differnew file mode 100644 index 0000000000..0a6ea48569 --- /dev/null +++ b/other-licenses/nsis/Plugins/BitsUtils.dll diff --git a/other-licenses/nsis/Plugins/CertCheck.dll b/other-licenses/nsis/Plugins/CertCheck.dll Binary files differnew file mode 100644 index 0000000000..0f0934140e --- /dev/null +++ b/other-licenses/nsis/Plugins/CertCheck.dll diff --git a/other-licenses/nsis/Plugins/CityHash.dll b/other-licenses/nsis/Plugins/CityHash.dll Binary files differnew file mode 100644 index 0000000000..d357a785ad --- /dev/null +++ b/other-licenses/nsis/Plugins/CityHash.dll diff --git a/other-licenses/nsis/Plugins/ExecInExplorer.dll b/other-licenses/nsis/Plugins/ExecInExplorer.dll Binary files differnew file mode 100644 index 0000000000..81509fdb81 --- /dev/null +++ b/other-licenses/nsis/Plugins/ExecInExplorer.dll diff --git a/other-licenses/nsis/Plugins/HttpPostFile.dll b/other-licenses/nsis/Plugins/HttpPostFile.dll Binary files differnew file mode 100644 index 0000000000..d6897f51e9 --- /dev/null +++ b/other-licenses/nsis/Plugins/HttpPostFile.dll diff --git a/other-licenses/nsis/Plugins/InetBgDL.dll b/other-licenses/nsis/Plugins/InetBgDL.dll Binary files differnew file mode 100644 index 0000000000..e5d705713b --- /dev/null +++ b/other-licenses/nsis/Plugins/InetBgDL.dll diff --git a/other-licenses/nsis/Plugins/InvokeShellVerb.dll b/other-licenses/nsis/Plugins/InvokeShellVerb.dll Binary files differnew file mode 100644 index 0000000000..e1eab1bbca --- /dev/null +++ b/other-licenses/nsis/Plugins/InvokeShellVerb.dll diff --git a/other-licenses/nsis/Plugins/ServicesHelper.dll b/other-licenses/nsis/Plugins/ServicesHelper.dll Binary files differnew file mode 100644 index 0000000000..152bd35772 --- /dev/null +++ b/other-licenses/nsis/Plugins/ServicesHelper.dll diff --git a/other-licenses/nsis/Plugins/ShellLink.dll b/other-licenses/nsis/Plugins/ShellLink.dll Binary files differnew file mode 100644 index 0000000000..386821dd5f --- /dev/null +++ b/other-licenses/nsis/Plugins/ShellLink.dll diff --git a/other-licenses/nsis/Plugins/UAC.dll b/other-licenses/nsis/Plugins/UAC.dll Binary files differnew file mode 100644 index 0000000000..94dc711548 --- /dev/null +++ b/other-licenses/nsis/Plugins/UAC.dll diff --git a/other-licenses/nsis/Plugins/WebBrowser.dll b/other-licenses/nsis/Plugins/WebBrowser.dll Binary files differnew file mode 100644 index 0000000000..7d8a41285b --- /dev/null +++ b/other-licenses/nsis/Plugins/WebBrowser.dll diff --git a/other-licenses/nsis/Plugins/liteFirewallW.dll b/other-licenses/nsis/Plugins/liteFirewallW.dll Binary files differnew file mode 100644 index 0000000000..f82a3ff907 --- /dev/null +++ b/other-licenses/nsis/Plugins/liteFirewallW.dll diff --git a/other-licenses/nsis/Plugins/nsJSON.dll b/other-licenses/nsis/Plugins/nsJSON.dll Binary files differnew file mode 100644 index 0000000000..c7999466b2 --- /dev/null +++ b/other-licenses/nsis/Plugins/nsJSON.dll diff --git a/other-licenses/nsis/nsisui.exe b/other-licenses/nsis/nsisui.exe Binary files differnew file mode 100644 index 0000000000..acac899eb4 --- /dev/null +++ b/other-licenses/nsis/nsisui.exe |