summaryrefslogtreecommitdiff
path: root/utils/zenutils/libraries/pelib-0.9/pelib/TlsDirectory.h
diff options
context:
space:
mode:
authorNicolas Pennequin <nicolas.pennequin@free.fr>2008-07-11 16:51:25 +0000
committerNicolas Pennequin <nicolas.pennequin@free.fr>2008-07-11 16:51:25 +0000
commitca5bb76d2b8f65aa97e50b633f828c1deb241526 (patch)
tree453a1b2de3a0dc0d0b2f7080d10d033bf8fbcdf1 /utils/zenutils/libraries/pelib-0.9/pelib/TlsDirectory.h
parent141774be48940d56e3ad4dbf451d245b61d4f8b2 (diff)
downloadrockbox-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/TlsDirectory.h')
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/TlsDirectory.h608
1 files changed, 304 insertions, 304 deletions
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/TlsDirectory.h b/utils/zenutils/libraries/pelib-0.9/pelib/TlsDirectory.h
index ebea929f94..8190e65c3c 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/TlsDirectory.h
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/TlsDirectory.h
@@ -1,304 +1,304 @@
1/* 1/*
2* TlsDirectory.h - Part of the PeLib library. 2* TlsDirectory.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#ifndef TLSDIRECTORY_H 13#ifndef TLSDIRECTORY_H
14#define TLSDIRECTORY_H 14#define TLSDIRECTORY_H
15 15
16namespace PeLib 16namespace PeLib
17{ 17{
18 /// Class that handles the TLS directory. 18 /// Class that handles the TLS directory.
19 /** 19 /**
20 * This class handles the TLS (Thread Local Storage) directory. 20 * This class handles the TLS (Thread Local Storage) directory.
21 **/ 21 **/
22 template<int bits> 22 template<int bits>
23 class TlsDirectory 23 class TlsDirectory
24 { 24 {
25 private: 25 private:
26 PELIB_IMAGE_TLS_DIRECTORY<bits> m_tls; ///< Structure that holds all information about the directory. 26 PELIB_IMAGE_TLS_DIRECTORY<bits> m_tls; ///< Structure that holds all information about the directory.
27 27
28 void read(InputBuffer& inputbuffer); 28 void read(InputBuffer& inputbuffer);
29 29
30 public: 30 public:
31 /// Reads a file's TLS directory. 31 /// Reads a file's TLS directory.
32 int read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize); // EXPORT 32 int read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize); // EXPORT
33 int read(unsigned char* buffer, unsigned int buffersize); // EXPORT 33 int read(unsigned char* buffer, unsigned int buffersize); // EXPORT
34 /// Rebuilds the TLS directory. 34 /// Rebuilds the TLS directory.
35 void rebuild(std::vector<byte>& vBuffer) const; // EXPORT 35 void rebuild(std::vector<byte>& vBuffer) const; // EXPORT
36 /// Returns the size of the TLS Directory. 36 /// Returns the size of the TLS Directory.
37 unsigned int size() const; // EXPORT 37 unsigned int size() const; // EXPORT
38 /// Writes the TLS directory to a file. 38 /// Writes the TLS directory to a file.
39 int write(const std::string& strFilename, unsigned int dwOffset) const; // EXPORT 39 int write(const std::string& strFilename, unsigned int dwOffset) const; // EXPORT
40 40
41 /// Returns the StartAddressOfRawData value of the TLS header. 41 /// Returns the StartAddressOfRawData value of the TLS header.
42 dword getStartAddressOfRawData() const; // EXPORT 42 dword getStartAddressOfRawData() const; // EXPORT
43 /// Returns the EndAddressOfRawData value of the TLS header. 43 /// Returns the EndAddressOfRawData value of the TLS header.
44 dword getEndAddressOfRawData() const; // EXPORT 44 dword getEndAddressOfRawData() const; // EXPORT
45 /// Returns the AddressOfIndex value of the TLS header. 45 /// Returns the AddressOfIndex value of the TLS header.
46 dword getAddressOfIndex() const; // EXPORT 46 dword getAddressOfIndex() const; // EXPORT
47 /// Returns the AddressOfCallBacks value of the TLS header. 47 /// Returns the AddressOfCallBacks value of the TLS header.
48 dword getAddressOfCallBacks() const; // EXPORT 48 dword getAddressOfCallBacks() const; // EXPORT
49 /// Returns the SizeOfZeroFill value of the TLS header. 49 /// Returns the SizeOfZeroFill value of the TLS header.
50 dword getSizeOfZeroFill() const; // EXPORT 50 dword getSizeOfZeroFill() const; // EXPORT
51 /// Returns the Characteristics value of the TLS header. 51 /// Returns the Characteristics value of the TLS header.
52 dword getCharacteristics() const; // EXPORT 52 dword getCharacteristics() const; // EXPORT
53 53
54 /// Sets the StartAddressOfRawData value of the TLS header. 54 /// Sets the StartAddressOfRawData value of the TLS header.
55 void setStartAddressOfRawData(dword dwValue); // EXPORT 55 void setStartAddressOfRawData(dword dwValue); // EXPORT
56 /// Sets the EndAddressOfRawData value of the TLS header. 56 /// Sets the EndAddressOfRawData value of the TLS header.
57 void setEndAddressOfRawData(dword dwValue); // EXPORT 57 void setEndAddressOfRawData(dword dwValue); // EXPORT
58 /// Sets the AddressOfIndex value of the TLS header. 58 /// Sets the AddressOfIndex value of the TLS header.
59 void setAddressOfIndex(dword dwValue); // EXPORT 59 void setAddressOfIndex(dword dwValue); // EXPORT
60 /// Sets the AddressOfCallBacks value of the TLS header. 60 /// Sets the AddressOfCallBacks value of the TLS header.
61 void setAddressOfCallBacks(dword dwValue); // EXPORT 61 void setAddressOfCallBacks(dword dwValue); // EXPORT
62 /// Sets the SizeOfZeroFill value of the TLS header. 62 /// Sets the SizeOfZeroFill value of the TLS header.
63 void setSizeOfZeroFill(dword dwValue); // EXPORT 63 void setSizeOfZeroFill(dword dwValue); // EXPORT
64 /// Sets the Characteristics value of the TLS header. 64 /// Sets the Characteristics value of the TLS header.
65 void setCharacteristics(dword dwValue); // EXPORT 65 void setCharacteristics(dword dwValue); // EXPORT
66 }; 66 };
67 67
68 template<int bits> 68 template<int bits>
69 void TlsDirectory<bits>::read(InputBuffer& inputBuffer) 69 void TlsDirectory<bits>::read(InputBuffer& inputBuffer)
70 { 70 {
71 PELIB_IMAGE_TLS_DIRECTORY<bits> itdCurr; 71 PELIB_IMAGE_TLS_DIRECTORY<bits> itdCurr;
72 72
73 inputBuffer >> itdCurr.StartAddressOfRawData; 73 inputBuffer >> itdCurr.StartAddressOfRawData;
74 inputBuffer >> itdCurr.EndAddressOfRawData; 74 inputBuffer >> itdCurr.EndAddressOfRawData;
75 inputBuffer >> itdCurr.AddressOfIndex; 75 inputBuffer >> itdCurr.AddressOfIndex;
76 inputBuffer >> itdCurr.AddressOfCallBacks; 76 inputBuffer >> itdCurr.AddressOfCallBacks;
77 inputBuffer >> itdCurr.SizeOfZeroFill; 77 inputBuffer >> itdCurr.SizeOfZeroFill;
78 inputBuffer >> itdCurr.Characteristics; 78 inputBuffer >> itdCurr.Characteristics;
79 79
80 std::swap(itdCurr, m_tls); 80 std::swap(itdCurr, m_tls);
81 } 81 }
82 82
83 template<int bits> 83 template<int bits>
84 int TlsDirectory<bits>::read(unsigned char* buffer, unsigned int buffersize) 84 int TlsDirectory<bits>::read(unsigned char* buffer, unsigned int buffersize)
85 { 85 {
86 if (buffersize < PELIB_IMAGE_TLS_DIRECTORY<bits>::size()) 86 if (buffersize < PELIB_IMAGE_TLS_DIRECTORY<bits>::size())
87 { 87 {
88 return ERROR_INVALID_FILE; 88 return ERROR_INVALID_FILE;
89 } 89 }
90 90
91 std::vector<byte> vTlsDirectory(buffer, buffer + buffersize); 91 std::vector<byte> vTlsDirectory(buffer, buffer + buffersize);
92 92
93 InputBuffer ibBuffer(vTlsDirectory); 93 InputBuffer ibBuffer(vTlsDirectory);
94 read(ibBuffer); 94 read(ibBuffer);
95 return NO_ERROR; 95 return NO_ERROR;
96 } 96 }
97 97
98 /** 98 /**
99 * Reads a file's TLS directory. 99 * Reads a file's TLS directory.
100 * @param strFilename Name of the file. 100 * @param strFilename Name of the file.
101 * @param uiOffset File offset of the TLS directory. 101 * @param uiOffset File offset of the TLS directory.
102 * @param uiSize Size of the TLS directory. 102 * @param uiSize Size of the TLS directory.
103 **/ 103 **/
104 template<int bits> 104 template<int bits>
105 int TlsDirectory<bits>::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize) 105 int TlsDirectory<bits>::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize)
106 { 106 {
107 std::ifstream ifFile(strFilename.c_str(), std::ios::binary); 107 std::ifstream ifFile(strFilename.c_str(), std::ios::binary);
108 unsigned int ulFileSize = fileSize(ifFile); 108 unsigned int ulFileSize = fileSize(ifFile);
109 109
110 if (!ifFile) 110 if (!ifFile)
111 { 111 {
112 return ERROR_OPENING_FILE; 112 return ERROR_OPENING_FILE;
113 } 113 }
114 114
115 if (ulFileSize < uiOffset + uiSize) 115 if (ulFileSize < uiOffset + uiSize)
116 { 116 {
117 return ERROR_INVALID_FILE; 117 return ERROR_INVALID_FILE;
118 } 118 }
119 119
120 ifFile.seekg(uiOffset, std::ios::beg); 120 ifFile.seekg(uiOffset, std::ios::beg);
121 121
122 std::vector<byte> vTlsDirectory(uiSize); 122 std::vector<byte> vTlsDirectory(uiSize);
123 ifFile.read(reinterpret_cast<char*>(&vTlsDirectory[0]), uiSize); 123 ifFile.read(reinterpret_cast<char*>(&vTlsDirectory[0]), uiSize);
124 124
125 InputBuffer ibBuffer(vTlsDirectory); 125 InputBuffer ibBuffer(vTlsDirectory);
126 read(ibBuffer); 126 read(ibBuffer);
127 return NO_ERROR; 127 return NO_ERROR;
128 } 128 }
129 129
130 /** 130 /**
131 * Rebuilds the current TLS Directory. 131 * Rebuilds the current TLS Directory.
132 * @param vBuffer Buffer where the TLS directory will be written to. 132 * @param vBuffer Buffer where the TLS directory will be written to.
133 **/ 133 **/
134 template<int bits> 134 template<int bits>
135 void TlsDirectory<bits>::rebuild(std::vector<byte>& vBuffer) const 135 void TlsDirectory<bits>::rebuild(std::vector<byte>& vBuffer) const
136 { 136 {
137 OutputBuffer obBuffer(vBuffer); 137 OutputBuffer obBuffer(vBuffer);
138 138
139 obBuffer << m_tls.StartAddressOfRawData; 139 obBuffer << m_tls.StartAddressOfRawData;
140 obBuffer << m_tls.EndAddressOfRawData; 140 obBuffer << m_tls.EndAddressOfRawData;
141 obBuffer << m_tls.AddressOfIndex; 141 obBuffer << m_tls.AddressOfIndex;
142 obBuffer << m_tls.AddressOfCallBacks; 142 obBuffer << m_tls.AddressOfCallBacks;
143 obBuffer << m_tls.SizeOfZeroFill; 143 obBuffer << m_tls.SizeOfZeroFill;
144 obBuffer << m_tls.Characteristics; 144 obBuffer << m_tls.Characteristics;
145 } 145 }
146 146
147 /** 147 /**
148 * Returns the size of the TLS directory. Due to the static nature of this structure the return value 148 * Returns the size of the TLS directory. Due to the static nature of this structure the return value
149 * will always be 24. 149 * will always be 24.
150 * @return Size in bytes. 150 * @return Size in bytes.
151 **/ 151 **/
152 template<int bits> 152 template<int bits>
153 unsigned int TlsDirectory<bits>::size() const 153 unsigned int TlsDirectory<bits>::size() const
154 { 154 {
155 return PELIB_IMAGE_TLS_DIRECTORY<bits>::size(); 155 return PELIB_IMAGE_TLS_DIRECTORY<bits>::size();
156 } 156 }
157 157
158 /** 158 /**
159 * @param strFilename Name of the file. 159 * @param strFilename Name of the file.
160 * @param dwOffset File offset the TLS Directory will be written to. 160 * @param dwOffset File offset the TLS Directory will be written to.
161 **/ 161 **/
162 template<int bits> 162 template<int bits>
163 int TlsDirectory<bits>::write(const std::string& strFilename, unsigned int dwOffset) const 163 int TlsDirectory<bits>::write(const std::string& strFilename, unsigned int dwOffset) const
164 { 164 {
165 std::fstream ofFile(strFilename.c_str(), std::ios_base::in); 165 std::fstream ofFile(strFilename.c_str(), std::ios_base::in);
166 166
167 if (!ofFile) 167 if (!ofFile)
168 { 168 {
169 ofFile.clear(); 169 ofFile.clear();
170 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); 170 ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary);
171 } 171 }
172 else 172 else
173 { 173 {
174 ofFile.close(); 174 ofFile.close();
175 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); 175 ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary);
176 } 176 }
177 177
178 if (!ofFile) 178 if (!ofFile)
179 { 179 {
180 return ERROR_OPENING_FILE; 180 return ERROR_OPENING_FILE;
181 } 181 }
182 182
183 ofFile.seekp(dwOffset, std::ios::beg); 183 ofFile.seekp(dwOffset, std::ios::beg);
184 184
185 std::vector<unsigned char> vBuffer; 185 std::vector<unsigned char> vBuffer;
186 rebuild(vBuffer); 186 rebuild(vBuffer);
187 187
188 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), vBuffer.size()); 188 ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), vBuffer.size());
189 189
190 ofFile.close(); 190 ofFile.close();
191 191
192 return NO_ERROR; 192 return NO_ERROR;
193 } 193 }
194 194
195 /** 195 /**
196 * @return The StartAddressOfRawData value of the TLS directory. 196 * @return The StartAddressOfRawData value of the TLS directory.
197 **/ 197 **/
198 template<int bits> 198 template<int bits>
199 dword TlsDirectory<bits>::getStartAddressOfRawData() const 199 dword TlsDirectory<bits>::getStartAddressOfRawData() const
200 { 200 {
201 return m_tls.StartAddressOfRawData; 201 return m_tls.StartAddressOfRawData;
202 } 202 }
203 203
204 /** 204 /**
205 * @return The EndAddressOfRawData value of the TLS directory. 205 * @return The EndAddressOfRawData value of the TLS directory.
206 **/ 206 **/
207 template<int bits> 207 template<int bits>
208 dword TlsDirectory<bits>::getEndAddressOfRawData() const 208 dword TlsDirectory<bits>::getEndAddressOfRawData() const
209 { 209 {
210 return m_tls.EndAddressOfRawData; 210 return m_tls.EndAddressOfRawData;
211 } 211 }
212 212
213 /** 213 /**
214 * @return The AddressOfIndex value of the TLS directory. 214 * @return The AddressOfIndex value of the TLS directory.
215 **/ 215 **/
216 template<int bits> 216 template<int bits>
217 dword TlsDirectory<bits>::getAddressOfIndex() const 217 dword TlsDirectory<bits>::getAddressOfIndex() const
218 { 218 {
219 return m_tls.AddressOfIndex; 219 return m_tls.AddressOfIndex;
220 } 220 }
221 221
222 /** 222 /**
223 * @return The AddressOfCallBacks value of the TLS directory. 223 * @return The AddressOfCallBacks value of the TLS directory.
224 **/ 224 **/
225 template<int bits> 225 template<int bits>
226 dword TlsDirectory<bits>::getAddressOfCallBacks() const 226 dword TlsDirectory<bits>::getAddressOfCallBacks() const
227 { 227 {
228 return m_tls.AddressOfCallBacks; 228 return m_tls.AddressOfCallBacks;
229 } 229 }
230 230
231 /** 231 /**
232 * @return The SizeOfZeroFill value of the TLS directory. 232 * @return The SizeOfZeroFill value of the TLS directory.
233 **/ 233 **/
234 template<int bits> 234 template<int bits>
235 dword TlsDirectory<bits>::getSizeOfZeroFill() const 235 dword TlsDirectory<bits>::getSizeOfZeroFill() const
236 { 236 {
237 return m_tls.SizeOfZeroFill; 237 return m_tls.SizeOfZeroFill;
238 } 238 }
239 239
240 /** 240 /**
241 * @return The Characteristics value of the TLS directory. 241 * @return The Characteristics value of the TLS directory.
242 **/ 242 **/
243 template<int bits> 243 template<int bits>
244 dword TlsDirectory<bits>::getCharacteristics() const 244 dword TlsDirectory<bits>::getCharacteristics() const
245 { 245 {
246 return m_tls.Characteristics; 246 return m_tls.Characteristics;
247 } 247 }
248 248
249 /** 249 /**
250 * @param dwValue The new StartAddressOfRawData value of the TLS directory. 250 * @param dwValue The new StartAddressOfRawData value of the TLS directory.
251 **/ 251 **/
252 template<int bits> 252 template<int bits>
253 void TlsDirectory<bits>::setStartAddressOfRawData(dword dwValue) 253 void TlsDirectory<bits>::setStartAddressOfRawData(dword dwValue)
254 { 254 {
255 m_tls.StartAddressOfRawData = dwValue; 255 m_tls.StartAddressOfRawData = dwValue;
256 } 256 }
257 257
258 /** 258 /**
259 * @param dwValue The new EndAddressOfRawData value of the TLS directory. 259 * @param dwValue The new EndAddressOfRawData value of the TLS directory.
260 **/ 260 **/
261 template<int bits> 261 template<int bits>
262 void TlsDirectory<bits>::setEndAddressOfRawData(dword dwValue) 262 void TlsDirectory<bits>::setEndAddressOfRawData(dword dwValue)
263 { 263 {
264 m_tls.EndAddressOfRawData = dwValue; 264 m_tls.EndAddressOfRawData = dwValue;
265 } 265 }
266 266
267 /** 267 /**
268 * @param dwValue The new AddressOfIndex value of the TLS directory. 268 * @param dwValue The new AddressOfIndex value of the TLS directory.
269 **/ 269 **/
270 template<int bits> 270 template<int bits>
271 void TlsDirectory<bits>::setAddressOfIndex(dword dwValue) 271 void TlsDirectory<bits>::setAddressOfIndex(dword dwValue)
272 { 272 {
273 m_tls.AddressOfIndex = dwValue; 273 m_tls.AddressOfIndex = dwValue;
274 } 274 }
275 275
276 /** 276 /**
277 * @param dwValue The new AddressOfCallBacks value of the TLS directory. 277 * @param dwValue The new AddressOfCallBacks value of the TLS directory.
278 **/ 278 **/
279 template<int bits> 279 template<int bits>
280 void TlsDirectory<bits>::setAddressOfCallBacks(dword dwValue) 280 void TlsDirectory<bits>::setAddressOfCallBacks(dword dwValue)
281 { 281 {
282 m_tls.AddressOfCallBacks = dwValue; 282 m_tls.AddressOfCallBacks = dwValue;
283 } 283 }
284 284
285 /** 285 /**
286 * @param dwValue The new SizeOfZeroFill value of the TLS directory. 286 * @param dwValue The new SizeOfZeroFill value of the TLS directory.
287 **/ 287 **/
288 template<int bits> 288 template<int bits>
289 void TlsDirectory<bits>::setSizeOfZeroFill(dword dwValue) 289 void TlsDirectory<bits>::setSizeOfZeroFill(dword dwValue)
290 { 290 {
291 m_tls.SizeOfZeroFill = dwValue; 291 m_tls.SizeOfZeroFill = dwValue;
292 } 292 }
293 293
294 /** 294 /**
295 * @param dwValue The new Characteristics value of the TLS directory. 295 * @param dwValue The new Characteristics value of the TLS directory.
296 **/ 296 **/
297 template<int bits> 297 template<int bits>
298 void TlsDirectory<bits>::setCharacteristics(dword dwValue) 298 void TlsDirectory<bits>::setCharacteristics(dword dwValue)
299 { 299 {
300 m_tls.Characteristics = dwValue; 300 m_tls.Characteristics = dwValue;
301 } 301 }
302 302
303} 303}
304#endif 304#endif