summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
Diffstat (limited to 'base')
-rw-r--r--base/image_util.h69
-rw-r--r--base/process_util.h7
-rw-r--r--base/process_util_posix.cc11
-rw-r--r--base/process_util_win.cc8
4 files changed, 62 insertions, 33 deletions
diff --git a/base/image_util.h b/base/image_util.h
index 6f0a19a..33ca08f 100644
--- a/base/image_util.h
+++ b/base/image_util.h
@@ -6,22 +6,25 @@
// information about PE (Portable Executable) headers within
// images (dll's / exe's )
-#ifndef BASE_IMAGE_UTIL_H__
-#define BASE_IMAGE_UTIL_H__
+#ifndef BASE_IMAGE_UTIL_H_
+#define BASE_IMAGE_UTIL_H_
+#include <windows.h>
#include <vector>
+
#include "base/basictypes.h"
-#include <windows.h>
namespace image_util {
// Contains both the PE section name (.text, .reloc etc) and its size.
struct ImageSectionData {
+ ImageSectionData (const std::string& section_name, size_t section_size)
+ : name (section_name),
+ size_in_bytes(section_size) {
+ }
+
std::string name;
size_t size_in_bytes;
- ImageSectionData (const std::string& section_name, size_t section_size) :
- name (section_name), size_in_bytes(section_size) {
- }
};
typedef std::vector<ImageSectionData> ImageSectionsData;
@@ -31,34 +34,34 @@ typedef std::vector<ImageSectionData> ImageSectionsData;
// to get an instance for a specified process, then access the information via
// methods.
class ImageMetrics {
- public:
- // Creates an ImageMetrics instance for given process owned by
- // the caller.
- explicit ImageMetrics(HANDLE process);
- ~ImageMetrics();
-
- // Fills a vector of ImageSectionsData containing name/size info
- // for every section found in the specified dll's PE section table.
- // The DLL must be loaded by the process associated with this ImageMetrics
- // instance.
- bool GetDllImageSectionData(const std::string& loaded_dll_name,
- ImageSectionsData* section_sizes);
-
- // Fills a vector if ImageSectionsData containing name/size info
- // for every section found in the executable file of the process
- // associated with this ImageMetrics instance.
- bool GetProcessImageSectionData(ImageSectionsData* section_sizes);
-
- private:
- // Helper for GetDllImageSectionData and GetProcessImageSectionData
- bool GetImageSectionSizes(char* qualified_path, ImageSectionsData* result);
-
- HANDLE process_;
-
- DISALLOW_EVIL_CONSTRUCTORS(ImageMetrics);
+ public:
+ // Creates an ImageMetrics instance for given process owned by
+ // the caller.
+ explicit ImageMetrics(HANDLE process);
+ ~ImageMetrics();
+
+ // Fills a vector of ImageSectionsData containing name/size info
+ // for every section found in the specified dll's PE section table.
+ // The DLL must be loaded by the process associated with this ImageMetrics
+ // instance.
+ bool GetDllImageSectionData(const std::string& loaded_dll_name,
+ ImageSectionsData* section_sizes);
+
+ // Fills a vector if ImageSectionsData containing name/size info
+ // for every section found in the executable file of the process
+ // associated with this ImageMetrics instance.
+ bool GetProcessImageSectionData(ImageSectionsData* section_sizes);
+
+ private:
+ // Helper for GetDllImageSectionData and GetProcessImageSectionData
+ bool GetImageSectionSizes(char* qualified_path, ImageSectionsData* result);
+
+ HANDLE process_;
+
+ DISALLOW_COPY_AND_ASSIGN(ImageMetrics);
};
-} // namespace image_util
+} // namespace image_util
-#endif
+#endif // BASE_IMAGE_UTIL_H_
diff --git a/base/process_util.h b/base/process_util.h
index 8c4c5d4..c921d7a 100644
--- a/base/process_util.h
+++ b/base/process_util.h
@@ -66,6 +66,13 @@ int GetCurrentProcId();
// Returns the ProcessHandle of the current process.
ProcessHandle GetCurrentProcessHandle();
+
+// Converts a PID to a process handle. This handle must be closed by
+// CloseProcessHandle when you are done with it.
+ProcessHandle OpenProcessHandle(int pid);
+
+// Closes the process handle opened by OpenProcessHandle.
+void CloseProcessHandle(ProcessHandle process);
// Returns the unique ID for the specified process. This is functionally the
// same as Windows' GetProcessId(), but works on versions of Windows before
diff --git a/base/process_util_posix.cc b/base/process_util_posix.cc
index 680cacc..7cabb3a 100644
--- a/base/process_util_posix.cc
+++ b/base/process_util_posix.cc
@@ -34,6 +34,17 @@ ProcessHandle GetCurrentProcessHandle() {
return GetCurrentProcId();
}
+ProcessHandle OpenProcessHandle(int pid) {
+ // On Posix platforms, process handles are the same as PIDs, so we
+ // don't need to do anything.
+ return pid;
+}
+
+void CloseProcessHandle(ProcessHandle process) {
+ // See OpenProcessHandle, nothing to do.
+ return;
+}
+
int GetProcId(ProcessHandle process) {
return process;
}
diff --git a/base/process_util_win.cc b/base/process_util_win.cc
index f1fd72c..bb0e626 100644
--- a/base/process_util_win.cc
+++ b/base/process_util_win.cc
@@ -33,6 +33,14 @@ ProcessHandle GetCurrentProcessHandle() {
return ::GetCurrentProcess();
}
+ProcessHandle OpenProcessHandle(int pid) {
+ return OpenProcess(PROCESS_DUP_HANDLE | PROCESS_TERMINATE, FALSE, pid);
+}
+
+void CloseProcessHandle(ProcessHandle process) {
+ CloseHandle(process);
+}
+
// Helper for GetProcId()
bool GetProcIdViaGetProcessId(ProcessHandle process, DWORD* id) {
// Dynamically get a pointer to GetProcessId().