diff options
author | Nicolas Pennequin <nicolas.pennequin@free.fr> | 2008-07-11 16:51:25 +0000 |
---|---|---|
committer | Nicolas Pennequin <nicolas.pennequin@free.fr> | 2008-07-11 16:51:25 +0000 |
commit | ca5bb76d2b8f65aa97e50b633f828c1deb241526 (patch) | |
tree | 453a1b2de3a0dc0d0b2f7080d10d033bf8fbcdf1 /utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.cpp | |
parent | 141774be48940d56e3ad4dbf451d245b61d4f8b2 (diff) | |
download | rockbox-ca5bb76d2b8f65aa97e50b633f828c1deb241526.tar.gz rockbox-ca5bb76d2b8f65aa97e50b633f828c1deb241526.zip |
Delete the svn:executable property and set svn:eol-style to native for all those text files.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@18012 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.cpp')
-rw-r--r--[-rwxr-xr-x] | utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.cpp | 2994 |
1 files changed, 1497 insertions, 1497 deletions
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.cpp b/utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.cpp index 5e4d3010bf..d1e4c59e5a 100755..100644 --- a/utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.cpp +++ b/utils/zenutils/libraries/pelib-0.9/pelib/ResourceDirectory.cpp | |||
@@ -1,1497 +1,1497 @@ | |||
1 | /* | 1 | /* |
2 | * ResourceDirectory.h - Part of the PeLib library. | 2 | * ResourceDirectory.h - Part of the PeLib library. |
3 | * | 3 | * |
4 | * Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) | 4 | * Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com) |
5 | * All rights reserved. | 5 | * All rights reserved. |
6 | * | 6 | * |
7 | * This software is licensed under the zlib/libpng License. | 7 | * This software is licensed under the zlib/libpng License. |
8 | * For more details see http://www.opensource.org/licenses/zlib-license.php | 8 | * For more details see http://www.opensource.org/licenses/zlib-license.php |
9 | * or the license information file (license.htm) in the root directory | 9 | * or the license information file (license.htm) in the root directory |
10 | * of PeLib. | 10 | * of PeLib. |
11 | */ | 11 | */ |
12 | 12 | ||
13 | #include "ResourceDirectory.h" | 13 | #include "ResourceDirectory.h" |
14 | 14 | ||
15 | namespace PeLib | 15 | namespace PeLib |
16 | { | 16 | { |
17 | // -------------------------------------------------- ResourceChild ------------------------------------------- | 17 | // -------------------------------------------------- ResourceChild ------------------------------------------- |
18 | 18 | ||
19 | ResourceChild::ResourceChild() | 19 | ResourceChild::ResourceChild() |
20 | { | 20 | { |
21 | } | 21 | } |
22 | 22 | ||
23 | ResourceChild::ResourceChild(const ResourceChild& rhs) | 23 | ResourceChild::ResourceChild(const ResourceChild& rhs) |
24 | { | 24 | { |
25 | if (dynamic_cast<ResourceNode*>(rhs.child)) | 25 | if (dynamic_cast<ResourceNode*>(rhs.child)) |
26 | { | 26 | { |
27 | ResourceNode* oldnode = static_cast<ResourceNode*>(rhs.child); | 27 | ResourceNode* oldnode = static_cast<ResourceNode*>(rhs.child); |
28 | 28 | ||
29 | entry = rhs.entry; | 29 | entry = rhs.entry; |
30 | 30 | ||
31 | child = new ResourceNode; | 31 | child = new ResourceNode; |
32 | child->uiElementRva = rhs.child->getElementRva(); | 32 | child->uiElementRva = rhs.child->getElementRva(); |
33 | static_cast<ResourceNode*>(child)->header = oldnode->header; | 33 | static_cast<ResourceNode*>(child)->header = oldnode->header; |
34 | static_cast<ResourceNode*>(child)->children = oldnode->children; | 34 | static_cast<ResourceNode*>(child)->children = oldnode->children; |
35 | } | 35 | } |
36 | else | 36 | else |
37 | { | 37 | { |
38 | ResourceLeaf* oldnode = static_cast<ResourceLeaf*>(rhs.child); | 38 | ResourceLeaf* oldnode = static_cast<ResourceLeaf*>(rhs.child); |
39 | 39 | ||
40 | child = new ResourceLeaf; | 40 | child = new ResourceLeaf; |
41 | child->uiElementRva = rhs.child->getElementRva(); | 41 | child->uiElementRva = rhs.child->getElementRva(); |
42 | static_cast<ResourceLeaf*>(child)->m_data = oldnode->m_data; | 42 | static_cast<ResourceLeaf*>(child)->m_data = oldnode->m_data; |
43 | static_cast<ResourceLeaf*>(child)->entry = oldnode->entry; | 43 | static_cast<ResourceLeaf*>(child)->entry = oldnode->entry; |
44 | } | 44 | } |
45 | } | 45 | } |
46 | 46 | ||
47 | ResourceChild& ResourceChild::operator=(const ResourceChild& rhs) | 47 | ResourceChild& ResourceChild::operator=(const ResourceChild& rhs) |
48 | { | 48 | { |
49 | if (this != &rhs) | 49 | if (this != &rhs) |
50 | { | 50 | { |
51 | if (dynamic_cast<ResourceNode*>(rhs.child)) | 51 | if (dynamic_cast<ResourceNode*>(rhs.child)) |
52 | { | 52 | { |
53 | ResourceNode* oldnode = static_cast<ResourceNode*>(rhs.child); | 53 | ResourceNode* oldnode = static_cast<ResourceNode*>(rhs.child); |
54 | 54 | ||
55 | entry = rhs.entry; | 55 | entry = rhs.entry; |
56 | 56 | ||
57 | child = new ResourceNode; | 57 | child = new ResourceNode; |
58 | child->uiElementRva = rhs.child->getElementRva(); | 58 | child->uiElementRva = rhs.child->getElementRva(); |
59 | static_cast<ResourceNode*>(child)->header = oldnode->header; | 59 | static_cast<ResourceNode*>(child)->header = oldnode->header; |
60 | static_cast<ResourceNode*>(child)->children = oldnode->children; | 60 | static_cast<ResourceNode*>(child)->children = oldnode->children; |
61 | } | 61 | } |
62 | else | 62 | else |
63 | { | 63 | { |
64 | ResourceLeaf* oldnode = static_cast<ResourceLeaf*>(rhs.child); | 64 | ResourceLeaf* oldnode = static_cast<ResourceLeaf*>(rhs.child); |
65 | 65 | ||
66 | child = new ResourceLeaf; | 66 | child = new ResourceLeaf; |
67 | child->uiElementRva = rhs.child->getElementRva(); | 67 | child->uiElementRva = rhs.child->getElementRva(); |
68 | static_cast<ResourceLeaf*>(child)->m_data = oldnode->m_data; | 68 | static_cast<ResourceLeaf*>(child)->m_data = oldnode->m_data; |
69 | static_cast<ResourceLeaf*>(child)->entry = oldnode->entry; | 69 | static_cast<ResourceLeaf*>(child)->entry = oldnode->entry; |
70 | } | 70 | } |
71 | } | 71 | } |
72 | 72 | ||
73 | return *this; | 73 | return *this; |
74 | } | 74 | } |
75 | 75 | ||
76 | ResourceChild::~ResourceChild() | 76 | ResourceChild::~ResourceChild() |
77 | { | 77 | { |
78 | delete child; | 78 | delete child; |
79 | } | 79 | } |
80 | 80 | ||
81 | /** | 81 | /** |
82 | * Compares the resource child's id to the parameter dwId. | 82 | * Compares the resource child's id to the parameter dwId. |
83 | * @param dwId ID of a resource. | 83 | * @param dwId ID of a resource. |
84 | * @return True, if the resource child's id equals the parameter. | 84 | * @return True, if the resource child's id equals the parameter. |
85 | **/ | 85 | **/ |
86 | bool ResourceChild::equalId(dword dwId) const | 86 | bool ResourceChild::equalId(dword dwId) const |
87 | { | 87 | { |
88 | return entry.irde.Name == dwId; | 88 | return entry.irde.Name == dwId; |
89 | } | 89 | } |
90 | 90 | ||
91 | /** | 91 | /** |
92 | * Compares the resource child's name to the parameter strName. | 92 | * Compares the resource child's name to the parameter strName. |
93 | * @param strName ID of a resource. | 93 | * @param strName ID of a resource. |
94 | * @return True, if the resource child's name equals the parameter. | 94 | * @return True, if the resource child's name equals the parameter. |
95 | **/ | 95 | **/ |
96 | bool ResourceChild::equalName(std::string strName) const | 96 | bool ResourceChild::equalName(std::string strName) const |
97 | { | 97 | { |
98 | return entry.wstrName == strName; | 98 | return entry.wstrName == strName; |
99 | } | 99 | } |
100 | 100 | ||
101 | /** | 101 | /** |
102 | * Returns true if the resource was given a name. | 102 | * Returns true if the resource was given a name. |
103 | **/ | 103 | **/ |
104 | bool ResourceChild::isNamedResource() const | 104 | bool ResourceChild::isNamedResource() const |
105 | { | 105 | { |
106 | return entry.wstrName.size() != 0; | 106 | return entry.wstrName.size() != 0; |
107 | } | 107 | } |
108 | 108 | ||
109 | /** | 109 | /** |
110 | * The children of a resource must be ordered in a certain way. First come the named resources | 110 | * The children of a resource must be ordered in a certain way. First come the named resources |
111 | * in sorted order, afterwards followed the unnamed resources in sorted order. | 111 | * in sorted order, afterwards followed the unnamed resources in sorted order. |
112 | **/ | 112 | **/ |
113 | bool ResourceChild::operator<(const ResourceChild& rc) const | 113 | bool ResourceChild::operator<(const ResourceChild& rc) const |
114 | { | 114 | { |
115 | if (this->isNamedResource() && !rc.isNamedResource()) | 115 | if (this->isNamedResource() && !rc.isNamedResource()) |
116 | { | 116 | { |
117 | return true; | 117 | return true; |
118 | } | 118 | } |
119 | else if (!this->isNamedResource() && rc.isNamedResource()) | 119 | else if (!this->isNamedResource() && rc.isNamedResource()) |
120 | { | 120 | { |
121 | return false; | 121 | return false; |
122 | } | 122 | } |
123 | else if (this->isNamedResource() && rc.isNamedResource()) | 123 | else if (this->isNamedResource() && rc.isNamedResource()) |
124 | { | 124 | { |
125 | return this->entry.wstrName < rc.entry.wstrName; | 125 | return this->entry.wstrName < rc.entry.wstrName; |
126 | } | 126 | } |
127 | else | 127 | else |
128 | { | 128 | { |
129 | return this->entry.irde.Name < rc.entry.irde.Name; | 129 | return this->entry.irde.Name < rc.entry.irde.Name; |
130 | } | 130 | } |
131 | } | 131 | } |
132 | 132 | ||
133 | /* unsigned int ResourceChild::size() const | 133 | /* unsigned int ResourceChild::size() const |
134 | { | 134 | { |
135 | return PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY::size() | 135 | return PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY::size() |
136 | + child->size() | 136 | + child->size() |
137 | + (entry.wstrName.size() ? entry.wstrName.size() + 2 : 0); | 137 | + (entry.wstrName.size() ? entry.wstrName.size() + 2 : 0); |
138 | } | 138 | } |
139 | */ | 139 | */ |
140 | // -------------------------------------------------- ResourceElement ------------------------------------------- | 140 | // -------------------------------------------------- ResourceElement ------------------------------------------- |
141 | 141 | ||
142 | /** | 142 | /** |
143 | * Returns the RVA of a ResourceElement. This is the RVA where the ResourceElement can be | 143 | * Returns the RVA of a ResourceElement. This is the RVA where the ResourceElement can be |
144 | * found in the file. | 144 | * found in the file. |
145 | * @return RVA of the ResourceElement. | 145 | * @return RVA of the ResourceElement. |
146 | **/ | 146 | **/ |
147 | unsigned int ResourceElement::getElementRva() const | 147 | unsigned int ResourceElement::getElementRva() const |
148 | { | 148 | { |
149 | return uiElementRva; | 149 | return uiElementRva; |
150 | } | 150 | } |
151 | 151 | ||
152 | // -------------------------------------------------- ResourceLeaf ------------------------------------------- | 152 | // -------------------------------------------------- ResourceLeaf ------------------------------------------- |
153 | 153 | ||
154 | /** | 154 | /** |
155 | * Checks if a ResourceElement is a leaf or not. | 155 | * Checks if a ResourceElement is a leaf or not. |
156 | * @return Always returns true. | 156 | * @return Always returns true. |
157 | **/ | 157 | **/ |
158 | bool ResourceLeaf::isLeaf() const | 158 | bool ResourceLeaf::isLeaf() const |
159 | { | 159 | { |
160 | return true; | 160 | return true; |
161 | } | 161 | } |
162 | 162 | ||
163 | /** | 163 | /** |
164 | * Reads the next resource leaf from the InputBuffer. | 164 | * Reads the next resource leaf from the InputBuffer. |
165 | * @param inpBuffer An InputBuffer that holds the complete resource directory. | 165 | * @param inpBuffer An InputBuffer that holds the complete resource directory. |
166 | * @param uiOffset Offset of the resource leaf that's to be read. | 166 | * @param uiOffset Offset of the resource leaf that's to be read. |
167 | * @param uiRva RVA of the beginning of the resource directory. | 167 | * @param uiRva RVA of the beginning of the resource directory. |
168 | * @param pad Used for debugging purposes. | 168 | * @param pad Used for debugging purposes. |
169 | **/ | 169 | **/ |
170 | int ResourceLeaf::read(InputBuffer& inpBuffer, unsigned int uiOffset, unsigned int uiRva/*, const std::string& pad*/) | 170 | int ResourceLeaf::read(InputBuffer& inpBuffer, unsigned int uiOffset, unsigned int uiRva/*, const std::string& pad*/) |
171 | { | 171 | { |
172 | // std::cout << pad << "Leaf:" << std::endl; | 172 | // std::cout << pad << "Leaf:" << std::endl; |
173 | 173 | ||
174 | // Invalid leaf. | 174 | // Invalid leaf. |
175 | if (uiOffset + PELIB_IMAGE_RESOURCE_DATA_ENTRY::size() > inpBuffer.size()) | 175 | if (uiOffset + PELIB_IMAGE_RESOURCE_DATA_ENTRY::size() > inpBuffer.size()) |
176 | { | 176 | { |
177 | return 1; | 177 | return 1; |
178 | } | 178 | } |
179 | 179 | ||
180 | uiElementRva = uiOffset + uiRva; | 180 | uiElementRva = uiOffset + uiRva; |
181 | 181 | ||
182 | inpBuffer.set(uiOffset); | 182 | inpBuffer.set(uiOffset); |
183 | 183 | ||
184 | inpBuffer >> entry.OffsetToData; | 184 | inpBuffer >> entry.OffsetToData; |
185 | inpBuffer >> entry.Size; | 185 | inpBuffer >> entry.Size; |
186 | inpBuffer >> entry.CodePage; | 186 | inpBuffer >> entry.CodePage; |
187 | inpBuffer >> entry.Reserved; | 187 | inpBuffer >> entry.Reserved; |
188 | 188 | ||
189 | /* std::cout << pad << std::hex << "Offset: " << entry.OffsetToData << std::endl; | 189 | /* std::cout << pad << std::hex << "Offset: " << entry.OffsetToData << std::endl; |
190 | std::cout << pad << std::hex << "Size: " << entry.Size << std::endl; | 190 | std::cout << pad << std::hex << "Size: " << entry.Size << std::endl; |
191 | std::cout << pad << std::hex << "CodePage: " << entry.CodePage << std::endl; | 191 | std::cout << pad << std::hex << "CodePage: " << entry.CodePage << std::endl; |
192 | std::cout << pad << std::hex << "Reserved: " << entry.Reserved << std::endl; | 192 | std::cout << pad << std::hex << "Reserved: " << entry.Reserved << std::endl; |
193 | */ | 193 | */ |
194 | // Invalid leaf. | 194 | // Invalid leaf. |
195 | if (entry.OffsetToData - uiRva + entry.Size > inpBuffer.size()) | 195 | if (entry.OffsetToData - uiRva + entry.Size > inpBuffer.size()) |
196 | { | 196 | { |
197 | // std::cout << entry.OffsetToData << " XXX " << uiRva << " - " << entry.Size << " - " << inpBuffer.size() << std::endl; | 197 | // std::cout << entry.OffsetToData << " XXX " << uiRva << " - " << entry.Size << " - " << inpBuffer.size() << std::endl; |
198 | return 1; | 198 | return 1; |
199 | } | 199 | } |
200 | 200 | ||
201 | // std::cout << entry.OffsetToData << " - " << uiRva << " - " << entry.Size << " - " << inpBuffer.size() << std::endl; | 201 | // std::cout << entry.OffsetToData << " - " << uiRva << " - " << entry.Size << " - " << inpBuffer.size() << std::endl; |
202 | inpBuffer.set(entry.OffsetToData - uiRva); | 202 | inpBuffer.set(entry.OffsetToData - uiRva); |
203 | m_data.assign(inpBuffer.data() + inpBuffer.get(), inpBuffer.data() + inpBuffer.get() + entry.Size); | 203 | m_data.assign(inpBuffer.data() + inpBuffer.get(), inpBuffer.data() + inpBuffer.get() + entry.Size); |
204 | // std::cout << pad << std::hex << "Vector: " << m_data.size() << std::endl; | 204 | // std::cout << pad << std::hex << "Vector: " << m_data.size() << std::endl; |
205 | // std::copy(m_data.begin(), m_data.end(), std::ostream_iterator<int>(std::cout << std::hex, " ")); | 205 | // std::copy(m_data.begin(), m_data.end(), std::ostream_iterator<int>(std::cout << std::hex, " ")); |
206 | return 0; | 206 | return 0; |
207 | } | 207 | } |
208 | 208 | ||
209 | /** | 209 | /** |
210 | * Rebuilds the current resource leaf. | 210 | * Rebuilds the current resource leaf. |
211 | * @param obBuffer OutputBuffer where the rebuilt resource leaf is stored. | 211 | * @param obBuffer OutputBuffer where the rebuilt resource leaf is stored. |
212 | * @param uiOffset Offset of the resource leaf inside the resource directory. | 212 | * @param uiOffset Offset of the resource leaf inside the resource directory. |
213 | * @param uiRva RVA of the resource directory. | 213 | * @param uiRva RVA of the resource directory. |
214 | **/ | 214 | **/ |
215 | void ResourceLeaf::rebuild(OutputBuffer& obBuffer, unsigned int& uiOffset, unsigned int uiRva, const std::string&) const | 215 | void ResourceLeaf::rebuild(OutputBuffer& obBuffer, unsigned int& uiOffset, unsigned int uiRva, const std::string&) const |
216 | { | 216 | { |
217 | // std::cout << std::hex << pad << "Leaf: " << uiOffset << std::endl; | 217 | // std::cout << std::hex << pad << "Leaf: " << uiOffset << std::endl; |
218 | uiOffset += PELIB_IMAGE_RESOURCE_DATA_ENTRY::size(); | 218 | uiOffset += PELIB_IMAGE_RESOURCE_DATA_ENTRY::size(); |
219 | 219 | ||
220 | // obBuffer << entry.OffsetToData; | 220 | // obBuffer << entry.OffsetToData; |
221 | // obBuffer << uiOffset; | 221 | // obBuffer << uiOffset; |
222 | obBuffer << uiRva + uiOffset + (uiOffset % 4); | 222 | obBuffer << uiRva + uiOffset + (uiOffset % 4); |
223 | obBuffer << entry.Size; | 223 | obBuffer << entry.Size; |
224 | obBuffer << entry.CodePage; | 224 | obBuffer << entry.CodePage; |
225 | obBuffer << entry.Reserved; | 225 | obBuffer << entry.Reserved; |
226 | 226 | ||
227 | while (uiOffset % 4) | 227 | while (uiOffset % 4) |
228 | { | 228 | { |
229 | uiOffset++; | 229 | uiOffset++; |
230 | obBuffer << (byte)0; | 230 | obBuffer << (byte)0; |
231 | } | 231 | } |
232 | 232 | ||
233 | uiOffset += static_cast<unsigned int>(m_data.size()); | 233 | uiOffset += static_cast<unsigned int>(m_data.size()); |
234 | 234 | ||
235 | for (unsigned int i=0;i<m_data.size();i++) | 235 | for (unsigned int i=0;i<m_data.size();i++) |
236 | { | 236 | { |
237 | obBuffer << m_data[i]; | 237 | obBuffer << m_data[i]; |
238 | } | 238 | } |
239 | // std::cout << "LeafChild: " << std::endl; | 239 | // std::cout << "LeafChild: " << std::endl; |
240 | } | 240 | } |
241 | 241 | ||
242 | void ResourceLeaf::makeValid() | 242 | void ResourceLeaf::makeValid() |
243 | { | 243 | { |
244 | entry.Size = static_cast<unsigned int>(m_data.size()); | 244 | entry.Size = static_cast<unsigned int>(m_data.size()); |
245 | } | 245 | } |
246 | 246 | ||
247 | /* /// Returns the size of a resource leaf. | 247 | /* /// Returns the size of a resource leaf. |
248 | unsigned int ResourceLeaf::size() const | 248 | unsigned int ResourceLeaf::size() const |
249 | { | 249 | { |
250 | return PELIB_IMAGE_RESOURCE_DATA_ENTRY::size() + m_data.size(); | 250 | return PELIB_IMAGE_RESOURCE_DATA_ENTRY::size() + m_data.size(); |
251 | } | 251 | } |
252 | */ | 252 | */ |
253 | 253 | ||
254 | /** | 254 | /** |
255 | * Returns a vector that contains the raw data of a resource leaf. | 255 | * Returns a vector that contains the raw data of a resource leaf. |
256 | * @return Raw data of the resource. | 256 | * @return Raw data of the resource. |
257 | **/ | 257 | **/ |
258 | std::vector<byte> ResourceLeaf::getData() const | 258 | std::vector<byte> ResourceLeaf::getData() const |
259 | { | 259 | { |
260 | return m_data; | 260 | return m_data; |
261 | } | 261 | } |
262 | 262 | ||
263 | /** | 263 | /** |
264 | * Overwrites the raw data of a resource. | 264 | * Overwrites the raw data of a resource. |
265 | * @param vData New data of the resource. | 265 | * @param vData New data of the resource. |
266 | **/ | 266 | **/ |
267 | void ResourceLeaf::setData(const std::vector<byte>& vData) | 267 | void ResourceLeaf::setData(const std::vector<byte>& vData) |
268 | { | 268 | { |
269 | m_data = vData; | 269 | m_data = vData; |
270 | } | 270 | } |
271 | 271 | ||
272 | /** | 272 | /** |
273 | * Returns the leaf's OffsetToData value. That's the RVA where the raw data of the resource | 273 | * Returns the leaf's OffsetToData value. That's the RVA where the raw data of the resource |
274 | * can be found. | 274 | * can be found. |
275 | * @return The leaf's OffsetToData value. | 275 | * @return The leaf's OffsetToData value. |
276 | **/ | 276 | **/ |
277 | dword ResourceLeaf::getOffsetToData() const | 277 | dword ResourceLeaf::getOffsetToData() const |
278 | { | 278 | { |
279 | return entry.OffsetToData; | 279 | return entry.OffsetToData; |
280 | } | 280 | } |
281 | 281 | ||
282 | /** | 282 | /** |
283 | * Returns the leaf's Size value. That's the size of the raw data of the resource. | 283 | * Returns the leaf's Size value. That's the size of the raw data of the resource. |
284 | * @return The leaf's Size value. | 284 | * @return The leaf's Size value. |
285 | **/ | 285 | **/ |
286 | dword ResourceLeaf::getSize() const | 286 | dword ResourceLeaf::getSize() const |
287 | { | 287 | { |
288 | return entry.Size; | 288 | return entry.Size; |
289 | } | 289 | } |
290 | 290 | ||
291 | /** | 291 | /** |
292 | * Returns the leaf's CodePage value. | 292 | * Returns the leaf's CodePage value. |
293 | * @return The leaf's CodePage value. | 293 | * @return The leaf's CodePage value. |
294 | **/ | 294 | **/ |
295 | dword ResourceLeaf::getCodePage() const | 295 | dword ResourceLeaf::getCodePage() const |
296 | { | 296 | { |
297 | return entry.CodePage; | 297 | return entry.CodePage; |
298 | } | 298 | } |
299 | 299 | ||
300 | /** | 300 | /** |
301 | * Returns the leaf's Reserved value. | 301 | * Returns the leaf's Reserved value. |
302 | * @return The leaf's Reserved value. | 302 | * @return The leaf's Reserved value. |
303 | **/ | 303 | **/ |
304 | dword ResourceLeaf::getReserved() const | 304 | dword ResourceLeaf::getReserved() const |
305 | { | 305 | { |
306 | return entry.Reserved; | 306 | return entry.Reserved; |
307 | } | 307 | } |
308 | 308 | ||
309 | /** | 309 | /** |
310 | * Sets the leaf's OffsetToData value. | 310 | * Sets the leaf's OffsetToData value. |
311 | * @param dwValue The leaf's new OffsetToData value. | 311 | * @param dwValue The leaf's new OffsetToData value. |
312 | **/ | 312 | **/ |
313 | void ResourceLeaf::setOffsetToData(dword dwValue) | 313 | void ResourceLeaf::setOffsetToData(dword dwValue) |
314 | { | 314 | { |
315 | entry.OffsetToData = dwValue; | 315 | entry.OffsetToData = dwValue; |
316 | } | 316 | } |
317 | 317 | ||
318 | /** | 318 | /** |
319 | * Sets the leaf's Size value. | 319 | * Sets the leaf's Size value. |
320 | * @param dwValue The leaf's new Size value. | 320 | * @param dwValue The leaf's new Size value. |
321 | **/ | 321 | **/ |
322 | void ResourceLeaf::setSize(dword dwValue) | 322 | void ResourceLeaf::setSize(dword dwValue) |
323 | { | 323 | { |
324 | entry.Size = dwValue; | 324 | entry.Size = dwValue; |
325 | } | 325 | } |
326 | 326 | ||
327 | /** | 327 | /** |
328 | * Sets the leaf's CodePage value. | 328 | * Sets the leaf's CodePage value. |
329 | * @param dwValue The leaf's new CodePage value. | 329 | * @param dwValue The leaf's new CodePage value. |
330 | **/ | 330 | **/ |
331 | void ResourceLeaf::setCodePage(dword dwValue) | 331 | void ResourceLeaf::setCodePage(dword dwValue) |
332 | { | 332 | { |
333 | entry.CodePage = dwValue; | 333 | entry.CodePage = dwValue; |
334 | } | 334 | } |
335 | 335 | ||
336 | /** | 336 | /** |
337 | * Sets the leaf's Reserved value. | 337 | * Sets the leaf's Reserved value. |
338 | * @param dwValue The leaf's new Reserved value. | 338 | * @param dwValue The leaf's new Reserved value. |
339 | **/ | 339 | **/ |
340 | void ResourceLeaf::setReserved(dword dwValue) | 340 | void ResourceLeaf::setReserved(dword dwValue) |
341 | { | 341 | { |
342 | entry.Reserved = dwValue; | 342 | entry.Reserved = dwValue; |
343 | } | 343 | } |
344 | 344 | ||
345 | 345 | ||
346 | // -------------------------------------------------- ResourceNode ------------------------------------------- | 346 | // -------------------------------------------------- ResourceNode ------------------------------------------- |
347 | 347 | ||
348 | /** | 348 | /** |
349 | * Checks if a ResourceElement is a leaf or not. | 349 | * Checks if a ResourceElement is a leaf or not. |
350 | * @return Always returns false. | 350 | * @return Always returns false. |
351 | **/ | 351 | **/ |
352 | bool ResourceNode::isLeaf() const | 352 | bool ResourceNode::isLeaf() const |
353 | { | 353 | { |
354 | return false; | 354 | return false; |
355 | } | 355 | } |
356 | 356 | ||
357 | /** | 357 | /** |
358 | * Sorts the node's children and corrects the node's header. | 358 | * Sorts the node's children and corrects the node's header. |
359 | **/ | 359 | **/ |
360 | void ResourceNode::makeValid() | 360 | void ResourceNode::makeValid() |
361 | { | 361 | { |
362 | std::sort(children.begin(), children.end()); | 362 | std::sort(children.begin(), children.end()); |
363 | header.NumberOfNamedEntries = static_cast<PeLib::word>(std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource))); | 363 | header.NumberOfNamedEntries = static_cast<PeLib::word>(std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource))); |
364 | header.NumberOfIdEntries = static_cast<unsigned int>(children.size()) - header.NumberOfNamedEntries; | 364 | header.NumberOfIdEntries = static_cast<unsigned int>(children.size()) - header.NumberOfNamedEntries; |
365 | } | 365 | } |
366 | 366 | ||
367 | /** | 367 | /** |
368 | * Rebuilds the current resource node. | 368 | * Rebuilds the current resource node. |
369 | * @param obBuffer OutputBuffer where the rebuilt resource node is stored. | 369 | * @param obBuffer OutputBuffer where the rebuilt resource node is stored. |
370 | * @param uiOffset Offset of the resource node inside the resource directory. | 370 | * @param uiOffset Offset of the resource node inside the resource directory. |
371 | * @param uiRva RVA of the resource directory. | 371 | * @param uiRva RVA of the resource directory. |
372 | * @param pad Used for debugging. | 372 | * @param pad Used for debugging. |
373 | **/ | 373 | **/ |
374 | void ResourceNode::rebuild(OutputBuffer& obBuffer, unsigned int& uiOffset, unsigned int uiRva, const std::string& pad) const | 374 | void ResourceNode::rebuild(OutputBuffer& obBuffer, unsigned int& uiOffset, unsigned int uiRva, const std::string& pad) const |
375 | { | 375 | { |
376 | /* std::cout << std::hex << pad << uiOffset << std::endl; | 376 | /* std::cout << std::hex << pad << uiOffset << std::endl; |
377 | 377 | ||
378 | std::cout << std::hex << pad << "header.Characteristics: " << header.Characteristics << std::endl; | 378 | std::cout << std::hex << pad << "header.Characteristics: " << header.Characteristics << std::endl; |
379 | std::cout << std::hex << pad << "header.TimeDateStamp: " << header.TimeDateStamp << std::endl; | 379 | std::cout << std::hex << pad << "header.TimeDateStamp: " << header.TimeDateStamp << std::endl; |
380 | std::cout << std::hex << pad << "header.MajorVersion: " << header.MajorVersion << std::endl; | 380 | std::cout << std::hex << pad << "header.MajorVersion: " << header.MajorVersion << std::endl; |
381 | std::cout << std::hex << pad << "header.MinorVersion: " << header.MinorVersion << std::endl; | 381 | std::cout << std::hex << pad << "header.MinorVersion: " << header.MinorVersion << std::endl; |
382 | std::cout << std::hex << pad << "header.NumberOfNamedEntries: " << header.NumberOfNamedEntries << std::endl; | 382 | std::cout << std::hex << pad << "header.NumberOfNamedEntries: " << header.NumberOfNamedEntries << std::endl; |
383 | std::cout << std::hex << pad << "header.NumberOfIdEntries: " << header.NumberOfIdEntries << std::endl; | 383 | std::cout << std::hex << pad << "header.NumberOfIdEntries: " << header.NumberOfIdEntries << std::endl; |
384 | */ | 384 | */ |
385 | obBuffer << header.Characteristics; | 385 | obBuffer << header.Characteristics; |
386 | obBuffer << header.TimeDateStamp; | 386 | obBuffer << header.TimeDateStamp; |
387 | obBuffer << header.MajorVersion; | 387 | obBuffer << header.MajorVersion; |
388 | obBuffer << header.MinorVersion; | 388 | obBuffer << header.MinorVersion; |
389 | //std::cout << pad << "Children: " << children.size() << std::endl; | 389 | //std::cout << pad << "Children: " << children.size() << std::endl; |
390 | //std::cout << pad << std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)) << std::endl; | 390 | //std::cout << pad << std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)) << std::endl; |
391 | //std::cout << pad << children.size() - std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)) << std::endl; | 391 | //std::cout << pad << children.size() - std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)) << std::endl; |
392 | // obBuffer << std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)); | 392 | // obBuffer << std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)); |
393 | // obBuffer << children.size() - std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)); | 393 | // obBuffer << children.size() - std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource)); |
394 | obBuffer << header.NumberOfNamedEntries; | 394 | obBuffer << header.NumberOfNamedEntries; |
395 | obBuffer << header.NumberOfIdEntries; | 395 | obBuffer << header.NumberOfIdEntries; |
396 | 396 | ||
397 | uiOffset += PELIB_IMAGE_RESOURCE_DIRECTORY::size(); | 397 | uiOffset += PELIB_IMAGE_RESOURCE_DIRECTORY::size(); |
398 | 398 | ||
399 | for (unsigned int i=0;i<children.size();i++) | 399 | for (unsigned int i=0;i<children.size();i++) |
400 | { | 400 | { |
401 | obBuffer << (dword)0; | 401 | obBuffer << (dword)0; |
402 | obBuffer << (dword)0; | 402 | obBuffer << (dword)0; |
403 | } | 403 | } |
404 | 404 | ||
405 | unsigned int newoffs = (uiOffset + children.size() * 8); | 405 | unsigned int newoffs = (uiOffset + children.size() * 8); |
406 | 406 | ||
407 | for (unsigned int i=0;i<children.size();i++) | 407 | for (unsigned int i=0;i<children.size();i++) |
408 | { | 408 | { |
409 | if (!children[i].entry.wstrName.size()) | 409 | if (!children[i].entry.wstrName.size()) |
410 | { | 410 | { |
411 | obBuffer.update(uiOffset, children[i].entry.irde.Name); | 411 | obBuffer.update(uiOffset, children[i].entry.irde.Name); |
412 | } | 412 | } |
413 | else | 413 | else |
414 | { | 414 | { |
415 | obBuffer.update(uiOffset, newoffs | PELIB_IMAGE_RESOURCE_NAME_IS_STRING); | 415 | obBuffer.update(uiOffset, newoffs | PELIB_IMAGE_RESOURCE_NAME_IS_STRING); |
416 | obBuffer << (word)children[i].entry.wstrName.size(); | 416 | obBuffer << (word)children[i].entry.wstrName.size(); |
417 | newoffs += 2; | 417 | newoffs += 2; |
418 | for (unsigned int j=0;j<children[i].entry.wstrName.size();j++) | 418 | for (unsigned int j=0;j<children[i].entry.wstrName.size();j++) |
419 | { | 419 | { |
420 | // std::cout << children[i].entry.wstrName[j]; | 420 | // std::cout << children[i].entry.wstrName[j]; |
421 | obBuffer << (word)children[i].entry.wstrName[j]; | 421 | obBuffer << (word)children[i].entry.wstrName[j]; |
422 | newoffs += 2; | 422 | newoffs += 2; |
423 | } | 423 | } |
424 | } | 424 | } |
425 | uiOffset += 4; | 425 | uiOffset += 4; |
426 | // obBuffer << children[i].entry.OffsetToData; | 426 | // obBuffer << children[i].entry.OffsetToData; |
427 | obBuffer.update(uiOffset, newoffs | (children[i].entry.irde.OffsetToData & PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY)); | 427 | obBuffer.update(uiOffset, newoffs | (children[i].entry.irde.OffsetToData & PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY)); |
428 | uiOffset += 4; | 428 | uiOffset += 4; |
429 | children[i].child->rebuild(obBuffer, newoffs, uiRva, pad + " "); | 429 | children[i].child->rebuild(obBuffer, newoffs, uiRva, pad + " "); |
430 | } | 430 | } |
431 | uiOffset = newoffs; | 431 | uiOffset = newoffs; |
432 | } | 432 | } |
433 | 433 | ||
434 | /** | 434 | /** |
435 | * Reads the next resource node from the InputBuffer. | 435 | * Reads the next resource node from the InputBuffer. |
436 | * @param inpBuffer An InputBuffer that holds the complete resource directory. | 436 | * @param inpBuffer An InputBuffer that holds the complete resource directory. |
437 | * @param uiOffset Offset of the resource node that's to be read. | 437 | * @param uiOffset Offset of the resource node that's to be read. |
438 | * @param uiRva RVA of the beginning of the resource directory. | 438 | * @param uiRva RVA of the beginning of the resource directory. |
439 | * @param pad Something I need for debugging. Will be removed soon. | 439 | * @param pad Something I need for debugging. Will be removed soon. |
440 | **/ | 440 | **/ |
441 | int ResourceNode::read(InputBuffer& inpBuffer, unsigned int uiOffset, unsigned int uiRva/*, const std::string& pad*/) | 441 | int ResourceNode::read(InputBuffer& inpBuffer, unsigned int uiOffset, unsigned int uiRva/*, const std::string& pad*/) |
442 | { | 442 | { |
443 | // Not enough space to be a valid node. | 443 | // Not enough space to be a valid node. |
444 | if (uiOffset + PELIB_IMAGE_RESOURCE_DIRECTORY::size() > inpBuffer.size()) | 444 | if (uiOffset + PELIB_IMAGE_RESOURCE_DIRECTORY::size() > inpBuffer.size()) |
445 | { | 445 | { |
446 | return 1; | 446 | return 1; |
447 | } | 447 | } |
448 | 448 | ||
449 | uiElementRva = uiOffset + uiRva; | 449 | uiElementRva = uiOffset + uiRva; |
450 | 450 | ||
451 | inpBuffer.set(uiOffset); | 451 | inpBuffer.set(uiOffset); |
452 | 452 | ||
453 | inpBuffer >> header.Characteristics; | 453 | inpBuffer >> header.Characteristics; |
454 | inpBuffer >> header.TimeDateStamp; | 454 | inpBuffer >> header.TimeDateStamp; |
455 | inpBuffer >> header.MajorVersion; | 455 | inpBuffer >> header.MajorVersion; |
456 | inpBuffer >> header.MinorVersion; | 456 | inpBuffer >> header.MinorVersion; |
457 | inpBuffer >> header.NumberOfNamedEntries; | 457 | inpBuffer >> header.NumberOfNamedEntries; |
458 | inpBuffer >> header.NumberOfIdEntries; | 458 | inpBuffer >> header.NumberOfIdEntries; |
459 | 459 | ||
460 | // Not enough space to be a valid node. | 460 | // Not enough space to be a valid node. |
461 | if (uiOffset + PELIB_IMAGE_RESOURCE_DIRECTORY::size() | 461 | if (uiOffset + PELIB_IMAGE_RESOURCE_DIRECTORY::size() |
462 | + (header.NumberOfNamedEntries + header.NumberOfIdEntries) * PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY::size() | 462 | + (header.NumberOfNamedEntries + header.NumberOfIdEntries) * PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY::size() |
463 | > inpBuffer.size()) | 463 | > inpBuffer.size()) |
464 | { | 464 | { |
465 | return 1; | 465 | return 1; |
466 | } | 466 | } |
467 | 467 | ||
468 | // std::cout << std::hex << pad << "Characteristics: " << header.Characteristics << std::endl; | 468 | // std::cout << std::hex << pad << "Characteristics: " << header.Characteristics << std::endl; |
469 | // std::cout << std::hex << pad << "TimeDateStamp: " << header.TimeDateStamp << std::endl; | 469 | // std::cout << std::hex << pad << "TimeDateStamp: " << header.TimeDateStamp << std::endl; |
470 | // std::cout << std::hex << pad << "MajorVersion: " << header.MajorVersion << std::endl; | 470 | // std::cout << std::hex << pad << "MajorVersion: " << header.MajorVersion << std::endl; |
471 | // std::cout << std::hex << pad << "MinorVersion: " << header.MinorVersion << std::endl; | 471 | // std::cout << std::hex << pad << "MinorVersion: " << header.MinorVersion << std::endl; |
472 | // std::cout << std::hex << pad << "NumberOfNamedEntries: " << header.NumberOfNamedEntries << std::endl; | 472 | // std::cout << std::hex << pad << "NumberOfNamedEntries: " << header.NumberOfNamedEntries << std::endl; |
473 | // std::cout << std::hex << pad << "NumberOfIdEntries: " << header.NumberOfIdEntries << std::endl; | 473 | // std::cout << std::hex << pad << "NumberOfIdEntries: " << header.NumberOfIdEntries << std::endl; |
474 | 474 | ||
475 | for (int i=0;i<header.NumberOfNamedEntries + header.NumberOfIdEntries;i++) | 475 | for (int i=0;i<header.NumberOfNamedEntries + header.NumberOfIdEntries;i++) |
476 | { | 476 | { |
477 | ResourceChild rc; | 477 | ResourceChild rc; |
478 | inpBuffer >> rc.entry.irde.Name; | 478 | inpBuffer >> rc.entry.irde.Name; |
479 | inpBuffer >> rc.entry.irde.OffsetToData; | 479 | inpBuffer >> rc.entry.irde.OffsetToData; |
480 | 480 | ||
481 | unsigned int lastPos = inpBuffer.get(); | 481 | unsigned int lastPos = inpBuffer.get(); |
482 | 482 | ||
483 | if (rc.entry.irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING) | 483 | if (rc.entry.irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING) |
484 | { | 484 | { |
485 | // Enough space to read string length? | 485 | // Enough space to read string length? |
486 | if ((rc.entry.irde.Name & ~PELIB_IMAGE_RESOURCE_NAME_IS_STRING) + 2 < inpBuffer.size()) | 486 | if ((rc.entry.irde.Name & ~PELIB_IMAGE_RESOURCE_NAME_IS_STRING) + 2 < inpBuffer.size()) |
487 | { | 487 | { |
488 | inpBuffer.set(rc.entry.irde.Name & ~PELIB_IMAGE_RESOURCE_NAME_IS_STRING); | 488 | inpBuffer.set(rc.entry.irde.Name & ~PELIB_IMAGE_RESOURCE_NAME_IS_STRING); |
489 | word strlen; | 489 | word strlen; |
490 | inpBuffer >> strlen; | 490 | inpBuffer >> strlen; |
491 | 491 | ||
492 | // Enough space to read string? | 492 | // Enough space to read string? |
493 | if ((rc.entry.irde.Name & ~PELIB_IMAGE_RESOURCE_NAME_IS_STRING) + 2 * strlen < inpBuffer.size()) | 493 | if ((rc.entry.irde.Name & ~PELIB_IMAGE_RESOURCE_NAME_IS_STRING) + 2 * strlen < inpBuffer.size()) |
494 | { | 494 | { |
495 | wchar_t c; | 495 | wchar_t c; |
496 | for (word i=0;i<strlen;i++) | 496 | for (word i=0;i<strlen;i++) |
497 | { | 497 | { |
498 | inpBuffer >> c; | 498 | inpBuffer >> c; |
499 | rc.entry.wstrName += c; | 499 | rc.entry.wstrName += c; |
500 | } | 500 | } |
501 | } | 501 | } |
502 | } | 502 | } |
503 | 503 | ||
504 | // std::wcout << rc.entry.wstrName << std::endl; | 504 | // std::wcout << rc.entry.wstrName << std::endl; |
505 | 505 | ||
506 | // std::cout << strlen << std::endl; | 506 | // std::cout << strlen << std::endl; |
507 | inpBuffer.set(lastPos); | 507 | inpBuffer.set(lastPos); |
508 | } | 508 | } |
509 | 509 | ||
510 | if (rc.entry.irde.OffsetToData & PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY) | 510 | if (rc.entry.irde.OffsetToData & PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY) |
511 | { | 511 | { |
512 | rc.child = new ResourceNode; | 512 | rc.child = new ResourceNode; |
513 | rc.child->read(inpBuffer, rc.entry.irde.OffsetToData & ~PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY, uiRva/*, pad + " "*/); | 513 | rc.child->read(inpBuffer, rc.entry.irde.OffsetToData & ~PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY, uiRva/*, pad + " "*/); |
514 | } | 514 | } |
515 | else | 515 | else |
516 | { | 516 | { |
517 | rc.child = new ResourceLeaf; | 517 | rc.child = new ResourceLeaf; |
518 | rc.child->read(inpBuffer, rc.entry.irde.OffsetToData, uiRva/*, pad + " "*/); | 518 | rc.child->read(inpBuffer, rc.entry.irde.OffsetToData, uiRva/*, pad + " "*/); |
519 | } | 519 | } |
520 | // std::cout << std::hex << pad << "Entry " << i << "(Name): " << rc.entry.irde.Name << std::endl; | 520 | // std::cout << std::hex << pad << "Entry " << i << "(Name): " << rc.entry.irde.Name << std::endl; |
521 | // std::cout << std::hex << pad << "Entry " << i << "(Offset): " << rc.entry.irde.OffsetToData << std::endl; | 521 | // std::cout << std::hex << pad << "Entry " << i << "(Offset): " << rc.entry.irde.OffsetToData << std::endl; |
522 | 522 | ||
523 | children.push_back(rc); | 523 | children.push_back(rc); |
524 | inpBuffer.set(lastPos); | 524 | inpBuffer.set(lastPos); |
525 | } | 525 | } |
526 | 526 | ||
527 | return 0; | 527 | return 0; |
528 | } | 528 | } |
529 | 529 | ||
530 | /** | 530 | /** |
531 | * Returns the number of children of the current node. Note that this number is the number | 531 | * Returns the number of children of the current node. Note that this number is the number |
532 | * of defined children, not the value from the header. | 532 | * of defined children, not the value from the header. |
533 | * @return Number of node's children. | 533 | * @return Number of node's children. |
534 | **/ | 534 | **/ |
535 | unsigned int ResourceNode::getNumberOfChildren() const | 535 | unsigned int ResourceNode::getNumberOfChildren() const |
536 | { | 536 | { |
537 | return static_cast<unsigned int>(children.size()); | 537 | return static_cast<unsigned int>(children.size()); |
538 | } | 538 | } |
539 | 539 | ||
540 | /** | 540 | /** |
541 | * Adds another child to the current node. | 541 | * Adds another child to the current node. |
542 | **/ | 542 | **/ |
543 | void ResourceNode::addChild() | 543 | void ResourceNode::addChild() |
544 | { | 544 | { |
545 | ResourceChild c; | 545 | ResourceChild c; |
546 | c.child = 0; | 546 | c.child = 0; |
547 | children.push_back(c); | 547 | children.push_back(c); |
548 | } | 548 | } |
549 | 549 | ||
550 | /** | 550 | /** |
551 | * Returns a node's child. | 551 | * Returns a node's child. |
552 | * @param uiIndex Index of the child. | 552 | * @param uiIndex Index of the child. |
553 | * @return The child identified by uiIndex. This child can be either a ResourceNode or a ResourceLeaf. | 553 | * @return The child identified by uiIndex. This child can be either a ResourceNode or a ResourceLeaf. |
554 | **/ | 554 | **/ |
555 | ResourceElement* ResourceNode::getChild(unsigned int uiIndex) | 555 | ResourceElement* ResourceNode::getChild(unsigned int uiIndex) |
556 | { | 556 | { |
557 | return children[uiIndex].child; | 557 | return children[uiIndex].child; |
558 | } | 558 | } |
559 | 559 | ||
560 | /** | 560 | /** |
561 | * Removes a child from the current node. | 561 | * Removes a child from the current node. |
562 | * @param uiIndex Index of the child. | 562 | * @param uiIndex Index of the child. |
563 | **/ | 563 | **/ |
564 | void ResourceNode::removeChild(unsigned int uiIndex) | 564 | void ResourceNode::removeChild(unsigned int uiIndex) |
565 | { | 565 | { |
566 | children.erase(children.begin() + uiIndex); | 566 | children.erase(children.begin() + uiIndex); |
567 | } | 567 | } |
568 | 568 | ||
569 | /** | 569 | /** |
570 | * Returns the name of a child. | 570 | * Returns the name of a child. |
571 | * @param uiIndex Index of the child. | 571 | * @param uiIndex Index of the child. |
572 | * @return Either the name of the specified child or an empty string. | 572 | * @return Either the name of the specified child or an empty string. |
573 | **/ | 573 | **/ |
574 | std::string ResourceNode::getChildName(unsigned int uiIndex) const | 574 | std::string ResourceNode::getChildName(unsigned int uiIndex) const |
575 | { | 575 | { |
576 | return children[uiIndex].entry.wstrName; | 576 | return children[uiIndex].entry.wstrName; |
577 | } | 577 | } |
578 | 578 | ||
579 | /** | 579 | /** |
580 | * Returns the Name value of a child. | 580 | * Returns the Name value of a child. |
581 | * @param uiIndex Index of the child. | 581 | * @param uiIndex Index of the child. |
582 | * @return Name value of a child. | 582 | * @return Name value of a child. |
583 | **/ | 583 | **/ |
584 | dword ResourceNode::getOffsetToChildName(unsigned int uiIndex) const | 584 | dword ResourceNode::getOffsetToChildName(unsigned int uiIndex) const |
585 | { | 585 | { |
586 | return children[uiIndex].entry.irde.Name; | 586 | return children[uiIndex].entry.irde.Name; |
587 | } | 587 | } |
588 | 588 | ||
589 | /** | 589 | /** |
590 | * Returns the OffsetToData value of a child. | 590 | * Returns the OffsetToData value of a child. |
591 | * @param uiIndex Index of the child. | 591 | * @param uiIndex Index of the child. |
592 | * @return OffsetToData value of a child. | 592 | * @return OffsetToData value of a child. |
593 | **/ | 593 | **/ |
594 | dword ResourceNode::getOffsetToChildData(unsigned int uiIndex) const | 594 | dword ResourceNode::getOffsetToChildData(unsigned int uiIndex) const |
595 | { | 595 | { |
596 | return children[uiIndex].entry.irde.OffsetToData; | 596 | return children[uiIndex].entry.irde.OffsetToData; |
597 | } | 597 | } |
598 | 598 | ||
599 | 599 | ||
600 | /** | 600 | /** |
601 | * Sets the name of a child. | 601 | * Sets the name of a child. |
602 | * @param uiIndex Index of the child. | 602 | * @param uiIndex Index of the child. |
603 | * @param strNewName New name of the resource. | 603 | * @param strNewName New name of the resource. |
604 | **/ | 604 | **/ |
605 | void ResourceNode::setChildName(unsigned int uiIndex, const std::string& strNewName) | 605 | void ResourceNode::setChildName(unsigned int uiIndex, const std::string& strNewName) |
606 | { | 606 | { |
607 | children[uiIndex].entry.wstrName = strNewName; | 607 | children[uiIndex].entry.wstrName = strNewName; |
608 | } | 608 | } |
609 | 609 | ||
610 | /** | 610 | /** |
611 | * Sets the Name value of a child. | 611 | * Sets the Name value of a child. |
612 | * @param uiIndex Index of the child. | 612 | * @param uiIndex Index of the child. |
613 | * @param dwNewOffset New Name value of the resource. | 613 | * @param dwNewOffset New Name value of the resource. |
614 | **/ | 614 | **/ |
615 | void ResourceNode::setOffsetToChildName(unsigned int uiIndex, dword dwNewOffset) | 615 | void ResourceNode::setOffsetToChildName(unsigned int uiIndex, dword dwNewOffset) |
616 | { | 616 | { |
617 | children[uiIndex].entry.irde.Name = dwNewOffset; | 617 | children[uiIndex].entry.irde.Name = dwNewOffset; |
618 | } | 618 | } |
619 | 619 | ||
620 | /** | 620 | /** |
621 | * Sets the OffsetToData value of a child. | 621 | * Sets the OffsetToData value of a child. |
622 | * @param uiIndex Index of the child. | 622 | * @param uiIndex Index of the child. |
623 | * @param dwNewOffset New OffsetToData value of the resource. | 623 | * @param dwNewOffset New OffsetToData value of the resource. |
624 | **/ | 624 | **/ |
625 | void ResourceNode::setOffsetToChildData(unsigned int uiIndex, dword dwNewOffset) | 625 | void ResourceNode::setOffsetToChildData(unsigned int uiIndex, dword dwNewOffset) |
626 | { | 626 | { |
627 | children[uiIndex].entry.irde.OffsetToData = dwNewOffset; | 627 | children[uiIndex].entry.irde.OffsetToData = dwNewOffset; |
628 | } | 628 | } |
629 | 629 | ||
630 | /** | 630 | /** |
631 | * Returns the Characteristics value of the node. | 631 | * Returns the Characteristics value of the node. |
632 | * @return Characteristics value of the node. | 632 | * @return Characteristics value of the node. |
633 | **/ | 633 | **/ |
634 | dword ResourceNode::getCharacteristics() const | 634 | dword ResourceNode::getCharacteristics() const |
635 | { | 635 | { |
636 | return header.Characteristics; | 636 | return header.Characteristics; |
637 | } | 637 | } |
638 | 638 | ||
639 | /** | 639 | /** |
640 | * Returns the TimeDateStamp value of the node. | 640 | * Returns the TimeDateStamp value of the node. |
641 | * @return TimeDateStamp value of the node. | 641 | * @return TimeDateStamp value of the node. |
642 | **/ | 642 | **/ |
643 | dword ResourceNode::getTimeDateStamp() const | 643 | dword ResourceNode::getTimeDateStamp() const |
644 | { | 644 | { |
645 | return header.TimeDateStamp; | 645 | return header.TimeDateStamp; |
646 | } | 646 | } |
647 | 647 | ||
648 | /** | 648 | /** |
649 | * Returns the MajorVersion value of the node. | 649 | * Returns the MajorVersion value of the node. |
650 | * @return MajorVersion value of the node. | 650 | * @return MajorVersion value of the node. |
651 | **/ | 651 | **/ |
652 | word ResourceNode::getMajorVersion() const | 652 | word ResourceNode::getMajorVersion() const |
653 | { | 653 | { |
654 | return header.MajorVersion; | 654 | return header.MajorVersion; |
655 | } | 655 | } |
656 | 656 | ||
657 | /** | 657 | /** |
658 | * Returns the MinorVersion value of the node. | 658 | * Returns the MinorVersion value of the node. |
659 | * @return MinorVersion value of the node. | 659 | * @return MinorVersion value of the node. |
660 | **/ | 660 | **/ |
661 | word ResourceNode::getMinorVersion() const | 661 | word ResourceNode::getMinorVersion() const |
662 | { | 662 | { |
663 | return header.MinorVersion; | 663 | return header.MinorVersion; |
664 | } | 664 | } |
665 | 665 | ||
666 | /** | 666 | /** |
667 | * Returns the NumberOfNamedEntries value of the node. | 667 | * Returns the NumberOfNamedEntries value of the node. |
668 | * @return NumberOfNamedEntries value of the node. | 668 | * @return NumberOfNamedEntries value of the node. |
669 | **/ | 669 | **/ |
670 | word ResourceNode::getNumberOfNamedEntries() const | 670 | word ResourceNode::getNumberOfNamedEntries() const |
671 | { | 671 | { |
672 | return header.NumberOfNamedEntries; | 672 | return header.NumberOfNamedEntries; |
673 | } | 673 | } |
674 | 674 | ||
675 | /** | 675 | /** |
676 | * Returns the NumberOfIdEntries value of the node. | 676 | * Returns the NumberOfIdEntries value of the node. |
677 | * @return NumberOfIdEntries value of the node. | 677 | * @return NumberOfIdEntries value of the node. |
678 | **/ | 678 | **/ |
679 | word ResourceNode::getNumberOfIdEntries() const | 679 | word ResourceNode::getNumberOfIdEntries() const |
680 | { | 680 | { |
681 | return header.NumberOfIdEntries; | 681 | return header.NumberOfIdEntries; |
682 | } | 682 | } |
683 | 683 | ||
684 | /** | 684 | /** |
685 | * Sets the Characteristics value of the node. | 685 | * Sets the Characteristics value of the node. |
686 | * @param value New Characteristics value of the node. | 686 | * @param value New Characteristics value of the node. |
687 | **/ | 687 | **/ |
688 | void ResourceNode::setCharacteristics(dword value) | 688 | void ResourceNode::setCharacteristics(dword value) |
689 | { | 689 | { |
690 | header.Characteristics = value; | 690 | header.Characteristics = value; |
691 | } | 691 | } |
692 | 692 | ||
693 | /** | 693 | /** |
694 | * Sets the TimeDateStamp value of the node. | 694 | * Sets the TimeDateStamp value of the node. |
695 | * @param value New TimeDateStamp value of the node. | 695 | * @param value New TimeDateStamp value of the node. |
696 | **/ | 696 | **/ |
697 | void ResourceNode::setTimeDateStamp(dword value) | 697 | void ResourceNode::setTimeDateStamp(dword value) |
698 | { | 698 | { |
699 | header.TimeDateStamp = value; | 699 | header.TimeDateStamp = value; |
700 | } | 700 | } |
701 | 701 | ||
702 | /** | 702 | /** |
703 | * Sets the MajorVersion value of the node. | 703 | * Sets the MajorVersion value of the node. |
704 | * @param value New MajorVersion value of the node. | 704 | * @param value New MajorVersion value of the node. |
705 | **/ | 705 | **/ |
706 | void ResourceNode::setMajorVersion(word value) | 706 | void ResourceNode::setMajorVersion(word value) |
707 | { | 707 | { |
708 | header.MajorVersion = value; | 708 | header.MajorVersion = value; |
709 | } | 709 | } |
710 | 710 | ||
711 | /** | 711 | /** |
712 | * Sets the MinorVersion value of the node. | 712 | * Sets the MinorVersion value of the node. |
713 | * @param value New MinorVersion value of the node. | 713 | * @param value New MinorVersion value of the node. |
714 | **/ | 714 | **/ |
715 | void ResourceNode::setMinorVersion(word value) | 715 | void ResourceNode::setMinorVersion(word value) |
716 | { | 716 | { |
717 | header.MinorVersion = value; | 717 | header.MinorVersion = value; |
718 | } | 718 | } |
719 | 719 | ||
720 | /** | 720 | /** |
721 | * Sets the NumberOfNamedEntries value of the node. | 721 | * Sets the NumberOfNamedEntries value of the node. |
722 | * @param value New NumberOfNamedEntries value of the node. | 722 | * @param value New NumberOfNamedEntries value of the node. |
723 | **/ | 723 | **/ |
724 | void ResourceNode::setNumberOfNamedEntries(word value) | 724 | void ResourceNode::setNumberOfNamedEntries(word value) |
725 | { | 725 | { |
726 | header.NumberOfNamedEntries = value; | 726 | header.NumberOfNamedEntries = value; |
727 | } | 727 | } |
728 | 728 | ||
729 | /** | 729 | /** |
730 | * Sets the NumberOfIdEntries value of the node. | 730 | * Sets the NumberOfIdEntries value of the node. |
731 | * @param value New NumberOfIdEntries value of the node. | 731 | * @param value New NumberOfIdEntries value of the node. |
732 | **/ | 732 | **/ |
733 | void ResourceNode::setNumberOfIdEntries(word value) | 733 | void ResourceNode::setNumberOfIdEntries(word value) |
734 | { | 734 | { |
735 | header.NumberOfIdEntries = value; | 735 | header.NumberOfIdEntries = value; |
736 | } | 736 | } |
737 | 737 | ||
738 | 738 | ||
739 | /* /// Returns the size of a resource node. | 739 | /* /// Returns the size of a resource node. |
740 | unsigned int ResourceNode::size() const | 740 | unsigned int ResourceNode::size() const |
741 | { | 741 | { |
742 | if (children.size()) | 742 | if (children.size()) |
743 | { | 743 | { |
744 | std::cout << std::accumulate(children.begin(), children.end(), 0, accumulate<ResourceChild>) << std::endl; | 744 | std::cout << std::accumulate(children.begin(), children.end(), 0, accumulate<ResourceChild>) << std::endl; |
745 | return PELIB_IMAGE_RESOURCE_DIRECTORY::size() | 745 | return PELIB_IMAGE_RESOURCE_DIRECTORY::size() |
746 | + std::accumulate(children.begin(), children.end(), 0, accumulate<ResourceChild>); | 746 | + std::accumulate(children.begin(), children.end(), 0, accumulate<ResourceChild>); |
747 | } | 747 | } |
748 | else | 748 | else |
749 | { | 749 | { |
750 | return 0; | 750 | return 0; |
751 | } | 751 | } |
752 | } | 752 | } |
753 | */ | 753 | */ |
754 | // -------------------------------------------------- ResourceDirectory ------------------------------------------- | 754 | // -------------------------------------------------- ResourceDirectory ------------------------------------------- |
755 | 755 | ||
756 | /** | 756 | /** |
757 | * Returns the root node of the resource directory. | 757 | * Returns the root node of the resource directory. |
758 | * @return Root node of the resource directory. | 758 | * @return Root node of the resource directory. |
759 | **/ | 759 | **/ |
760 | ResourceNode* ResourceDirectory::getRoot() | 760 | ResourceNode* ResourceDirectory::getRoot() |
761 | { | 761 | { |
762 | return &m_rnRoot; | 762 | return &m_rnRoot; |
763 | } | 763 | } |
764 | 764 | ||
765 | /** | 765 | /** |
766 | * Correctly sorts the resource nodes of the resource tree. This function should be called | 766 | * Correctly sorts the resource nodes of the resource tree. This function should be called |
767 | * before calling rebuild. | 767 | * before calling rebuild. |
768 | **/ | 768 | **/ |
769 | void ResourceDirectory::makeValid() | 769 | void ResourceDirectory::makeValid() |
770 | { | 770 | { |
771 | m_rnRoot.makeValid(); | 771 | m_rnRoot.makeValid(); |
772 | } | 772 | } |
773 | 773 | ||
774 | /** | 774 | /** |
775 | * Reads the resource directory from a file. | 775 | * Reads the resource directory from a file. |
776 | * @param strFilename Name of the file. | 776 | * @param strFilename Name of the file. |
777 | * @param uiOffset File offset of the resource directory. | 777 | * @param uiOffset File offset of the resource directory. |
778 | * @param uiSize Raw size of the resource directory. | 778 | * @param uiSize Raw size of the resource directory. |
779 | * @param uiResDirRva RVA of the beginning of the resource directory. | 779 | * @param uiResDirRva RVA of the beginning of the resource directory. |
780 | **/ | 780 | **/ |
781 | int ResourceDirectory::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize, unsigned int uiResDirRva) | 781 | int ResourceDirectory::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize, unsigned int uiResDirRva) |
782 | { | 782 | { |
783 | if (!uiSize || !uiOffset) | 783 | if (!uiSize || !uiOffset) |
784 | { | 784 | { |
785 | return 1; | 785 | return 1; |
786 | } | 786 | } |
787 | 787 | ||
788 | std::ifstream ifFile(strFilename.c_str(), std::ios::binary); | 788 | std::ifstream ifFile(strFilename.c_str(), std::ios::binary); |
789 | 789 | ||
790 | if (!ifFile) | 790 | if (!ifFile) |
791 | { | 791 | { |
792 | // throw Exceptions::CannotOpenFile(ResourceDirectoryId, __LINE__); | 792 | // throw Exceptions::CannotOpenFile(ResourceDirectoryId, __LINE__); |
793 | return 1; | 793 | return 1; |
794 | } | 794 | } |
795 | 795 | ||
796 | if (fileSize(ifFile) < uiOffset + uiSize) | 796 | if (fileSize(ifFile) < uiOffset + uiSize) |
797 | { | 797 | { |
798 | // throw Exceptions::InvalidFormat(ResourceDirectoryId, __LINE__); | 798 | // throw Exceptions::InvalidFormat(ResourceDirectoryId, __LINE__); |
799 | return 1; | 799 | return 1; |
800 | } | 800 | } |
801 | 801 | ||
802 | ifFile.seekg(uiOffset, std::ios::beg); | 802 | ifFile.seekg(uiOffset, std::ios::beg); |
803 | 803 | ||
804 | PELIB_IMAGE_RESOURCE_DIRECTORY irdCurrRoot; | 804 | PELIB_IMAGE_RESOURCE_DIRECTORY irdCurrRoot; |
805 | 805 | ||
806 | std::vector<byte> vResourceDirectory(uiSize); | 806 | std::vector<byte> vResourceDirectory(uiSize); |
807 | ifFile.read(reinterpret_cast<char*>(&vResourceDirectory[0]), uiSize); | 807 | ifFile.read(reinterpret_cast<char*>(&vResourceDirectory[0]), uiSize); |
808 | 808 | ||
809 | InputBuffer inpBuffer(vResourceDirectory); | 809 | InputBuffer inpBuffer(vResourceDirectory); |
810 | 810 | ||
811 | // ResourceNode currNode; | 811 | // ResourceNode currNode; |
812 | return m_rnRoot.read(inpBuffer, 0, uiResDirRva/*, ""*/); | 812 | return m_rnRoot.read(inpBuffer, 0, uiResDirRva/*, ""*/); |
813 | // std::swap(currNode, m_rnRoot); | 813 | // std::swap(currNode, m_rnRoot); |
814 | } | 814 | } |
815 | 815 | ||
816 | /** | 816 | /** |
817 | * Rebuilds the resource directory. | 817 | * Rebuilds the resource directory. |
818 | * @param vBuffer Buffer the source directory will be written to. | 818 | * @param vBuffer Buffer the source directory will be written to. |
819 | * @param uiRva RVA of the resource directory. | 819 | * @param uiRva RVA of the resource directory. |
820 | **/ | 820 | **/ |
821 | void ResourceDirectory::rebuild(std::vector<byte>& vBuffer, unsigned int uiRva) const | 821 | void ResourceDirectory::rebuild(std::vector<byte>& vBuffer, unsigned int uiRva) const |
822 | { | 822 | { |
823 | OutputBuffer obBuffer(vBuffer); | 823 | OutputBuffer obBuffer(vBuffer); |
824 | unsigned int offs = 0; | 824 | unsigned int offs = 0; |
825 | // std::cout << "Root: " << m_rnRoot.children.size() << std::endl; | 825 | // std::cout << "Root: " << m_rnRoot.children.size() << std::endl; |
826 | m_rnRoot.rebuild(obBuffer, offs, uiRva, ""); | 826 | m_rnRoot.rebuild(obBuffer, offs, uiRva, ""); |
827 | } | 827 | } |
828 | 828 | ||
829 | /** | 829 | /** |
830 | * Returns the size of the entire rebuilt resource directory. That's the size of the entire | 830 | * Returns the size of the entire rebuilt resource directory. That's the size of the entire |
831 | * structure as it's written back to a file. | 831 | * structure as it's written back to a file. |
832 | **/ | 832 | **/ |
833 | /* unsigned int ResourceDirectory::size() const | 833 | /* unsigned int ResourceDirectory::size() const |
834 | { | 834 | { |
835 | return m_rnRoot.size(); | 835 | return m_rnRoot.size(); |
836 | } | 836 | } |
837 | */ | 837 | */ |
838 | /** | 838 | /** |
839 | * Writes the current resource directory back into a file. | 839 | * Writes the current resource directory back into a file. |
840 | * @param strFilename Name of the output file. | 840 | * @param strFilename Name of the output file. |
841 | * @param uiOffset File offset where the resource directory will be written to. | 841 | * @param uiOffset File offset where the resource directory will be written to. |
842 | * @param uiRva RVA of the file offset. | 842 | * @param uiRva RVA of the file offset. |
843 | **/ | 843 | **/ |
844 | int ResourceDirectory::write(const std::string& strFilename, unsigned int uiOffset, unsigned int uiRva) const | 844 | int ResourceDirectory::write(const std::string& strFilename, unsigned int uiOffset, unsigned int uiRva) const |
845 | { | 845 | { |
846 | std::fstream ofFile(strFilename.c_str(), std::ios_base::in); | 846 | std::fstream ofFile(strFilename.c_str(), std::ios_base::in); |
847 | 847 | ||
848 | if (!ofFile) | 848 | if (!ofFile) |
849 | { | 849 | { |
850 | ofFile.clear(); | 850 | ofFile.clear(); |
851 | ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); | 851 | ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); |
852 | } | 852 | } |
853 | else | 853 | else |
854 | { | 854 | { |
855 | ofFile.close(); | 855 | ofFile.close(); |
856 | ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); | 856 | ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); |
857 | } | 857 | } |
858 | 858 | ||
859 | if (!ofFile) | 859 | if (!ofFile) |
860 | { | 860 | { |
861 | return ERROR_OPENING_FILE; | 861 | return ERROR_OPENING_FILE; |
862 | } | 862 | } |
863 | 863 | ||
864 | ofFile.seekp(uiOffset, std::ios::beg); | 864 | ofFile.seekp(uiOffset, std::ios::beg); |
865 | 865 | ||
866 | std::vector<unsigned char> vBuffer; | 866 | std::vector<unsigned char> vBuffer; |
867 | rebuild(vBuffer, uiRva); | 867 | rebuild(vBuffer, uiRva); |
868 | 868 | ||
869 | ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size())); | 869 | ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size())); |
870 | 870 | ||
871 | ofFile.close(); | 871 | ofFile.close(); |
872 | 872 | ||
873 | return 0; | 873 | return 0; |
874 | } | 874 | } |
875 | 875 | ||
876 | /** | 876 | /** |
877 | * Adds another resource type. The new resource type is identified by the ID dwResTypeId. | 877 | * Adds another resource type. The new resource type is identified by the ID dwResTypeId. |
878 | * @param dwResTypeId ID which identifies the resource type. | 878 | * @param dwResTypeId ID which identifies the resource type. |
879 | **/ | 879 | **/ |
880 | int ResourceDirectory::addResourceType(dword dwResTypeId) | 880 | int ResourceDirectory::addResourceType(dword dwResTypeId) |
881 | { | 881 | { |
882 | std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalId), dwResTypeId)); | 882 | std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalId), dwResTypeId)); |
883 | if (Iter != m_rnRoot.children.end()) | 883 | if (Iter != m_rnRoot.children.end()) |
884 | { | 884 | { |
885 | return 1; | 885 | return 1; |
886 | // throw Exceptions::EntryAlreadyExists(ResourceDirectoryId, __LINE__); | 886 | // throw Exceptions::EntryAlreadyExists(ResourceDirectoryId, __LINE__); |
887 | } | 887 | } |
888 | 888 | ||
889 | ResourceChild rcCurr; | 889 | ResourceChild rcCurr; |
890 | rcCurr.child = new ResourceNode; | 890 | rcCurr.child = new ResourceNode; |
891 | rcCurr.entry.irde.Name = dwResTypeId; | 891 | rcCurr.entry.irde.Name = dwResTypeId; |
892 | m_rnRoot.children.push_back(rcCurr); | 892 | m_rnRoot.children.push_back(rcCurr); |
893 | 893 | ||
894 | return 0; | 894 | return 0; |
895 | } | 895 | } |
896 | 896 | ||
897 | /** | 897 | /** |
898 | * Adds another resource type. The new resource type is identified by the name strResTypeName. | 898 | * Adds another resource type. The new resource type is identified by the name strResTypeName. |
899 | * @param strResTypeName Name which identifies the resource type. | 899 | * @param strResTypeName Name which identifies the resource type. |
900 | **/ | 900 | **/ |
901 | int ResourceDirectory::addResourceType(const std::string& strResTypeName) | 901 | int ResourceDirectory::addResourceType(const std::string& strResTypeName) |
902 | { | 902 | { |
903 | std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalName), strResTypeName)); | 903 | std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalName), strResTypeName)); |
904 | if (Iter != m_rnRoot.children.end()) | 904 | if (Iter != m_rnRoot.children.end()) |
905 | { | 905 | { |
906 | return 1; | 906 | return 1; |
907 | // throw Exceptions::EntryAlreadyExists(ResourceDirectoryId, __LINE__); | 907 | // throw Exceptions::EntryAlreadyExists(ResourceDirectoryId, __LINE__); |
908 | } | 908 | } |
909 | 909 | ||
910 | ResourceChild rcCurr; | 910 | ResourceChild rcCurr; |
911 | rcCurr.entry.wstrName = strResTypeName; | 911 | rcCurr.entry.wstrName = strResTypeName; |
912 | rcCurr.child = new ResourceNode; | 912 | rcCurr.child = new ResourceNode; |
913 | m_rnRoot.children.push_back(rcCurr); | 913 | m_rnRoot.children.push_back(rcCurr); |
914 | 914 | ||
915 | return 0; | 915 | return 0; |
916 | } | 916 | } |
917 | 917 | ||
918 | /** | 918 | /** |
919 | * Removes the resource type identified by the ID dwResTypeId. | 919 | * Removes the resource type identified by the ID dwResTypeId. |
920 | * @param dwResTypeId ID which identifies the resource type. | 920 | * @param dwResTypeId ID which identifies the resource type. |
921 | **/ | 921 | **/ |
922 | int ResourceDirectory::removeResourceType(dword dwResTypeId) | 922 | int ResourceDirectory::removeResourceType(dword dwResTypeId) |
923 | { | 923 | { |
924 | std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalId), dwResTypeId)); | 924 | std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalId), dwResTypeId)); |
925 | if (Iter == m_rnRoot.children.end()) | 925 | if (Iter == m_rnRoot.children.end()) |
926 | { | 926 | { |
927 | return 1; | 927 | return 1; |
928 | // throw Exceptions::ResourceTypeDoesNotExist(ResourceDirectoryId, __LINE__); | 928 | // throw Exceptions::ResourceTypeDoesNotExist(ResourceDirectoryId, __LINE__); |
929 | } | 929 | } |
930 | 930 | ||
931 | bool isNamed = false; | 931 | bool isNamed = false; |
932 | if (Iter->isNamedResource()) isNamed = true; | 932 | if (Iter->isNamedResource()) isNamed = true; |
933 | 933 | ||
934 | m_rnRoot.children.erase(Iter); | 934 | m_rnRoot.children.erase(Iter); |
935 | 935 | ||
936 | if (isNamed) m_rnRoot.header.NumberOfNamedEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); | 936 | if (isNamed) m_rnRoot.header.NumberOfNamedEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); |
937 | else m_rnRoot.header.NumberOfIdEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); | 937 | else m_rnRoot.header.NumberOfIdEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); |
938 | 938 | ||
939 | return 0; | 939 | return 0; |
940 | } | 940 | } |
941 | 941 | ||
942 | /** | 942 | /** |
943 | * Removes the resource type identified by the name strResTypeName. | 943 | * Removes the resource type identified by the name strResTypeName. |
944 | * @param strResTypeName Name which identifies the resource type. | 944 | * @param strResTypeName Name which identifies the resource type. |
945 | **/ | 945 | **/ |
946 | int ResourceDirectory::removeResourceType(const std::string& strResTypeName) | 946 | int ResourceDirectory::removeResourceType(const std::string& strResTypeName) |
947 | { | 947 | { |
948 | std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalName), strResTypeName)); | 948 | std::vector<ResourceChild>::iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalName), strResTypeName)); |
949 | if (Iter == m_rnRoot.children.end()) | 949 | if (Iter == m_rnRoot.children.end()) |
950 | { | 950 | { |
951 | return 1; | 951 | return 1; |
952 | // throw Exceptions::ResourceTypeDoesNotExist(ResourceDirectoryId, __LINE__); | 952 | // throw Exceptions::ResourceTypeDoesNotExist(ResourceDirectoryId, __LINE__); |
953 | } | 953 | } |
954 | 954 | ||
955 | bool isNamed = false; | 955 | bool isNamed = false; |
956 | if (Iter->isNamedResource()) isNamed = true; | 956 | if (Iter->isNamedResource()) isNamed = true; |
957 | 957 | ||
958 | m_rnRoot.children.erase(Iter); | 958 | m_rnRoot.children.erase(Iter); |
959 | 959 | ||
960 | if (isNamed) m_rnRoot.header.NumberOfNamedEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); | 960 | if (isNamed) m_rnRoot.header.NumberOfNamedEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); |
961 | else m_rnRoot.header.NumberOfIdEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); | 961 | else m_rnRoot.header.NumberOfIdEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); |
962 | 962 | ||
963 | return 0; | 963 | return 0; |
964 | } | 964 | } |
965 | 965 | ||
966 | /** | 966 | /** |
967 | * Removes the resource type identified by the index uiIndex. | 967 | * Removes the resource type identified by the index uiIndex. |
968 | * @param uiIndex Index which identifies the resource type. | 968 | * @param uiIndex Index which identifies the resource type. |
969 | **/ | 969 | **/ |
970 | int ResourceDirectory::removeResourceTypeByIndex(unsigned int uiIndex) | 970 | int ResourceDirectory::removeResourceTypeByIndex(unsigned int uiIndex) |
971 | { | 971 | { |
972 | bool isNamed = false; | 972 | bool isNamed = false; |
973 | if (m_rnRoot.children[uiIndex].isNamedResource()) isNamed = true; | 973 | if (m_rnRoot.children[uiIndex].isNamedResource()) isNamed = true; |
974 | 974 | ||
975 | m_rnRoot.children.erase(m_rnRoot.children.begin() + uiIndex); | 975 | m_rnRoot.children.erase(m_rnRoot.children.begin() + uiIndex); |
976 | 976 | ||
977 | if (isNamed) m_rnRoot.header.NumberOfNamedEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); | 977 | if (isNamed) m_rnRoot.header.NumberOfNamedEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); |
978 | else m_rnRoot.header.NumberOfIdEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); | 978 | else m_rnRoot.header.NumberOfIdEntries = static_cast<PeLib::word>(m_rnRoot.children.size()); |
979 | 979 | ||
980 | return 0; | 980 | return 0; |
981 | } | 981 | } |
982 | 982 | ||
983 | /** | 983 | /** |
984 | * Adds another resource to the resource tree. The first parameter identifies the resource type | 984 | * Adds another resource to the resource tree. The first parameter identifies the resource type |
985 | * of the new resource, the second parameter identifies the resource itself. | 985 | * of the new resource, the second parameter identifies the resource itself. |
986 | * @param dwResTypeId ID of the resource type. | 986 | * @param dwResTypeId ID of the resource type. |
987 | * @param dwResId ID of the resource. | 987 | * @param dwResId ID of the resource. |
988 | **/ | 988 | **/ |
989 | int ResourceDirectory::addResource(dword dwResTypeId, dword dwResId) | 989 | int ResourceDirectory::addResource(dword dwResTypeId, dword dwResId) |
990 | { | 990 | { |
991 | ResourceChild rcCurr; | 991 | ResourceChild rcCurr; |
992 | rcCurr.entry.irde.Name = dwResId; | 992 | rcCurr.entry.irde.Name = dwResId; |
993 | return addResourceT(dwResTypeId, dwResId, rcCurr); | 993 | return addResourceT(dwResTypeId, dwResId, rcCurr); |
994 | } | 994 | } |
995 | 995 | ||
996 | /** | 996 | /** |
997 | * Adds another resource to the resource tree. The first parameter identifies the resource type | 997 | * Adds another resource to the resource tree. The first parameter identifies the resource type |
998 | * of the new resource, the second parameter identifies the resource itself. | 998 | * of the new resource, the second parameter identifies the resource itself. |
999 | * @param dwResTypeId ID of the resource type. | 999 | * @param dwResTypeId ID of the resource type. |
1000 | * @param strResName Name of the resource. | 1000 | * @param strResName Name of the resource. |
1001 | **/ | 1001 | **/ |
1002 | int ResourceDirectory::addResource(dword dwResTypeId, const std::string& strResName) | 1002 | int ResourceDirectory::addResource(dword dwResTypeId, const std::string& strResName) |
1003 | { | 1003 | { |
1004 | ResourceChild rcCurr; | 1004 | ResourceChild rcCurr; |
1005 | rcCurr.entry.wstrName = strResName; | 1005 | rcCurr.entry.wstrName = strResName; |
1006 | return addResourceT(dwResTypeId, strResName, rcCurr); | 1006 | return addResourceT(dwResTypeId, strResName, rcCurr); |
1007 | } | 1007 | } |
1008 | 1008 | ||
1009 | /** | 1009 | /** |
1010 | * Adds another resource to the resource tree. The first parameter identifies the resource type | 1010 | * Adds another resource to the resource tree. The first parameter identifies the resource type |
1011 | * of the new resource, the second parameter identifies the resource itself. | 1011 | * of the new resource, the second parameter identifies the resource itself. |
1012 | * @param strResTypeName Name of the resource type. | 1012 | * @param strResTypeName Name of the resource type. |
1013 | * @param dwResId ID of the resource. | 1013 | * @param dwResId ID of the resource. |
1014 | **/ | 1014 | **/ |
1015 | int ResourceDirectory::addResource(const std::string& strResTypeName, dword dwResId) | 1015 | int ResourceDirectory::addResource(const std::string& strResTypeName, dword dwResId) |
1016 | { | 1016 | { |
1017 | ResourceChild rcCurr; | 1017 | ResourceChild rcCurr; |
1018 | rcCurr.entry.irde.Name = dwResId; | 1018 | rcCurr.entry.irde.Name = dwResId; |
1019 | return addResourceT(strResTypeName, dwResId, rcCurr); | 1019 | return addResourceT(strResTypeName, dwResId, rcCurr); |
1020 | } | 1020 | } |
1021 | 1021 | ||
1022 | /** | 1022 | /** |
1023 | * Adds another resource to the resource tree. The first parameter identifies the resource type | 1023 | * Adds another resource to the resource tree. The first parameter identifies the resource type |
1024 | * of the new resource, the second parameter identifies the resource itself. | 1024 | * of the new resource, the second parameter identifies the resource itself. |
1025 | * @param strResTypeName Name of the resource type. | 1025 | * @param strResTypeName Name of the resource type. |
1026 | * @param strResName Name of the resource. | 1026 | * @param strResName Name of the resource. |
1027 | **/ | 1027 | **/ |
1028 | int ResourceDirectory::addResource(const std::string& strResTypeName, const std::string& strResName) | 1028 | int ResourceDirectory::addResource(const std::string& strResTypeName, const std::string& strResName) |
1029 | { | 1029 | { |
1030 | ResourceChild rcCurr; | 1030 | ResourceChild rcCurr; |
1031 | rcCurr.entry.wstrName = strResName; | 1031 | rcCurr.entry.wstrName = strResName; |
1032 | return addResourceT(strResTypeName, strResName, rcCurr); | 1032 | return addResourceT(strResTypeName, strResName, rcCurr); |
1033 | } | 1033 | } |
1034 | 1034 | ||
1035 | /** | 1035 | /** |
1036 | * Removes a resource from the resource tree. The first parameter identifies the resource type | 1036 | * Removes a resource from the resource tree. The first parameter identifies the resource type |
1037 | * of the new resource, the second parameter identifies the resource itself. | 1037 | * of the new resource, the second parameter identifies the resource itself. |
1038 | * @param dwResTypeIndex ID of the resource type. | 1038 | * @param dwResTypeIndex ID of the resource type. |
1039 | * @param dwResId ID of the resource. | 1039 | * @param dwResId ID of the resource. |
1040 | **/ | 1040 | **/ |
1041 | int ResourceDirectory::removeResource(dword dwResTypeIndex, dword dwResId) | 1041 | int ResourceDirectory::removeResource(dword dwResTypeIndex, dword dwResId) |
1042 | { | 1042 | { |
1043 | return removeResourceT(dwResTypeIndex, dwResId); | 1043 | return removeResourceT(dwResTypeIndex, dwResId); |
1044 | } | 1044 | } |
1045 | 1045 | ||
1046 | /** | 1046 | /** |
1047 | * Removes a resource from the resource tree. The first parameter identifies the resource type | 1047 | * Removes a resource from the resource tree. The first parameter identifies the resource type |
1048 | * of the new resource, the second parameter identifies the resource itself. | 1048 | * of the new resource, the second parameter identifies the resource itself. |
1049 | * @param dwResTypeIndex ID of the resource type. | 1049 | * @param dwResTypeIndex ID of the resource type. |
1050 | * @param strResName Name of the resource. | 1050 | * @param strResName Name of the resource. |
1051 | **/ | 1051 | **/ |
1052 | int ResourceDirectory::removeResource(dword dwResTypeIndex, const std::string& strResName) | 1052 | int ResourceDirectory::removeResource(dword dwResTypeIndex, const std::string& strResName) |
1053 | { | 1053 | { |
1054 | return removeResourceT(dwResTypeIndex, strResName); | 1054 | return removeResourceT(dwResTypeIndex, strResName); |
1055 | } | 1055 | } |
1056 | 1056 | ||
1057 | /** | 1057 | /** |
1058 | * Removes a resource from the resource tree. The first parameter identifies the resource type | 1058 | * Removes a resource from the resource tree. The first parameter identifies the resource type |
1059 | * of the new resource, the second parameter identifies the resource itself. | 1059 | * of the new resource, the second parameter identifies the resource itself. |
1060 | * @param strResTypeName Name of the resource type. | 1060 | * @param strResTypeName Name of the resource type. |
1061 | * @param dwResId ID of the resource. | 1061 | * @param dwResId ID of the resource. |
1062 | **/ | 1062 | **/ |
1063 | int ResourceDirectory::removeResource(const std::string& strResTypeName, dword dwResId) | 1063 | int ResourceDirectory::removeResource(const std::string& strResTypeName, dword dwResId) |
1064 | { | 1064 | { |
1065 | return removeResourceT(strResTypeName, dwResId); | 1065 | return removeResourceT(strResTypeName, dwResId); |
1066 | } | 1066 | } |
1067 | 1067 | ||
1068 | /** | 1068 | /** |
1069 | * Removes a resource from the resource tree. The first parameter identifies the resource type | 1069 | * Removes a resource from the resource tree. The first parameter identifies the resource type |
1070 | * of the new resource, the second parameter identifies the resource itself. | 1070 | * of the new resource, the second parameter identifies the resource itself. |
1071 | * @param strResTypeName Name of the resource type. | 1071 | * @param strResTypeName Name of the resource type. |
1072 | * @param strResName Name of the resource. | 1072 | * @param strResName Name of the resource. |
1073 | **/ | 1073 | **/ |
1074 | int ResourceDirectory::removeResource(const std::string& strResTypeName, const std::string& strResName) | 1074 | int ResourceDirectory::removeResource(const std::string& strResTypeName, const std::string& strResName) |
1075 | { | 1075 | { |
1076 | return removeResourceT(strResTypeName, strResName); | 1076 | return removeResourceT(strResTypeName, strResName); |
1077 | } | 1077 | } |
1078 | 1078 | ||
1079 | /** | 1079 | /** |
1080 | * Returns the number of resource types. | 1080 | * Returns the number of resource types. |
1081 | **/ | 1081 | **/ |
1082 | unsigned int ResourceDirectory::getNumberOfResourceTypes() const | 1082 | unsigned int ResourceDirectory::getNumberOfResourceTypes() const |
1083 | { | 1083 | { |
1084 | return static_cast<unsigned int>(m_rnRoot.children.size()); | 1084 | return static_cast<unsigned int>(m_rnRoot.children.size()); |
1085 | } | 1085 | } |
1086 | 1086 | ||
1087 | /** | 1087 | /** |
1088 | * Returns the ID of a resource type which was specified through an index. | 1088 | * Returns the ID of a resource type which was specified through an index. |
1089 | * The valid range of the parameter uiIndex is 0...getNumberOfResourceTypes() - 1. | 1089 | * The valid range of the parameter uiIndex is 0...getNumberOfResourceTypes() - 1. |
1090 | * Leaving the invalid range leads to undefined behaviour. | 1090 | * Leaving the invalid range leads to undefined behaviour. |
1091 | * @param uiIndex Index which identifies a resource type. | 1091 | * @param uiIndex Index which identifies a resource type. |
1092 | * @return The ID of the specified resource type. | 1092 | * @return The ID of the specified resource type. |
1093 | **/ | 1093 | **/ |
1094 | dword ResourceDirectory::getResourceTypeIdByIndex(unsigned int uiIndex) const | 1094 | dword ResourceDirectory::getResourceTypeIdByIndex(unsigned int uiIndex) const |
1095 | { | 1095 | { |
1096 | return m_rnRoot.children[uiIndex].entry.irde.Name; | 1096 | return m_rnRoot.children[uiIndex].entry.irde.Name; |
1097 | } | 1097 | } |
1098 | 1098 | ||
1099 | /** | 1099 | /** |
1100 | * Returns the name of a resource type which was specified through an index. | 1100 | * Returns the name of a resource type which was specified through an index. |
1101 | * The valid range of the parameter uiIndex is 0...getNumberOfResourceTypes() - 1. | 1101 | * The valid range of the parameter uiIndex is 0...getNumberOfResourceTypes() - 1. |
1102 | * Leaving the invalid range leads to undefined behaviour. | 1102 | * Leaving the invalid range leads to undefined behaviour. |
1103 | * @param uiIndex Index which identifies a resource type. | 1103 | * @param uiIndex Index which identifies a resource type. |
1104 | * @return The name of the specified resource type. | 1104 | * @return The name of the specified resource type. |
1105 | **/ | 1105 | **/ |
1106 | std::string ResourceDirectory::getResourceTypeNameByIndex(unsigned int uiIndex) const | 1106 | std::string ResourceDirectory::getResourceTypeNameByIndex(unsigned int uiIndex) const |
1107 | { | 1107 | { |
1108 | return m_rnRoot.children[uiIndex].entry.wstrName; | 1108 | return m_rnRoot.children[uiIndex].entry.wstrName; |
1109 | } | 1109 | } |
1110 | 1110 | ||
1111 | /** | 1111 | /** |
1112 | * Converts the ID of a resource type to an index. | 1112 | * Converts the ID of a resource type to an index. |
1113 | * @param dwResTypeId ID of the resource type. | 1113 | * @param dwResTypeId ID of the resource type. |
1114 | * @return Index of that resource type. | 1114 | * @return Index of that resource type. |
1115 | **/ | 1115 | **/ |
1116 | int ResourceDirectory::resourceTypeIdToIndex(dword dwResTypeId) const | 1116 | int ResourceDirectory::resourceTypeIdToIndex(dword dwResTypeId) const |
1117 | { | 1117 | { |
1118 | std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalId), dwResTypeId)); | 1118 | std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalId), dwResTypeId)); |
1119 | if (Iter == m_rnRoot.children.end()) return -1; | 1119 | if (Iter == m_rnRoot.children.end()) return -1; |
1120 | return static_cast<unsigned int>(std::distance(m_rnRoot.children.begin(), Iter)); | 1120 | return static_cast<unsigned int>(std::distance(m_rnRoot.children.begin(), Iter)); |
1121 | } | 1121 | } |
1122 | 1122 | ||
1123 | /** | 1123 | /** |
1124 | * Converts the name of a resource type to an index. | 1124 | * Converts the name of a resource type to an index. |
1125 | * @param strResTypeName ID of the resource type. | 1125 | * @param strResTypeName ID of the resource type. |
1126 | * @return Index of that resource type. | 1126 | * @return Index of that resource type. |
1127 | **/ | 1127 | **/ |
1128 | int ResourceDirectory::resourceTypeNameToIndex(const std::string& strResTypeName) const | 1128 | int ResourceDirectory::resourceTypeNameToIndex(const std::string& strResTypeName) const |
1129 | { | 1129 | { |
1130 | std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalName), strResTypeName)); | 1130 | std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalName), strResTypeName)); |
1131 | if (Iter == m_rnRoot.children.end()) return -1; | 1131 | if (Iter == m_rnRoot.children.end()) return -1; |
1132 | return static_cast<unsigned int>(std::distance(m_rnRoot.children.begin(), Iter)); | 1132 | return static_cast<unsigned int>(std::distance(m_rnRoot.children.begin(), Iter)); |
1133 | } | 1133 | } |
1134 | 1134 | ||
1135 | /** | 1135 | /** |
1136 | * Returns the number of resources of a specific resource type. | 1136 | * Returns the number of resources of a specific resource type. |
1137 | * @param dwId ID of the resource type. | 1137 | * @param dwId ID of the resource type. |
1138 | * @return Number of resources of resource type dwId. | 1138 | * @return Number of resources of resource type dwId. |
1139 | **/ | 1139 | **/ |
1140 | unsigned int ResourceDirectory::getNumberOfResources(dword dwId) const | 1140 | unsigned int ResourceDirectory::getNumberOfResources(dword dwId) const |
1141 | { | 1141 | { |
1142 | // std::vector<ResourceChild>::const_iterator IterD = m_rnRoot.children.begin(); | 1142 | // std::vector<ResourceChild>::const_iterator IterD = m_rnRoot.children.begin(); |
1143 | // std::cout << dwId << std::endl; | 1143 | // std::cout << dwId << std::endl; |
1144 | // while (IterD != m_rnRoot.children.end()) | 1144 | // while (IterD != m_rnRoot.children.end()) |
1145 | // { | 1145 | // { |
1146 | // std::cout << IterD->entry.irde.Name << std::endl; | 1146 | // std::cout << IterD->entry.irde.Name << std::endl; |
1147 | // ++IterD; | 1147 | // ++IterD; |
1148 | // } | 1148 | // } |
1149 | 1149 | ||
1150 | std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalId), dwId)); | 1150 | std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalId), dwId)); |
1151 | if (Iter == m_rnRoot.children.end()) | 1151 | if (Iter == m_rnRoot.children.end()) |
1152 | { | 1152 | { |
1153 | return 0xFFFFFFFF; | 1153 | return 0xFFFFFFFF; |
1154 | } | 1154 | } |
1155 | else | 1155 | else |
1156 | { | 1156 | { |
1157 | ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child); | 1157 | ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child); |
1158 | return static_cast<unsigned int>(currNode->children.size()); | 1158 | return static_cast<unsigned int>(currNode->children.size()); |
1159 | } | 1159 | } |
1160 | } | 1160 | } |
1161 | 1161 | ||
1162 | /** | 1162 | /** |
1163 | * Returns the number of resources of a specific resource type. | 1163 | * Returns the number of resources of a specific resource type. |
1164 | * @param strResTypeName Name of the resource type. | 1164 | * @param strResTypeName Name of the resource type. |
1165 | * @return Number of resources of resource type strResTypeName. | 1165 | * @return Number of resources of resource type strResTypeName. |
1166 | **/ | 1166 | **/ |
1167 | unsigned int ResourceDirectory::getNumberOfResources(const std::string& strResTypeName) const | 1167 | unsigned int ResourceDirectory::getNumberOfResources(const std::string& strResTypeName) const |
1168 | { | 1168 | { |
1169 | std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalName), strResTypeName)); | 1169 | std::vector<ResourceChild>::const_iterator Iter = std::find_if(m_rnRoot.children.begin(), m_rnRoot.children.end(), std::bind2nd(std::mem_fun_ref(&ResourceChild::equalName), strResTypeName)); |
1170 | if (Iter == m_rnRoot.children.end()) | 1170 | if (Iter == m_rnRoot.children.end()) |
1171 | { | 1171 | { |
1172 | return 0xFFFFFFFF; | 1172 | return 0xFFFFFFFF; |
1173 | } | 1173 | } |
1174 | else | 1174 | else |
1175 | { | 1175 | { |
1176 | ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child); | 1176 | ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child); |
1177 | return static_cast<unsigned int>(currNode->children.size()); | 1177 | return static_cast<unsigned int>(currNode->children.size()); |
1178 | } | 1178 | } |
1179 | } | 1179 | } |
1180 | 1180 | ||
1181 | /** | 1181 | /** |
1182 | * Returns the number of resources of a resource type which was specified through an index. | 1182 | * Returns the number of resources of a resource type which was specified through an index. |
1183 | * The valid range of the parameter uiIndex is 0...getNumberOfResourceTypes() - 1. | 1183 | * The valid range of the parameter uiIndex is 0...getNumberOfResourceTypes() - 1. |
1184 | * Leaving the invalid range leads to undefined behaviour. | 1184 | * Leaving the invalid range leads to undefined behaviour. |
1185 | * @param uiIndex Index which identifies a resource type. | 1185 | * @param uiIndex Index which identifies a resource type. |
1186 | * @return The number of resources of the specified resource type. | 1186 | * @return The number of resources of the specified resource type. |
1187 | **/ | 1187 | **/ |
1188 | unsigned int ResourceDirectory::getNumberOfResourcesByIndex(unsigned int uiIndex) const | 1188 | unsigned int ResourceDirectory::getNumberOfResourcesByIndex(unsigned int uiIndex) const |
1189 | { | 1189 | { |
1190 | ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiIndex].child); | 1190 | ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiIndex].child); |
1191 | return static_cast<unsigned int>(currNode->children.size()); | 1191 | return static_cast<unsigned int>(currNode->children.size()); |
1192 | } | 1192 | } |
1193 | 1193 | ||
1194 | /** | 1194 | /** |
1195 | * Gets the resource data of a specific resource. | 1195 | * Gets the resource data of a specific resource. |
1196 | * @param dwResTypeId Identifies the resource type of the resource. | 1196 | * @param dwResTypeId Identifies the resource type of the resource. |
1197 | * @param dwResId Identifies the resource. | 1197 | * @param dwResId Identifies the resource. |
1198 | * @param data Vector where the data is stored. | 1198 | * @param data Vector where the data is stored. |
1199 | **/ | 1199 | **/ |
1200 | void ResourceDirectory::getResourceData(dword dwResTypeId, dword dwResId, std::vector<byte>& data) const | 1200 | void ResourceDirectory::getResourceData(dword dwResTypeId, dword dwResId, std::vector<byte>& data) const |
1201 | { | 1201 | { |
1202 | getResourceDataT(dwResTypeId, dwResId, data); | 1202 | getResourceDataT(dwResTypeId, dwResId, data); |
1203 | } | 1203 | } |
1204 | 1204 | ||
1205 | /** | 1205 | /** |
1206 | * Gets the resource data of a specific resource. | 1206 | * Gets the resource data of a specific resource. |
1207 | * @param dwResTypeId Identifies the resource type of the resource. | 1207 | * @param dwResTypeId Identifies the resource type of the resource. |
1208 | * @param strResName Identifies the resource. | 1208 | * @param strResName Identifies the resource. |
1209 | * @param data Vector where the data is stored. | 1209 | * @param data Vector where the data is stored. |
1210 | **/ | 1210 | **/ |
1211 | void ResourceDirectory::getResourceData(dword dwResTypeId, const std::string& strResName, std::vector<byte>& data) const | 1211 | void ResourceDirectory::getResourceData(dword dwResTypeId, const std::string& strResName, std::vector<byte>& data) const |
1212 | { | 1212 | { |
1213 | getResourceDataT(dwResTypeId, strResName, data); | 1213 | getResourceDataT(dwResTypeId, strResName, data); |
1214 | } | 1214 | } |
1215 | 1215 | ||
1216 | /** | 1216 | /** |
1217 | * Gets the resource data of a specific resource. | 1217 | * Gets the resource data of a specific resource. |
1218 | * @param strResTypeName Identifies the resource type of the resource. | 1218 | * @param strResTypeName Identifies the resource type of the resource. |
1219 | * @param dwResId Identifies the resource. | 1219 | * @param dwResId Identifies the resource. |
1220 | * @param data Vector where the data is stored. | 1220 | * @param data Vector where the data is stored. |
1221 | **/ | 1221 | **/ |
1222 | void ResourceDirectory::getResourceData(const std::string& strResTypeName, dword dwResId, std::vector<byte>& data) const | 1222 | void ResourceDirectory::getResourceData(const std::string& strResTypeName, dword dwResId, std::vector<byte>& data) const |
1223 | { | 1223 | { |
1224 | getResourceDataT(strResTypeName, dwResId, data); | 1224 | getResourceDataT(strResTypeName, dwResId, data); |
1225 | } | 1225 | } |
1226 | 1226 | ||
1227 | /** | 1227 | /** |
1228 | * Gets the resource data of a specific resource. | 1228 | * Gets the resource data of a specific resource. |
1229 | * @param strResTypeName Identifies the resource type of the resource. | 1229 | * @param strResTypeName Identifies the resource type of the resource. |
1230 | * @param strResName Identifies the resource. | 1230 | * @param strResName Identifies the resource. |
1231 | * @param data Vector where the data is stored. | 1231 | * @param data Vector where the data is stored. |
1232 | **/ | 1232 | **/ |
1233 | void ResourceDirectory::getResourceData(const std::string& strResTypeName, const std::string& strResName, std::vector<byte>& data) const | 1233 | void ResourceDirectory::getResourceData(const std::string& strResTypeName, const std::string& strResName, std::vector<byte>& data) const |
1234 | { | 1234 | { |
1235 | getResourceDataT(strResTypeName, strResName, data); | 1235 | getResourceDataT(strResTypeName, strResName, data); |
1236 | } | 1236 | } |
1237 | 1237 | ||
1238 | /** | 1238 | /** |
1239 | * Gets the resource data of a specific resource by index. | 1239 | * Gets the resource data of a specific resource by index. |
1240 | * The valid range of the parameter uiResTypeIndex is 0...getNumberOfResourceTypes() - 1. | 1240 | * The valid range of the parameter uiResTypeIndex is 0...getNumberOfResourceTypes() - 1. |
1241 | * The valid range of the parameter uiResIndex is 0...getNumberOfResources() - 1. | 1241 | * The valid range of the parameter uiResIndex is 0...getNumberOfResources() - 1. |
1242 | * Leaving the invalid range leads to undefined behaviour. | 1242 | * Leaving the invalid range leads to undefined behaviour. |
1243 | * @param uiResTypeIndex Identifies the resource type of the resource. | 1243 | * @param uiResTypeIndex Identifies the resource type of the resource. |
1244 | * @param uiResIndex Identifies the resource. | 1244 | * @param uiResIndex Identifies the resource. |
1245 | * @param data Vector where the data is stored. | 1245 | * @param data Vector where the data is stored. |
1246 | **/ | 1246 | **/ |
1247 | void ResourceDirectory::getResourceDataByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, std::vector<byte>& data) const | 1247 | void ResourceDirectory::getResourceDataByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, std::vector<byte>& data) const |
1248 | { | 1248 | { |
1249 | ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); | 1249 | ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); |
1250 | currNode = static_cast<ResourceNode*>(currNode->children[uiResIndex].child); | 1250 | currNode = static_cast<ResourceNode*>(currNode->children[uiResIndex].child); |
1251 | ResourceLeaf* currLeaf = static_cast<ResourceLeaf*>(currNode->children[0].child); | 1251 | ResourceLeaf* currLeaf = static_cast<ResourceLeaf*>(currNode->children[0].child); |
1252 | 1252 | ||
1253 | data.assign(currLeaf->m_data.begin(), currLeaf->m_data.end()); | 1253 | data.assign(currLeaf->m_data.begin(), currLeaf->m_data.end()); |
1254 | } | 1254 | } |
1255 | 1255 | ||
1256 | /** | 1256 | /** |
1257 | * Sets the resource data of a specific resource. | 1257 | * Sets the resource data of a specific resource. |
1258 | * @param dwResTypeId Identifies the resource type of the resource. | 1258 | * @param dwResTypeId Identifies the resource type of the resource. |
1259 | * @param dwResId Identifies the resource. | 1259 | * @param dwResId Identifies the resource. |
1260 | * @param data The new resource data. | 1260 | * @param data The new resource data. |
1261 | **/ | 1261 | **/ |
1262 | void ResourceDirectory::setResourceData(dword dwResTypeId, dword dwResId, std::vector<byte>& data) | 1262 | void ResourceDirectory::setResourceData(dword dwResTypeId, dword dwResId, std::vector<byte>& data) |
1263 | { | 1263 | { |
1264 | setResourceDataT(dwResTypeId, dwResId, data); | 1264 | setResourceDataT(dwResTypeId, dwResId, data); |
1265 | } | 1265 | } |
1266 | 1266 | ||
1267 | /** | 1267 | /** |
1268 | * Sets the resource data of a specific resource. | 1268 | * Sets the resource data of a specific resource. |
1269 | * @param dwResTypeId Identifies the resource type of the resource. | 1269 | * @param dwResTypeId Identifies the resource type of the resource. |
1270 | * @param strResName Identifies the resource. | 1270 | * @param strResName Identifies the resource. |
1271 | * @param data The new resource data. | 1271 | * @param data The new resource data. |
1272 | **/ | 1272 | **/ |
1273 | void ResourceDirectory::setResourceData(dword dwResTypeId, const std::string& strResName, std::vector<byte>& data) | 1273 | void ResourceDirectory::setResourceData(dword dwResTypeId, const std::string& strResName, std::vector<byte>& data) |
1274 | { | 1274 | { |
1275 | setResourceDataT(dwResTypeId, strResName, data); | 1275 | setResourceDataT(dwResTypeId, strResName, data); |
1276 | } | 1276 | } |
1277 | 1277 | ||
1278 | /** | 1278 | /** |
1279 | * Sets the resource data of a specific resource. | 1279 | * Sets the resource data of a specific resource. |
1280 | * @param strResTypeName Identifies the resource type of the resource. | 1280 | * @param strResTypeName Identifies the resource type of the resource. |
1281 | * @param dwResId Identifies the resource. | 1281 | * @param dwResId Identifies the resource. |
1282 | * @param data The new resource data. | 1282 | * @param data The new resource data. |
1283 | **/ | 1283 | **/ |
1284 | void ResourceDirectory::setResourceData(const std::string& strResTypeName, dword dwResId, std::vector<byte>& data) | 1284 | void ResourceDirectory::setResourceData(const std::string& strResTypeName, dword dwResId, std::vector<byte>& data) |
1285 | { | 1285 | { |
1286 | setResourceDataT(strResTypeName, dwResId, data); | 1286 | setResourceDataT(strResTypeName, dwResId, data); |
1287 | } | 1287 | } |
1288 | 1288 | ||
1289 | /** | 1289 | /** |
1290 | * Sets the resource data of a specific resource. | 1290 | * Sets the resource data of a specific resource. |
1291 | * @param strResTypeName Identifies the resource type of the resource. | 1291 | * @param strResTypeName Identifies the resource type of the resource. |
1292 | * @param strResName Identifies the resource. | 1292 | * @param strResName Identifies the resource. |
1293 | * @param data The new resource data. | 1293 | * @param data The new resource data. |
1294 | **/ | 1294 | **/ |
1295 | void ResourceDirectory::setResourceData(const std::string& strResTypeName, const std::string& strResName, std::vector<byte>& data) | 1295 | void ResourceDirectory::setResourceData(const std::string& strResTypeName, const std::string& strResName, std::vector<byte>& data) |
1296 | { | 1296 | { |
1297 | setResourceDataT(strResTypeName, strResName, data); | 1297 | setResourceDataT(strResTypeName, strResName, data); |
1298 | } | 1298 | } |
1299 | 1299 | ||
1300 | /** | 1300 | /** |
1301 | * Sets the resource data of a specific resource by index. | 1301 | * Sets the resource data of a specific resource by index. |
1302 | * The valid range of the parameter uiResTypeIndex is 0...getNumberOfResourceTypes() - 1. | 1302 | * The valid range of the parameter uiResTypeIndex is 0...getNumberOfResourceTypes() - 1. |
1303 | * The valid range of the parameter uiResIndex is 0...getNumberOfResources() - 1. | 1303 | * The valid range of the parameter uiResIndex is 0...getNumberOfResources() - 1. |
1304 | * Leaving the invalid range leads to undefined behaviour. | 1304 | * Leaving the invalid range leads to undefined behaviour. |
1305 | * @param uiResTypeIndex Identifies the resource type of the resource. | 1305 | * @param uiResTypeIndex Identifies the resource type of the resource. |
1306 | * @param uiResIndex Identifies the resource. | 1306 | * @param uiResIndex Identifies the resource. |
1307 | * @param data The new resource data. | 1307 | * @param data The new resource data. |
1308 | **/ | 1308 | **/ |
1309 | void ResourceDirectory::setResourceDataByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, std::vector<byte>& data) | 1309 | void ResourceDirectory::setResourceDataByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, std::vector<byte>& data) |
1310 | { | 1310 | { |
1311 | ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); | 1311 | ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); |
1312 | currNode = static_cast<ResourceNode*>(currNode->children[uiResIndex].child); | 1312 | currNode = static_cast<ResourceNode*>(currNode->children[uiResIndex].child); |
1313 | ResourceLeaf* currLeaf = static_cast<ResourceLeaf*>(currNode->children[0].child); | 1313 | ResourceLeaf* currLeaf = static_cast<ResourceLeaf*>(currNode->children[0].child); |
1314 | currLeaf->m_data.assign(data.begin(), data.end()); | 1314 | currLeaf->m_data.assign(data.begin(), data.end()); |
1315 | } | 1315 | } |
1316 | 1316 | ||
1317 | /** | 1317 | /** |
1318 | * Gets the ID of a specific resource. | 1318 | * Gets the ID of a specific resource. |
1319 | * @param dwResTypeId Identifies the resource type of the resource. | 1319 | * @param dwResTypeId Identifies the resource type of the resource. |
1320 | * @param strResName Identifies the resource. | 1320 | * @param strResName Identifies the resource. |
1321 | * @return ID of the specified resource. | 1321 | * @return ID of the specified resource. |
1322 | **/ | 1322 | **/ |
1323 | dword ResourceDirectory::getResourceId(dword dwResTypeId, const std::string& strResName) const | 1323 | dword ResourceDirectory::getResourceId(dword dwResTypeId, const std::string& strResName) const |
1324 | { | 1324 | { |
1325 | return getResourceIdT(dwResTypeId, strResName); | 1325 | return getResourceIdT(dwResTypeId, strResName); |
1326 | } | 1326 | } |
1327 | 1327 | ||
1328 | /** | 1328 | /** |
1329 | * Gets the ID of a specific resource. | 1329 | * Gets the ID of a specific resource. |
1330 | * @param strResTypeName Identifies the resource type of the resource. | 1330 | * @param strResTypeName Identifies the resource type of the resource. |
1331 | * @param strResName Identifies the resource. | 1331 | * @param strResName Identifies the resource. |
1332 | * @return ID of the specified resource. | 1332 | * @return ID of the specified resource. |
1333 | **/ | 1333 | **/ |
1334 | dword ResourceDirectory::getResourceId(const std::string& strResTypeName, const std::string& strResName) const | 1334 | dword ResourceDirectory::getResourceId(const std::string& strResTypeName, const std::string& strResName) const |
1335 | { | 1335 | { |
1336 | return getResourceIdT(strResTypeName, strResName); | 1336 | return getResourceIdT(strResTypeName, strResName); |
1337 | } | 1337 | } |
1338 | 1338 | ||
1339 | /** | 1339 | /** |
1340 | * Gets the ID of a specific resource by index. | 1340 | * Gets the ID of a specific resource by index. |
1341 | * @param uiResTypeIndex Identifies the resource type of the resource. | 1341 | * @param uiResTypeIndex Identifies the resource type of the resource. |
1342 | * @param uiResIndex Identifies the resource. | 1342 | * @param uiResIndex Identifies the resource. |
1343 | * @return ID of the specified resource. | 1343 | * @return ID of the specified resource. |
1344 | **/ | 1344 | **/ |
1345 | dword ResourceDirectory::getResourceIdByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex) const | 1345 | dword ResourceDirectory::getResourceIdByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex) const |
1346 | { | 1346 | { |
1347 | ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); | 1347 | ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); |
1348 | return currNode->children[uiResIndex].entry.irde.Name; | 1348 | return currNode->children[uiResIndex].entry.irde.Name; |
1349 | } | 1349 | } |
1350 | 1350 | ||
1351 | /** | 1351 | /** |
1352 | * Sets the ID of a specific resource. | 1352 | * Sets the ID of a specific resource. |
1353 | * @param dwResTypeId Identifies the resource type of the resource. | 1353 | * @param dwResTypeId Identifies the resource type of the resource. |
1354 | * @param dwResId Identifies the resource. | 1354 | * @param dwResId Identifies the resource. |
1355 | * @param dwNewResId New ID of the resource. | 1355 | * @param dwNewResId New ID of the resource. |
1356 | **/ | 1356 | **/ |
1357 | void ResourceDirectory::setResourceId(dword dwResTypeId, dword dwResId, dword dwNewResId) | 1357 | void ResourceDirectory::setResourceId(dword dwResTypeId, dword dwResId, dword dwNewResId) |
1358 | { | 1358 | { |
1359 | setResourceIdT(dwResTypeId, dwResId, dwNewResId); | 1359 | setResourceIdT(dwResTypeId, dwResId, dwNewResId); |
1360 | } | 1360 | } |
1361 | 1361 | ||
1362 | /** | 1362 | /** |
1363 | * Sets the ID of a specific resource. | 1363 | * Sets the ID of a specific resource. |
1364 | * @param dwResTypeId Identifies the resource type of the resource. | 1364 | * @param dwResTypeId Identifies the resource type of the resource. |
1365 | * @param strResName Identifies the resource. | 1365 | * @param strResName Identifies the resource. |
1366 | * @param dwNewResId New ID of the resource. | 1366 | * @param dwNewResId New ID of the resource. |
1367 | **/ | 1367 | **/ |
1368 | void ResourceDirectory::setResourceId(dword dwResTypeId, const std::string& strResName, dword dwNewResId) | 1368 | void ResourceDirectory::setResourceId(dword dwResTypeId, const std::string& strResName, dword dwNewResId) |
1369 | { | 1369 | { |
1370 | setResourceIdT(dwResTypeId, strResName, dwNewResId); | 1370 | setResourceIdT(dwResTypeId, strResName, dwNewResId); |
1371 | } | 1371 | } |
1372 | 1372 | ||
1373 | /** | 1373 | /** |
1374 | * Sets the ID of a specific resource. | 1374 | * Sets the ID of a specific resource. |
1375 | * @param strResTypeName Identifies the resource type of the resource. | 1375 | * @param strResTypeName Identifies the resource type of the resource. |
1376 | * @param dwResId Identifies the resource. | 1376 | * @param dwResId Identifies the resource. |
1377 | * @param dwNewResId New ID of the resource. | 1377 | * @param dwNewResId New ID of the resource. |
1378 | **/ | 1378 | **/ |
1379 | void ResourceDirectory::setResourceId(const std::string& strResTypeName, dword dwResId, dword dwNewResId) | 1379 | void ResourceDirectory::setResourceId(const std::string& strResTypeName, dword dwResId, dword dwNewResId) |
1380 | { | 1380 | { |
1381 | setResourceIdT(strResTypeName, dwResId, dwNewResId); | 1381 | setResourceIdT(strResTypeName, dwResId, dwNewResId); |
1382 | } | 1382 | } |
1383 | 1383 | ||
1384 | /** | 1384 | /** |
1385 | * Sets the ID of a specific resource. | 1385 | * Sets the ID of a specific resource. |
1386 | * @param strResTypeName Identifies the resource type of the resource. | 1386 | * @param strResTypeName Identifies the resource type of the resource. |
1387 | * @param strResName Identifies the resource. | 1387 | * @param strResName Identifies the resource. |
1388 | * @param dwNewResId New ID of the resource. | 1388 | * @param dwNewResId New ID of the resource. |
1389 | **/ | 1389 | **/ |
1390 | void ResourceDirectory::setResourceId(const std::string& strResTypeName, const std::string& strResName, dword dwNewResId) | 1390 | void ResourceDirectory::setResourceId(const std::string& strResTypeName, const std::string& strResName, dword dwNewResId) |
1391 | { | 1391 | { |
1392 | setResourceIdT(strResTypeName, strResName, dwNewResId); | 1392 | setResourceIdT(strResTypeName, strResName, dwNewResId); |
1393 | } | 1393 | } |
1394 | 1394 | ||
1395 | /** | 1395 | /** |
1396 | * Sets the ID of a specific resource by index. | 1396 | * Sets the ID of a specific resource by index. |
1397 | * @param uiResTypeIndex Identifies the resource type of the resource. | 1397 | * @param uiResTypeIndex Identifies the resource type of the resource. |
1398 | * @param uiResIndex Identifies the resource. | 1398 | * @param uiResIndex Identifies the resource. |
1399 | * @param dwNewResId New ID of the specified resource. | 1399 | * @param dwNewResId New ID of the specified resource. |
1400 | **/ | 1400 | **/ |
1401 | void ResourceDirectory::setResourceIdByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, dword dwNewResId) | 1401 | void ResourceDirectory::setResourceIdByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, dword dwNewResId) |
1402 | { | 1402 | { |
1403 | ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); | 1403 | ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); |
1404 | currNode->children[uiResIndex].entry.irde.Name = dwNewResId; | 1404 | currNode->children[uiResIndex].entry.irde.Name = dwNewResId; |
1405 | } | 1405 | } |
1406 | 1406 | ||
1407 | /** | 1407 | /** |
1408 | * Gets the Name of a specific resource. | 1408 | * Gets the Name of a specific resource. |
1409 | * @param dwResTypeId Identifies the resource type of the resource. | 1409 | * @param dwResTypeId Identifies the resource type of the resource. |
1410 | * @param dwResId Identifies the resource. | 1410 | * @param dwResId Identifies the resource. |
1411 | * @return Name of the specified resource. | 1411 | * @return Name of the specified resource. |
1412 | **/ | 1412 | **/ |
1413 | std::string ResourceDirectory::getResourceName(dword dwResTypeId, dword dwResId) const | 1413 | std::string ResourceDirectory::getResourceName(dword dwResTypeId, dword dwResId) const |
1414 | { | 1414 | { |
1415 | return getResourceNameT(dwResTypeId, dwResId); | 1415 | return getResourceNameT(dwResTypeId, dwResId); |
1416 | } | 1416 | } |
1417 | 1417 | ||
1418 | /** | 1418 | /** |
1419 | * Gets the Name of a specific resource. | 1419 | * Gets the Name of a specific resource. |
1420 | * @param strResTypeName Identifies the resource type of the resource. | 1420 | * @param strResTypeName Identifies the resource type of the resource. |
1421 | * @param dwResId Identifies the resource. | 1421 | * @param dwResId Identifies the resource. |
1422 | * @return Name of the specified resource. | 1422 | * @return Name of the specified resource. |
1423 | **/ | 1423 | **/ |
1424 | std::string ResourceDirectory::getResourceName(const std::string& strResTypeName, dword dwResId) const | 1424 | std::string ResourceDirectory::getResourceName(const std::string& strResTypeName, dword dwResId) const |
1425 | { | 1425 | { |
1426 | return getResourceNameT(strResTypeName, dwResId); | 1426 | return getResourceNameT(strResTypeName, dwResId); |
1427 | } | 1427 | } |
1428 | 1428 | ||
1429 | /** | 1429 | /** |
1430 | * Gets the name of a specific resource by index. | 1430 | * Gets the name of a specific resource by index. |
1431 | * @param uiResTypeIndex Identifies the resource type of the resource. | 1431 | * @param uiResTypeIndex Identifies the resource type of the resource. |
1432 | * @param uiResIndex Identifies the resource. | 1432 | * @param uiResIndex Identifies the resource. |
1433 | * @return Name of the specified resource. | 1433 | * @return Name of the specified resource. |
1434 | **/ | 1434 | **/ |
1435 | std::string ResourceDirectory::getResourceNameByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex) const | 1435 | std::string ResourceDirectory::getResourceNameByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex) const |
1436 | { | 1436 | { |
1437 | ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); | 1437 | ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); |
1438 | return currNode->children[uiResIndex].entry.wstrName; | 1438 | return currNode->children[uiResIndex].entry.wstrName; |
1439 | } | 1439 | } |
1440 | 1440 | ||
1441 | /** | 1441 | /** |
1442 | * Sets the name of a specific resource. | 1442 | * Sets the name of a specific resource. |
1443 | * @param dwResTypeId Identifies the resource type of the resource. | 1443 | * @param dwResTypeId Identifies the resource type of the resource. |
1444 | * @param dwResId Identifies the resource. | 1444 | * @param dwResId Identifies the resource. |
1445 | * @param strNewResName New name of the specified resource. | 1445 | * @param strNewResName New name of the specified resource. |
1446 | **/ | 1446 | **/ |
1447 | void ResourceDirectory::setResourceName(dword dwResTypeId, dword dwResId, const std::string& strNewResName) | 1447 | void ResourceDirectory::setResourceName(dword dwResTypeId, dword dwResId, const std::string& strNewResName) |
1448 | { | 1448 | { |
1449 | setResourceNameT(dwResTypeId, dwResId, strNewResName); | 1449 | setResourceNameT(dwResTypeId, dwResId, strNewResName); |
1450 | } | 1450 | } |
1451 | 1451 | ||
1452 | /** | 1452 | /** |
1453 | * Sets the name of a specific resource. | 1453 | * Sets the name of a specific resource. |
1454 | * @param dwResTypeId Identifies the resource type of the resource. | 1454 | * @param dwResTypeId Identifies the resource type of the resource. |
1455 | * @param strResName Identifies the resource. | 1455 | * @param strResName Identifies the resource. |
1456 | * @param strNewResName New name of the specified resource. | 1456 | * @param strNewResName New name of the specified resource. |
1457 | **/ | 1457 | **/ |
1458 | void ResourceDirectory::setResourceName(dword dwResTypeId, const std::string& strResName, const std::string& strNewResName) | 1458 | void ResourceDirectory::setResourceName(dword dwResTypeId, const std::string& strResName, const std::string& strNewResName) |
1459 | { | 1459 | { |
1460 | setResourceNameT(dwResTypeId, strResName, strNewResName); | 1460 | setResourceNameT(dwResTypeId, strResName, strNewResName); |
1461 | } | 1461 | } |
1462 | 1462 | ||
1463 | /** | 1463 | /** |
1464 | * Sets the name of a specific resource. | 1464 | * Sets the name of a specific resource. |
1465 | * @param strResTypeName Identifies the resource type of the resource. | 1465 | * @param strResTypeName Identifies the resource type of the resource. |
1466 | * @param dwResId Identifies the resource. | 1466 | * @param dwResId Identifies the resource. |
1467 | * @param strNewResName New name of the specified resource. | 1467 | * @param strNewResName New name of the specified resource. |
1468 | **/ | 1468 | **/ |
1469 | void ResourceDirectory::setResourceName(const std::string& strResTypeName, dword dwResId, const std::string& strNewResName) | 1469 | void ResourceDirectory::setResourceName(const std::string& strResTypeName, dword dwResId, const std::string& strNewResName) |
1470 | { | 1470 | { |
1471 | setResourceNameT(strResTypeName, dwResId, strNewResName); | 1471 | setResourceNameT(strResTypeName, dwResId, strNewResName); |
1472 | } | 1472 | } |
1473 | 1473 | ||
1474 | /** | 1474 | /** |
1475 | * Sets the name of a specific resource. | 1475 | * Sets the name of a specific resource. |
1476 | * @param strResTypeName Identifies the resource type of the resource. | 1476 | * @param strResTypeName Identifies the resource type of the resource. |
1477 | * @param strResName Identifies the resource. | 1477 | * @param strResName Identifies the resource. |
1478 | * @param strNewResName New name of the specified resource. | 1478 | * @param strNewResName New name of the specified resource. |
1479 | **/ | 1479 | **/ |
1480 | void ResourceDirectory::setResourceName(const std::string& strResTypeName, const std::string& strResName, const std::string& strNewResName) | 1480 | void ResourceDirectory::setResourceName(const std::string& strResTypeName, const std::string& strResName, const std::string& strNewResName) |
1481 | { | 1481 | { |
1482 | setResourceNameT(strResTypeName, strResName, strNewResName); | 1482 | setResourceNameT(strResTypeName, strResName, strNewResName); |
1483 | } | 1483 | } |
1484 | 1484 | ||
1485 | /** | 1485 | /** |
1486 | * Sets the name of a specific resource by index. | 1486 | * Sets the name of a specific resource by index. |
1487 | * @param uiResTypeIndex Identifies the resource type of the resource. | 1487 | * @param uiResTypeIndex Identifies the resource type of the resource. |
1488 | * @param uiResIndex Identifies the resource. | 1488 | * @param uiResIndex Identifies the resource. |
1489 | * @param strNewResName New name of the specified resource. | 1489 | * @param strNewResName New name of the specified resource. |
1490 | **/ | 1490 | **/ |
1491 | void ResourceDirectory::setResourceNameByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, const std::string& strNewResName) | 1491 | void ResourceDirectory::setResourceNameByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, const std::string& strNewResName) |
1492 | { | 1492 | { |
1493 | ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); | 1493 | ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child); |
1494 | currNode->children[uiResIndex].entry.wstrName = strNewResName; | 1494 | currNode->children[uiResIndex].entry.wstrName = strNewResName; |
1495 | } | 1495 | } |
1496 | 1496 | ||
1497 | } | 1497 | } |