diff options
author | Nicolas Pennequin <nicolas.pennequin@free.fr> | 2008-07-11 16:51:25 +0000 |
---|---|---|
committer | Nicolas Pennequin <nicolas.pennequin@free.fr> | 2008-07-11 16:51:25 +0000 |
commit | ca5bb76d2b8f65aa97e50b633f828c1deb241526 (patch) | |
tree | 453a1b2de3a0dc0d0b2f7080d10d033bf8fbcdf1 /utils/zenutils/libraries/pelib-0.9/pelib/RelocationsDirectory.cpp | |
parent | 141774be48940d56e3ad4dbf451d245b61d4f8b2 (diff) | |
download | rockbox-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/RelocationsDirectory.cpp')
-rw-r--r--[-rwxr-xr-x] | utils/zenutils/libraries/pelib-0.9/pelib/RelocationsDirectory.cpp | 422 |
1 files changed, 211 insertions, 211 deletions
diff --git a/utils/zenutils/libraries/pelib-0.9/pelib/RelocationsDirectory.cpp b/utils/zenutils/libraries/pelib-0.9/pelib/RelocationsDirectory.cpp index d8b5035abf..392261d242 100755..100644 --- a/utils/zenutils/libraries/pelib-0.9/pelib/RelocationsDirectory.cpp +++ b/utils/zenutils/libraries/pelib-0.9/pelib/RelocationsDirectory.cpp | |||
@@ -1,211 +1,211 @@ | |||
1 | /* | 1 | /* |
2 | * Relocations.cpp - Part of the PeLib library. | 2 | * Relocations.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 "RelocationsDirectory.h" | 14 | #include "RelocationsDirectory.h" |
15 | 15 | ||
16 | namespace PeLib | 16 | namespace PeLib |
17 | { | 17 | { |
18 | void RelocationsDirectory::setRelocationData(unsigned int ulRelocation, unsigned int ulDataNumber, word wData) | 18 | void RelocationsDirectory::setRelocationData(unsigned int ulRelocation, unsigned int ulDataNumber, word wData) |
19 | { | 19 | { |
20 | m_vRelocations[ulRelocation].vRelocData[ulDataNumber] = wData; | 20 | m_vRelocations[ulRelocation].vRelocData[ulDataNumber] = wData; |
21 | } | 21 | } |
22 | 22 | ||
23 | void RelocationsDirectory::read(InputBuffer& inputbuffer, unsigned int uiSize) | 23 | void RelocationsDirectory::read(InputBuffer& inputbuffer, unsigned int uiSize) |
24 | { | 24 | { |
25 | IMG_BASE_RELOC ibrCurr; | 25 | IMG_BASE_RELOC ibrCurr; |
26 | 26 | ||
27 | std::vector<IMG_BASE_RELOC> vCurrReloc; | 27 | std::vector<IMG_BASE_RELOC> vCurrReloc; |
28 | 28 | ||
29 | do | 29 | do |
30 | { | 30 | { |
31 | inputbuffer >> ibrCurr.ibrRelocation.VirtualAddress; | 31 | inputbuffer >> ibrCurr.ibrRelocation.VirtualAddress; |
32 | inputbuffer >> ibrCurr.ibrRelocation.SizeOfBlock; | 32 | inputbuffer >> ibrCurr.ibrRelocation.SizeOfBlock; |
33 | 33 | ||
34 | ibrCurr.vRelocData.clear(); | 34 | ibrCurr.vRelocData.clear(); |
35 | 35 | ||
36 | // That's not how to check if there are relocations, some DLLs start at VA 0. | 36 | // That's not how to check if there are relocations, some DLLs start at VA 0. |
37 | // if (!ibrCurr.ibrRelocation.VirtualAddress) break; | 37 | // if (!ibrCurr.ibrRelocation.VirtualAddress) break; |
38 | 38 | ||
39 | for (unsigned int i=0;i<(ibrCurr.ibrRelocation.SizeOfBlock - PELIB_IMAGE_SIZEOF_BASE_RELOCATION) / sizeof(word);i++) | 39 | for (unsigned int i=0;i<(ibrCurr.ibrRelocation.SizeOfBlock - PELIB_IMAGE_SIZEOF_BASE_RELOCATION) / sizeof(word);i++) |
40 | { | 40 | { |
41 | word wData; | 41 | word wData; |
42 | inputbuffer >> wData; | 42 | inputbuffer >> wData; |
43 | ibrCurr.vRelocData.push_back(wData); | 43 | ibrCurr.vRelocData.push_back(wData); |
44 | } | 44 | } |
45 | 45 | ||
46 | vCurrReloc.push_back(ibrCurr); | 46 | vCurrReloc.push_back(ibrCurr); |
47 | } while (ibrCurr.ibrRelocation.VirtualAddress && inputbuffer.get() < uiSize); | 47 | } while (ibrCurr.ibrRelocation.VirtualAddress && inputbuffer.get() < uiSize); |
48 | 48 | ||
49 | std::swap(vCurrReloc, m_vRelocations); | 49 | std::swap(vCurrReloc, m_vRelocations); |
50 | } | 50 | } |
51 | 51 | ||
52 | // TODO: Return value is wrong if buffer was too small. | 52 | // TODO: Return value is wrong if buffer was too small. |
53 | int RelocationsDirectory::read(const unsigned char* buffer, unsigned int buffersize) | 53 | int RelocationsDirectory::read(const unsigned char* buffer, unsigned int buffersize) |
54 | { | 54 | { |
55 | std::vector<unsigned char> vRelocDirectory(buffer, buffer + buffersize); | 55 | std::vector<unsigned char> vRelocDirectory(buffer, buffer + buffersize); |
56 | 56 | ||
57 | InputBuffer ibBuffer(vRelocDirectory); | 57 | InputBuffer ibBuffer(vRelocDirectory); |
58 | read(ibBuffer, buffersize); | 58 | read(ibBuffer, buffersize); |
59 | 59 | ||
60 | return NO_ERROR; | 60 | return NO_ERROR; |
61 | } | 61 | } |
62 | 62 | ||
63 | int RelocationsDirectory::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize) | 63 | int RelocationsDirectory::read(const std::string& strFilename, unsigned int uiOffset, unsigned int uiSize) |
64 | { | 64 | { |
65 | std::ifstream ifFile(strFilename.c_str(), std::ios::binary); | 65 | std::ifstream ifFile(strFilename.c_str(), std::ios::binary); |
66 | unsigned int ulFileSize = fileSize(ifFile); | 66 | unsigned int ulFileSize = fileSize(ifFile); |
67 | 67 | ||
68 | if (!ifFile) | 68 | if (!ifFile) |
69 | { | 69 | { |
70 | return ERROR_OPENING_FILE; | 70 | return ERROR_OPENING_FILE; |
71 | } | 71 | } |
72 | 72 | ||
73 | if (ulFileSize < uiOffset + uiSize) | 73 | if (ulFileSize < uiOffset + uiSize) |
74 | { | 74 | { |
75 | return ERROR_INVALID_FILE; | 75 | return ERROR_INVALID_FILE; |
76 | } | 76 | } |
77 | 77 | ||
78 | ifFile.seekg(uiOffset, std::ios::beg); | 78 | ifFile.seekg(uiOffset, std::ios::beg); |
79 | 79 | ||
80 | std::vector<unsigned char> vRelocDirectory(uiSize); | 80 | std::vector<unsigned char> vRelocDirectory(uiSize); |
81 | ifFile.read(reinterpret_cast<char*>(&vRelocDirectory[0]), uiSize); | 81 | ifFile.read(reinterpret_cast<char*>(&vRelocDirectory[0]), uiSize); |
82 | 82 | ||
83 | InputBuffer ibBuffer(vRelocDirectory); | 83 | InputBuffer ibBuffer(vRelocDirectory); |
84 | read(ibBuffer, uiSize); | 84 | read(ibBuffer, uiSize); |
85 | 85 | ||
86 | return NO_ERROR; | 86 | return NO_ERROR; |
87 | } | 87 | } |
88 | 88 | ||
89 | unsigned int RelocationsDirectory::size() const | 89 | unsigned int RelocationsDirectory::size() const |
90 | { | 90 | { |
91 | unsigned int size = static_cast<unsigned int>(m_vRelocations.size()) * PELIB_IMAGE_BASE_RELOCATION::size(); | 91 | unsigned int size = static_cast<unsigned int>(m_vRelocations.size()) * PELIB_IMAGE_BASE_RELOCATION::size(); |
92 | 92 | ||
93 | for (unsigned int i=0;i<m_vRelocations.size();i++) | 93 | for (unsigned int i=0;i<m_vRelocations.size();i++) |
94 | { | 94 | { |
95 | size += static_cast<unsigned int>(m_vRelocations[i].vRelocData.size()) * sizeof(word); | 95 | size += static_cast<unsigned int>(m_vRelocations[i].vRelocData.size()) * sizeof(word); |
96 | } | 96 | } |
97 | 97 | ||
98 | return size; | 98 | return size; |
99 | } | 99 | } |
100 | 100 | ||
101 | void RelocationsDirectory::rebuild(std::vector<byte>& vBuffer) const | 101 | void RelocationsDirectory::rebuild(std::vector<byte>& vBuffer) const |
102 | { | 102 | { |
103 | OutputBuffer obBuffer(vBuffer); | 103 | OutputBuffer obBuffer(vBuffer); |
104 | 104 | ||
105 | for (unsigned int i=0;i<m_vRelocations.size();i++) | 105 | for (unsigned int i=0;i<m_vRelocations.size();i++) |
106 | { | 106 | { |
107 | obBuffer << m_vRelocations[i].ibrRelocation.VirtualAddress; | 107 | obBuffer << m_vRelocations[i].ibrRelocation.VirtualAddress; |
108 | obBuffer << m_vRelocations[i].ibrRelocation.SizeOfBlock; | 108 | obBuffer << m_vRelocations[i].ibrRelocation.SizeOfBlock; |
109 | 109 | ||
110 | for (unsigned int j=0;j<m_vRelocations[i].vRelocData.size();j++) | 110 | for (unsigned int j=0;j<m_vRelocations[i].vRelocData.size();j++) |
111 | { | 111 | { |
112 | obBuffer << m_vRelocations[i].vRelocData[j]; | 112 | obBuffer << m_vRelocations[i].vRelocData[j]; |
113 | } | 113 | } |
114 | } | 114 | } |
115 | } | 115 | } |
116 | 116 | ||
117 | unsigned int RelocationsDirectory::calcNumberOfRelocations() const | 117 | unsigned int RelocationsDirectory::calcNumberOfRelocations() const |
118 | { | 118 | { |
119 | return static_cast<unsigned int>(m_vRelocations.size()); | 119 | return static_cast<unsigned int>(m_vRelocations.size()); |
120 | } | 120 | } |
121 | 121 | ||
122 | dword RelocationsDirectory::getVirtualAddress(unsigned int ulRelocation) const | 122 | dword RelocationsDirectory::getVirtualAddress(unsigned int ulRelocation) const |
123 | { | 123 | { |
124 | return m_vRelocations[ulRelocation].ibrRelocation.VirtualAddress; | 124 | return m_vRelocations[ulRelocation].ibrRelocation.VirtualAddress; |
125 | } | 125 | } |
126 | 126 | ||
127 | dword RelocationsDirectory::getSizeOfBlock(unsigned int ulRelocation) const | 127 | dword RelocationsDirectory::getSizeOfBlock(unsigned int ulRelocation) const |
128 | { | 128 | { |
129 | return m_vRelocations[ulRelocation].ibrRelocation.SizeOfBlock; | 129 | return m_vRelocations[ulRelocation].ibrRelocation.SizeOfBlock; |
130 | } | 130 | } |
131 | 131 | ||
132 | unsigned int RelocationsDirectory::calcNumberOfRelocationData(unsigned int ulRelocation) const | 132 | unsigned int RelocationsDirectory::calcNumberOfRelocationData(unsigned int ulRelocation) const |
133 | { | 133 | { |
134 | return static_cast<unsigned int>(m_vRelocations[ulRelocation].vRelocData.size()); | 134 | return static_cast<unsigned int>(m_vRelocations[ulRelocation].vRelocData.size()); |
135 | } | 135 | } |
136 | 136 | ||
137 | word RelocationsDirectory::getRelocationData(unsigned int ulRelocation, unsigned int ulDataNumber) const | 137 | word RelocationsDirectory::getRelocationData(unsigned int ulRelocation, unsigned int ulDataNumber) const |
138 | { | 138 | { |
139 | return m_vRelocations[ulRelocation].vRelocData[ulDataNumber]; | 139 | return m_vRelocations[ulRelocation].vRelocData[ulDataNumber]; |
140 | } | 140 | } |
141 | 141 | ||
142 | void RelocationsDirectory::setVirtualAddress(unsigned int ulRelocation, dword dwValue) | 142 | void RelocationsDirectory::setVirtualAddress(unsigned int ulRelocation, dword dwValue) |
143 | { | 143 | { |
144 | m_vRelocations[ulRelocation].ibrRelocation.VirtualAddress = dwValue; | 144 | m_vRelocations[ulRelocation].ibrRelocation.VirtualAddress = dwValue; |
145 | } | 145 | } |
146 | 146 | ||
147 | void RelocationsDirectory::setSizeOfBlock(unsigned int ulRelocation, dword dwValue) | 147 | void RelocationsDirectory::setSizeOfBlock(unsigned int ulRelocation, dword dwValue) |
148 | { | 148 | { |
149 | m_vRelocations[ulRelocation].ibrRelocation.SizeOfBlock = dwValue; | 149 | m_vRelocations[ulRelocation].ibrRelocation.SizeOfBlock = dwValue; |
150 | } | 150 | } |
151 | 151 | ||
152 | void RelocationsDirectory::addRelocation() | 152 | void RelocationsDirectory::addRelocation() |
153 | { | 153 | { |
154 | IMG_BASE_RELOC newrelocation; | 154 | IMG_BASE_RELOC newrelocation; |
155 | m_vRelocations.push_back(newrelocation); | 155 | m_vRelocations.push_back(newrelocation); |
156 | } | 156 | } |
157 | 157 | ||
158 | void RelocationsDirectory::addRelocationData(unsigned int ulRelocation, word wValue) | 158 | void RelocationsDirectory::addRelocationData(unsigned int ulRelocation, word wValue) |
159 | { | 159 | { |
160 | m_vRelocations[ulRelocation].vRelocData.push_back(wValue); | 160 | m_vRelocations[ulRelocation].vRelocData.push_back(wValue); |
161 | } | 161 | } |
162 | 162 | ||
163 | /* void RelocationsDirectory::removeRelocationData(unsigned int ulRelocation, word wValue) | 163 | /* void RelocationsDirectory::removeRelocationData(unsigned int ulRelocation, word wValue) |
164 | { | 164 | { |
165 | // If you get an error with Borland C++ here you have two options: Upgrade your compiler | 165 | // If you get an error with Borland C++ here you have two options: Upgrade your compiler |
166 | // or use the commented line instead of the line below. | 166 | // or use the commented line instead of the line below. |
167 | m_vRelocations[ulRelocation].vRelocData.erase(std::remove(m_vRelocations[ulRelocation].vRelocData.begin(), m_vRelocations[ulRelocation].vRelocData.end(), wValue), m_vRelocations[ulRelocation].vRelocData.end()); | 167 | m_vRelocations[ulRelocation].vRelocData.erase(std::remove(m_vRelocations[ulRelocation].vRelocData.begin(), m_vRelocations[ulRelocation].vRelocData.end(), wValue), m_vRelocations[ulRelocation].vRelocData.end()); |
168 | } | 168 | } |
169 | */ | 169 | */ |
170 | void RelocationsDirectory::removeRelocation(unsigned int index) | 170 | void RelocationsDirectory::removeRelocation(unsigned int index) |
171 | { | 171 | { |
172 | m_vRelocations.erase(m_vRelocations.begin() + index); | 172 | m_vRelocations.erase(m_vRelocations.begin() + index); |
173 | } | 173 | } |
174 | 174 | ||
175 | void RelocationsDirectory::removeRelocationData(unsigned int relocindex, unsigned int dataindex) | 175 | void RelocationsDirectory::removeRelocationData(unsigned int relocindex, unsigned int dataindex) |
176 | { | 176 | { |
177 | m_vRelocations[relocindex].vRelocData.erase(m_vRelocations[relocindex].vRelocData.begin() + dataindex); | 177 | m_vRelocations[relocindex].vRelocData.erase(m_vRelocations[relocindex].vRelocData.begin() + dataindex); |
178 | } | 178 | } |
179 | 179 | ||
180 | int RelocationsDirectory::write(const std::string& strFilename, unsigned int uiOffset) const | 180 | int RelocationsDirectory::write(const std::string& strFilename, unsigned int uiOffset) const |
181 | { | 181 | { |
182 | std::fstream ofFile(strFilename.c_str(), std::ios_base::in); | 182 | std::fstream ofFile(strFilename.c_str(), std::ios_base::in); |
183 | 183 | ||
184 | if (!ofFile) | 184 | if (!ofFile) |
185 | { | 185 | { |
186 | ofFile.clear(); | 186 | ofFile.clear(); |
187 | ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); | 187 | ofFile.open(strFilename.c_str(), std::ios_base::out | std::ios_base::binary); |
188 | } | 188 | } |
189 | else | 189 | else |
190 | { | 190 | { |
191 | ofFile.close(); | 191 | ofFile.close(); |
192 | ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); | 192 | ofFile.open(strFilename.c_str(), std::ios_base::in | std::ios_base::out | std::ios_base::binary); |
193 | } | 193 | } |
194 | 194 | ||
195 | if (!ofFile) | 195 | if (!ofFile) |
196 | { | 196 | { |
197 | return ERROR_OPENING_FILE; | 197 | return ERROR_OPENING_FILE; |
198 | } | 198 | } |
199 | 199 | ||
200 | ofFile.seekp(uiOffset, std::ios::beg); | 200 | ofFile.seekp(uiOffset, std::ios::beg); |
201 | 201 | ||
202 | std::vector<unsigned char> vBuffer; | 202 | std::vector<unsigned char> vBuffer; |
203 | rebuild(vBuffer); | 203 | rebuild(vBuffer); |
204 | 204 | ||
205 | ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<std::streamsize>(vBuffer.size())); | 205 | ofFile.write(reinterpret_cast<const char*>(&vBuffer[0]), static_cast<std::streamsize>(vBuffer.size())); |
206 | 206 | ||
207 | ofFile.close(); | 207 | ofFile.close(); |
208 | 208 | ||
209 | return NO_ERROR; | 209 | return NO_ERROR; |
210 | } | 210 | } |
211 | } | 211 | } |