Debian Codegraph @

Source/fileform.cpp

raw
1 /*
2 * fileform.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
17 #include "fileform.h"
18 #include "exehead/config.h"
19 #include "Platform.h"
20
21 #include <cassert>
22
23 // These functions MUST be synchronized with the structures in Source/exehead/fileform.h !
24 // Data must be written in the same order it's defined in Source/exehead/fileform.h
25 // In the future, I hope to get one of the two automatically generated from the other
26
27 void firstheader_writer::write(const firstheader *data)
28 {
29 m_sink->write_int(data->flags);
30 m_sink->write_int(data->siginfo);
31 m_sink->write_int_array(data->nsinst, 3);
32 m_sink->write_int(data->length_of_header);
33 m_sink->write_int(data->length_of_all_following_data);
34 }
35
36 void block_header_writer::write(const block_header *data, const writer_target_info&ti)
37 {
38 if (ti.is_64bit())
39 m_sink->write_int64(data->offset);
40 else
41 m_sink->write_int(data->offset);
42 m_sink->write_int(data->num);
43 }
44
45 void header_writer::write(const header *data, const writer_target_info&ti)
46 {
47 m_sink->write_int(data->flags);
48
49 block_header_writer bw(writer::m_sink);
50 for (int i = 0; i < BLOCKS_NUM; i++)
51 {
52 bw.write(&data->blocks[i], ti);
53 }
54
55 m_sink->write_int(data->install_reg_rootkey);
56 m_sink->write_int(data->install_reg_key_ptr);
57 m_sink->write_int(data->install_reg_value_ptr);
58
59 #ifdef NSIS_SUPPORT_BGBG
60 m_sink->write_int(data->bg_color1);
61 m_sink->write_int(data->bg_color2);
62 m_sink->write_int(data->bg_textcolor);
63 #endif
64
65 #ifdef NSIS_CONFIG_VISIBLE_SUPPORT
66 m_sink->write_int(data->lb_bg);
67 m_sink->write_int(data->lb_fg);
68 #endif
69
70 m_sink->write_int(data->langtable_size);
71
72 #ifdef NSIS_CONFIG_LICENSEPAGE
73 m_sink->write_int(data->license_bg);
74 #endif//NSIS_CONFIG_LICENSEPAGE
75
76 #ifdef NSIS_SUPPORT_CODECALLBACKS
77 m_sink->write_int(data->code_onInit);
78 m_sink->write_int(data->code_onInstSuccess);
79 m_sink->write_int(data->code_onInstFailed);
80 m_sink->write_int(data->code_onUserAbort);
81 #ifdef NSIS_CONFIG_ENHANCEDUI_SUPPORT
82 m_sink->write_int(data->code_onGUIInit);
83 m_sink->write_int(data->code_onGUIEnd);
84 m_sink->write_int(data->code_onMouseOverSection);
85 #endif//NSIS_CONFIG_ENHANCEDUI_SUPPORT
86 m_sink->write_int(data->code_onVerifyInstDir);
87 #ifdef NSIS_CONFIG_COMPONENTPAGE
88 m_sink->write_int(data->code_onSelChange);
89 #endif//NSIS_CONFIG_COMPONENTPAGE
90 #ifdef NSIS_SUPPORT_REBOOT
91 m_sink->write_int(data->code_onRebootFailed);
92 #endif//NSIS_SUPPORT_REBOOT
93 #endif//NSIS_SUPPORT_CODECALLBACKS
94
95 #ifdef NSIS_CONFIG_COMPONENTPAGE
96 m_sink->write_int_array(data->install_types, NSIS_MAX_INST_TYPES + 1);
97 #endif
98
99 m_sink->write_int(data->install_directory_ptr);
100 m_sink->write_int(data->install_directory_auto_append);
101
102 #ifdef NSIS_CONFIG_UNINSTALL_SUPPORT
103 m_sink->write_int(data->str_uninstchild);
104 m_sink->write_int(data->str_uninstcmd);
105 #endif//NSIS_CONFIG_UNINSTALL_SUPPORT
106 #ifdef NSIS_SUPPORT_MOVEONREBOOT
107 m_sink->write_int(data->str_wininit);
108 #endif//NSIS_SUPPORT_MOVEONREBOOT
109 }
110
111 void section_writer::write(const section *data)
112 {
113 m_sink->write_int(data->name_ptr);
114 m_sink->write_int(data->install_types);
115 m_sink->write_int(data->flags);
116 m_sink->write_int(data->code);
117 m_sink->write_int(data->code_size);
118 m_sink->write_int(data->size_kb);
119 m_sink->write_string(data->name, NSIS_MAX_STRLEN);
120 }
121
122 void entry_writer::write(const entry *data)
123 {
124 m_sink->write_int(data->which);
125 m_sink->write_int_array(data->offsets, MAX_ENTRY_OFFSETS);
126 }
127
128 void page_writer::write(const page *data)
129 {
130 m_sink->write_int(data->dlg_id);
131 m_sink->write_int(data->wndproc_id);
132
133 #ifdef NSIS_SUPPORT_CODECALLBACKS
134 m_sink->write_int(data->prefunc);
135 m_sink->write_int(data->showfunc);
136 m_sink->write_int(data->leavefunc);
137 #endif //NSIS_SUPPORT_CODECALLBACKS
138
139 m_sink->write_int(data->flags);
140
141 m_sink->write_int(data->caption);
142 m_sink->write_int(data->back);
143 m_sink->write_int(data->next);
144 m_sink->write_int(data->clicknext);
145 m_sink->write_int(data->cancel);
146
147 m_sink->write_int_array(data->parms, 5);
148 }
149
150 void ctlcolors_writer::write(const ctlcolors *data, const writer_target_info&ti)
151 {
152 assert(CC_FLAGSMASK >> CC_FLAGSSHIFTFORZERO == 0);
153 assert(sizeof(int) == 4 && sizeof(ctlcolors64) > sizeof(ctlcolors32));
154 const ctlcolors *p = data;
155 m_sink->write_int(p->text);
156 m_sink->write_int(p->bkc);
157 if (ti.is_64bit())
158 {
159 assert(!p->bkb);
160 m_sink->write_int64(p->bkb);
161 m_sink->write_int(p->lbStyle);
162 }
163 else
164 {
165 m_sink->write_int(p->lbStyle);
166 m_sink->write_int(p->bkb);
167 }
168 m_sink->write_int(p->bkmode);
169 m_sink->write_int(p->flags);
170 }
171
172 void LOGFONT_writer::write(const LOGFONT *data)
173 {
174 m_sink->write_int(data->lfHeight);
175 m_sink->write_int(data->lfWidth);
176 m_sink->write_int(data->lfEscapement);
177 m_sink->write_int(data->lfOrientation);
178 m_sink->write_int(data->lfWeight);
179 m_sink->write_byte(data->lfItalic);
180 m_sink->write_byte(data->lfUnderline);
181 m_sink->write_byte(data->lfStrikeOut);
182 m_sink->write_byte(data->lfCharSet);
183 m_sink->write_byte(data->lfOutPrecision);
184 m_sink->write_byte(data->lfClipPrecision);
185 m_sink->write_byte(data->lfQuality);
186 m_sink->write_byte(data->lfPitchAndFamily);
187 m_sink->write_string(data->lfFaceName, LF_FACESIZE);
188 }
189
190 void lang_table_writer::write(const unsigned char *data)
191 {
192 assert(sizeof(LANGID) == sizeof(short));
193
194 m_sink->write_short(* (short *) data);
195 data += sizeof(short);
196 m_sink->write_int_array((int *) data, m_lang_strings + 2);
197 }
198
199 void lang_table_writer::write_block(IGrowBuf *buf, writer_sink *sink, const size_t table_size)
200 {
201 unsigned char *tables = (unsigned char *) buf->get();
202 // langtable has LANGID(WORD) + dlgoffset(int) + right-to-left(int) + string pointers.
203 size_t lang_strings = ( table_size - 2 * sizeof(int) - sizeof(LANGID) ) / sizeof(int);
204 size_t l = buf->getlen() / table_size;
205 lang_table_writer writer(sink, lang_strings);
206 for (size_t i = 0; i < l; i++)
207 {
208 writer.write(tables + i * table_size);
209 }
210 }