Fix yellow by making the ifdef hell slightly worse
[kugel-rb.git] / utils / zenutils / libraries / pelib-0.9 / pelib / ResourceDirectory.cpp
blobd1e4c59e5a0c2af3ab22c01430b89c1cc312966d
1 /*
2 * ResourceDirectory.h - Part of the PeLib library.
4 * Copyright (c) 2004 - 2005 Sebastian Porst (webmaster@the-interweb.com)
5 * All rights reserved.
7 * This software is licensed under the zlib/libpng License.
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
10 * of PeLib.
13 #include "ResourceDirectory.h"
15 namespace PeLib
17 // -------------------------------------------------- ResourceChild -------------------------------------------
19 ResourceChild::ResourceChild()
23 ResourceChild::ResourceChild(const ResourceChild& rhs)
25 if (dynamic_cast<ResourceNode*>(rhs.child))
27 ResourceNode* oldnode = static_cast<ResourceNode*>(rhs.child);
29 entry = rhs.entry;
31 child = new ResourceNode;
32 child->uiElementRva = rhs.child->getElementRva();
33 static_cast<ResourceNode*>(child)->header = oldnode->header;
34 static_cast<ResourceNode*>(child)->children = oldnode->children;
36 else
38 ResourceLeaf* oldnode = static_cast<ResourceLeaf*>(rhs.child);
40 child = new ResourceLeaf;
41 child->uiElementRva = rhs.child->getElementRva();
42 static_cast<ResourceLeaf*>(child)->m_data = oldnode->m_data;
43 static_cast<ResourceLeaf*>(child)->entry = oldnode->entry;
47 ResourceChild& ResourceChild::operator=(const ResourceChild& rhs)
49 if (this != &rhs)
51 if (dynamic_cast<ResourceNode*>(rhs.child))
53 ResourceNode* oldnode = static_cast<ResourceNode*>(rhs.child);
55 entry = rhs.entry;
57 child = new ResourceNode;
58 child->uiElementRva = rhs.child->getElementRva();
59 static_cast<ResourceNode*>(child)->header = oldnode->header;
60 static_cast<ResourceNode*>(child)->children = oldnode->children;
62 else
64 ResourceLeaf* oldnode = static_cast<ResourceLeaf*>(rhs.child);
66 child = new ResourceLeaf;
67 child->uiElementRva = rhs.child->getElementRva();
68 static_cast<ResourceLeaf*>(child)->m_data = oldnode->m_data;
69 static_cast<ResourceLeaf*>(child)->entry = oldnode->entry;
73 return *this;
76 ResourceChild::~ResourceChild()
78 delete child;
81 /**
82 * Compares the resource child's id to the parameter dwId.
83 * @param dwId ID of a resource.
84 * @return True, if the resource child's id equals the parameter.
85 **/
86 bool ResourceChild::equalId(dword dwId) const
88 return entry.irde.Name == dwId;
91 /**
92 * Compares the resource child's name to the parameter strName.
93 * @param strName ID of a resource.
94 * @return True, if the resource child's name equals the parameter.
95 **/
96 bool ResourceChild::equalName(std::string strName) const
98 return entry.wstrName == strName;
102 * Returns true if the resource was given a name.
104 bool ResourceChild::isNamedResource() const
106 return entry.wstrName.size() != 0;
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.
113 bool ResourceChild::operator<(const ResourceChild& rc) const
115 if (this->isNamedResource() && !rc.isNamedResource())
117 return true;
119 else if (!this->isNamedResource() && rc.isNamedResource())
121 return false;
123 else if (this->isNamedResource() && rc.isNamedResource())
125 return this->entry.wstrName < rc.entry.wstrName;
127 else
129 return this->entry.irde.Name < rc.entry.irde.Name;
133 /* unsigned int ResourceChild::size() const
135 return PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY::size()
136 + child->size()
137 + (entry.wstrName.size() ? entry.wstrName.size() + 2 : 0);
140 // -------------------------------------------------- ResourceElement -------------------------------------------
143 * Returns the RVA of a ResourceElement. This is the RVA where the ResourceElement can be
144 * found in the file.
145 * @return RVA of the ResourceElement.
147 unsigned int ResourceElement::getElementRva() const
149 return uiElementRva;
152 // -------------------------------------------------- ResourceLeaf -------------------------------------------
155 * Checks if a ResourceElement is a leaf or not.
156 * @return Always returns true.
158 bool ResourceLeaf::isLeaf() const
160 return true;
164 * Reads the next resource leaf from the InputBuffer.
165 * @param inpBuffer An InputBuffer that holds the complete resource directory.
166 * @param uiOffset Offset of the resource leaf that's to be read.
167 * @param uiRva RVA of the beginning of the resource directory.
168 * @param pad Used for debugging purposes.
170 int ResourceLeaf::read(InputBuffer& inpBuffer, unsigned int uiOffset, unsigned int uiRva/*, const std::string& pad*/)
172 // std::cout << pad << "Leaf:" << std::endl;
174 // Invalid leaf.
175 if (uiOffset + PELIB_IMAGE_RESOURCE_DATA_ENTRY::size() > inpBuffer.size())
177 return 1;
180 uiElementRva = uiOffset + uiRva;
182 inpBuffer.set(uiOffset);
184 inpBuffer >> entry.OffsetToData;
185 inpBuffer >> entry.Size;
186 inpBuffer >> entry.CodePage;
187 inpBuffer >> entry.Reserved;
189 /* std::cout << pad << std::hex << "Offset: " << entry.OffsetToData << std::endl;
190 std::cout << pad << std::hex << "Size: " << entry.Size << std::endl;
191 std::cout << pad << std::hex << "CodePage: " << entry.CodePage << std::endl;
192 std::cout << pad << std::hex << "Reserved: " << entry.Reserved << std::endl;
194 // Invalid leaf.
195 if (entry.OffsetToData - uiRva + entry.Size > inpBuffer.size())
197 // std::cout << entry.OffsetToData << " XXX " << uiRva << " - " << entry.Size << " - " << inpBuffer.size() << std::endl;
198 return 1;
201 // std::cout << entry.OffsetToData << " - " << uiRva << " - " << entry.Size << " - " << inpBuffer.size() << std::endl;
202 inpBuffer.set(entry.OffsetToData - uiRva);
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;
205 // std::copy(m_data.begin(), m_data.end(), std::ostream_iterator<int>(std::cout << std::hex, " "));
206 return 0;
210 * Rebuilds the current resource leaf.
211 * @param obBuffer OutputBuffer where the rebuilt resource leaf is stored.
212 * @param uiOffset Offset of the resource leaf inside the resource directory.
213 * @param uiRva RVA of the resource directory.
215 void ResourceLeaf::rebuild(OutputBuffer& obBuffer, unsigned int& uiOffset, unsigned int uiRva, const std::string&) const
217 // std::cout << std::hex << pad << "Leaf: " << uiOffset << std::endl;
218 uiOffset += PELIB_IMAGE_RESOURCE_DATA_ENTRY::size();
220 // obBuffer << entry.OffsetToData;
221 // obBuffer << uiOffset;
222 obBuffer << uiRva + uiOffset + (uiOffset % 4);
223 obBuffer << entry.Size;
224 obBuffer << entry.CodePage;
225 obBuffer << entry.Reserved;
227 while (uiOffset % 4)
229 uiOffset++;
230 obBuffer << (byte)0;
233 uiOffset += static_cast<unsigned int>(m_data.size());
235 for (unsigned int i=0;i<m_data.size();i++)
237 obBuffer << m_data[i];
239 // std::cout << "LeafChild: " << std::endl;
242 void ResourceLeaf::makeValid()
244 entry.Size = static_cast<unsigned int>(m_data.size());
247 /* /// Returns the size of a resource leaf.
248 unsigned int ResourceLeaf::size() const
250 return PELIB_IMAGE_RESOURCE_DATA_ENTRY::size() + m_data.size();
255 * Returns a vector that contains the raw data of a resource leaf.
256 * @return Raw data of the resource.
258 std::vector<byte> ResourceLeaf::getData() const
260 return m_data;
264 * Overwrites the raw data of a resource.
265 * @param vData New data of the resource.
267 void ResourceLeaf::setData(const std::vector<byte>& vData)
269 m_data = vData;
273 * Returns the leaf's OffsetToData value. That's the RVA where the raw data of the resource
274 * can be found.
275 * @return The leaf's OffsetToData value.
277 dword ResourceLeaf::getOffsetToData() const
279 return entry.OffsetToData;
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.
286 dword ResourceLeaf::getSize() const
288 return entry.Size;
292 * Returns the leaf's CodePage value.
293 * @return The leaf's CodePage value.
295 dword ResourceLeaf::getCodePage() const
297 return entry.CodePage;
301 * Returns the leaf's Reserved value.
302 * @return The leaf's Reserved value.
304 dword ResourceLeaf::getReserved() const
306 return entry.Reserved;
310 * Sets the leaf's OffsetToData value.
311 * @param dwValue The leaf's new OffsetToData value.
313 void ResourceLeaf::setOffsetToData(dword dwValue)
315 entry.OffsetToData = dwValue;
319 * Sets the leaf's Size value.
320 * @param dwValue The leaf's new Size value.
322 void ResourceLeaf::setSize(dword dwValue)
324 entry.Size = dwValue;
328 * Sets the leaf's CodePage value.
329 * @param dwValue The leaf's new CodePage value.
331 void ResourceLeaf::setCodePage(dword dwValue)
333 entry.CodePage = dwValue;
337 * Sets the leaf's Reserved value.
338 * @param dwValue The leaf's new Reserved value.
340 void ResourceLeaf::setReserved(dword dwValue)
342 entry.Reserved = dwValue;
346 // -------------------------------------------------- ResourceNode -------------------------------------------
349 * Checks if a ResourceElement is a leaf or not.
350 * @return Always returns false.
352 bool ResourceNode::isLeaf() const
354 return false;
358 * Sorts the node's children and corrects the node's header.
360 void ResourceNode::makeValid()
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)));
364 header.NumberOfIdEntries = static_cast<unsigned int>(children.size()) - header.NumberOfNamedEntries;
368 * Rebuilds the current resource node.
369 * @param obBuffer OutputBuffer where the rebuilt resource node is stored.
370 * @param uiOffset Offset of the resource node inside the resource directory.
371 * @param uiRva RVA of the resource directory.
372 * @param pad Used for debugging.
374 void ResourceNode::rebuild(OutputBuffer& obBuffer, unsigned int& uiOffset, unsigned int uiRva, const std::string& pad) const
376 /* std::cout << std::hex << pad << uiOffset << 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;
380 std::cout << std::hex << pad << "header.MajorVersion: " << header.MajorVersion << 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;
383 std::cout << std::hex << pad << "header.NumberOfIdEntries: " << header.NumberOfIdEntries << std::endl;
385 obBuffer << header.Characteristics;
386 obBuffer << header.TimeDateStamp;
387 obBuffer << header.MajorVersion;
388 obBuffer << header.MinorVersion;
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;
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));
393 // obBuffer << children.size() - std::count_if(children.begin(), children.end(), std::mem_fun_ref(&ResourceChild::isNamedResource));
394 obBuffer << header.NumberOfNamedEntries;
395 obBuffer << header.NumberOfIdEntries;
397 uiOffset += PELIB_IMAGE_RESOURCE_DIRECTORY::size();
399 for (unsigned int i=0;i<children.size();i++)
401 obBuffer << (dword)0;
402 obBuffer << (dword)0;
405 unsigned int newoffs = (uiOffset + children.size() * 8);
407 for (unsigned int i=0;i<children.size();i++)
409 if (!children[i].entry.wstrName.size())
411 obBuffer.update(uiOffset, children[i].entry.irde.Name);
413 else
415 obBuffer.update(uiOffset, newoffs | PELIB_IMAGE_RESOURCE_NAME_IS_STRING);
416 obBuffer << (word)children[i].entry.wstrName.size();
417 newoffs += 2;
418 for (unsigned int j=0;j<children[i].entry.wstrName.size();j++)
420 // std::cout << children[i].entry.wstrName[j];
421 obBuffer << (word)children[i].entry.wstrName[j];
422 newoffs += 2;
425 uiOffset += 4;
426 // obBuffer << children[i].entry.OffsetToData;
427 obBuffer.update(uiOffset, newoffs | (children[i].entry.irde.OffsetToData & PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY));
428 uiOffset += 4;
429 children[i].child->rebuild(obBuffer, newoffs, uiRva, pad + " ");
431 uiOffset = newoffs;
435 * Reads the next resource node from the InputBuffer.
436 * @param inpBuffer An InputBuffer that holds the complete resource directory.
437 * @param uiOffset Offset of the resource node that's to be read.
438 * @param uiRva RVA of the beginning of the resource directory.
439 * @param pad Something I need for debugging. Will be removed soon.
441 int ResourceNode::read(InputBuffer& inpBuffer, unsigned int uiOffset, unsigned int uiRva/*, const std::string& pad*/)
443 // Not enough space to be a valid node.
444 if (uiOffset + PELIB_IMAGE_RESOURCE_DIRECTORY::size() > inpBuffer.size())
446 return 1;
449 uiElementRva = uiOffset + uiRva;
451 inpBuffer.set(uiOffset);
453 inpBuffer >> header.Characteristics;
454 inpBuffer >> header.TimeDateStamp;
455 inpBuffer >> header.MajorVersion;
456 inpBuffer >> header.MinorVersion;
457 inpBuffer >> header.NumberOfNamedEntries;
458 inpBuffer >> header.NumberOfIdEntries;
460 // Not enough space to be a valid node.
461 if (uiOffset + PELIB_IMAGE_RESOURCE_DIRECTORY::size()
462 + (header.NumberOfNamedEntries + header.NumberOfIdEntries) * PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY::size()
463 > inpBuffer.size())
465 return 1;
468 // std::cout << std::hex << pad << "Characteristics: " << header.Characteristics << std::endl;
469 // std::cout << std::hex << pad << "TimeDateStamp: " << header.TimeDateStamp << std::endl;
470 // std::cout << std::hex << pad << "MajorVersion: " << header.MajorVersion << std::endl;
471 // std::cout << std::hex << pad << "MinorVersion: " << header.MinorVersion << std::endl;
472 // std::cout << std::hex << pad << "NumberOfNamedEntries: " << header.NumberOfNamedEntries << std::endl;
473 // std::cout << std::hex << pad << "NumberOfIdEntries: " << header.NumberOfIdEntries << std::endl;
475 for (int i=0;i<header.NumberOfNamedEntries + header.NumberOfIdEntries;i++)
477 ResourceChild rc;
478 inpBuffer >> rc.entry.irde.Name;
479 inpBuffer >> rc.entry.irde.OffsetToData;
481 unsigned int lastPos = inpBuffer.get();
483 if (rc.entry.irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING)
485 // Enough space to read string length?
486 if ((rc.entry.irde.Name & ~PELIB_IMAGE_RESOURCE_NAME_IS_STRING) + 2 < inpBuffer.size())
488 inpBuffer.set(rc.entry.irde.Name & ~PELIB_IMAGE_RESOURCE_NAME_IS_STRING);
489 word strlen;
490 inpBuffer >> strlen;
492 // Enough space to read string?
493 if ((rc.entry.irde.Name & ~PELIB_IMAGE_RESOURCE_NAME_IS_STRING) + 2 * strlen < inpBuffer.size())
495 wchar_t c;
496 for (word i=0;i<strlen;i++)
498 inpBuffer >> c;
499 rc.entry.wstrName += c;
504 // std::wcout << rc.entry.wstrName << std::endl;
506 // std::cout << strlen << std::endl;
507 inpBuffer.set(lastPos);
510 if (rc.entry.irde.OffsetToData & PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY)
512 rc.child = new ResourceNode;
513 rc.child->read(inpBuffer, rc.entry.irde.OffsetToData & ~PELIB_IMAGE_RESOURCE_DATA_IS_DIRECTORY, uiRva/*, pad + " "*/);
515 else
517 rc.child = new ResourceLeaf;
518 rc.child->read(inpBuffer, rc.entry.irde.OffsetToData, uiRva/*, pad + " "*/);
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;
523 children.push_back(rc);
524 inpBuffer.set(lastPos);
527 return 0;
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.
533 * @return Number of node's children.
535 unsigned int ResourceNode::getNumberOfChildren() const
537 return static_cast<unsigned int>(children.size());
541 * Adds another child to the current node.
543 void ResourceNode::addChild()
545 ResourceChild c;
546 c.child = 0;
547 children.push_back(c);
551 * Returns a node's 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.
555 ResourceElement* ResourceNode::getChild(unsigned int uiIndex)
557 return children[uiIndex].child;
561 * Removes a child from the current node.
562 * @param uiIndex Index of the child.
564 void ResourceNode::removeChild(unsigned int uiIndex)
566 children.erase(children.begin() + uiIndex);
570 * Returns the name of a child.
571 * @param uiIndex Index of the child.
572 * @return Either the name of the specified child or an empty string.
574 std::string ResourceNode::getChildName(unsigned int uiIndex) const
576 return children[uiIndex].entry.wstrName;
580 * Returns the Name value of a child.
581 * @param uiIndex Index of the child.
582 * @return Name value of a child.
584 dword ResourceNode::getOffsetToChildName(unsigned int uiIndex) const
586 return children[uiIndex].entry.irde.Name;
590 * Returns the OffsetToData value of a child.
591 * @param uiIndex Index of the child.
592 * @return OffsetToData value of a child.
594 dword ResourceNode::getOffsetToChildData(unsigned int uiIndex) const
596 return children[uiIndex].entry.irde.OffsetToData;
601 * Sets the name of a child.
602 * @param uiIndex Index of the child.
603 * @param strNewName New name of the resource.
605 void ResourceNode::setChildName(unsigned int uiIndex, const std::string& strNewName)
607 children[uiIndex].entry.wstrName = strNewName;
611 * Sets the Name value of a child.
612 * @param uiIndex Index of the child.
613 * @param dwNewOffset New Name value of the resource.
615 void ResourceNode::setOffsetToChildName(unsigned int uiIndex, dword dwNewOffset)
617 children[uiIndex].entry.irde.Name = dwNewOffset;
621 * Sets the OffsetToData value of a child.
622 * @param uiIndex Index of the child.
623 * @param dwNewOffset New OffsetToData value of the resource.
625 void ResourceNode::setOffsetToChildData(unsigned int uiIndex, dword dwNewOffset)
627 children[uiIndex].entry.irde.OffsetToData = dwNewOffset;
631 * Returns the Characteristics value of the node.
632 * @return Characteristics value of the node.
634 dword ResourceNode::getCharacteristics() const
636 return header.Characteristics;
640 * Returns the TimeDateStamp value of the node.
641 * @return TimeDateStamp value of the node.
643 dword ResourceNode::getTimeDateStamp() const
645 return header.TimeDateStamp;
649 * Returns the MajorVersion value of the node.
650 * @return MajorVersion value of the node.
652 word ResourceNode::getMajorVersion() const
654 return header.MajorVersion;
658 * Returns the MinorVersion value of the node.
659 * @return MinorVersion value of the node.
661 word ResourceNode::getMinorVersion() const
663 return header.MinorVersion;
667 * Returns the NumberOfNamedEntries value of the node.
668 * @return NumberOfNamedEntries value of the node.
670 word ResourceNode::getNumberOfNamedEntries() const
672 return header.NumberOfNamedEntries;
676 * Returns the NumberOfIdEntries value of the node.
677 * @return NumberOfIdEntries value of the node.
679 word ResourceNode::getNumberOfIdEntries() const
681 return header.NumberOfIdEntries;
685 * Sets the Characteristics value of the node.
686 * @param value New Characteristics value of the node.
688 void ResourceNode::setCharacteristics(dword value)
690 header.Characteristics = value;
694 * Sets the TimeDateStamp value of the node.
695 * @param value New TimeDateStamp value of the node.
697 void ResourceNode::setTimeDateStamp(dword value)
699 header.TimeDateStamp = value;
703 * Sets the MajorVersion value of the node.
704 * @param value New MajorVersion value of the node.
706 void ResourceNode::setMajorVersion(word value)
708 header.MajorVersion = value;
712 * Sets the MinorVersion value of the node.
713 * @param value New MinorVersion value of the node.
715 void ResourceNode::setMinorVersion(word value)
717 header.MinorVersion = value;
721 * Sets the NumberOfNamedEntries value of the node.
722 * @param value New NumberOfNamedEntries value of the node.
724 void ResourceNode::setNumberOfNamedEntries(word value)
726 header.NumberOfNamedEntries = value;
730 * Sets the NumberOfIdEntries value of the node.
731 * @param value New NumberOfIdEntries value of the node.
733 void ResourceNode::setNumberOfIdEntries(word value)
735 header.NumberOfIdEntries = value;
739 /* /// Returns the size of a resource node.
740 unsigned int ResourceNode::size() const
742 if (children.size())
744 std::cout << std::accumulate(children.begin(), children.end(), 0, accumulate<ResourceChild>) << std::endl;
745 return PELIB_IMAGE_RESOURCE_DIRECTORY::size()
746 + std::accumulate(children.begin(), children.end(), 0, accumulate<ResourceChild>);
748 else
750 return 0;
754 // -------------------------------------------------- ResourceDirectory -------------------------------------------
757 * Returns the root node of the resource directory.
758 * @return Root node of the resource directory.
760 ResourceNode* ResourceDirectory::getRoot()
762 return &m_rnRoot;
766 * Correctly sorts the resource nodes of the resource tree. This function should be called
767 * before calling rebuild.
769 void ResourceDirectory::makeValid()
771 m_rnRoot.makeValid();
775 * Reads the resource directory from a file.
776 * @param strFilename Name of the file.
777 * @param uiOffset File offset of the resource directory.
778 * @param uiSize Raw size of the resource directory.
779 * @param uiResDirRva RVA of the beginning of the resource directory.
781 int ResourceDirectory::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize, unsigned int uiResDirRva)
783 if (!uiSize || !uiOffset)
785 return 1;
788 std::ifstream ifFile(strFilename.c_str(), std::ios::binary);
790 if (!ifFile)
792 // throw Exceptions::CannotOpenFile(ResourceDirectoryId, __LINE__);
793 return 1;
796 if (fileSize(ifFile) < uiOffset + uiSize)
798 // throw Exceptions::InvalidFormat(ResourceDirectoryId, __LINE__);
799 return 1;
802 ifFile.seekg(uiOffset, std::ios::beg);
804 PELIB_IMAGE_RESOURCE_DIRECTORY irdCurrRoot;
806 std::vector<byte> vResourceDirectory(uiSize);
807 ifFile.read(reinterpret_cast<char*>(&vResourceDirectory[0]), uiSize);
809 InputBuffer inpBuffer(vResourceDirectory);
811 // ResourceNode currNode;
812 return m_rnRoot.read(inpBuffer, 0, uiResDirRva/*, ""*/);
813 // std::swap(currNode, m_rnRoot);
817 * Rebuilds the resource directory.
818 * @param vBuffer Buffer the source directory will be written to.
819 * @param uiRva RVA of the resource directory.
821 void ResourceDirectory::rebuild(std::vector<byte>& vBuffer, unsigned int uiRva) const
823 OutputBuffer obBuffer(vBuffer);
824 unsigned int offs = 0;
825 // std::cout << "Root: " << m_rnRoot.children.size() << std::endl;
826 m_rnRoot.rebuild(obBuffer, offs, uiRva, "");
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.
833 /* unsigned int ResourceDirectory::size() const
835 return m_rnRoot.size();
839 * Writes the current resource directory back into a file.
840 * @param strFilename Name of the output file.
841 * @param uiOffset File offset where the resource directory will be written to.
842 * @param uiRva RVA of the file offset.
844 int ResourceDirectory::write(const std::string& strFilename, unsigned int uiOffset, unsigned int uiRva) const
846 std::fstream ofFile(strFilename.c_str(), std::ios_base::in);
848 if (!ofFile)
850 ofFile.clear();
851 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary);
853 else
855 ofFile.close();
856 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
859 if (!ofFile)
861 return ERROR_OPENING_FILE;
864 ofFile.seekp(uiOffset, std::ios::beg);
866 std::vector<unsigned char> vBuffer;
867 rebuild(vBuffer, uiRva);
869 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<unsigned int>(vBuffer.size()));
871 ofFile.close();
873 return 0;
877 * Adds another resource type. The new resource type is identified by the ID dwResTypeId.
878 * @param dwResTypeId ID which identifies the resource type.
880 int ResourceDirectory::addResourceType(dword 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())
885 return 1;
886 // throw Exceptions::EntryAlreadyExists(ResourceDirectoryId, __LINE__);
889 ResourceChild rcCurr;
890 rcCurr.child = new ResourceNode;
891 rcCurr.entry.irde.Name = dwResTypeId;
892 m_rnRoot.children.push_back(rcCurr);
894 return 0;
898 * Adds another resource type. The new resource type is identified by the name strResTypeName.
899 * @param strResTypeName Name which identifies the resource type.
901 int ResourceDirectory::addResourceType(const std::string& 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())
906 return 1;
907 // throw Exceptions::EntryAlreadyExists(ResourceDirectoryId, __LINE__);
910 ResourceChild rcCurr;
911 rcCurr.entry.wstrName = strResTypeName;
912 rcCurr.child = new ResourceNode;
913 m_rnRoot.children.push_back(rcCurr);
915 return 0;
919 * Removes the resource type identified by the ID dwResTypeId.
920 * @param dwResTypeId ID which identifies the resource type.
922 int ResourceDirectory::removeResourceType(dword 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())
927 return 1;
928 // throw Exceptions::ResourceTypeDoesNotExist(ResourceDirectoryId, __LINE__);
931 bool isNamed = false;
932 if (Iter->isNamedResource()) isNamed = true;
934 m_rnRoot.children.erase(Iter);
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());
939 return 0;
943 * Removes the resource type identified by the name strResTypeName.
944 * @param strResTypeName Name which identifies the resource type.
946 int ResourceDirectory::removeResourceType(const std::string& 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())
951 return 1;
952 // throw Exceptions::ResourceTypeDoesNotExist(ResourceDirectoryId, __LINE__);
955 bool isNamed = false;
956 if (Iter->isNamedResource()) isNamed = true;
958 m_rnRoot.children.erase(Iter);
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());
963 return 0;
967 * Removes the resource type identified by the index uiIndex.
968 * @param uiIndex Index which identifies the resource type.
970 int ResourceDirectory::removeResourceTypeByIndex(unsigned int uiIndex)
972 bool isNamed = false;
973 if (m_rnRoot.children[uiIndex].isNamedResource()) isNamed = true;
975 m_rnRoot.children.erase(m_rnRoot.children.begin() + uiIndex);
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());
980 return 0;
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.
986 * @param dwResTypeId ID of the resource type.
987 * @param dwResId ID of the resource.
989 int ResourceDirectory::addResource(dword dwResTypeId, dword dwResId)
991 ResourceChild rcCurr;
992 rcCurr.entry.irde.Name = dwResId;
993 return addResourceT(dwResTypeId, dwResId, rcCurr);
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.
999 * @param dwResTypeId ID of the resource type.
1000 * @param strResName Name of the resource.
1002 int ResourceDirectory::addResource(dword dwResTypeId, const std::string& strResName)
1004 ResourceChild rcCurr;
1005 rcCurr.entry.wstrName = strResName;
1006 return addResourceT(dwResTypeId, strResName, rcCurr);
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.
1012 * @param strResTypeName Name of the resource type.
1013 * @param dwResId ID of the resource.
1015 int ResourceDirectory::addResource(const std::string& strResTypeName, dword dwResId)
1017 ResourceChild rcCurr;
1018 rcCurr.entry.irde.Name = dwResId;
1019 return addResourceT(strResTypeName, dwResId, rcCurr);
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.
1025 * @param strResTypeName Name of the resource type.
1026 * @param strResName Name of the resource.
1028 int ResourceDirectory::addResource(const std::string& strResTypeName, const std::string& strResName)
1030 ResourceChild rcCurr;
1031 rcCurr.entry.wstrName = strResName;
1032 return addResourceT(strResTypeName, strResName, rcCurr);
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.
1038 * @param dwResTypeIndex ID of the resource type.
1039 * @param dwResId ID of the resource.
1041 int ResourceDirectory::removeResource(dword dwResTypeIndex, dword dwResId)
1043 return removeResourceT(dwResTypeIndex, dwResId);
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.
1049 * @param dwResTypeIndex ID of the resource type.
1050 * @param strResName Name of the resource.
1052 int ResourceDirectory::removeResource(dword dwResTypeIndex, const std::string& strResName)
1054 return removeResourceT(dwResTypeIndex, strResName);
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.
1060 * @param strResTypeName Name of the resource type.
1061 * @param dwResId ID of the resource.
1063 int ResourceDirectory::removeResource(const std::string& strResTypeName, dword dwResId)
1065 return removeResourceT(strResTypeName, dwResId);
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.
1071 * @param strResTypeName Name of the resource type.
1072 * @param strResName Name of the resource.
1074 int ResourceDirectory::removeResource(const std::string& strResTypeName, const std::string& strResName)
1076 return removeResourceT(strResTypeName, strResName);
1080 * Returns the number of resource types.
1082 unsigned int ResourceDirectory::getNumberOfResourceTypes() const
1084 return static_cast<unsigned int>(m_rnRoot.children.size());
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.
1090 * Leaving the invalid range leads to undefined behaviour.
1091 * @param uiIndex Index which identifies a resource type.
1092 * @return The ID of the specified resource type.
1094 dword ResourceDirectory::getResourceTypeIdByIndex(unsigned int uiIndex) const
1096 return m_rnRoot.children[uiIndex].entry.irde.Name;
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.
1102 * Leaving the invalid range leads to undefined behaviour.
1103 * @param uiIndex Index which identifies a resource type.
1104 * @return The name of the specified resource type.
1106 std::string ResourceDirectory::getResourceTypeNameByIndex(unsigned int uiIndex) const
1108 return m_rnRoot.children[uiIndex].entry.wstrName;
1112 * Converts the ID of a resource type to an index.
1113 * @param dwResTypeId ID of the resource type.
1114 * @return Index of that resource type.
1116 int ResourceDirectory::resourceTypeIdToIndex(dword dwResTypeId) const
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;
1120 return static_cast<unsigned int>(std::distance(m_rnRoot.children.begin(), Iter));
1124 * Converts the name of a resource type to an index.
1125 * @param strResTypeName ID of the resource type.
1126 * @return Index of that resource type.
1128 int ResourceDirectory::resourceTypeNameToIndex(const std::string& strResTypeName) const
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;
1132 return static_cast<unsigned int>(std::distance(m_rnRoot.children.begin(), Iter));
1136 * Returns the number of resources of a specific resource type.
1137 * @param dwId ID of the resource type.
1138 * @return Number of resources of resource type dwId.
1140 unsigned int ResourceDirectory::getNumberOfResources(dword dwId) const
1142 // std::vector<ResourceChild>::const_iterator IterD = m_rnRoot.children.begin();
1143 // std::cout << dwId << std::endl;
1144 // while (IterD != m_rnRoot.children.end())
1145 // {
1146 // std::cout << IterD->entry.irde.Name << std::endl;
1147 // ++IterD;
1148 // }
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())
1153 return 0xFFFFFFFF;
1155 else
1157 ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child);
1158 return static_cast<unsigned int>(currNode->children.size());
1163 * Returns the number of resources of a specific resource type.
1164 * @param strResTypeName Name of the resource type.
1165 * @return Number of resources of resource type strResTypeName.
1167 unsigned int ResourceDirectory::getNumberOfResources(const std::string& strResTypeName) const
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())
1172 return 0xFFFFFFFF;
1174 else
1176 ResourceNode* currNode = static_cast<ResourceNode*>(Iter->child);
1177 return static_cast<unsigned int>(currNode->children.size());
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.
1184 * Leaving the invalid range leads to undefined behaviour.
1185 * @param uiIndex Index which identifies a resource type.
1186 * @return The number of resources of the specified resource type.
1188 unsigned int ResourceDirectory::getNumberOfResourcesByIndex(unsigned int uiIndex) const
1190 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiIndex].child);
1191 return static_cast<unsigned int>(currNode->children.size());
1195 * Gets the resource data of a specific resource.
1196 * @param dwResTypeId Identifies the resource type of the resource.
1197 * @param dwResId Identifies the resource.
1198 * @param data Vector where the data is stored.
1200 void ResourceDirectory::getResourceData(dword dwResTypeId, dword dwResId, std::vector<byte>& data) const
1202 getResourceDataT(dwResTypeId, dwResId, data);
1206 * Gets the resource data of a specific resource.
1207 * @param dwResTypeId Identifies the resource type of the resource.
1208 * @param strResName Identifies the resource.
1209 * @param data Vector where the data is stored.
1211 void ResourceDirectory::getResourceData(dword dwResTypeId, const std::string& strResName, std::vector<byte>& data) const
1213 getResourceDataT(dwResTypeId, strResName, data);
1217 * Gets the resource data of a specific resource.
1218 * @param strResTypeName Identifies the resource type of the resource.
1219 * @param dwResId Identifies the resource.
1220 * @param data Vector where the data is stored.
1222 void ResourceDirectory::getResourceData(const std::string& strResTypeName, dword dwResId, std::vector<byte>& data) const
1224 getResourceDataT(strResTypeName, dwResId, data);
1228 * Gets the resource data of a specific resource.
1229 * @param strResTypeName Identifies the resource type of the resource.
1230 * @param strResName Identifies the resource.
1231 * @param data Vector where the data is stored.
1233 void ResourceDirectory::getResourceData(const std::string& strResTypeName, const std::string& strResName, std::vector<byte>& data) const
1235 getResourceDataT(strResTypeName, strResName, data);
1239 * Gets the resource data of a specific resource by index.
1240 * The valid range of the parameter uiResTypeIndex is 0...getNumberOfResourceTypes() - 1.
1241 * The valid range of the parameter uiResIndex is 0...getNumberOfResources() - 1.
1242 * Leaving the invalid range leads to undefined behaviour.
1243 * @param uiResTypeIndex Identifies the resource type of the resource.
1244 * @param uiResIndex Identifies the resource.
1245 * @param data Vector where the data is stored.
1247 void ResourceDirectory::getResourceDataByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, std::vector<byte>& data) const
1249 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child);
1250 currNode = static_cast<ResourceNode*>(currNode->children[uiResIndex].child);
1251 ResourceLeaf* currLeaf = static_cast<ResourceLeaf*>(currNode->children[0].child);
1253 data.assign(currLeaf->m_data.begin(), currLeaf->m_data.end());
1257 * Sets the resource data of a specific resource.
1258 * @param dwResTypeId Identifies the resource type of the resource.
1259 * @param dwResId Identifies the resource.
1260 * @param data The new resource data.
1262 void ResourceDirectory::setResourceData(dword dwResTypeId, dword dwResId, std::vector<byte>& data)
1264 setResourceDataT(dwResTypeId, dwResId, data);
1268 * Sets the resource data of a specific resource.
1269 * @param dwResTypeId Identifies the resource type of the resource.
1270 * @param strResName Identifies the resource.
1271 * @param data The new resource data.
1273 void ResourceDirectory::setResourceData(dword dwResTypeId, const std::string& strResName, std::vector<byte>& data)
1275 setResourceDataT(dwResTypeId, strResName, data);
1279 * Sets the resource data of a specific resource.
1280 * @param strResTypeName Identifies the resource type of the resource.
1281 * @param dwResId Identifies the resource.
1282 * @param data The new resource data.
1284 void ResourceDirectory::setResourceData(const std::string& strResTypeName, dword dwResId, std::vector<byte>& data)
1286 setResourceDataT(strResTypeName, dwResId, data);
1290 * Sets the resource data of a specific resource.
1291 * @param strResTypeName Identifies the resource type of the resource.
1292 * @param strResName Identifies the resource.
1293 * @param data The new resource data.
1295 void ResourceDirectory::setResourceData(const std::string& strResTypeName, const std::string& strResName, std::vector<byte>& data)
1297 setResourceDataT(strResTypeName, strResName, data);
1301 * Sets the resource data of a specific resource by index.
1302 * The valid range of the parameter uiResTypeIndex is 0...getNumberOfResourceTypes() - 1.
1303 * The valid range of the parameter uiResIndex is 0...getNumberOfResources() - 1.
1304 * Leaving the invalid range leads to undefined behaviour.
1305 * @param uiResTypeIndex Identifies the resource type of the resource.
1306 * @param uiResIndex Identifies the resource.
1307 * @param data The new resource data.
1309 void ResourceDirectory::setResourceDataByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, std::vector<byte>& data)
1311 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child);
1312 currNode = static_cast<ResourceNode*>(currNode->children[uiResIndex].child);
1313 ResourceLeaf* currLeaf = static_cast<ResourceLeaf*>(currNode->children[0].child);
1314 currLeaf->m_data.assign(data.begin(), data.end());
1318 * Gets the ID of a specific resource.
1319 * @param dwResTypeId Identifies the resource type of the resource.
1320 * @param strResName Identifies the resource.
1321 * @return ID of the specified resource.
1323 dword ResourceDirectory::getResourceId(dword dwResTypeId, const std::string& strResName) const
1325 return getResourceIdT(dwResTypeId, strResName);
1329 * Gets the ID of a specific resource.
1330 * @param strResTypeName Identifies the resource type of the resource.
1331 * @param strResName Identifies the resource.
1332 * @return ID of the specified resource.
1334 dword ResourceDirectory::getResourceId(const std::string& strResTypeName, const std::string& strResName) const
1336 return getResourceIdT(strResTypeName, strResName);
1340 * Gets the ID of a specific resource by index.
1341 * @param uiResTypeIndex Identifies the resource type of the resource.
1342 * @param uiResIndex Identifies the resource.
1343 * @return ID of the specified resource.
1345 dword ResourceDirectory::getResourceIdByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex) const
1347 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child);
1348 return currNode->children[uiResIndex].entry.irde.Name;
1352 * Sets the ID of a specific resource.
1353 * @param dwResTypeId Identifies the resource type of the resource.
1354 * @param dwResId Identifies the resource.
1355 * @param dwNewResId New ID of the resource.
1357 void ResourceDirectory::setResourceId(dword dwResTypeId, dword dwResId, dword dwNewResId)
1359 setResourceIdT(dwResTypeId, dwResId, dwNewResId);
1363 * Sets the ID of a specific resource.
1364 * @param dwResTypeId Identifies the resource type of the resource.
1365 * @param strResName Identifies the resource.
1366 * @param dwNewResId New ID of the resource.
1368 void ResourceDirectory::setResourceId(dword dwResTypeId, const std::string& strResName, dword dwNewResId)
1370 setResourceIdT(dwResTypeId, strResName, dwNewResId);
1374 * Sets the ID of a specific resource.
1375 * @param strResTypeName Identifies the resource type of the resource.
1376 * @param dwResId Identifies the resource.
1377 * @param dwNewResId New ID of the resource.
1379 void ResourceDirectory::setResourceId(const std::string& strResTypeName, dword dwResId, dword dwNewResId)
1381 setResourceIdT(strResTypeName, dwResId, dwNewResId);
1385 * Sets the ID of a specific resource.
1386 * @param strResTypeName Identifies the resource type of the resource.
1387 * @param strResName Identifies the resource.
1388 * @param dwNewResId New ID of the resource.
1390 void ResourceDirectory::setResourceId(const std::string& strResTypeName, const std::string& strResName, dword dwNewResId)
1392 setResourceIdT(strResTypeName, strResName, dwNewResId);
1396 * Sets the ID of a specific resource by index.
1397 * @param uiResTypeIndex Identifies the resource type of the resource.
1398 * @param uiResIndex Identifies the resource.
1399 * @param dwNewResId New ID of the specified resource.
1401 void ResourceDirectory::setResourceIdByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, dword dwNewResId)
1403 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child);
1404 currNode->children[uiResIndex].entry.irde.Name = dwNewResId;
1408 * Gets the Name of a specific resource.
1409 * @param dwResTypeId Identifies the resource type of the resource.
1410 * @param dwResId Identifies the resource.
1411 * @return Name of the specified resource.
1413 std::string ResourceDirectory::getResourceName(dword dwResTypeId, dword dwResId) const
1415 return getResourceNameT(dwResTypeId, dwResId);
1419 * Gets the Name of a specific resource.
1420 * @param strResTypeName Identifies the resource type of the resource.
1421 * @param dwResId Identifies the resource.
1422 * @return Name of the specified resource.
1424 std::string ResourceDirectory::getResourceName(const std::string& strResTypeName, dword dwResId) const
1426 return getResourceNameT(strResTypeName, dwResId);
1430 * Gets the name of a specific resource by index.
1431 * @param uiResTypeIndex Identifies the resource type of the resource.
1432 * @param uiResIndex Identifies the resource.
1433 * @return Name of the specified resource.
1435 std::string ResourceDirectory::getResourceNameByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex) const
1437 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child);
1438 return currNode->children[uiResIndex].entry.wstrName;
1442 * Sets the name of a specific resource.
1443 * @param dwResTypeId Identifies the resource type of the resource.
1444 * @param dwResId Identifies the resource.
1445 * @param strNewResName New name of the specified resource.
1447 void ResourceDirectory::setResourceName(dword dwResTypeId, dword dwResId, const std::string& strNewResName)
1449 setResourceNameT(dwResTypeId, dwResId, strNewResName);
1453 * Sets the name of a specific resource.
1454 * @param dwResTypeId Identifies the resource type of the resource.
1455 * @param strResName Identifies the resource.
1456 * @param strNewResName New name of the specified resource.
1458 void ResourceDirectory::setResourceName(dword dwResTypeId, const std::string& strResName, const std::string& strNewResName)
1460 setResourceNameT(dwResTypeId, strResName, strNewResName);
1464 * Sets the name of a specific resource.
1465 * @param strResTypeName Identifies the resource type of the resource.
1466 * @param dwResId Identifies the resource.
1467 * @param strNewResName New name of the specified resource.
1469 void ResourceDirectory::setResourceName(const std::string& strResTypeName, dword dwResId, const std::string& strNewResName)
1471 setResourceNameT(strResTypeName, dwResId, strNewResName);
1475 * Sets the name of a specific resource.
1476 * @param strResTypeName Identifies the resource type of the resource.
1477 * @param strResName Identifies the resource.
1478 * @param strNewResName New name of the specified resource.
1480 void ResourceDirectory::setResourceName(const std::string& strResTypeName, const std::string& strResName, const std::string& strNewResName)
1482 setResourceNameT(strResTypeName, strResName, strNewResName);
1486 * Sets the name of a specific resource by index.
1487 * @param uiResTypeIndex Identifies the resource type of the resource.
1488 * @param uiResIndex Identifies the resource.
1489 * @param strNewResName New name of the specified resource.
1491 void ResourceDirectory::setResourceNameByIndex(unsigned int uiResTypeIndex, unsigned int uiResIndex, const std::string& strNewResName)
1493 ResourceNode* currNode = static_cast<ResourceNode*>(m_rnRoot.children[uiResTypeIndex].child);
1494 currNode->children[uiResIndex].entry.wstrName = strNewResName;