| 1 |
/* |
| 2 |
* build.h |
| 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/10/2007 |
| 17 |
*/ |
| 18 |
|
| 19 |
#ifndef _BUILD_H_ |
| 20 |
#define _BUILD_H_ |
| 21 |
|
| 22 |
#include "strlist.h" |
| 23 |
#include "lineparse.h" |
| 24 |
#include "lang.h" |
| 25 |
#include "ResourceEditor.h" |
| 26 |
#include "ResourceVersionInfo.h" |
| 27 |
#include "uservars.h" |
| 28 |
#include "ShConstants.h" |
| 29 |
#include "mmap.h" |
| 30 |
#include "manifest.h" |
| 31 |
#include "icon.h" |
| 32 |
#include <memory.h> |
| 33 |
#include "utf.h" |
| 34 |
|
| 35 |
#include "exehead/fileform.h" |
| 36 |
#include "exehead/config.h" |
| 37 |
|
| 38 |
#include "tstring.h" |
| 39 |
#include <set> |
| 40 |
#include <map> |
| 41 |
|
| 42 |
#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES |
| 43 |
// Added by Sunil Kamath 11 June 2003 |
| 44 |
# include <time.h> |
| 45 |
# include <sys/stat.h> |
| 46 |
#endif |
| 47 |
|
| 48 |
#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT |
| 49 |
// Changed by Amir Szekely 31st July 2002 |
| 50 |
#include "compressor.h" |
| 51 |
#include "czlib.h" |
| 52 |
#include "cbzip2.h" |
| 53 |
#include "clzma.h" |
| 54 |
#endif //~ NSIS_CONFIG_COMPRESSION_SUPPORT |
| 55 |
|
| 56 |
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT |
| 57 |
# include "Plugins.h" |
| 58 |
#endif //~ NSIS_CONFIG_PLUGIN_SUPPORT |
| 59 |
|
| 60 |
// 1000..4999 Errors |
| 61 |
// 5000..5999 Important generic warnings |
| 62 |
// 6000..6999 Script warnings |
| 63 |
// 7000..7499 Recovered from bad input etc. warnings |
| 64 |
// 7500..7999 Discouraged usage warnings (allocated high to low to reserve as much space as possible for more bad input codes) |
| 65 |
// 8000..8999 Generic warnings |
| 66 |
// 9000..9999 Breaking our and/or MS guidelines warnings |
| 67 |
typedef enum { |
| 68 |
//DE_OOM = 1000?, // Generic out of memory |
| 69 |
//DE_MMAP = 1001?, |
| 70 |
//DE_STUB_SECTION = 1100?, |
| 71 |
//DE_PP_VERBOSE_BAD_LEVEL = 4000?, |
| 72 |
//DW_STALE_TEMP = 5020?, TODO: There is currently no way to disable this |
| 73 |
DW_PACKHDR_RETNONZERO = 5021, |
| 74 |
DW_BADFORMAT_EXTERNAL_FILE = 5040, |
| 75 |
DW_UNSUPP_STORE_FILE_ATT = 5050, |
| 76 |
//DW_CMDLINE_UNSUPP = 5200?, |
| 77 |
//DW_CMDLINE_UNSUPP_WIN = 5201?, |
| 78 |
DW_CMDLINE_UNSUPP_NIX = 5202, |
| 79 |
DW_CMDLINE_BAD_INPUTENC = 5210, // reserved ..5229 |
| 80 |
DW_VAR_IGNORED_UNKNOWN = 6000, // reserved ..6009 |
| 81 |
DW_VAR_NOREF = 6001, |
| 82 |
DW_UNUSED_FUNCTION = 6010, // reserved ..6019 |
| 83 |
DW_UNUSED_GLOBALLABEL = 6011, |
| 84 |
DW_UNUSED_LABEL = 6012, |
| 85 |
DW_UNCODE_WITHOUT_UNEXE = 6020, |
| 86 |
DW_INNERSTRING_MULTISETWASTE = 6029, |
| 87 |
DW_STRING_MULTISETWASTE = DW_INNERSTRING_MULTISETWASTE, |
| 88 |
DW_LANGSTRING_MULTISETWASTE = 6030, // reserved ..6049 |
| 89 |
DW_LANGSTRING_NOTSETINLANG = 6040, |
| 90 |
DW_LANGSTRING_SILENTLICENSE = 6049, |
| 91 |
DW_COMMENT_NEWLINE = 6050, // reserved ..6079 |
| 92 |
DW_PLUGIN_NOUNLOAD_PLACEMENT = 6080, // reserved ..6099 |
| 93 |
DW_PP_PRAGMA_UNKNOWN = 6100, // reserved ..6199 |
| 94 |
DW_PP_PRAGMA_INVALID = 6101, |
| 95 |
DW_PP_DELFILE_DELERROR = 6149, |
| 96 |
DW_PP_DELFILE_NOMATCH = DW_PP_DELFILE_DELERROR, |
| 97 |
DW_PP_VERBOSE_POP_EMPTY_STACK = 6150, |
| 98 |
//DW_PP_VERBOSE_BAD_LEVEL = 6151?, // 2.x failed to issue a warning. 3.x currently aborts with hard error. |
| 99 |
DW_PP_UNDEF_UNDEFINED = 6155, |
| 100 |
DW_INCLUDE_NONFATAL_NOT_FOUND = 7000, // reserved ..7009 |
| 101 |
DW_FILE_NONFATAL_NOT_FOUND = 7010, // reserved ..7019 |
| 102 |
DW_LANGSTRING_OVERLONGLENGTH = 7020, // reserved ..7024 |
| 103 |
DW_BAD_LANGID = 7025, // reserved ..7029 |
| 104 |
DW_NLF_OLDVERSION = 7030, // reserved ..7049 |
| 105 |
DW_NLF_SYSCP = 7031, |
| 106 |
DW_NLF_UNSUPPORTED_CP = 7032, |
| 107 |
DW_NLF_NOT_PREFERRED_ENC = 7033, |
| 108 |
DW_LICENSE_EMPTY = 7050, |
| 109 |
DW_ATTRIBUTE_OVERLONGSTRING = 7060, |
| 110 |
DW_PARSE_BADNUMBER = 7070, |
| 111 |
DW_PARSE_NUMBEROUTOFSPEC = 7071, |
| 112 |
DW_PARSE_LNK_HK = 7075, |
| 113 |
DW_GENERIC_DEPRECATED = 7998, |
| 114 |
DW_PARSE_REGPATHPREFIX = 7999, |
| 115 |
DW_INSTFILESPAGE_NOT_USED = 8000, // reserved ..8019 |
| 116 |
DW_COMP_FINAL = 8020, // reserved ..8059 |
| 117 |
DW_COMP_WHOLE_IGNORE_OFF = 8021, |
| 118 |
DW_COMP_LEVEL_IGNORE = 8025, |
| 119 |
DW_COMP_DICT_IGNORE = 8026, |
| 120 |
DW_COMP_DICTWHOLE = 8030, |
| 121 |
DW_CMDLINE_HIGHPRIORITY = 8499, |
| 122 |
DW_INSECURE_OUTFILENAME = 9000, |
| 123 |
DW_VI_MISSINGSTDKEY = 9100, |
| 124 |
|
| 125 |
DIAGCODE_INTERNAL_HIDEDIAGCODE = 9999, |
| 126 |
DIAGCODE_INTERNAL_FIRST = 1000, DIAGCODE_INTERNAL_LAST = 9999 |
| 127 |
} DIAGCODE; |
| 128 |
|
| 129 |
|
| 130 |
#define PS_OK 0 |
| 131 |
#define PS_EOF 1 |
| 132 |
#define PS_ERROR 50 |
| 133 |
#define PS_WARNING 100 |
| 134 |
|
| 135 |
// token placement |
| 136 |
#define TP_SEC 1 |
| 137 |
#define TP_FUNC 2 |
| 138 |
#define TP_CODE (TP_SEC | TP_FUNC) |
| 139 |
#define TP_GLOBAL 4 |
| 140 |
#define TP_PAGEEX 8 |
| 141 |
#define TP_PG (TP_GLOBAL | TP_PAGEEX) |
| 142 |
#define TP_ALL (TP_CODE | TP_PG) |
| 143 |
|
| 144 |
namespace MakensisAPI { |
| 145 |
extern const TCHAR* SigintEventNameFmt; |
| 146 |
extern const TCHAR* SigintEventNameLegacy; |
| 147 |
|
| 148 |
enum datatransfer_e { |
| 149 |
NOTIFY_SCRIPT, // Compiler -> Host: main nsi file(s) |
| 150 |
NOTIFY_WARNING, |
| 151 |
NOTIFY_ERROR, |
| 152 |
NOTIFY_OUTPUT, // Compiler -> Host: Generated .exe file |
| 153 |
PROMPT_FILEPATH // [0x03006000] Compiler -> Host -> Compiler |
| 154 |
}; |
| 155 |
#ifdef _WIN32 |
| 156 |
enum sndmsg_e { |
| 157 |
QUERYHOST = WM_APP // [0x03000000] QUERYHOST_e in wParam. MUST return 0 for unknown QUERYHOST_e values! |
| 158 |
}; |
| 159 |
#endif |
| 160 |
enum QUERYHOST_e { |
| 161 |
QH_OUTPUTCHARSET = 1, // [0x03000000] return (wincodepage+1) or 0 for default (This encoding is used by stdout, stderr and the notify messages) |
| 162 |
QH_ENABLESTDERR, // [0x03001000] return 1 to output error messages to stderr or 0 to output error messages to stdout |
| 163 |
QH_SUPPORTEDVERSION, // [0x03006000] The host must return new highest makensis compiler version it supports |
| 164 |
}; |
| 165 |
typedef struct { |
| 166 |
unsigned char Platform; // Bitness OR'ed with sizeof(TCHAR) of the compiler |
| 167 |
unsigned char Reserved; |
| 168 |
TCHAR Path[1]; |
| 169 |
} PROMPT_FILEPATH_DATA; |
| 170 |
} |
| 171 |
|
| 172 |
#define PAGE_CUSTOM 0 |
| 173 |
#define PAGE_LICENSE 1 |
| 174 |
#define PAGE_COMPONENTS 2 |
| 175 |
#define PAGE_DIRECTORY 3 |
| 176 |
#define PAGE_INSTFILES 4 |
| 177 |
#define PAGE_UNINSTCONFIRM 5 |
| 178 |
#define PAGE_COMPLETED 6 |
| 179 |
|
| 180 |
#define FLAG_OFFSET(flag) (FIELD_OFFSET(exec_flags_t, flag)/sizeof(int)) |
| 181 |
|
| 182 |
class DiagState { |
| 183 |
template<class C, class K, class V> void insert_or_assign(C&c, const K&k, V val) |
| 184 |
{ |
| 185 |
typename C::value_type item(k, val); |
| 186 |
std::pair<NSIS_CXX_TYPENAME C::iterator, bool> ret = c.insert(item); |
| 187 |
if (!ret.second) ret.first->second = val; |
| 188 |
} |
| 189 |
template<class C, class K> typename STL::mapped_type<C>::type get_paired_value(const C&c, const K&k, typename STL::mapped_type<C>::type defval) const |
| 190 |
{ |
| 191 |
typename C::const_iterator it = c.find(k); |
| 192 |
return c.end() == it ? defval : it->second; |
| 193 |
} |
| 194 |
template<class T> int get_code_state(T t, int def) const { return get_paired_value(m_Warnings, static_cast<unsigned short>(t), def); } |
| 195 |
public: |
| 196 |
typedef enum { wunspecified = -1, wdisabled = 0, wwarning, wenabled, werror } WARNSTATE; |
| 197 |
DiagState() : m_pStack(0), m_FallbackState(get_default_state()) { assert(DIAGCODE_INTERNAL_LAST <= 0xffff); } |
| 198 |
~DiagState() { delete m_pStack; } |
| 199 |
static WARNSTATE get_default_state(DIAGCODE n = (DIAGCODE) 0) { return wenabled; } // All warnings currently default to enabled |
| 200 |
void def(DIAGCODE n) { insert_or_assign(m_Warnings, static_cast<unsigned short>(n), get_default_state(n)); } |
| 201 |
void enable(DIAGCODE n) { insert_or_assign(m_Warnings, static_cast<unsigned short>(n), wenabled); } |
| 202 |
void disable(DIAGCODE n) { insert_or_assign(m_Warnings, static_cast<unsigned short>(n), wdisabled); } |
| 203 |
void warning(DIAGCODE n) { insert_or_assign(m_Warnings, static_cast<unsigned short>(n), wwarning); } // Always !warning |
| 204 |
void error(DIAGCODE n) { insert_or_assign(m_Warnings, static_cast<unsigned short>(n), werror); } // Always !error |
| 205 |
bool is_disabled(DIAGCODE n) const { return get_code_state(n, m_FallbackState) == wdisabled; } |
| 206 |
bool is_error(DIAGCODE n) const { int s = get_code_state(n, m_FallbackState); return s == werror; } |
| 207 |
void push(); |
| 208 |
bool pop(); |
| 209 |
void set_all(WARNSTATE wm) { m_Warnings.clear(); m_FallbackState = wm; } |
| 210 |
void set_warning_as_error() { set_all(werror); } |
| 211 |
static bool is_valid_code(unsigned int n) { return n >= DIAGCODE_INTERNAL_FIRST && n <= DIAGCODE_INTERNAL_LAST; } |
| 212 |
protected: |
| 213 |
DiagState *m_pStack; |
| 214 |
signed char m_FallbackState; // A fallback state so we don't have to fill the m_Warnings map with values for codes that are not explicitly set by the user |
| 215 |
std::map<unsigned short, signed char> m_Warnings; |
| 216 |
}; |
| 217 |
|
| 218 |
class CEXEBuild { |
| 219 |
public: |
| 220 |
CEXEBuild(signed char pponly, bool warnaserror); |
| 221 |
void initialize(const TCHAR *makensis_path); |
| 222 |
~CEXEBuild(); |
| 223 |
|
| 224 |
enum { |
| 225 |
MAX_LINELENGTH = 16384, // NSI/NSH line limit, in TCHARs (including \0) |
| 226 |
MAX_MACRORECURSION = 50 |
| 227 |
}; |
| 228 |
static const TCHAR* get_commandlinecode_filename() { return _T("<command line>"); } |
| 229 |
static const TCHAR* get_memorycode_filename() { return _T("<memory>"); } |
| 230 |
|
| 231 |
void warning(DIAGCODE dc, const TCHAR *s, ...); // to add a warning to the compiler's warning list. |
| 232 |
void warning_fl(DIAGCODE dc, const TCHAR *s, ...); // warning with file name and line number |
| 233 |
void ERROR_MSG(const TCHAR *s, ...) const; |
| 234 |
void SCRIPT_MSG(const TCHAR *s, ...) const; |
| 235 |
void INFO_MSG(const TCHAR *s, ...) const; |
| 236 |
|
| 237 |
typedef enum { |
| 238 |
TARGETFIRST, |
| 239 |
TARGET_X86ANSI = TARGETFIRST, |
| 240 |
TARGET_X86UNICODE, |
| 241 |
TARGET_AMD64, // Always Unicode |
| 242 |
TARGET_ARM64, // Always Unicode |
| 243 |
TARGET_UNKNOWN, |
| 244 |
TARGETCOUNT = (TARGET_UNKNOWN-TARGETFIRST) |
| 245 |
} TARGETTYPE; |
| 246 |
TARGETTYPE m_target_type; |
| 247 |
TARGETTYPE get_target_type(const TCHAR*s) const; |
| 248 |
bool m_previous_x86_unicode; |
| 249 |
const TCHAR* get_target_suffix(CEXEBuild::TARGETTYPE tt, const TCHAR*defval = _T("?")) const; |
| 250 |
const TCHAR* get_target_suffix() const { return get_target_suffix(m_target_type); } |
| 251 |
static bool is_targettype_64bit(TARGETTYPE tt) { return TARGET_AMD64 == tt || TARGET_ARM64 == tt; } |
| 252 |
bool is_target_64bit() const { return is_targettype_64bit(m_target_type); } |
| 253 |
void print_bad_targettype_parameter(const TCHAR*cmdname, const TCHAR*prefix = _T("")) const; |
| 254 |
unsigned int get_header_size() const { return (unsigned int)sizeof(header) + (is_target_64bit() ? (4 * BLOCKS_NUM) : 0); } |
| 255 |
|
| 256 |
void set_default_output_filename(const tstring& filename); |
| 257 |
const TCHAR* get_output_filename() const { return build_output_filename; } |
| 258 |
|
| 259 |
// process a script (you can process as many scripts as you want, |
| 260 |
// it is as if they are concatenated) |
| 261 |
int process_script(NIStream&Strm, const TCHAR *filename); |
| 262 |
enum PROCESSLINEFLAGS { PLF_MACRO = 0x01, PLF_VIRTUALFILE = 0x02 }; |
| 263 |
int process_oneline(const TCHAR *line, const TCHAR *curfilename, int lineptr, unsigned int plflags); |
| 264 |
|
| 265 |
// you only get to call write_output once, so use it wisely. |
| 266 |
int write_output(void); |
| 267 |
|
| 268 |
void print_help(const TCHAR *commandname=NULL); |
| 269 |
bool print_cmdhelp(const TCHAR *commandname, bool cmdhelp=false); |
| 270 |
|
| 271 |
DefineList definedlist; // List of identifiers marked as "defined" like |
| 272 |
// C++ macro definitions such as _UNICODE. |
| 273 |
void define(const TCHAR *p, const TCHAR *v=_T("")); // to add a defined thing. |
| 274 |
signed char preprocessonly; // > 0 = safe, < 0 = unsafe |
| 275 |
|
| 276 |
int get_verbosity() const; |
| 277 |
void set_verbosity(int lvl); |
| 278 |
bool display_errors; |
| 279 |
bool display_script; |
| 280 |
bool display_warnings; |
| 281 |
bool display_info; |
| 282 |
|
| 283 |
int linecnt; |
| 284 |
const TCHAR *curfilename; |
| 285 |
NStreamLineReader* curlinereader; |
| 286 |
|
| 287 |
HWND notify_hwnd; |
| 288 |
void notify(MakensisAPI::datatransfer_e code, const TCHAR *data) const; |
| 289 |
#ifdef _WIN32 |
| 290 |
typedef bool (CALLBACK*HOSTAPIREQUESTDATAPROC)(void*cookie, HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam); |
| 291 |
#else |
| 292 |
typedef bool (*HOSTAPIREQUESTDATAPROC)(void*cookie); |
| 293 |
#endif |
| 294 |
bool hostapi_request_data(MakensisAPI::datatransfer_e operation, UINT minver, HOSTAPIREQUESTDATAPROC proc, void*cookie, const void* input, size_t inputsize) const; |
| 295 |
bool prompt_for_output_path(TCHAR*path, UINT pathcap) const; |
| 296 |
|
| 297 |
private: |
| 298 |
int check_write_output_errors() const; |
| 299 |
int prepare_uninstaller(); |
| 300 |
int pack_exe_header(); |
| 301 |
|
| 302 |
int set_compressor(const tstring& compressor, const bool solid); |
| 303 |
int load_stub(); |
| 304 |
int update_exehead(const tstring& file, size_t *size=NULL); |
| 305 |
void update_exehead(const unsigned char *new_exehead, size_t new_size); |
| 306 |
|
| 307 |
// tokens.cpp |
| 308 |
bool is_ppbranch_token(const TCHAR *s); |
| 309 |
bool is_pp_token(int tkid); |
| 310 |
bool is_unsafe_pp_token(int tkid); |
| 311 |
int get_commandtoken(const TCHAR *s, int *np, int *op, int *pos); |
| 312 |
const TCHAR* get_commandtoken_name(int tok); |
| 313 |
|
| 314 |
/** |
| 315 |
* Returns the current "state" by looking at whether it is in a |
| 316 |
* section/function/pagex or global. |
| 317 |
* @return TP_FUNC, TP_SEC, TP_PAGEEX, TP_GLOBAL. |
| 318 |
*/ |
| 319 |
int GetCurrentTokenPlace(); |
| 320 |
int IsTokenPlacedRight(int pos, const TCHAR *tok); |
| 321 |
|
| 322 |
// script.cpp |
| 323 |
#ifdef NSIS_SUPPORT_STANDARD_PREDEFINES |
| 324 |
// Added by Sunil Kamath 11 June 2003 |
| 325 |
TCHAR* set_file_predefine(const TCHAR *); |
| 326 |
void restore_file_predefine(TCHAR *); |
| 327 |
TCHAR* set_timestamp_predefine(const TCHAR *); |
| 328 |
void restore_timestamp_predefine(TCHAR *); |
| 329 |
TCHAR* set_line_predefine(int, BOOL); |
| 330 |
void restore_line_predefine(TCHAR *); |
| 331 |
void set_date_time_predefines(); |
| 332 |
void del_date_time_predefines(); |
| 333 |
#endif |
| 334 |
int parseScript(); |
| 335 |
int includeScript(const TCHAR *f, NStreamEncoding&enc); |
| 336 |
int includeScriptLines(const TCHAR *start, const TCHAR *end, const TCHAR *name); |
| 337 |
TCHAR* GetMacro(const TCHAR *macroname, TCHAR**macroend = 0); |
| 338 |
TCHAR* GetMacro(size_t idx); |
| 339 |
bool MacroExists(const TCHAR *macroname) { return !!GetMacro(macroname); } |
| 340 |
LANGID ParseLangIdParameter(const LineParser&line, int token); |
| 341 |
int LoadLicenseFile(const TCHAR *file, TCHAR** pdata, const TCHAR *cmdname, WORD AnsiCP); |
| 342 |
#ifdef NSIS_FIX_DEFINES_IN_STRINGS |
| 343 |
void ps_addtoline(const TCHAR *str, GrowBuf &linedata, StringList &hist, bool bIgnoreDefines = false); |
| 344 |
#else |
| 345 |
void ps_addtoline(const TCHAR *str, GrowBuf &linedata, StringList &hist); |
| 346 |
#endif |
| 347 |
int doParse(int verbosity, const TCHAR *fmt, ...); |
| 348 |
int doParse(const TCHAR *str); |
| 349 |
int doCommand(int which_token, LineParser &line); |
| 350 |
TCHAR m_templinebuf[MAX_LINELENGTH]; // Buffer used by parseScript() & doCommand(), not recursion safe! |
| 351 |
int add_flag_instruction_entry(int which_token, int opcode, LineParser &line, int offset, int data = 0); |
| 352 |
|
| 353 |
int do_add_file(const TCHAR *lgss, int attrib, int recurse, int *total_files, const TCHAR |
| 354 |
*name_override=0, int generatecode=1, int *data_handle=0, |
| 355 |
const std::set<tstring>& excluded=std::set<tstring>(), |
| 356 |
const tstring& basedir=tstring(_T("")), bool dir_created=false); |
| 357 |
int add_file(const tstring& dir, const tstring& file, int attrib, const TCHAR |
| 358 |
*name_override, int generatecode, int *data_handle); |
| 359 |
int do_add_file_create_dir(const tstring& local_dir, const tstring& dir, int attrib=0); |
| 360 |
|
| 361 |
GrowBuf m_linebuild; // used for concatenating lines |
| 362 |
|
| 363 |
// used by doParse to do preprocessing |
| 364 |
struct ifblock |
| 365 |
{ |
| 366 |
int hasexeced; |
| 367 |
int elseused; |
| 368 |
int ignore; |
| 369 |
int inherited_ignore; |
| 370 |
} *cur_ifblock; |
| 371 |
|
| 372 |
TinyGrowBuf build_preprocessor_data; |
| 373 |
|
| 374 |
void start_ifblock(); |
| 375 |
void end_ifblock(); |
| 376 |
int num_ifblock(); |
| 377 |
|
| 378 |
int last_line_had_slash; |
| 379 |
bool inside_comment; |
| 380 |
int multiple_entries_instruction; // 1 (true) or 0 (false) |
| 381 |
|
| 382 |
int pp_boolifyexpression(LineParser&line, int &result, bool allow_logicneg = true, int ignore_last_tokens = 0); |
| 383 |
int pp_assert(LineParser&line); |
| 384 |
int pp_macro(LineParser&line); |
| 385 |
int pp_macroundef(LineParser&line); |
| 386 |
int pp_insertmacro(LineParser&line); |
| 387 |
int pp_tempfile(LineParser&line); |
| 388 |
int pp_delfile(LineParser&line); |
| 389 |
int pp_appendfile(LineParser&line); |
| 390 |
int pp_appendmemfile(LineParser&line); |
| 391 |
int pp_getversionhelper(const TCHAR *cmdname, const TCHAR *path, const TCHAR *basesymname, DWORD high, DWORD low, DWORD flags); |
| 392 |
int pp_getversion(int which_token, LineParser&line); |
| 393 |
int pp_searchreplacestring(LineParser&line); |
| 394 |
int pp_searchparsestring(LineParser&line); |
| 395 |
DefineList *searchParseString(const TCHAR *source_string, LineParser&line, int parmOffs, bool ignCase, bool noErrors, UINT*failParam = 0); |
| 396 |
int pp_verbose(LineParser&line); |
| 397 |
int pp_define(LineParser&line); |
| 398 |
int pp_undef(LineParser&line); |
| 399 |
int pp_packhdr(LineParser&line); |
| 400 |
int pp_finalize(int which_token, LineParser&line); |
| 401 |
int pp_execute(int which_token, LineParser&line); |
| 402 |
int pp_addincludedir(LineParser&line); |
| 403 |
int pp_include(LineParser&line); |
| 404 |
int pp_cd(LineParser&line); |
| 405 |
int pp_pragma(LineParser&line); |
| 406 |
|
| 407 |
// build.cpp functions used mostly by script.cpp |
| 408 |
int set_target_architecture_data(); |
| 409 |
int change_target_architecture(TARGETTYPE tt); |
| 410 |
void set_code_type_predefines(const TCHAR *value = NULL); |
| 411 |
int getcurdbsize(); |
| 412 |
int add_section(const TCHAR *secname, const TCHAR *defname, int expand=0); |
| 413 |
int section_end(); |
| 414 |
int add_function(const TCHAR *funname); |
| 415 |
int function_end(); |
| 416 |
void section_add_size_kb(int kb); |
| 417 |
int section_add_flags(int flags); |
| 418 |
int section_add_install_type(int inst_type); |
| 419 |
int add_page(int type); |
| 420 |
int page_end(); |
| 421 |
int add_label(const TCHAR *name); |
| 422 |
int add_entry(const entry *ent); |
| 423 |
int add_entry_direct(int which, int o0=0, int o1=0, int o2=0, int o3=0, int o4=0, int o5=0); |
| 424 |
int add_db_data(IMMap *map); // returns offset |
| 425 |
int add_db_data(const char *data, int length); // returns offset |
| 426 |
int add_db_data(const char *data, size_t length) { assert(length <= 0x7FFFFFFF); return add_db_data(data, (int)length); } |
| 427 |
int add_data(const char *data, int length, IGrowBuf *dblock); // returns offset |
| 428 |
int add_string(const TCHAR *string, int process=1, UINT codepage=-2); // returns offset (in string table) |
| 429 |
int add_asciistring(const TCHAR *string, int process=1); // For hardcoded 7bit/ASCII strings |
| 430 |
int add_intstring(const int i); // returns offset in stringblock |
| 431 |
|
| 432 |
int preprocess_string(TCHAR *out, const TCHAR *in, WORD codepage=CP_ACP); |
| 433 |
void init_shellconstantvalues(); |
| 434 |
int parse_pragma(LineParser &line); |
| 435 |
|
| 436 |
#ifdef NSIS_CONFIG_PLUGIN_SUPPORT |
| 437 |
int add_plugins_dir_initializer(void); |
| 438 |
int initialize_default_plugins(bool newtargetarc = false); |
| 439 |
Plugins m_plugins[TARGETCOUNT], *m_pPlugins; |
| 440 |
bool plugin_used; |
| 441 |
bool uninst_plugin_used; |
| 442 |
int build_plugin_unload; // TOK_SETPLUGINUNLOAD |
| 443 |
#endif //NSIS_CONFIG_PLUGIN_SUPPORT |
| 444 |
|
| 445 |
// build.cpp functions used mostly within build.cpp |
| 446 |
int datablock_optimize(int start_offset, int first_int); |
| 447 |
bool datablock_finddata(IMMap&mmap, int mmstart, int size, int*ofs); |
| 448 |
void printline(int l); |
| 449 |
int process_jump(LineParser &line, int wt, int *offs); |
| 450 |
|
| 451 |
int AddVersionInfo(); |
| 452 |
int ProcessPages(); |
| 453 |
void PrepareInstTypes(); |
| 454 |
void AddStandardStrings(); |
| 455 |
void PrepareHeaders(IGrowBuf *hdrbuf); |
| 456 |
int SetVarsSection(); |
| 457 |
int SetManifest(); |
| 458 |
int UpdatePEHeader(); |
| 459 |
|
| 460 |
int resolve_jump_int(const TCHAR *fn, int *a, int offs, int start, int end); |
| 461 |
int resolve_call_int(const TCHAR *fn, const TCHAR *str, int fptr, int *ofs); |
| 462 |
int resolve_instruction(const TCHAR *fn, const TCHAR *str, entry *w, int offs, int start, int end); |
| 463 |
|
| 464 |
int resolve_coderefs(const TCHAR *str); |
| 465 |
int uninstall_generate(); |
| 466 |
|
| 467 |
void print_warnings(); |
| 468 |
void warninghelper(DIAGCODE dc, bool fl, const TCHAR *fmt, va_list args); |
| 469 |
DiagState diagstate; |
| 470 |
bool changed_target; |
| 471 |
|
| 472 |
/** Are we defining an uninstall version of the code? |
| 473 |
* @param un Use like a boolean to define whether in uninstall mode. |
| 474 |
*/ |
| 475 |
void set_uninstall_mode(int un); |
| 476 |
|
| 477 |
// lang.cpp functions and variables |
| 478 |
void InitLangTables(); |
| 479 |
|
| 480 |
/** |
| 481 |
* This function gets a LanguageTable structure for the specified language |
| 482 |
* via LANGID. If create == true, it will create a new LanguageTable if |
| 483 |
* the appropriate one cannot be found. If lang is LANG_NEUTRAL (0), then |
| 484 |
* it will get the LanguageTable of the last used language or more |
| 485 |
* correctly, the last Language ID that generated a valid return value |
| 486 |
* (not NULL). |
| 487 |
* |
| 488 |
* @param lang [in/out] Language ID reference. If LANG_NEUTRAL, it gets |
| 489 |
* set to thelast used language ID. |
| 490 |
* @param create Create a new LanguageTable? Default = true. |
| 491 |
* @return Appropriate LanguagTable* if exists, otherwise NULL. |
| 492 |
*/ |
| 493 |
LanguageTable *GetLangTable(LANGID &lang, bool create = true); |
| 494 |
|
| 495 |
/** |
| 496 |
* Get the language name as a TCHAR* and the code page value via an |
| 497 |
* out parameter. It will look for a LanguageTable to get the values. |
| 498 |
* If not found, then it will set the codepage to English for ANSI |
| 499 |
* or Unicode for Unicode version of NSIS. The language name is looked |
| 500 |
* up via the LanguageTable if it exists, otherwise, it returns "???" except |
| 501 |
* a hardcoded check for 1033 (english). It really should fall back to |
| 502 |
* calling GetLocaleInfo() with the LANGID to get the string. |
| 503 |
* |
| 504 |
* This function is not thread-safe! For a thread-safe version, the |
| 505 |
* parameter must include the buffer to write to. |
| 506 |
* |
| 507 |
* @param lang The language ID |
| 508 |
* @param codepage [out] The code page referred to by the language ID. |
| 509 |
* @return The language string in English. |
| 510 |
*/ |
| 511 |
const TCHAR *GetLangNameAndCP(LANGID lang, unsigned int *codepage = NULL); |
| 512 |
const TCHAR *GetLangNameAndCPForVersionResource(LANGID &lang, unsigned int *codepage = NULL, bool deflangfallback = true); |
| 513 |
|
| 514 |
int DefineLangString(const TCHAR *name, int process=-1); |
| 515 |
int DefineInnerLangString(int id, int process=-1); |
| 516 |
|
| 517 |
/** |
| 518 |
* A LangString is a string variable that varies in value depending on what |
| 519 |
* language is being used. This function sets the string value for the |
| 520 |
* variable 'name' for a given language ID. |
| 521 |
* |
| 522 |
* @return If the language id, the variable name or string is invalid, it will |
| 523 |
* return a PS_ERROR. If this function call is overwriting a set user string, |
| 524 |
* this will return a PS_WARNING. |
| 525 |
*/ |
| 526 |
int SetLangString(const TCHAR *name, LANGID lang, const TCHAR *str, BOOL LicenseData); |
| 527 |
int SetLangString(const TCHAR *name, LANGID lang, const TCHAR *str); |
| 528 |
|
| 529 |
/** |
| 530 |
* Sets the user string to the specific NLF_STRINGS id. |
| 531 |
* |
| 532 |
* @return If the id is invalid or the string is not valid, it will return |
| 533 |
* a PS_ERROR. If this function call is overwriting a set user string, |
| 534 |
* this will return a PS_WARNING. |
| 535 |
*/ |
| 536 |
int SetInnerString(int id, const TCHAR *str); |
| 537 |
|
| 538 |
int GenerateLangTable(LanguageTable *lt, int num_lang_tables); |
| 539 |
int GenerateLangTables(); |
| 540 |
void FillLanguageTable(LanguageTable *table); |
| 541 |
int HasUserDefined(int id) { |
| 542 |
const TCHAR *us = UserInnerStrings.get(id); |
| 543 |
return us && *us; |
| 544 |
}; |
| 545 |
|
| 546 |
LanguageTable *LoadLangFile(TCHAR *filename); |
| 547 |
void DeleteLangTable(LanguageTable *table); |
| 548 |
|
| 549 |
NLFRef NLFRefs[NLF_STRINGS]; |
| 550 |
bool keep_ref; |
| 551 |
StringsArray UserInnerStrings; |
| 552 |
bool defcodepage_set; |
| 553 |
GrowBuf lang_tables; |
| 554 |
LANGID last_used_lang; |
| 555 |
LangStringList build_langstrings; |
| 556 |
|
| 557 |
int build_langstring_num, ubuild_langstring_num; |
| 558 |
TCHAR build_font[1024]; |
| 559 |
int build_font_size; |
| 560 |
|
| 561 |
unsigned int uDefCodePage; |
| 562 |
|
| 563 |
// pages stuff |
| 564 |
int license_res_id; |
| 565 |
page *cur_page; // Current page we are defining, NULL if not. |
| 566 |
int cur_page_type; |
| 567 |
int enable_last_page_cancel, uenable_last_page_cancel; |
| 568 |
|
| 569 |
int disable_window_icon; |
| 570 |
|
| 571 |
// User variables stuff |
| 572 |
int GetUnsafeUserVarIndex(LineParser &line, int token); |
| 573 |
int GetUserVarIndex(LineParser &line, int token); |
| 574 |
// Added by ramon 3 jun 2003 |
| 575 |
UserVarsStringList m_UserVarNames; |
| 576 |
int m_iBaseVarsNum; |
| 577 |
int DeclaredUserVar(const TCHAR *VarName); |
| 578 |
void VerifyDeclaredUserVarRefs(UserVarsStringList *pVarsStringList); |
| 579 |
bool IsIntOrUserVar(const LineParser &line, int token) const; |
| 580 |
static bool IsVarPrefix(const TCHAR*s) { return *s++ == _T('$') && *s > ' '; } |
| 581 |
|
| 582 |
ConstantsStringList m_ShellConstants; |
| 583 |
|
| 584 |
// a whole bunch O data. |
| 585 |
|
| 586 |
tstring stubs_dir; |
| 587 |
tstring stub_filename; |
| 588 |
|
| 589 |
#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT |
| 590 |
ICompressor *compressor; |
| 591 |
CZlib zlib_compressor; |
| 592 |
CBzip2 bzip2_compressor; |
| 593 |
CLZMA lzma_compressor; |
| 594 |
#endif |
| 595 |
bool build_compressor_set; |
| 596 |
bool build_compressor_final; |
| 597 |
bool build_compress_whole; |
| 598 |
int build_compress; |
| 599 |
int build_compress_level; |
| 600 |
int build_compress_dict_size; |
| 601 |
|
| 602 |
bool no_space_texts; |
| 603 |
bool build_unicode;// generate installer with unicode exehead? |
| 604 |
bool build_lockedunicodetarget; |
| 605 |
class writer_target_info mk_writer_target_info(); |
| 606 |
|
| 607 |
bool has_called_write_output; |
| 608 |
|
| 609 |
struct postbuild_cmd |
| 610 |
{ |
| 611 |
struct postbuild_cmd*next; |
| 612 |
int cmpop, cmpval; |
| 613 |
TCHAR cmd[1]; |
| 614 |
void delete_all(); |
| 615 |
static postbuild_cmd* make(const TCHAR *cmdstr, int cmpop, int cmpval); |
| 616 |
} *postbuild_cmds, *postubuild_cmds; |
| 617 |
int run_postbuild_cmds(const postbuild_cmd *cmds, const TCHAR *templatearg_pc1, const TCHAR* commandname); |
| 618 |
int check_external_exitcode(int exitcode, int op, int val); |
| 619 |
|
| 620 |
TCHAR build_packname[1024], build_packcmd[1024]; |
| 621 |
int build_overwrite, build_last_overwrite, build_crcchk, |
| 622 |
build_datesave, build_optimize_datablock, |
| 623 |
build_allowskipfiles; // Added by ramon 23 May 2003 |
| 624 |
|
| 625 |
header build_header, build_uninst, *cur_header; |
| 626 |
int uninstall_mode; // Are we in uninstall mode? Acts like a bool. |
| 627 |
UINT32 uninstall_size,uninstall_size_full; |
| 628 |
int uninstaller_writes_used; |
| 629 |
|
| 630 |
TCHAR build_output_filename[1024]; |
| 631 |
|
| 632 |
int build_include_depth; |
| 633 |
|
| 634 |
// Added by ramon 6 jun 2003 |
| 635 |
#ifdef NSIS_SUPPORT_VERSION_INFO |
| 636 |
CResourceVersionInfo rVersionInfo; |
| 637 |
unsigned int version_fixedflags; |
| 638 |
#endif |
| 639 |
|
| 640 |
int sectiongroup_open_cnt; |
| 641 |
FastStringList m_warnings; |
| 642 |
const TCHAR* m_currentmacroname; |
| 643 |
GrowBuf m_macros; |
| 644 |
|
| 645 |
UINT64 db_opt_save, db_opt_save_u, db_full_size, db_full_size_u; |
| 646 |
int db_comp_save, db_comp_save_u; |
| 647 |
|
| 648 |
FastStringList include_dirs; |
| 649 |
|
| 650 |
StringList ns_func; // function namespace |
| 651 |
StringList ns_label; // label namespace |
| 652 |
|
| 653 |
int build_cursection_isfunc; // Are we in the middle of func definition? |
| 654 |
section *build_cursection; // The section we are defining, NULL if not in section. |
| 655 |
// This could be a function or a section. |
| 656 |
|
| 657 |
// The ubuild prefixed objects / variables are for the uninstall versions |
| 658 |
// of the code. The cur prefix objects are what the current objects that |
| 659 |
// need to be referenced should be. What is pointed to by the cur* objects |
| 660 |
// are determined by whether or not we are in uninstall mode or not. |
| 661 |
TinyGrowBuf build_sections, ubuild_sections, *cur_sections; |
| 662 |
GrowBuf build_entries,ubuild_entries, *cur_entries; |
| 663 |
GrowBuf build_instruction_entry_map,ubuild_instruction_entry_map, *cur_instruction_entry_map; |
| 664 |
TinyGrowBuf build_functions, ubuild_functions, *cur_functions; |
| 665 |
TinyGrowBuf build_labels, ubuild_labels, *cur_labels; |
| 666 |
ExeHeadStringList build_strlist, ubuild_strlist, *cur_strlist; |
| 667 |
GrowBuf build_langtables, ubuild_langtables, *cur_langtables; |
| 668 |
TinyGrowBuf build_pages, ubuild_pages, *cur_pages; |
| 669 |
TinyGrowBuf build_ctlcolors, ubuild_ctlcolors, *cur_ctlcolors; |
| 670 |
|
| 671 |
// don't forget to update the cache after updating the datablock |
| 672 |
// see datablock_optimize for an example |
| 673 |
MMapBuf build_datablock, ubuild_datablock; |
| 674 |
TinyGrowBuf build_datablock_cache, ubuild_datablock_cache; |
| 675 |
IGrowBuf *cur_datablock, *cur_datablock_cache; |
| 676 |
struct cached_db_size |
| 677 |
{ |
| 678 |
int first_int; // size | (compressed ? 0x80000000 : 0) |
| 679 |
int start_offset; |
| 680 |
}; |
| 681 |
|
| 682 |
int build_filebuflen; |
| 683 |
|
| 684 |
TinyGrowBuf verbose_stack; |
| 685 |
|
| 686 |
unsigned char *m_exehead; |
| 687 |
size_t m_exehead_size; |
| 688 |
size_t m_exehead_original_size; |
| 689 |
|
| 690 |
bool branding_image_found; |
| 691 |
WORD branding_image_id; |
| 692 |
|
| 693 |
IconGroup installer_icon; |
| 694 |
IconGroup uninstaller_icon; |
| 695 |
size_t m_unicon_size; |
| 696 |
|
| 697 |
#ifdef NSIS_SUPPORT_BGBG |
| 698 |
LOGFONT bg_font; |
| 699 |
LOGFONT bg_default_font; |
| 700 |
#endif |
| 701 |
|
| 702 |
#ifdef NSIS_CONFIG_COMPRESSION_SUPPORT |
| 703 |
int deflateToFile(FILE *fp, char *buf, int len); // len==0 to flush |
| 704 |
#endif |
| 705 |
|
| 706 |
WORD PEDllCharacteristics, PESubsysVerMaj, PESubsysVerMin; |
| 707 |
unsigned int manifest_flags; |
| 708 |
manifest::comctl manifest_comctl; |
| 709 |
manifest::exec_level manifest_exec_level; |
| 710 |
manifest::dpiaware manifest_dpiaware; |
| 711 |
tstring manifest_dpiawareness; |
| 712 |
manifest::longpathaware manifest_lpaware; |
| 713 |
manifest::SupportedOSList manifest_sosl; |
| 714 |
tstring manifest_maxversiontested; |
| 715 |
|
| 716 |
CResourceEditor *res_editor; |
| 717 |
void init_res_editor(); |
| 718 |
void close_res_editor(); |
| 719 |
}; |
| 720 |
|
| 721 |
#endif //_BUILD_H_ |