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.
5 // This file/namespace contains utility functions for gathering
6 // information about PE (Portable Executable) headers within
7 // images (dll's / exe's )
9 #ifndef BASE_IMAGE_UTIL_H_
10 #define BASE_IMAGE_UTIL_H_
16 #include "base/basictypes.h"
18 namespace image_util
{
20 // Contains both the PE section name (.text, .reloc etc) and its size.
21 struct ImageSectionData
{
22 ImageSectionData(const std::string
& section_name
, size_t section_size
)
24 size_in_bytes(section_size
) {
31 typedef std::vector
<ImageSectionData
> ImageSectionsData
;
33 // Provides image statistics for modules of a specified process, or for the
34 // specified process' own executable file. To use, invoke CreateImageMetrics()
35 // to get an instance for a specified process, then access the information via
39 // Creates an ImageMetrics instance for given process owned by
41 explicit ImageMetrics(HANDLE process
);
44 // Fills a vector of ImageSectionsData containing name/size info
45 // for every section found in the specified dll's PE section table.
46 // The DLL must be loaded by the process associated with this ImageMetrics
48 bool GetDllImageSectionData(const std::string
& loaded_dll_name
,
49 ImageSectionsData
* section_sizes
);
51 // Fills a vector if ImageSectionsData containing name/size info
52 // for every section found in the executable file of the process
53 // associated with this ImageMetrics instance.
54 bool GetProcessImageSectionData(ImageSectionsData
* section_sizes
);
57 // Helper for GetDllImageSectionData and GetProcessImageSectionData
58 bool GetImageSectionSizes(char* qualified_path
, ImageSectionsData
* result
);
62 DISALLOW_COPY_AND_ASSIGN(ImageMetrics
);
65 } // namespace image_util
67 #endif // BASE_IMAGE_UTIL_H_