home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Source / exehead / fileform.h < prev    next >
C/C++ Source or Header  |  2004-01-04  |  15KB  |  482 lines

  1. #include "config.h"
  2.  
  3. #ifndef _FILEFORM_H_
  4. #define _FILEFORM_H_
  5.  
  6.  
  7. // * the installer is compsed of the following parts:
  8. // exehead (~34kb)
  9. // firstheader (struct firstheader)
  10. // * headers (compressed together):
  11. //   header (struct header)
  12. //   * nsis blocks (described in header->blocks)
  13. //     pages (struct page)
  14. //     section headers (struct section)
  15. //     entries/instructions (struct entry)
  16. //     strings (null seperated)
  17. //     language tables (language id, dialog offset, language strings)
  18. //     colors (struct color)
  19. // data block (files and uninstaller data)
  20. // * not compressed
  21. // CRC (optional - 4 bytes)
  22. //
  23. // headers + datablock is at least 512 bytes if CRC enabled
  24.  
  25.  
  26. #define MAX_ENTRY_OFFSETS 6
  27.  
  28.  
  29. // if you want people to not be able to decompile your installers as easily,
  30. // reorder the lines following EW_INVALID_OPCODE randomly.
  31.  
  32. enum
  33. {
  34.   EW_INVALID_OPCODE,    // zero is invalid. useful for catching errors. (otherwise an all zeroes instruction
  35.                         // does nothing, which is easily ignored but means something is wrong.
  36.   EW_RET,               // return from function call
  37.   EW_NOP,               // Nop/Jump, do nothing: 1, [?new address+1:advance one]
  38.   EW_ABORT,             // Abort: 1 [status]
  39.   EW_QUIT,              // Quit: 0
  40.   EW_CALL,              // Call: 1 [new address+1]
  41.   EW_UPDATETEXT,        // Update status text: 2 [update str, ui_st_updateflag=?ui_st_updateflag:this]
  42.   EW_SLEEP,             // Sleep: 1 [sleep time in milliseconds]
  43.   EW_BRINGTOFRONT,      // BringToFront: 0
  44.   EW_CHDETAILSVIEW,     // SetDetailsView: 2 [listaction,buttonaction]
  45.   EW_SETFILEATTRIBUTES, // SetFileAttributes: 2 [filename, attributes]
  46.   EW_CREATEDIR,         // Create directory: 2, [path, ?update$INSTDIR]
  47.   EW_IFFILEEXISTS,      // IfFileExists: 3, [file name, jump amount if exists, jump amount if not exists]
  48.   EW_SETFLAG,           // Sets a flag: 2 [id, data]
  49.   EW_IFFLAG,            // If a flag: 4 [on, off, id, new value mask]
  50.   EW_GETFLAG,           // Gets a flag: 2 [output, id]
  51. #ifdef NSIS_SUPPORT_RENAME
  52.   EW_RENAME,            // Rename: 3 [old, new, rebootok]
  53. #endif
  54. #ifdef NSIS_SUPPORT_FNUTIL
  55.   EW_GETFULLPATHNAME,   // GetFullPathName: 2 [output, input, ?lfn:sfn]
  56.   EW_SEARCHPATH,        // SearchPath: 2 [output, filename]
  57.   EW_GETTEMPFILENAME,   // GetTempFileName: 2 [output, base_dir]
  58. #endif
  59. #ifdef NSIS_SUPPORT_FILE
  60.   EW_EXTRACTFILE,       // File to extract: 6 [overwriteflag, output filename, compressed filedata, filedatetimelow, filedatetimehigh, allow ignore]
  61.                         //  overwriteflag: 0x1 = no. 0x0=force, 0x2=try, 0x3=if date is newer
  62. #endif
  63. #ifdef NSIS_SUPPORT_DELETE
  64.   EW_DELETEFILE,        // Delete File: 2, [filename, rebootok]
  65. #endif
  66. #ifdef NSIS_SUPPORT_MESSAGEBOX
  67.   EW_MESSAGEBOX,        // MessageBox: 5,[MB_flags,text,retv1:retv2,moveonretv1:moveonretv2]
  68. #endif
  69. #ifdef NSIS_SUPPORT_RMDIR
  70.   EW_RMDIR,             // RMDir: 2 [path, recursiveflag]
  71. #endif
  72. #ifdef NSIS_SUPPORT_STROPTS
  73.   EW_STRLEN,            // StrLen: 2 [output, input]
  74.   EW_ASSIGNVAR,         // Assign: 4 [variable (0-9) to assign, string to assign, maxlen, startpos]
  75.   EW_STRCMP,            // StrCmp: 4 [str1, str2, jump_if_equal, jump_if_not_equal] (case-insensitive)
  76. #endif
  77. #ifdef NSIS_SUPPORT_ENVIRONMENT
  78.   EW_READENVSTR,        // ReadEnvStr/ExpandEnvStrings: 3 [output, string_with_env_variables, IsRead]
  79. #endif
  80. #ifdef NSIS_SUPPORT_INTOPTS
  81.   EW_INTCMP,            // IntCmp: 6 [val1, val2, equal, val1<val2, val1>val2, unsigned?]
  82.   EW_INTOP,             // IntOp: 4 [output, input1, input2, op] where op: 0=add, 1=sub, 2=mul, 3=div, 4=bor, 5=band, 6=bxor, 7=bnot input1, 8=lnot input1, 9=lor, 10=land], 11=1%2
  83.   EW_INTFMT,            // IntFmt: [output, format, input]
  84. #endif
  85. #ifdef NSIS_SUPPORT_STACK
  86.   EW_PUSHPOP,           // Push/Pop/Exchange: 3 [variable/string, ?pop:push, ?exch]
  87. #endif
  88. #ifdef NSIS_SUPPORT_HWNDS
  89.   EW_FINDWINDOW,        // FindWindow: 5, [outputvar, window class,window name, window_parent, window_after]
  90.   EW_SENDMESSAGE,       // SendMessage: 6 [output, hwnd, msg, wparam, lparam, [wparamstring?1:0 | lparamstring?2:0 | timeout<<2]
  91.   EW_ISWINDOW,          // IsWindow: 3 [hwnd, jump_if_window, jump_if_notwindow]
  92. #endif
  93.  
  94. #ifdef NSIS_CONFIG_ENHANCEDUI_SUPPORT
  95.   EW_GETDLGITEM,        // GetDlgItem:        3: [outputvar, dialog, item_id]
  96.   EW_SETCTLCOLORS,      // SerCtlColors:      3: [hwnd, pointer to struct colors]
  97.   EW_SETBRANDINGIMAGE,  // SetBrandingImage:  1: [Bitmap file]
  98.   EW_CREATEFONT,        // CreateFont:        5: [handle output, face name, height, weight, flags]
  99.   EW_SHOWWINDOW,        // ShowWindow:        2: [hwnd, show state]
  100. #endif
  101.  
  102. #ifdef NSIS_SUPPORT_SHELLEXECUTE
  103.   EW_SHELLEXEC,         // ShellExecute program: 4, [shell action, complete commandline, parameters, showwindow]
  104. #endif
  105.  
  106. #ifdef NSIS_SUPPORT_EXECUTE
  107.   EW_EXECUTE,           // Execute program: 3,[complete command line,waitflag,>=0?output errorcode]
  108. #endif
  109.  
  110. #ifdef NSIS_SUPPORT_GETFILETIME
  111.   EW_GETFILETIME,       // GetFileTime; 3 [file highout lowout]
  112. #endif
  113.  
  114. #ifdef NSIS_SUPPORT_GETDLLVERSION
  115.   EW_GETDLLVERSION,     // GetDLLVersion: 3 [file highout lowout]
  116. #endif
  117.  
  118. #ifdef NSIS_SUPPORT_ACTIVEXREG
  119.   EW_REGISTERDLL,       // Register DLL: 3,[DLL file name, string ptr of function to call, text to put in display (<0 if none/pass parms), 1 - no unload, 0 - unload]
  120. #endif
  121.  
  122. #ifdef NSIS_SUPPORT_CREATESHORTCUT
  123.   EW_CREATESHORTCUT,    // Make Shortcut: 5, [link file, target file, parameters, icon file, iconindex|show mode<<8|hotkey<<16]
  124. #endif
  125.  
  126. #ifdef NSIS_SUPPORT_COPYFILES
  127.   EW_COPYFILES,         // CopyFiles: 3 [source mask, destination location, flags]
  128. #endif
  129.  
  130. #ifdef NSIS_SUPPORT_REBOOT
  131.   EW_REBOOT,            // Reboot: 0
  132. #endif
  133.  
  134. #ifdef NSIS_SUPPORT_INIFILES
  135.   EW_WRITEINI,          // Write INI String: 4, [Section, Name, Value, INI File]
  136.   EW_READINISTR,        // ReadINIStr: 4 [output, section, name, ini_file]
  137. #endif
  138.  
  139. #ifdef NSIS_SUPPORT_REGISTRYFUNCTIONS
  140.   EW_DELREG,            // DeleteRegValue/DeleteRegKey: 4, [root key(int), KeyName, ValueName, delkeyonlyifempty]. ValueName is -1 if delete key
  141.   EW_WRITEREG,          // Write Registry value: 5, [RootKey(int),KeyName,ItemName,ItemData,typelen]
  142.                         //  typelen=1 for str, 2 for dword, 3 for binary, 0 for expanded str
  143.   EW_READREGSTR,        // ReadRegStr: 5 [output, rootkey(int), keyname, itemname, ==1?int::str]
  144.   EW_REGENUM,           // RegEnum: 5 [output, rootkey, keyname, index, ?key:value]
  145. #endif
  146.  
  147. #ifdef NSIS_SUPPORT_FILEFUNCTIONS
  148.   EW_FCLOSE,            // FileClose: 1 [handle]
  149.   EW_FOPEN,             // FileOpen: 4  [name, openmode, createmode, outputhandle]
  150.   EW_FPUTS,             // FileWrite: 3 [handle, string, ?int:string]
  151.   EW_FGETS,             // FileRead: 4  [handle, output, maxlen, ?getchar:gets]
  152.   EW_FSEEK,             // FileSeek: 4  [handle, offset, mode, >=0?positionoutput]
  153. #endif//NSIS_SUPPORT_FILEFUNCTIONS
  154.  
  155. #ifdef NSIS_SUPPORT_FINDFIRST
  156.   EW_FINDCLOSE,         // FindClose: 1 [handle]
  157.   EW_FINDNEXT,          // FindNext: 2  [output, handle]
  158.   EW_FINDFIRST,         // FindFirst: 2 [filespec, output, handleoutput]
  159. #endif
  160.  
  161. #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
  162.   EW_WRITEUNINSTALLER,  // WriteUninstaller: 3 [name, offset, icon_size]
  163. #endif
  164.  
  165. #ifdef NSIS_CONFIG_LOG
  166.   EW_LOG,               // LogText: 2 [0, text] / LogSet: [1, logstate]
  167. #endif
  168.  
  169. #ifdef NSIS_CONFIG_COMPONENTPAGE
  170.   EW_SECTIONSET,        // SectionSetText:    3: [idx, 0, text]
  171.                         // SectionGetText:    3: [idx, 1, output]
  172.                         // SectionSetFlags:   3: [idx, 2, flags]
  173.                         // SectionGetFlags:   3: [idx, 3, output]
  174.   EW_INSTTYPESET,       // InstTypeSetFlags:  3: [idx, 0, flags]
  175.                         // InstTypeGetFlags:  3: [idx, 1, output]
  176. #endif
  177.  
  178.   // instructions not actually implemented in exehead, but used in compiler.
  179.   EW_GETLABELADDR,      // both of these get converted to EW_ASSIGNVAR
  180.   EW_GETFUNCTIONADDR,
  181.  
  182. #ifdef NSIS_LOCKWINDOW_SUPPORT
  183.   EW_LOCKWINDOW,
  184. #endif
  185. };
  186.  
  187. #define FH_FLAGS_MASK 15
  188. #define FH_FLAGS_UNINSTALL 1
  189. #ifdef NSIS_CONFIG_SILENT_SUPPORT
  190. #  define FH_FLAGS_SILENT 2
  191. #endif
  192. #ifdef NSIS_CONFIG_CRC_SUPPORT
  193. #  define FH_FLAGS_NO_CRC 4
  194. #  define FH_FLAGS_FORCE_CRC 8
  195. #endif
  196.  
  197. #define FH_SIG 0xDEADBEEF
  198.  
  199. // neato surprise signature that goes in firstheader. :)
  200. #define FH_INT1 0x6C6C754E
  201. #define FH_INT2 0x74666F73
  202. #define FH_INT3 0x74736E49
  203.  
  204. typedef struct
  205. {
  206.   int flags; // FH_FLAGS_*
  207.   int siginfo;  // FH_SIG
  208.  
  209.   int nsinst[3]; // FH_INT1,FH_INT2,FH_INT3
  210.  
  211.   // these point to the header+sections+entries+stringtable in the datablock
  212.   int length_of_header;
  213.  
  214.   // this specifies the length of all the data (including the firstheader and CRC)
  215.   int length_of_all_following_data;
  216. } firstheader;
  217.  
  218. // Flags for common_header.flags
  219. #define CH_FLAGS_DETAILS_SHOWDETAILS 1
  220. #define CH_FLAGS_DETAILS_NEVERSHOW 2
  221. #define CH_FLAGS_PROGRESS_COLORED 4
  222. #ifdef NSIS_CONFIG_SILENT_SUPPORT
  223.   #define CH_FLAGS_SILENT 8
  224.   #define CH_FLAGS_SILENT_LOG 16
  225. #endif
  226. #define CH_FLAGS_AUTO_CLOSE 32
  227. #define CH_FLAGS_DIR_NO_SHOW 64
  228. #define CH_FLAGS_NO_ROOT_DIR 128
  229. #ifdef NSIS_CONFIG_COMPONENTPAGE
  230.   #define CH_FLAGS_COMP_ONLY_ON_CUSTOM 256
  231.   #define CH_FLAGS_NO_CUSTOM 512
  232. #endif
  233.  
  234. // nsis blocks
  235. struct block_header {
  236.   int offset;
  237.   int num;
  238. };
  239.  
  240. enum {
  241. #ifdef NSIS_CONFIG_VISIBLE_SUPPORT
  242.   NB_PAGES,
  243. #endif
  244.   NB_SECTIONS,
  245.   NB_ENTRIES,
  246.   NB_STRINGS,
  247.   NB_LANGTABLES,
  248.   NB_CTLCOLORS,
  249.   NB_DATA,
  250.  
  251.   BLOCKS_NUM
  252. };
  253.  
  254. // Settings common to both installers and uninstallers
  255. typedef struct
  256. {
  257.   int flags; // CH_FLAGS_*
  258.   struct block_header blocks[BLOCKS_NUM];
  259.  
  260.   // InstallDirRegKey stuff
  261.   int install_reg_rootkey;
  262.   // these two are not processed!
  263.   int install_reg_key_ptr, install_reg_value_ptr;
  264.  
  265. #ifdef NSIS_SUPPORT_BGBG
  266.   int bg_color1, bg_color2, bg_textcolor;
  267. #endif
  268.  
  269. #ifdef NSIS_CONFIG_VISIBLE_SUPPORT
  270.   // installation log window colors
  271.   int lb_bg, lb_fg;
  272. #endif
  273.  
  274.   // langtable size
  275.   int langtable_size;
  276.  
  277. #ifdef NSIS_CONFIG_LICENSEPAGE
  278.   // license background color
  279.   int license_bg;
  280. #endif//NSIS_CONFIG_LICENSEPAGE
  281.  
  282. #ifdef NSIS_SUPPORT_CODECALLBACKS
  283.   // .on* calls
  284.   int code_onInit;
  285.   int code_onInstSuccess;
  286.   int code_onInstFailed;
  287.   int code_onUserAbort;
  288. #ifdef NSIS_CONFIG_ENHANCEDUI_SUPPORT
  289.   int code_onGUIInit;
  290.   int code_onGUIEnd;
  291. #endif
  292.   int code_onVerifyInstDir;
  293. #ifdef NSIS_CONFIG_ENHANCEDUI_SUPPORT
  294.   int code_onMouseOverSection;
  295. #endif
  296. #ifdef NSIS_CONFIG_COMPONENTPAGE
  297.   int code_onSelChange;
  298. #endif//NSIS_CONFIG_COMPONENTPAGE
  299. #endif//NSIS_SUPPORT_CODECALLBACKS
  300.  
  301. #ifdef NSIS_CONFIG_COMPONENTPAGE
  302.   int install_types[NSIS_MAX_INST_TYPES+1];
  303. #endif
  304.  
  305.   int install_directory_ptr; // default install dir.
  306.   int install_directory_auto_append; // auto append part
  307. } header;
  308.  
  309. // used for section->flags
  310. #define SF_SELECTED   1
  311. #define SF_SUBSEC     2
  312. #define SF_SUBSECEND  4
  313. #define SF_BOLD       8
  314. #define SF_RO         16
  315. #define SF_EXPAND     32
  316. #define SF_PSELECTED  64
  317.  
  318. typedef union
  319. {
  320.   struct
  321.   {
  322.     int name_ptr; // '' for non-optional components
  323.     int install_types; // bits set for each of the different install_types, if any.
  324.     int flags; // SF_* - defined above
  325.     int code;
  326.     int code_size;
  327.     int size_kb;
  328.   };
  329.   int fields[1];
  330. } section;
  331.  
  332. #define SECTION_OFFSET(field) (FIELD_OFFSET(section, field)/sizeof(int))
  333.  
  334. typedef struct
  335. {
  336.   int which;
  337.   int offsets[MAX_ENTRY_OFFSETS]; // count and meaning of offsets depend on 'which'
  338. } entry;
  339.  
  340. // page window proc
  341. enum
  342. {
  343. #ifdef NSIS_CONFIG_LICENSEPAGE
  344.   PWP_LICENSE,
  345. #endif
  346. #ifdef NSIS_CONFIG_COMPONENTPAGE
  347.   PWP_SELCOM,
  348. #endif
  349.   PWP_DIR,
  350.   PWP_INSTFILES,
  351. #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
  352.   PWP_UNINST,
  353. #endif
  354.   PWP_COMPLETED,
  355.   PWP_CUSTOM
  356. };
  357.  
  358. // page flags
  359. #define PF_BACK_ENABLE 256
  360. #define PF_NEXT_ENABLE 2
  361. #define PF_CANCEL_ENABLE 4
  362. #define PF_BACK_SHOW 8 // must be SW_SHOWNA, don't change
  363. #define PF_LICENSE_STREAM 16
  364. #define PF_LICENSE_FORCE_SELECTION 32
  365. #define PF_LICENSE_NO_FORCE_SELECTION 64
  366. #define PF_LICENSE_SELECTED 1 // must be 1
  367. #define PF_NO_NEXT_FOCUS 128
  368. #define PF_PAGE_EX 512
  369. #define PF_DIR_NO_BTN_DISABLE 1024
  370.  
  371. typedef struct
  372. {
  373.   int dlg_id; // dialog resource id
  374.   int wndproc_id;
  375.  
  376. #ifdef NSIS_SUPPORT_CODECALLBACKS
  377.   // called before the page is created, or if custom to show the page
  378.   // use Abort to skip the page
  379.   int prefunc;
  380.   // called right before page is shown
  381.   int showfunc;
  382.   // called when the user leaves to the next page
  383.   // use Abort to force the user to stay on this page
  384.   int leavefunc;
  385. #endif //NSIS_SUPPORT_CODECALLBACKS
  386.  
  387.   int flags;
  388.  
  389.   int caption;
  390.   int back;
  391.   int next;
  392.   int clicknext;
  393.   int cancel;
  394.  
  395.   int parms[5];
  396. } page;
  397.  
  398. #define CC_TEXT 1
  399. #define CC_TEXT_SYS 2
  400. #define CC_BK 4
  401. #define CC_BK_SYS 8
  402. #define CC_BKB 16
  403.  
  404. typedef struct {
  405.   COLORREF text;
  406.   COLORREF bkc;
  407.   UINT lbStyle;
  408.   HBRUSH bkb;
  409.   int bkmode;
  410.   int flags;
  411. } ctlcolors;
  412.  
  413. // the following are only used/implemented in exehead, not makensis.
  414.  
  415. int NSISCALL isheader(firstheader *h); // returns 0 on not header, length_of_datablock on success
  416.  
  417. // returns nonzero on error
  418. // returns 0 on success
  419. // on success, m_header will be set to a pointer that should eventually be GlobalFree()'d.
  420. // (or m_uninstheader)
  421. const char * NSISCALL loadHeaders(int cl_flags);
  422.  
  423. int NSISCALL _dodecomp(int offset, HANDLE hFileOut, char *outbuf, int outbuflen);
  424.  
  425. #define GetCompressedDataFromDataBlock(offset, hFileOut) _dodecomp(offset,hFileOut,NULL,0)
  426. #define GetCompressedDataFromDataBlockToMemory(offset, out, out_len) _dodecomp(offset,NULL,out,out_len)
  427.  
  428. extern HANDLE g_db_hFile;
  429. extern int g_quit_flag;
  430.  
  431. BOOL NSISCALL ReadSelfFile(LPVOID lpBuffer, DWORD nNumberOfBytesToRead);
  432. DWORD NSISCALL SetSelfFilePointer(LONG lDistanceToMove);
  433.  
  434. // $0..$9, $INSTDIR, etc are encoded as ASCII bytes starting from this value.
  435. // Added by ramon 3 jun 2003
  436. #define NS_SKIP_CODE 252
  437. #define NS_VAR_CODE 253
  438. #define NS_SHELL_CODE 254
  439. #define NS_LANG_CODE 255
  440. #define NS_CODES_START NS_SKIP_CODE
  441.  
  442. #define CODE_SHORT(x) (WORD)((((WORD)x & 0x7F) | (((WORD)x & 0x3F80) << 1) | 0x8080))
  443. #define MAX_CODED 16383
  444.  
  445. #define NSIS_INSTDIR_INVALID 1
  446. #define NSIS_INSTDIR_NOT_ENOUGH_SPACE 2
  447.  
  448. union exec_flags {
  449.   struct {
  450.     int autoclose;
  451.     int all_user_var;
  452.     int exec_error;
  453.     int abort;
  454. #ifdef NSIS_SUPPORT_REBOOT
  455.     int exec_reboot;
  456. #endif
  457.     int cur_insttype;
  458.     int insttype_changed;
  459. #ifdef NSIS_CONFIG_SILENT_SUPPORT
  460.     int silent;
  461. #endif
  462.     int instdir_error;
  463.     int rtl;
  464.   };
  465.   int flags[1];
  466. };
  467.  
  468. #ifdef EXEHEAD
  469. extern struct block_header g_blocks[BLOCKS_NUM];
  470. extern header *g_header;
  471. extern int g_flags;
  472. extern int g_filehdrsize;
  473. extern int g_is_uninstaller;
  474.  
  475. #define g_pages ((page*)g_blocks[NB_PAGES].offset)
  476. #define g_sections ((section*)g_blocks[NB_SECTIONS].offset)
  477. #define num_sections (g_blocks[NB_SECTIONS].num)
  478. #define g_entries ((entry*)g_blocks[NB_ENTRIES].offset)
  479. #endif
  480.  
  481. #endif //_FILEFORM_H_
  482.