1 //------------------------------------------------------------------------------
2 // <copyright file="ProcessModule.cs" company="Microsoft">
3 // Copyright (c) Microsoft Corporation. All rights reserved.
5 //------------------------------------------------------------------------------
7 namespace System
.Diagnostics
{
8 using System
.Diagnostics
;
10 using System
.Collections
;
12 using Microsoft
.Win32
;
13 using System
.ComponentModel
;
14 using System
.Globalization
;
15 using System
.Security
.Permissions
;
16 // using System.Windows.Forms;
17 using System
.Runtime
.Versioning
;
20 /// A process module component represents a DLL or EXE loaded into
21 /// a particular process. Using this component, you can determine
22 /// information about the module.
24 [Designer("System.Diagnostics.Design.ProcessModuleDesigner, " + AssemblyRef
.SystemDesign
)]
25 [PermissionSet(SecurityAction
.LinkDemand
, Name
="FullTrust")]
26 [PermissionSet(SecurityAction
.InheritanceDemand
, Name
="FullTrust")]
27 public class ProcessModule
: Component
{
28 internal ModuleInfo moduleInfo
;
29 FileVersionInfo fileVersionInfo
;
32 /// Initialize the module.
35 internal ProcessModule(ModuleInfo moduleInfo
) {
36 this.moduleInfo
= moduleInfo
;
37 GC
.SuppressFinalize(this);
41 /// Make sure we are running on NT.
44 internal void EnsureNtProcessInfo() {
45 if (Environment
.OSVersion
.Platform
!= PlatformID
.Win32NT
)
46 throw new PlatformNotSupportedException(SR
.GetString(SR
.WinNTRequired
));
50 /// Returns the name of the Module.
52 [MonitoringDescription(SR
.ProcModModuleName
)]
53 public string ModuleName
{
55 return moduleInfo
.baseName
;
60 /// Returns the full file path for the location of the module.
62 [MonitoringDescription(SR
.ProcModFileName
)]
63 public string FileName
{
64 [ResourceExposure(ResourceScope
.Machine
)]
66 return moduleInfo
.fileName
;
71 /// Returns the memory address that the module was loaded at.
73 [MonitoringDescription(SR
.ProcModBaseAddress
)]
74 public IntPtr BaseAddress
{
75 [ResourceExposure(ResourceScope
.Process
)]
77 return moduleInfo
.baseOfDll
;
82 /// Returns the amount of memory required to load the module. This does
83 /// not include any additional memory allocations made by the module once
84 /// it is running; it only includes the size of the static code and data
85 /// in the module file.
87 [MonitoringDescription(SR
.ProcModModuleMemorySize
)]
88 public int ModuleMemorySize
{
90 return moduleInfo
.sizeOfImage
;
95 /// Returns the memory address for function that runs when the module is
98 [MonitoringDescription(SR
.ProcModEntryPointAddress
)]
99 public IntPtr EntryPointAddress
{
101 EnsureNtProcessInfo();
102 return moduleInfo
.entryPoint
;
107 /// Returns version information about the module.
110 public FileVersionInfo FileVersionInfo
{
111 [ResourceExposure(ResourceScope
.Machine
)] // Let's review callers - why do they want this?
112 [ResourceConsumption(ResourceScope
.Machine
)]
114 if (fileVersionInfo
== null)
115 fileVersionInfo
= FileVersionInfo
.GetVersionInfo(FileName
);
116 return fileVersionInfo
;
120 public override string ToString() {
121 return String
.Format(CultureInfo
.CurrentCulture
, "{0} ({1})", base.ToString(), this.ModuleName
);