1 /* ScummVM - Graphic Adventure Engine 2 * 3 * ScummVM is the legal property of its developers, whose names 4 * are too numerous to list here. Please refer to the COPYRIGHT 5 * file distributed with this source distribution. 6 * 7 * This program is free software; you can redistribute it and/or 8 * modify it under the terms of the GNU General Public License 9 * as published by the Free Software Foundation; either version 2 10 * of the License, or (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 20 * 21 */ 22 23 #ifndef COMMON_WINEXE_PE_H 24 #define COMMON_WINEXE_PE_H 25 26 #include "common/hash-str.h" 27 #include "common/hashmap.h" 28 #include "common/str.h" 29 #include "common/winexe.h" 30 31 namespace Common { 32 33 /** 34 * @defgroup common_winexe_ne Windows Portable Executable resources 35 * @ingroup common_winexe 36 * 37 * @brief API for managing Windows Portable Executable resources. 38 * 39 * @{ 40 */ 41 42 template<class T> class Array; 43 class SeekableReadStream; 44 45 /** 46 * A class able to load resources from a Windows Portable Executable, such 47 * as cursors, bitmaps, and sounds. 48 */ 49 class PEResources : public WinResources { 50 public: 51 PEResources(); 52 ~PEResources(); 53 54 /** Clear all information. */ 55 void clear(); 56 57 /** Load from an EXE file. */ 58 using WinResources::loadFromEXE; 59 60 /** Load from a stream. */ 61 bool loadFromEXE(SeekableReadStream *stream, DisposeAfterUse::Flag disposeFileHandle = DisposeAfterUse::YES); 62 63 /** Return a list of resource types. */ 64 const Array<WinResourceID> getTypeList() const; 65 66 /** Return a list of IDs for a given type. */ 67 const Array<WinResourceID> getIDList(const WinResourceID &type) const; 68 69 /** Return a list of languages for a given type and ID. */ 70 const Array<WinResourceID> getLangList(const WinResourceID &type, const WinResourceID &id) const; 71 72 /** Return a stream to the specified resource, taking the first language found (or 0 if non-existent). */ 73 SeekableReadStream *getResource(const WinResourceID &type, const WinResourceID &id); 74 75 /** Return a stream to the specified resource (or 0 if non-existent). */ 76 SeekableReadStream *getResource(const WinResourceID &type, const WinResourceID &id, const WinResourceID &lang); 77 78 /** Get a string from a string resource. */ 79 String loadString(uint32 stringID); 80 81 protected: 82 VersionInfo *parseVersionInfo(SeekableReadStream *stream); 83 84 private: 85 struct Section { 86 uint32 virtualAddress; 87 uint32 size; 88 uint32 offset; 89 }; 90 91 HashMap<String, Section, IgnoreCase_Hash, IgnoreCase_EqualTo> _sections; 92 93 SeekableReadStream *_exe; 94 DisposeAfterUse::Flag _disposeFileHandle; 95 96 void parseResourceLevel(Section §ion, uint32 offset, int level); 97 WinResourceID _curType, _curID, _curLang; 98 99 struct Resource { 100 uint32 offset; 101 uint32 size; 102 }; 103 104 typedef HashMap<WinResourceID, Resource, WinResourceID_Hash, WinResourceID_EqualTo> LangMap; 105 typedef HashMap<WinResourceID, LangMap, WinResourceID_Hash, WinResourceID_EqualTo> IDMap; 106 typedef HashMap<WinResourceID, IDMap, WinResourceID_Hash, WinResourceID_EqualTo> TypeMap; 107 108 TypeMap _resources; 109 }; 110 111 /** @} */ 112 113 } // End of namespace Common 114 115 #endif 116