| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 // This class is an extension to the PEImage class that allows working with PE | 232 // This class is an extension to the PEImage class that allows working with PE |
| 233 // files mapped as data instead of as image file. | 233 // files mapped as data instead of as image file. |
| 234 class PEImageAsData : public PEImage { | 234 class PEImageAsData : public PEImage { |
| 235 public: | 235 public: |
| 236 explicit PEImageAsData(HMODULE hModule) : PEImage(hModule) {} | 236 explicit PEImageAsData(HMODULE hModule) : PEImage(hModule) {} |
| 237 | 237 |
| 238 virtual PVOID RVAToAddr(DWORD rva) const; | 238 virtual PVOID RVAToAddr(DWORD rva) const; |
| 239 }; | 239 }; |
| 240 | 240 |
| 241 inline bool PEImage::IsOrdinal(LPCSTR name) { | 241 inline bool PEImage::IsOrdinal(LPCSTR name) { |
| 242 #pragma warning(push) | 242 return reinterpret_cast<uintptr_t>(name) <= 0xFFFF; |
| 243 #pragma warning(disable: 4311) | |
| 244 // This cast generates a warning because it is 32 bit specific. | |
| 245 return reinterpret_cast<DWORD>(name) <= 0xFFFF; | |
| 246 #pragma warning(pop) | |
| 247 } | 243 } |
| 248 | 244 |
| 249 inline WORD PEImage::ToOrdinal(LPCSTR name) { | 245 inline WORD PEImage::ToOrdinal(LPCSTR name) { |
| 250 return reinterpret_cast<WORD>(name); | 246 return static_cast<WORD>(reinterpret_cast<intptr_t>(name)); |
| 251 } | 247 } |
| 252 | 248 |
| 253 inline HMODULE PEImage::module() const { | 249 inline HMODULE PEImage::module() const { |
| 254 return module_; | 250 return module_; |
| 255 } | 251 } |
| 256 | 252 |
| 257 inline PIMAGE_IMPORT_DESCRIPTOR PEImage::GetFirstImportChunk() const { | 253 inline PIMAGE_IMPORT_DESCRIPTOR PEImage::GetFirstImportChunk() const { |
| 258 return reinterpret_cast<PIMAGE_IMPORT_DESCRIPTOR>( | 254 return reinterpret_cast<PIMAGE_IMPORT_DESCRIPTOR>( |
| 259 GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_IMPORT)); | 255 GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_IMPORT)); |
| 260 } | 256 } |
| 261 | 257 |
| 262 inline PIMAGE_EXPORT_DIRECTORY PEImage::GetExportDirectory() const { | 258 inline PIMAGE_EXPORT_DIRECTORY PEImage::GetExportDirectory() const { |
| 263 return reinterpret_cast<PIMAGE_EXPORT_DIRECTORY>( | 259 return reinterpret_cast<PIMAGE_EXPORT_DIRECTORY>( |
| 264 GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_EXPORT)); | 260 GetImageDirectoryEntryAddr(IMAGE_DIRECTORY_ENTRY_EXPORT)); |
| 265 } | 261 } |
| 266 | 262 |
| 267 } // namespace win | 263 } // namespace win |
| 268 } // namespace base | 264 } // namespace base |
| 269 | 265 |
| 270 #endif // BASE_WIN_PE_IMAGE_H_ | 266 #endif // BASE_WIN_PE_IMAGE_H_ |
| OLD | NEW |