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 "file.h" 27 #include "hash-str.h" 28 #include "hashmap.h" 29 #include "common/str.h" 30 #include "winexe.h" 31 32 namespace Common { 33 34 template<class T> class Array; 35 class SeekableReadStream; 36 37 /** 38 * A class able to load resources from a Windows Portable Executable, such 39 * as cursors, bitmaps, and sounds. 40 */ 41 class PEResources : WinResources { 42 public: 43 PEResources(); 44 ~PEResources(); 45 46 /** Clear all information. */ 47 void clear(); 48 49 /** Load from an EXE file. */ 50 using WinResources::loadFromEXE; 51 52 bool loadFromEXE(File *stream); 53 54 /** Return a list of resource types. */ 55 const Array<WinResourceID> getTypeList() const; 56 57 /** Return a list of IDs for a given type. */ 58 const Array<WinResourceID> getIDList(const WinResourceID &type) const; 59 60 /** Return a list of languages for a given type and ID. */ 61 const Array<WinResourceID> getLangList(const WinResourceID &type, const WinResourceID &id) const; 62 63 /** Return a stream to the specified resource, taking the first language found (or 0 if non-existent). */ 64 File *getResource(const WinResourceID &type, const WinResourceID &id); 65 66 /** Return a stream to the specified resource (or 0 if non-existent). */ 67 File *getResource(const WinResourceID &type, const WinResourceID &id, const WinResourceID &lang); 68 69 /** Returns true if the resources is empty */ empty()70 bool empty() const { return _sections.empty(); } 71 private: 72 struct Section { 73 uint32 virtualAddress; 74 uint32 size; 75 uint32 offset; 76 }; 77 78 HashMap<String, Section, IgnoreCase_Hash, IgnoreCase_EqualTo> _sections; 79 80 File *_exe; 81 82 void parseResourceLevel(Section §ion, uint32 offset, int level); 83 WinResourceID _curType, _curID, _curLang; 84 85 struct Resource { 86 uint32 offset; 87 uint32 size; 88 }; 89 90 typedef HashMap<WinResourceID, Resource, WinResourceID_Hash, WinResourceID_EqualTo> LangMap; 91 typedef HashMap<WinResourceID, LangMap, WinResourceID_Hash, WinResourceID_EqualTo> IDMap; 92 typedef HashMap<WinResourceID, IDMap, WinResourceID_Hash, WinResourceID_EqualTo> TypeMap; 93 94 TypeMap _resources; 95 }; 96 97 } // End of namespace Common 98 99 #endif 100