summaryrefslogtreecommitdiff
path: root/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.cpp
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/PeLibAux.cpp
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/PeLibAux.cpp')
-rw-r--r--[-rwxr-xr-x]utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.cpp550
1 files changed, 275 insertions, 275 deletions
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.cpp b/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.cpp
index 1e06bae620..0a420ebecf 100755..100644
--- a/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.cpp
+++ b/utils/zenutils/libraries/pelib-0.9/pelib/PeLibAux.cpp
@@ -1,275 +1,275 @@
1/* 1/*
2* PeLibAux.cpp - Part of the PeLib library. 2* PeLibAux.cpp - 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#include "PeLibInc.h" 13#include "PeLibInc.h"
14#include "PeLibAux.h" 14#include "PeLibAux.h"
15#include "PeFile.h" 15#include "PeFile.h"
16 16
17#ifdef _MSC_VER 17#ifdef _MSC_VER
18 #include <ctype.h> 18 #include <ctype.h>
19#endif 19#endif
20 20
21namespace PeLib 21namespace PeLib
22{ 22{
23 const qword PELIB_IMAGE_ORDINAL_FLAGS<64>::IMAGE_ORDINAL_FLAG = 0x8000000000000000ULL; 23 const qword PELIB_IMAGE_ORDINAL_FLAGS<64>::IMAGE_ORDINAL_FLAG = 0x8000000000000000ULL;
24 24
25 bool PELIB_IMAGE_SECTION_HEADER::biggerFileOffset(const PELIB_IMAGE_SECTION_HEADER& ish) const 25 bool PELIB_IMAGE_SECTION_HEADER::biggerFileOffset(const PELIB_IMAGE_SECTION_HEADER& ish) const
26 { 26 {
27 return PointerToRawData < ish.PointerToRawData; 27 return PointerToRawData < ish.PointerToRawData;
28 } 28 }
29 29
30 bool PELIB_IMAGE_SECTION_HEADER::biggerVirtualAddress(const PELIB_IMAGE_SECTION_HEADER& ish) const 30 bool PELIB_IMAGE_SECTION_HEADER::biggerVirtualAddress(const PELIB_IMAGE_SECTION_HEADER& ish) const
31 { 31 {
32 return VirtualAddress < ish.VirtualAddress; 32 return VirtualAddress < ish.VirtualAddress;
33 } 33 }
34 34
35 unsigned int alignOffset(unsigned int uiOffset, unsigned int uiAlignment) 35 unsigned int alignOffset(unsigned int uiOffset, unsigned int uiAlignment)
36 { 36 {
37 if (!uiAlignment) return uiAlignment; 37 if (!uiAlignment) return uiAlignment;
38 return (uiOffset % uiAlignment) ? uiOffset + (uiAlignment - uiOffset % uiAlignment) : uiOffset; 38 return (uiOffset % uiAlignment) ? uiOffset + (uiAlignment - uiOffset % uiAlignment) : uiOffset;
39 } 39 }
40 40
41 unsigned int fileSize(const std::string& filename) 41 unsigned int fileSize(const std::string& filename)
42 { 42 {
43 std::fstream file(filename.c_str()); 43 std::fstream file(filename.c_str());
44 file.seekg(0, std::ios::end); 44 file.seekg(0, std::ios::end);
45 return file.tellg(); 45 return file.tellg();
46 } 46 }
47 47
48 unsigned int fileSize(std::ifstream& file) 48 unsigned int fileSize(std::ifstream& file)
49 { 49 {
50 unsigned int oldpos = file.tellg(); 50 unsigned int oldpos = file.tellg();
51 file.seekg(0, std::ios::end); 51 file.seekg(0, std::ios::end);
52 unsigned int filesize = file.tellg(); 52 unsigned int filesize = file.tellg();
53 file.seekg(oldpos, std::ios::beg); 53 file.seekg(oldpos, std::ios::beg);
54 return filesize; 54 return filesize;
55 } 55 }
56 56
57 unsigned int fileSize(std::fstream& file) 57 unsigned int fileSize(std::fstream& file)
58 { 58 {
59 unsigned int oldpos = file.tellg(); 59 unsigned int oldpos = file.tellg();
60 file.seekg(0, std::ios::end); 60 file.seekg(0, std::ios::end);
61 unsigned int filesize = file.tellg(); 61 unsigned int filesize = file.tellg();
62 file.seekg(oldpos, std::ios::beg); 62 file.seekg(oldpos, std::ios::beg);
63 return filesize; 63 return filesize;
64 } 64 }
65 65
66 unsigned int fileSize(std::ofstream& file) 66 unsigned int fileSize(std::ofstream& file)
67 { 67 {
68 unsigned int oldpos = file.tellp(); 68 unsigned int oldpos = file.tellp();
69 file.seekp(0, std::ios::end); 69 file.seekp(0, std::ios::end);
70 unsigned int filesize = file.tellp(); 70 unsigned int filesize = file.tellp();
71 file.seekp(oldpos, std::ios::beg); 71 file.seekp(oldpos, std::ios::beg);
72 return filesize; 72 return filesize;
73 } 73 }
74 74
75 bool isEqualNc(const std::string& s1, const std::string& s2) 75 bool isEqualNc(const std::string& s1, const std::string& s2)
76 { 76 {
77 std::string t1 = s1; 77 std::string t1 = s1;
78 std::string t2 = s2; 78 std::string t2 = s2;
79 79
80 // No std:: to make VC++ happy 80 // No std:: to make VC++ happy
81 #ifdef _MSC_VER 81 #ifdef _MSC_VER
82 std::transform(t1.begin(), t1.end(), t1.begin(), toupper); 82 std::transform(t1.begin(), t1.end(), t1.begin(), toupper);
83 std::transform(t2.begin(), t2.end(), t2.begin(), toupper); 83 std::transform(t2.begin(), t2.end(), t2.begin(), toupper);
84 #else 84 #else
85 // Weird syntax to make Borland C++ happy 85 // Weird syntax to make Borland C++ happy
86 std::transform(t1.begin(), t1.end(), t1.begin(), (int(*)(int))std::toupper); 86 std::transform(t1.begin(), t1.end(), t1.begin(), (int(*)(int))std::toupper);
87 std::transform(t2.begin(), t2.end(), t2.begin(), (int(*)(int))std::toupper); 87 std::transform(t2.begin(), t2.end(), t2.begin(), (int(*)(int))std::toupper);
88 #endif 88 #endif
89 return t1 == t2; 89 return t1 == t2;
90 } 90 }
91 91
92 PELIB_IMAGE_DOS_HEADER::PELIB_IMAGE_DOS_HEADER() 92 PELIB_IMAGE_DOS_HEADER::PELIB_IMAGE_DOS_HEADER()
93 { 93 {
94 e_magic = 0; 94 e_magic = 0;
95 e_cblp = 0; 95 e_cblp = 0;
96 e_cp = 0; 96 e_cp = 0;
97 e_crlc = 0; 97 e_crlc = 0;
98 e_cparhdr = 0; 98 e_cparhdr = 0;
99 e_minalloc = 0; 99 e_minalloc = 0;
100 e_maxalloc = 0; 100 e_maxalloc = 0;
101 e_ss = 0; 101 e_ss = 0;
102 e_sp = 0; 102 e_sp = 0;
103 e_csum = 0; 103 e_csum = 0;
104 e_ip = 0; 104 e_ip = 0;
105 e_cs = 0; 105 e_cs = 0;
106 e_lfarlc = 0; 106 e_lfarlc = 0;
107 e_ovno = 0; 107 e_ovno = 0;
108 108
109 for (unsigned int i=0;i<sizeof(e_res)/sizeof(e_res[0]);i++) 109 for (unsigned int i=0;i<sizeof(e_res)/sizeof(e_res[0]);i++)
110 { 110 {
111 e_res[i] = 0; 111 e_res[i] = 0;
112 } 112 }
113 113
114 e_oemid = 0; 114 e_oemid = 0;
115 e_oeminfo = 0; 115 e_oeminfo = 0;
116 116
117 for (unsigned int i=0;i<sizeof(e_res2)/sizeof(e_res2[0]);i++) 117 for (unsigned int i=0;i<sizeof(e_res2)/sizeof(e_res2[0]);i++)
118 { 118 {
119 e_res2[i] = 0; 119 e_res2[i] = 0;
120 } 120 }
121 121
122 e_lfanew = 0; 122 e_lfanew = 0;
123 } 123 }
124 124
125 PELIB_EXP_FUNC_INFORMATION::PELIB_EXP_FUNC_INFORMATION() 125 PELIB_EXP_FUNC_INFORMATION::PELIB_EXP_FUNC_INFORMATION()
126 { 126 {
127 addroffunc = 0; 127 addroffunc = 0;
128 addrofname = 0; 128 addrofname = 0;
129 ordinal = 0; 129 ordinal = 0;
130 } 130 }
131 131
132 PELIB_IMAGE_RESOURCE_DIRECTORY::PELIB_IMAGE_RESOURCE_DIRECTORY() 132 PELIB_IMAGE_RESOURCE_DIRECTORY::PELIB_IMAGE_RESOURCE_DIRECTORY()
133 { 133 {
134 Characteristics = 0; 134 Characteristics = 0;
135 TimeDateStamp = 0; 135 TimeDateStamp = 0;
136 MajorVersion = 0; 136 MajorVersion = 0;
137 MinorVersion = 0; 137 MinorVersion = 0;
138 NumberOfNamedEntries = 0; 138 NumberOfNamedEntries = 0;
139 NumberOfIdEntries = 0; 139 NumberOfIdEntries = 0;
140 } 140 }
141 141
142 PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY::PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY() 142 PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY::PELIB_IMAGE_RESOURCE_DIRECTORY_ENTRY()
143 { 143 {
144 Name = 0; 144 Name = 0;
145 OffsetToData = 0; 145 OffsetToData = 0;
146 } 146 }
147 147
148 bool PELIB_IMG_RES_DIR_ENTRY::operator<(const PELIB_IMG_RES_DIR_ENTRY& first) const 148 bool PELIB_IMG_RES_DIR_ENTRY::operator<(const PELIB_IMG_RES_DIR_ENTRY& first) const
149 { 149 {
150 if (irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING && first.irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING) 150 if (irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING && first.irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING)
151 { 151 {
152 return wstrName < first.wstrName; 152 return wstrName < first.wstrName;
153 } 153 }
154 else if (irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING) 154 else if (irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING)
155 { 155 {
156 return true; 156 return true;
157 } 157 }
158 else if (first.irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING) 158 else if (first.irde.Name & PELIB_IMAGE_RESOURCE_NAME_IS_STRING)
159 { 159 {
160 return false; 160 return false;
161 } 161 }
162 else 162 else
163 { 163 {
164 return irde.Name < first.irde.Name; 164 return irde.Name < first.irde.Name;
165 } 165 }
166 } 166 }
167 167
168 PELIB_IMAGE_BASE_RELOCATION::PELIB_IMAGE_BASE_RELOCATION() 168 PELIB_IMAGE_BASE_RELOCATION::PELIB_IMAGE_BASE_RELOCATION()
169 { 169 {
170 VirtualAddress = 0; 170 VirtualAddress = 0;
171 SizeOfBlock = 0; 171 SizeOfBlock = 0;
172 } 172 }
173 173
174 PELIB_IMAGE_COR20_HEADER::PELIB_IMAGE_COR20_HEADER() 174 PELIB_IMAGE_COR20_HEADER::PELIB_IMAGE_COR20_HEADER()
175 { 175 {
176 cb = 0; 176 cb = 0;
177 MajorRuntimeVersion = 0; 177 MajorRuntimeVersion = 0;
178 MinorRuntimeVersion = 0; 178 MinorRuntimeVersion = 0;
179 MetaData.VirtualAddress = 0; 179 MetaData.VirtualAddress = 0;
180 MetaData.Size = 0; 180 MetaData.Size = 0;
181 Flags = 0; 181 Flags = 0;
182 EntryPointToken = 0; 182 EntryPointToken = 0;
183 Resources.VirtualAddress = 0; 183 Resources.VirtualAddress = 0;
184 Resources.Size = 0; 184 Resources.Size = 0;
185 StrongNameSignature.VirtualAddress = 0; 185 StrongNameSignature.VirtualAddress = 0;
186 StrongNameSignature.Size = 0; 186 StrongNameSignature.Size = 0;
187 CodeManagerTable.VirtualAddress = 0; 187 CodeManagerTable.VirtualAddress = 0;
188 CodeManagerTable.Size = 0; 188 CodeManagerTable.Size = 0;
189 VTableFixups.VirtualAddress = 0; 189 VTableFixups.VirtualAddress = 0;
190 VTableFixups.Size = 0; 190 VTableFixups.Size = 0;
191 ExportAddressTableJumps.VirtualAddress = 0; 191 ExportAddressTableJumps.VirtualAddress = 0;
192 ExportAddressTableJumps.Size = 0; 192 ExportAddressTableJumps.Size = 0;
193 ManagedNativeHeader.VirtualAddress = 0; 193 ManagedNativeHeader.VirtualAddress = 0;
194 ManagedNativeHeader.Size = 0; 194 ManagedNativeHeader.Size = 0;
195 } 195 }
196 196
197 /** Compares the passed filename to the struct's filename. 197 /** Compares the passed filename to the struct's filename.
198 * @param strModuleName A filename. 198 * @param strModuleName A filename.
199 * @return True, if the passed filename equals the struct's filename. The comparison is case-sensitive. 199 * @return True, if the passed filename equals the struct's filename. The comparison is case-sensitive.
200 **/ 200 **/
201 bool PELIB_IMAGE_BOUND_DIRECTORY::equal(const std::string strModuleName) const 201 bool PELIB_IMAGE_BOUND_DIRECTORY::equal(const std::string strModuleName) const
202 { 202 {
203 return this->strModuleName == strModuleName; 203 return this->strModuleName == strModuleName;
204 } 204 }
205 205
206 bool PELIB_EXP_FUNC_INFORMATION::equal(const std::string strFunctionName) const 206 bool PELIB_EXP_FUNC_INFORMATION::equal(const std::string strFunctionName) const
207 { 207 {
208 return isEqualNc(this->funcname, strFunctionName); 208 return isEqualNc(this->funcname, strFunctionName);
209 } 209 }
210 210
211 /** 211 /**
212 * @param strFilename Name of a file. 212 * @param strFilename Name of a file.
213 * @return Either PEFILE32, PEFILE64 or PEFILE_UNKNOWN 213 * @return Either PEFILE32, PEFILE64 or PEFILE_UNKNOWN
214 **/ 214 **/
215 unsigned int getFileType(const std::string strFilename) 215 unsigned int getFileType(const std::string strFilename)
216 { 216 {
217 word machine, magic; 217 word machine, magic;
218 218
219 PeFile32 pef(strFilename); 219 PeFile32 pef(strFilename);
220 if (pef.readMzHeader() != NO_ERROR) return PEFILE_UNKNOWN; 220 if (pef.readMzHeader() != NO_ERROR) return PEFILE_UNKNOWN;
221 if (pef.readPeHeader() != NO_ERROR) return PEFILE_UNKNOWN; 221 if (pef.readPeHeader() != NO_ERROR) return PEFILE_UNKNOWN;
222 222
223 machine = pef.peHeader().getMachine(); 223 machine = pef.peHeader().getMachine();
224 magic = pef.peHeader().getMagic(); 224 magic = pef.peHeader().getMagic();
225 225
226 if (machine == PELIB_IMAGE_FILE_MACHINE_I386 && magic == PELIB_IMAGE_NT_OPTIONAL_HDR32_MAGIC) 226 if (machine == PELIB_IMAGE_FILE_MACHINE_I386 && magic == PELIB_IMAGE_NT_OPTIONAL_HDR32_MAGIC)
227 { 227 {
228 return PEFILE32; 228 return PEFILE32;
229 } 229 }
230 // 0x8664 == AMD64; no named constant yet 230 // 0x8664 == AMD64; no named constant yet
231 else if ((machine == 0x8664 || machine == PELIB_IMAGE_FILE_MACHINE_IA64) && magic == PELIB_IMAGE_NT_OPTIONAL_HDR64_MAGIC) 231 else if ((machine == 0x8664 || machine == PELIB_IMAGE_FILE_MACHINE_IA64) && magic == PELIB_IMAGE_NT_OPTIONAL_HDR64_MAGIC)
232 { 232 {
233 return PEFILE64; 233 return PEFILE64;
234 } 234 }
235 else 235 else
236 { 236 {
237 return PEFILE_UNKNOWN; 237 return PEFILE_UNKNOWN;
238 } 238 }
239 } 239 }
240 240
241 /** 241 /**
242 * Opens a PE file. The return type is either PeFile32 or PeFile64 object. If an error occurs the return 242 * Opens a PE file. The return type is either PeFile32 or PeFile64 object. If an error occurs the return
243 * value is 0. 243 * value is 0.
244 * @param strFilename Name of a file. 244 * @param strFilename Name of a file.
245 * @return Either a PeFile32 object, a PeFil64 object or 0. 245 * @return Either a PeFile32 object, a PeFil64 object or 0.
246 **/ 246 **/
247 PeFile* openPeFile(const std::string& strFilename) 247 PeFile* openPeFile(const std::string& strFilename)
248 { 248 {
249 unsigned int type = getFileType(strFilename); 249 unsigned int type = getFileType(strFilename);
250 250
251 if (type == PEFILE32) 251 if (type == PEFILE32)
252 { 252 {
253 return new PeFile32(strFilename); 253 return new PeFile32(strFilename);
254 } 254 }
255 else if (type == PEFILE64) 255 else if (type == PEFILE64)
256 { 256 {
257 return new PeFile64(strFilename); 257 return new PeFile64(strFilename);
258 } 258 }
259 else 259 else
260 { 260 {
261 return 0; 261 return 0;
262 } 262 }
263 } 263 }
264 264
265 unsigned int PELIB_IMAGE_BOUND_DIRECTORY::size() const 265 unsigned int PELIB_IMAGE_BOUND_DIRECTORY::size() const
266 { 266 {
267 unsigned int size = 0; 267 unsigned int size = 0;
268 for (unsigned int i=0;i<moduleForwarders.size();i++) 268 for (unsigned int i=0;i<moduleForwarders.size();i++)
269 { 269 {
270 size += moduleForwarders[i].size(); 270 size += moduleForwarders[i].size();
271 } 271 }
272 272
273 return size + PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR::size() + strModuleName.size() + 1; 273 return size + PELIB_IMAGE_BOUND_IMPORT_DESCRIPTOR::size() + strModuleName.size() + 1;
274 } 274 }
275} 275}