license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 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 |
| 3 | // found in the LICENSE file. |
initial.commit | 3f4a732 | 2008-07-27 06:49:38 +0900 | [diff] [blame] | 4 | |
| 5 | // This file/namespace contains utility functions for gathering |
| 6 | // information about PE (Portable Executable) headers within |
| 7 | // images (dll's / exe's ) |
| 8 | |
| 9 | #ifndef BASE_IMAGE_UTIL_H__ |
| 10 | #define BASE_IMAGE_UTIL_H__ |
| 11 | |
| 12 | #include <vector> |
| 13 | #include "base/basictypes.h" |
| 14 | #include <windows.h> |
| 15 | |
| 16 | namespace image_util { |
| 17 | |
| 18 | // Contains both the PE section name (.text, .reloc etc) and its size. |
| 19 | struct ImageSectionData { |
| 20 | std::string name; |
| 21 | size_t size_in_bytes; |
| 22 | ImageSectionData (const std::string& section_name, size_t section_size) : |
| 23 | name (section_name), size_in_bytes(section_size) { |
| 24 | } |
| 25 | }; |
| 26 | |
| 27 | typedef std::vector<ImageSectionData> ImageSectionsData; |
| 28 | |
| 29 | // Provides image statistics for modules of a specified process, or for the |
| 30 | // specified process' own executable file. To use, invoke CreateImageMetrics() |
| 31 | // to get an instance for a specified process, then access the information via |
| 32 | // methods. |
| 33 | class ImageMetrics { |
| 34 | public: |
| 35 | // Creates an ImageMetrics instance for given process owned by |
| 36 | // the caller. |
| 37 | explicit ImageMetrics(HANDLE process); |
| 38 | ~ImageMetrics(); |
| 39 | |
| 40 | // Fills a vector of ImageSectionsData containing name/size info |
| 41 | // for every section found in the specified dll's PE section table. |
| 42 | // The DLL must be loaded by the process associated with this ImageMetrics |
| 43 | // instance. |
| 44 | bool GetDllImageSectionData(const std::string& loaded_dll_name, |
| 45 | ImageSectionsData* section_sizes); |
| 46 | |
| 47 | // Fills a vector if ImageSectionsData containing name/size info |
| 48 | // for every section found in the executable file of the process |
| 49 | // associated with this ImageMetrics instance. |
| 50 | bool GetProcessImageSectionData(ImageSectionsData* section_sizes); |
| 51 | |
| 52 | private: |
| 53 | // Helper for GetDllImageSectionData and GetProcessImageSectionData |
| 54 | bool GetImageSectionSizes(char* qualified_path, ImageSectionsData* result); |
| 55 | |
| 56 | HANDLE process_; |
| 57 | |
| 58 | DISALLOW_EVIL_CONSTRUCTORS(ImageMetrics); |
| 59 | }; |
| 60 | |
| 61 | } // namespace image_util |
| 62 | |
deanm@google.com | 9713786 | 2008-08-14 20:44:17 +0900 | [diff] [blame] | 63 | #endif |
license.bot | f003cfe | 2008-08-24 09:55:55 +0900 | [diff] [blame^] | 64 | |