xoreos  0.0.5
pe_exe.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos 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 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos 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 xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef COMMON_PE_EXE_H
26 #define COMMON_PE_EXE_H
27 
28 #include <map>
29 #include <vector>
30 
31 #include <boost/noncopyable.hpp>
32 
33 #include "src/common/types.h"
34 #include "src/common/ustring.h"
35 #include "src/common/scopedptr.h"
36 
37 namespace Common {
38 
39 class SeekableReadStream;
40 class UString;
41 
42 class PEResourceID {
43 public:
44  PEResourceID();
47 
50 
51  bool operator==(const UString &x) const;
52  bool operator==(const uint32 &x) const;
53  bool operator==(const PEResourceID &x) const;
54 
55  bool operator<(const PEResourceID &x) const;
56 
57  UString getString() const;
58  uint32 getID() const;
59  UString toString() const;
60 
61 private:
63  enum IDType {
67  } _idType;
68 
71 };
72 
75  kPECursor = 0x1,
76  kPEBitmap = 0x2,
77  kPEIcon = 0x3,
78  kPEMenu = 0x4,
79  kPEDialog = 0x5,
80  kPEString = 0x6,
81  kPEFontDir = 0x7,
82  kPEFont = 0x8,
84  kPERCData = 0xA,
87  kPEGroupIcon = 0xE,
88  kPEVersion = 0x10,
89  kPEDlgInclude = 0x11,
90  kPEPlugPlay = 0x13,
91  kPEVXD = 0x14,
92  kPEAniCursor = 0x15,
93  kPEAniIcon = 0x16,
94  kPEHTML = 0x17,
95  kPEManifest = 0x18
96 };
97 
102 class PEResources : boost::noncopyable {
103 public:
105  ~PEResources();
106 
108  const std::vector<PEResourceID> getTypeList() const;
109 
111  const std::vector<PEResourceID> getNameList(const PEResourceID &type) const;
112 
114  const std::vector<PEResourceID> getLangList(const PEResourceID &type, const PEResourceID &name) const;
115 
117  SeekableReadStream *getResource(const PEResourceID &type, const PEResourceID &name);
118 
120  SeekableReadStream *getResource(const PEResourceID &type, const PEResourceID &name,
121  const PEResourceID &lang);
122 
123 private:
124  struct Section {
128  };
129 
130  struct Resource {
133  };
134 
135  typedef std::map<PEResourceID, Resource> LangMap;
136  typedef std::map<PEResourceID, LangMap> NameMap;
137  typedef std::map<PEResourceID, NameMap> TypeMap;
138 
139  std::map<UString, Section> _sections;
140 
141 
143 
147 
149 
150 
151  bool loadFromEXE(SeekableReadStream &exe);
152 
153  void parseResourceLevel(SeekableReadStream &exe, Section &section, uint32 offset, int level);
154 };
155 
156 } // End of namespace Common
157 
158 #endif // COMMON_PE_EXE_H
const std::vector< PEResourceID > getTypeList() const
Return a list of resource types.
Definition: pe_exe.cpp:221
Definition: 2dafile.h:39
A class holding an UTF-8 string.
Definition: ustring.h:48
PEResourceID _curLang
Definition: pe_exe.h:146
const std::vector< PEResourceID > getNameList(const PEResourceID &type) const
Return a list of names for a given type.
Definition: pe_exe.cpp:230
PEResourceID & operator=(UString string)
Definition: pe_exe.cpp:43
ScopedPtr< SeekableReadStream > _exe
Definition: pe_exe.h:142
SeekableReadStream * getResource(const PEResourceID &type, const PEResourceID &name)
Return a stream to the specified resource, taking the first language found (or 0 if non-existent)...
Definition: pe_exe.cpp:263
bool operator==(const UString &x) const
Definition: pe_exe.cpp:55
bool operator<(const PEResourceID &x) const
Definition: pe_exe.cpp:73
TypeMap _resources
Definition: pe_exe.h:148
IDType
An ID Type.
Definition: pe_exe.h:63
UString getString() const
Definition: pe_exe.cpp:77
A simple scoped smart pointer template.
std::map< UString, Section > _sections
Definition: pe_exe.h:139
std::map< PEResourceID, NameMap > TypeMap
Definition: pe_exe.h:137
PEResourceID _curType
Definition: pe_exe.h:144
PEResources(SeekableReadStream *exe)
Definition: pe_exe.cpp:104
PEResourceID _curName
Definition: pe_exe.h:145
UString _name
The resource&#39;s string ID.
Definition: pe_exe.h:69
bool loadFromEXE(SeekableReadStream &exe)
Definition: pe_exe.cpp:114
Low-level type definitions to handle fixed width types portably.
const std::vector< PEResourceID > getLangList(const PEResourceID &type, const PEResourceID &name) const
Return a list of languages for a given type and name.
Definition: pe_exe.cpp:244
A scoped plain pointer, allowing pointer-y access and normal deletion.
Definition: scopedptr.h:120
A class able to load resources from a Windows Portable Executable, such as cursors, bitmaps, and sounds.
Definition: pe_exe.h:102
std::map< PEResourceID, Resource > LangMap
Definition: pe_exe.h:135
Unicode string handling.
PEResourceType
The default Windows PE resources.
Definition: pe_exe.h:74
uint32_t uint32
Definition: types.h:204
UString toString() const
Definition: pe_exe.cpp:91
enum Common::PEResourceID::IDType _idType
void parseResourceLevel(SeekableReadStream &exe, Section &section, uint32 offset, int level)
Definition: pe_exe.cpp:162
uint32 getID() const
Definition: pe_exe.cpp:84
std::map< PEResourceID, LangMap > NameMap
Definition: pe_exe.h:136
Interface for a seekable & readable data stream.
Definition: readstream.h:265
uint32 _id
The resource&#39;s numerical ID.
Definition: pe_exe.h:70