| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // This file was adapted from GreenBorder's Code. | 5 // This file was adapted from GreenBorder's Code. |
| 6 // To understand what this class is about (for other than well known functions | 6 // To understand what this class is about (for other than well known functions |
| 7 // as GetProcAddress), a good starting point is "An In-Depth Look into the | 7 // as GetProcAddress), a good starting point is "An In-Depth Look into the |
| 8 // Win32 Portable Executable File Format" by Matt Pietrek: | 8 // Win32 Portable Executable File Format" by Matt Pietrek: |
| 9 // http://msdn.microsoft.com/msdnmag/issues/02/02/PE/default.aspx | 9 // http://msdn.microsoft.com/msdnmag/issues/02/02/PE/default.aspx |
| 10 | 10 |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 // Enumerates PE relocation entries. | 198 // Enumerates PE relocation entries. |
| 199 // cookie is a generic cookie to pass to the callback. | 199 // cookie is a generic cookie to pass to the callback. |
| 200 // Returns true on success. | 200 // Returns true on success. |
| 201 bool EnumRelocs(EnumRelocsFunction callback, PVOID cookie) const; | 201 bool EnumRelocs(EnumRelocsFunction callback, PVOID cookie) const; |
| 202 | 202 |
| 203 // Verifies the magic values on the PE file. | 203 // Verifies the magic values on the PE file. |
| 204 // Returns true if all values are correct. | 204 // Returns true if all values are correct. |
| 205 bool VerifyMagic() const; | 205 bool VerifyMagic() const; |
| 206 | 206 |
| 207 // Converts an rva value to the appropriate address. | 207 // Converts an rva value to the appropriate address. |
| 208 virtual PVOID RVAToAddr(DWORD_PTR rva) const; | 208 virtual PVOID RVAToAddr(DWORD rva) const; |
| 209 | 209 |
| 210 // Converts an rva value to an offset on disk. | 210 // Converts an rva value to an offset on disk. |
| 211 // Returns true on success. | 211 // Returns true on success. |
| 212 bool ImageRVAToOnDiskOffset(DWORD rva, DWORD *on_disk_offset) const; | 212 bool ImageRVAToOnDiskOffset(DWORD rva, DWORD *on_disk_offset) const; |
| 213 | 213 |
| 214 // Converts an address to an offset on disk. | 214 // Converts an address to an offset on disk. |
| 215 // Returns true on success. | 215 // Returns true on success. |
| 216 bool ImageAddrToOnDiskOffset(LPVOID address, DWORD *on_disk_offset) const; | 216 bool ImageAddrToOnDiskOffset(LPVOID address, DWORD *on_disk_offset) const; |
| 217 | 217 |
| 218 private: | 218 private: |
| 219 HMODULE module_; | 219 HMODULE module_; |
| 220 }; | 220 }; |
| 221 | 221 |
| 222 // This class is an extension to the PEImage class that allows working with PE | 222 // This class is an extension to the PEImage class that allows working with PE |
| 223 // files mapped as data instead of as image file. | 223 // files mapped as data instead of as image file. |
| 224 class PEImageAsData : public PEImage { | 224 class PEImageAsData : public PEImage { |
| 225 public: | 225 public: |
| 226 explicit PEImageAsData(HMODULE hModule) : PEImage(hModule) {} | 226 explicit PEImageAsData(HMODULE hModule) : PEImage(hModule) {} |
| 227 | 227 |
| 228 virtual PVOID RVAToAddr(DWORD_PTR rva) const; | 228 virtual PVOID RVAToAddr(DWORD rva) const; |
| 229 }; | 229 }; |
| 230 | 230 |
| 231 inline bool PEImage::IsOrdinal(LPCSTR name) { | 231 inline bool PEImage::IsOrdinal(LPCSTR name) { |
| 232 #pragma warning(push) | 232 #pragma warning(push) |
| 233 #pragma warning(disable: 4311) | 233 #pragma warning(disable: 4311) |
| 234 // This cast generates a warning because it is 32 bit specific. | 234 // This cast generates a warning because it is 32 bit specific. |
| 235 return reinterpret_cast<DWORD>(name) <= 0xFFFF; | 235 return reinterpret_cast<DWORD>(name) <= 0xFFFF; |
| 236 #pragma warning(pop) | 236 #pragma warning(pop) |
| 237 } | 237 } |
| 238 | 238 |
| 239 inline WORD PEImage::ToOrdinal(LPCSTR name) { | 239 inline WORD PEImage::ToOrdinal(LPCSTR name) { |
| 240 return reinterpret_cast<WORD>(name); | 240 return reinterpret_cast<WORD>(name); |
| 241 } | 241 } |
| 242 | 242 |
| 243 inline HMODULE PEImage::module() const { | 243 inline HMODULE PEImage::module() const { |
| 244 return module_; | 244 return module_; |
| 245 } | 245 } |
| 246 | 246 |
| 247 inline PIMAGE_IMPORT_DESCRIPTOR PEImage::GetFirstImportChunk() const { | 247 inline PIMAGE_IMPORT_DESCRIPTOR PEImage::GetFirstImportChunk() const { |
| 248 return reinterpret_cast<PIMAGE_IMPORT_DESCRIPTOR>( | 248 return reinterpret_cast<PIMAGE_IMPORT_DESCRIPTOR>( |
| 249 GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_IMPORT)); | 249 GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_IMPORT)); |
| 250 } | 250 } |
| 251 | 251 |
| 252 inline PIMAGE_EXPORT_DIRECTORY PEImage::GetExportDirectory() const { | 252 inline PIMAGE_EXPORT_DIRECTORY PEImage::GetExportDirectory() const { |
| 253 return reinterpret_cast<PIMAGE_EXPORT_DIRECTORY>( | 253 return reinterpret_cast<PIMAGE_EXPORT_DIRECTORY>( |
| 254 GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_EXPORT)); | 254 GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_EXPORT)); |
| 255 } | 255 } |
| 256 | 256 |
| 257 #endif // BASE_PE_IMAGE_H_ | 257 #endif // BASE_PE_IMAGE_H_ |
| OLD | NEW |