| 1 |
/* |
| 2 |
* manifest.cpp |
| 3 |
* |
| 4 |
* This file is a part of NSIS. |
| 5 |
* |
| 6 |
* Copyright (C) 1999-2026 Nullsoft and Contributors |
| 7 |
* |
| 8 |
* Licensed under the zlib/libpng license (the "License"); |
| 9 |
* you may not use this file except in compliance with the License. |
| 10 |
* |
| 11 |
* Licence details can be found in the file COPYING. |
| 12 |
* |
| 13 |
* This software is provided 'as-is', without any express or implied |
| 14 |
* warranty. |
| 15 |
* |
| 16 |
* Unicode support by Jim Park -- 08/22/2007 |
| 17 |
*/ |
| 18 |
|
| 19 |
#include "Platform.h" |
| 20 |
#include "manifest.h" |
| 21 |
#include <nsis-version.h> |
| 22 |
#include "tstring.h" |
| 23 |
#include "util.h" // RawTStrToASCII |
| 24 |
#include <vector> |
| 25 |
|
| 26 |
// Jim Park: The manifest must stay UTF-8. Do not convert. |
| 27 |
|
| 28 |
namespace manifest |
| 29 |
{ |
| 30 |
|
| 31 |
using namespace std; |
| 32 |
|
| 33 |
static bool isstrhexchars(const TCHAR*s,UINT cch) |
| 34 |
{ |
| 35 |
while(cch-- && *s) |
| 36 |
{ |
| 37 |
const TCHAR c = *s++, clw = ((TCHAR)c) | 32; |
| 38 |
if (!(c >= '0' && c <= '9') && !(clw >= 'a' && clw <= 'f')) return false; |
| 39 |
} |
| 40 |
return true; |
| 41 |
} |
| 42 |
|
| 43 |
static const struct { const TCHAR *name, *guidstr; } g_soslmap[] = { |
| 44 |
{ _T("WinVista"), _T("{e2011457-1546-43c5-a5fe-008deee3d3f0}") }, //msdn.microsoft.com/en-us/library/aa374191 |
| 45 |
{ _T("Win7"), _T("{35138b9a-5d96-4fbd-8e2d-a2440225f93a}") }, //msdn.microsoft.com/en-us/library/dd371711 |
| 46 |
{ _T("Win8"), _T("{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}") }, //msdn.microsoft.com/en-us/library/hh848036 |
| 47 |
{ _T("Win8.1"), _T("{1f676c76-80e1-4239-95bb-83d0f6d0da78}") }, //msdn.microsoft.com/en-us/library/windows/desktop/dn481241 |
| 48 |
{ _T("Win10"), _T("{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}") } //blogs.msdn.com/b/chuckw/archive/2013/09/10/manifest-madness.aspx |
| 49 |
}; |
| 50 |
|
| 51 |
bool SupportedOSList::addall() |
| 52 |
{ |
| 53 |
m_isdefaultlist = false; |
| 54 |
for (UINT i = 0; i < COUNTOF(g_soslmap); ++i) |
| 55 |
if (!append(g_soslmap[i].name)) |
| 56 |
return false; |
| 57 |
return true; |
| 58 |
} |
| 59 |
|
| 60 |
bool SupportedOSList::append(const TCHAR* osid) |
| 61 |
{ |
| 62 |
const TCHAR *guid = 0; |
| 63 |
if ('{' == *osid) |
| 64 |
{ |
| 65 |
if (38 == _tcsclen(osid) && '}' == osid[37] |
| 66 |
&& '-' == osid[9] && '-' == osid[14] && '-' == osid[19] && '-' == osid[24] |
| 67 |
&& isstrhexchars(osid+1,8) && isstrhexchars(osid+10,4) |
| 68 |
&& isstrhexchars(osid+15,4) && isstrhexchars(osid+20,4) |
| 69 |
&& isstrhexchars(osid+25,12) |
| 70 |
) |
| 71 |
{ |
| 72 |
guid = osid; |
| 73 |
} |
| 74 |
} |
| 75 |
else |
| 76 |
{ |
| 77 |
for (UINT i = 0; i < COUNTOF(g_soslmap); ++i) |
| 78 |
if (!_tcsicmp(osid, g_soslmap[i].name)) |
| 79 |
{ |
| 80 |
guid = g_soslmap[i].guidstr; |
| 81 |
break; |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
if (guid) |
| 86 |
{ |
| 87 |
m_list.add(guid,0); |
| 88 |
m_isdefaultlist = false; |
| 89 |
return true; |
| 90 |
} |
| 91 |
return false; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
static const TCHAR*g_appendpaths[] = { // Basic simulated XPath support |
| 96 |
_T("/"), |
| 97 |
_T("/assembly"), |
| 98 |
_T("/assembly/dependency"), |
| 99 |
_T("/assembly/dependency/dependentAssembly"), |
| 100 |
_T("/assembly/compatibility/application"), |
| 101 |
_T("/assembly/application/windowsSettings") |
| 102 |
}; |
| 103 |
std::vector<string> g_appendstrings[COUNTOF(g_appendpaths)]; |
| 104 |
|
| 105 |
static int isvalidappendpath(const TCHAR*path) |
| 106 |
{ |
| 107 |
for (int i = 0; i < (int) COUNTOF(g_appendpaths); ++i) |
| 108 |
if (!_tcsicmp(path, g_appendpaths[i])) |
| 109 |
return i; |
| 110 |
return -1; |
| 111 |
} |
| 112 |
|
| 113 |
bool addappendstring(const TCHAR*path, const TCHAR*data) |
| 114 |
{ |
| 115 |
int i = isvalidappendpath(path); |
| 116 |
if (i >= 0) |
| 117 |
{ |
| 118 |
string str = ""; |
| 119 |
str += TtoCString(data); |
| 120 |
g_appendstrings[i].push_back(str); |
| 121 |
return true; |
| 122 |
} |
| 123 |
return false; |
| 124 |
} |
| 125 |
|
| 126 |
static bool append(string& xml, const TCHAR*path, const char*prefix = 0, const char*suffix = 0) |
| 127 |
{ |
| 128 |
bool any = false; |
| 129 |
int i = isvalidappendpath(path); |
| 130 |
if (i >= 0) |
| 131 |
for (size_t j = 0; j < g_appendstrings[i].size(); ++j) |
| 132 |
{ |
| 133 |
if (!any && prefix) xml += prefix, any = true; |
| 134 |
xml += g_appendstrings[i][j]; |
| 135 |
} |
| 136 |
if (any && suffix) |
| 137 |
xml += suffix; |
| 138 |
return any; |
| 139 |
} |
| 140 |
|
| 141 |
string generate(comctl comctl_selection, exec_level exec_level_selection, const SPECIFICATION&spec) |
| 142 |
{ |
| 143 |
flags featureflags = spec.Flags; |
| 144 |
dpiaware dpia = spec.DPIA; |
| 145 |
const TCHAR *dpia2 = spec.DPIA2; |
| 146 |
longpathaware lpa = spec.lpaware; |
| 147 |
SupportedOSList& sosl = *spec.pSOSL; |
| 148 |
const TCHAR *mvt = spec.MaxVersionTested; |
| 149 |
|
| 150 |
bool default_or_empty_sosl = sosl.isdefaultlist() || !sosl.getcount(), any; |
| 151 |
if (comctl_selection == comctl_old && exec_level_selection == exec_level_none && default_or_empty_sosl && dpiaware_notset == dpia) |
| 152 |
return ""; |
| 153 |
|
| 154 |
string xmltmp; |
| 155 |
string xml = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\" manifestVersion=\"1.0\"><assemblyIdentity version=\"1.0.0.0\" processorArchitecture=\"*\" name=\"Nullsoft.NSIS.exehead\" type=\"win32\"/><description>Nullsoft Install System "; |
| 156 |
xml += TtoCString(NSIS_VERSION); |
| 157 |
xml += "</description>"; |
| 158 |
|
| 159 |
if (comctl_selection == comctl_xp) |
| 160 |
{ |
| 161 |
addappendstring(_T("/assembly/dependency/dependentAssembly"), _T("<assemblyIdentity type=\"win32\" name=\"Microsoft.Windows.Common-Controls\" version=\"6.0.0.0\" processorArchitecture=\"*\" publicKeyToken=\"6595b64144ccf1df\" language=\"*\" />")); |
| 162 |
} |
| 163 |
xmltmp = "<dependency>"; |
| 164 |
any = append(xmltmp, _T("/assembly/dependency")); |
| 165 |
any |= append(xmltmp, _T("/assembly/dependency/dependentAssembly"), "<dependentAssembly>", "</dependentAssembly>"); |
| 166 |
if (any) |
| 167 |
{ |
| 168 |
xmltmp += "</dependency>"; |
| 169 |
xml += xmltmp; |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
if (exec_level_selection != exec_level_none) |
| 174 |
{ |
| 175 |
string level = ""; |
| 176 |
|
| 177 |
switch (exec_level_selection) |
| 178 |
{ |
| 179 |
case exec_level_none: |
| 180 |
break; |
| 181 |
case exec_level_user: |
| 182 |
level = "asInvoker"; |
| 183 |
break; |
| 184 |
case exec_level_highest: |
| 185 |
level = "highestAvailable"; |
| 186 |
break; |
| 187 |
case exec_level_admin: |
| 188 |
level = "requireAdministrator"; |
| 189 |
break; |
| 190 |
} |
| 191 |
|
| 192 |
xml += "<trustInfo xmlns=\"urn:schemas-microsoft-com:asm.v3\"><security><requestedPrivileges><requestedExecutionLevel level=\""; |
| 193 |
xml += level; |
| 194 |
xml += "\" uiAccess=\"false\"/></requestedPrivileges></security></trustInfo>"; |
| 195 |
} |
| 196 |
else if (sosl.isdefaultlist()) |
| 197 |
{ |
| 198 |
// Don't add supportedOS list for exec_level_none to remain compatible with v2.46 |
| 199 |
sosl.deleteall(); |
| 200 |
} |
| 201 |
|
| 202 |
xmltmp = "", append(xmltmp, _T("/assembly/compatibility/application")); |
| 203 |
int soslcount = sosl.getcount(); |
| 204 |
if (!xmltmp.empty() || soslcount || *mvt) |
| 205 |
{ |
| 206 |
char buf[38+1]; |
| 207 |
xml += "<compatibility xmlns=\"urn:schemas-microsoft-com:compatibility.v1\"><application>"; |
| 208 |
while(soslcount--) |
| 209 |
{ |
| 210 |
xml += "<supportedOS Id=\""; |
| 211 |
xml += (RawTStrToASCII(sosl.get(soslcount), buf, COUNTOF(buf)), buf); |
| 212 |
xml += "\"/>"; |
| 213 |
} |
| 214 |
if (*mvt) |
| 215 |
{ |
| 216 |
xml += "<maxVersionTested Id=\""; |
| 217 |
xml += TtoCString(mvt); |
| 218 |
xml += "\"/>"; |
| 219 |
} |
| 220 |
xml += xmltmp; |
| 221 |
xml += "</application></compatibility>"; |
| 222 |
} |
| 223 |
|
| 224 |
string xml_aws = ""; // <application><windowsSettings> |
| 225 |
if (featureflags & disablewindowfiltering) |
| 226 |
{ |
| 227 |
xml_aws += "<disableWindowFiltering xmlns=\"http://schemas.microsoft.com/SMI/2011/WindowsSettings\">"; |
| 228 |
xml_aws += "true"; |
| 229 |
xml_aws += "</disableWindowFiltering>"; |
| 230 |
} |
| 231 |
if (featureflags & gdiscaling) |
| 232 |
{ |
| 233 |
xml_aws += "<gdiScaling xmlns=\"http://schemas.microsoft.com/SMI/2017/WindowsSettings\">"; |
| 234 |
xml_aws += "true"; |
| 235 |
xml_aws += "</gdiScaling>"; |
| 236 |
} |
| 237 |
if (dpiaware_notset != dpia) |
| 238 |
{ |
| 239 |
xml_aws += "<dpiAware xmlns=\"http://schemas.microsoft.com/SMI/2005/WindowsSettings\">"; |
| 240 |
xml_aws += dpia == dpiaware_explorer ? "Explorer" : dpia >= dpiaware_permonitor ? "True/PM" : dpiaware_false != dpia ? "true" : "false"; |
| 241 |
xml_aws += "</dpiAware>"; |
| 242 |
} |
| 243 |
if (*dpia2) |
| 244 |
{ |
| 245 |
xml_aws += "<dpiAwareness xmlns=\"http://schemas.microsoft.com/SMI/2016/WindowsSettings\">"; |
| 246 |
xml_aws += TtoCString(dpia2); |
| 247 |
xml_aws += "</dpiAwareness>"; |
| 248 |
} |
| 249 |
if (lpaware_notset != lpa) |
| 250 |
{ |
| 251 |
xml_aws += "<longPathAware xmlns=\"http://schemas.microsoft.com/SMI/2016/WindowsSettings\">"; |
| 252 |
xml_aws += lpaware_false != lpa ? "true" : "false"; |
| 253 |
xml_aws += "</longPathAware>"; |
| 254 |
} |
| 255 |
append(xml_aws, _T("/assembly/application/windowsSettings")); |
| 256 |
if (!xml_aws.empty()) |
| 257 |
{ |
| 258 |
xml += "<application xmlns=\"urn:schemas-microsoft-com:asm.v3\"><windowsSettings>"; |
| 259 |
xml += xml_aws; |
| 260 |
xml += "</windowsSettings></application>"; |
| 261 |
} |
| 262 |
|
| 263 |
append(xml, _T("/assembly")); |
| 264 |
xml += "</assembly>"; |
| 265 |
append(xml, _T("/")); |
| 266 |
|
| 267 |
return xml; |
| 268 |
} |
| 269 |
|
| 270 |
}; |