Ejemplo n.º 1
0
 public ModuleInfo(DbgProcess process, ulong addr, int size, string filename, DbgImageLayout imageLayout)
 {
     Process     = process;
     Address     = addr;
     Size        = size;
     Filename    = filename;
     ImageLayout = imageLayout;
 }
Ejemplo n.º 2
0
 internal void UpdateImageLayout_DbgThread(DbgImageLayout imageLayout)
 {
     Dispatcher.VerifyAccess();
     if (this.imageLayout != imageLayout)
     {
         this.imageLayout = imageLayout;
         OnPropertyChanged(nameof(ImageLayout));
     }
 }
Ejemplo n.º 3
0
        static void InitializeExeFields(DnModule dnModule, string filename, DbgImageLayout imageLayout, out bool isExe, out bool isDll, out DateTime?timestamp, out string version, out string assemblySimpleName)
        {
            isExe              = false;
            isDll              = false;
            timestamp          = null;
            version            = null;
            assemblySimpleName = null;

            if (dnModule.IsDynamic)
            {
                if (dnModule.CorModule.IsManifestModule)
                {
                    version = new AssemblyNameInfo(dnModule.Assembly.FullName).Version.ToString();
                }
            }
            else if (dnModule.IsInMemory)
            {
                Debug.Assert(imageLayout == DbgImageLayout.File, nameof(GetFileVersion) + " assumes file layout");

                var bytes = dnModule.Process.CorProcess.ReadMemory(dnModule.Address, (int)dnModule.Size);
                if (bytes != null)
                {
                    try {
                        version = GetFileVersion(bytes);
                        using (var peImage = new PEImage(bytes, imageLayout == DbgImageLayout.File ? ImageLayout.File : ImageLayout.Memory, true))
                            InitializeExeFieldsFrom(peImage, out isExe, out isDll, out timestamp, ref version, out assemblySimpleName);
                    }
                    catch {
                    }
                }
            }
            else
            {
                try {
                    version = GetFileVersion(filename);
                    using (var peImage = new PEImage(filename))
                        InitializeExeFieldsFrom(peImage, out isExe, out isDll, out timestamp, ref version, out assemblySimpleName);
                }
                catch {
                }
            }

            if (version == null)
            {
                version = string.Empty;
            }
        }
Ejemplo n.º 4
0
        void InitializeExeFields(string filename, DbgImageLayout imageLayout, out bool isExe, out bool isDll, out DateTime?timestamp, out string version, out string assemblySimpleName)
        {
            isExe              = false;
            isDll              = false;
            timestamp          = null;
            version            = null;
            assemblySimpleName = null;

            if (isDynamic)
            {
                if (monoModule.Assembly.ManifestModule == monoModule)
                {
                    version = monoModule.Assembly.GetName().Version.ToString();
                }
            }
            else if (isInMemory)
            {
                Debug.Assert(imageLayout == DbgImageLayout.File, nameof(GetFileVersion) + " assumes file layout");

                var bytes = moduleSize == 0 ? null : engine.DbgRuntime.Process.ReadMemory(moduleAddress, (int)moduleSize);
                if (bytes != null)
                {
                    try {
                        version = GetFileVersion(bytes);
                        using (var peImage = new PEImage(bytes, imageLayout == DbgImageLayout.File ? ImageLayout.File : ImageLayout.Memory, true))
                            InitializeExeFieldsFrom(peImage, out isExe, out isDll, out timestamp, ref version, out assemblySimpleName);
                    }
                    catch {
                    }
                }
            }
            else
            {
                try {
                    version = GetFileVersion(filename);
                    using (var peImage = new PEImage(filename))
                        InitializeExeFieldsFrom(peImage, out isExe, out isDll, out timestamp, ref version, out assemblySimpleName);
                }
                catch {
                }
            }

            if (version == null)
            {
                version = string.Empty;
            }
        }
Ejemplo n.º 5
0
 public DbgModuleImpl(DbgRuntimeImpl runtime, DbgAppDomainImpl appDomain, DbgInternalModule internalModule, bool isExe, ulong address, uint size, DbgImageLayout imageLayout, string name, string filename, bool isDynamic, bool isInMemory, bool?isOptimized, int order, DateTime?timestamp, string version)
 {
     lockObj          = new object();
     this.runtime     = runtime ?? throw new ArgumentNullException(nameof(runtime));
     this.appDomain   = appDomain;
     InternalModule   = internalModule ?? throw new ArgumentNullException(nameof(internalModule));
     this.isExe       = isExe;
     this.address     = address;
     this.size        = size;
     this.imageLayout = imageLayout;
     this.name        = name;
     this.filename    = filename;
     this.isDynamic   = isDynamic;
     this.isInMemory  = isInMemory;
     this.isOptimized = isOptimized;
     this.order       = order;
     this.timestamp   = timestamp?.ToUniversalTime();
     this.version     = version;
 }
Ejemplo n.º 6
0
 static Func <DmdLazyMetadataBytes> CreateGetMetadataDelegate(DbgEngineImpl engine, DbgRuntime runtime, DnModule dnModule, ClosedListenerCollection closedListenerCollection, DbgImageLayout imageLayout)
 {
     if (dnModule.IsDynamic)
     {
         return(CreateDynamicGetMetadataDelegate(engine, dnModule));
     }
     else
     {
         return(CreateNormalGetMetadataDelegate(engine, runtime, dnModule, closedListenerCollection, imageLayout));
     }
 }
Ejemplo n.º 7
0
        static Func <DmdLazyMetadataBytes> CreateNormalGetMetadataDelegate(DbgEngineImpl engine, DbgRuntime runtime, DnModule dnModule, ClosedListenerCollection closedListenerCollection, DbgImageLayout imageLayout)
        {
            Debug.Assert(!dnModule.IsDynamic);

            return(() => {
                var rawMd = engine.RawMetadataService.Create(runtime, imageLayout == DbgImageLayout.File, dnModule.Address, (int)dnModule.Size);
                try {
                    closedListenerCollection.Closed += (s, e) => rawMd.Release();
                    return new DmdLazyMetadataBytesPtr(rawMd.Address, (uint)rawMd.Size, rawMd.IsFileLayout);
                }
                catch {
                    rawMd.Release();
                    throw;
                }
            });
        }
Ejemplo n.º 8
0
        public override DbgEngineModule CreateModule <T>(DbgAppDomain appDomain, DbgInternalModule internalModule, bool isExe, ulong address, uint size, DbgImageLayout imageLayout, string name, string filename, bool isDynamic, bool isInMemory, bool?isOptimized, int order, DateTime?timestamp, string version, DbgEngineMessageFlags messageFlags, T data, Action <DbgEngineModule> onCreated)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(nameof(DbgObjectFactoryImpl));
            }
            var module = new DbgModuleImpl(runtime, VerifyOptionalAppDomain(appDomain), internalModule, isExe, address, size, imageLayout, name, filename, isDynamic, isInMemory, isOptimized, order, timestamp, version);

            if (data != null)
            {
                module.GetOrCreateData(() => data);
            }
            var engineModule = new DbgEngineModuleImpl(module);

            onCreated?.Invoke(engineModule);
            owner.Dispatcher.BeginInvoke(() => owner.AddModule_DbgThread(runtime, module, messageFlags));
            return(engineModule);
        }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates a module. The engine has paused the program.
 /// </summary>
 /// <param name="appDomain">New <see cref="DbgModule.AppDomain"/> value</param>
 /// <param name="internalModule">Module object created by the debug engine</param>
 /// <param name="isExe">New <see cref="DbgModule.IsExe"/> value</param>
 /// <param name="address">New <see cref="DbgModule.Address"/> value</param>
 /// <param name="size">New <see cref="DbgModule.Size"/> value</param>
 /// <param name="imageLayout">New <see cref="DbgModule.ImageLayout"/> value</param>
 /// <param name="name">New <see cref="DbgModule.Name"/> value</param>
 /// <param name="filename">New <see cref="DbgModule.Filename"/> value</param>
 /// <param name="isDynamic">New <see cref="DbgModule.IsDynamic"/> value</param>
 /// <param name="isInMemory">New <see cref="DbgModule.IsInMemory"/> value</param>
 /// <param name="isOptimized">New <see cref="DbgModule.IsOptimized"/> value</param>
 /// <param name="order">New <see cref="DbgModule.Order"/> value</param>
 /// <param name="timestamp">New <see cref="DbgModule.Timestamp"/> value</param>
 /// <param name="version">New <see cref="DbgModule.Version"/> value</param>
 /// <param name="messageFlags">Message flags</param>
 /// <returns></returns>
 public DbgEngineModule CreateModule(DbgAppDomain appDomain, DbgInternalModule internalModule, bool isExe, ulong address, uint size, DbgImageLayout imageLayout, string name, string filename, bool isDynamic, bool isInMemory, bool?isOptimized, int order, DateTime?timestamp, string version, DbgEngineMessageFlags messageFlags) =>
 CreateModule <object>(appDomain, internalModule, isExe, address, size, imageLayout, name, filename, isDynamic, isInMemory, isOptimized, order, timestamp, version, messageFlags, null, null);
Ejemplo n.º 10
0
 /// <summary>
 /// Creates a module. The engine has paused the program.
 /// </summary>
 /// <typeparam name="T">Type of data</typeparam>
 /// <param name="appDomain">New <see cref="DbgModule.AppDomain"/> value</param>
 /// <param name="internalModule">Module object created by the debug engine</param>
 /// <param name="isExe">New <see cref="DbgModule.IsExe"/> value</param>
 /// <param name="address">New <see cref="DbgModule.Address"/> value</param>
 /// <param name="size">New <see cref="DbgModule.Size"/> value</param>
 /// <param name="imageLayout">New <see cref="DbgModule.ImageLayout"/> value</param>
 /// <param name="name">New <see cref="DbgModule.Name"/> value</param>
 /// <param name="filename">New <see cref="DbgModule.Filename"/> value</param>
 /// <param name="isDynamic">New <see cref="DbgModule.IsDynamic"/> value</param>
 /// <param name="isInMemory">New <see cref="DbgModule.IsInMemory"/> value</param>
 /// <param name="isOptimized">New <see cref="DbgModule.IsOptimized"/> value</param>
 /// <param name="order">New <see cref="DbgModule.Order"/> value</param>
 /// <param name="timestamp">New <see cref="DbgModule.Timestamp"/> value</param>
 /// <param name="version">New <see cref="DbgModule.Version"/> value</param>
 /// <param name="messageFlags">Message flags</param>
 /// <param name="data">Data to add to the <see cref="DbgModule"/> or null if nothing gets added</param>
 /// <param name="onCreated">Called right after creating the module but before adding it to internal data structures. This can be null.</param>
 /// <returns></returns>
 public abstract DbgEngineModule CreateModule <T>(DbgAppDomain appDomain, DbgInternalModule internalModule, bool isExe, ulong address, uint size, DbgImageLayout imageLayout, string name, string filename, bool isDynamic, bool isInMemory, bool?isOptimized, int order, DateTime?timestamp, string version, DbgEngineMessageFlags messageFlags, T data, Action <DbgEngineModule> onCreated = null) where T : class;
Ejemplo n.º 11
0
 /// <summary>
 /// Updates <see cref="DbgModule"/> properties
 /// </summary>
 /// <param name="options">Options</param>
 /// <param name="isExe">New <see cref="DbgModule.IsExe"/> value</param>
 /// <param name="address">New <see cref="DbgModule.Address"/> value</param>
 /// <param name="size">New <see cref="DbgModule.Size"/> value</param>
 /// <param name="imageLayout">New <see cref="DbgModule.ImageLayout"/> value</param>
 /// <param name="name">New <see cref="DbgModule.Name"/> value</param>
 /// <param name="filename">New <see cref="DbgModule.Filename"/> value</param>
 /// <param name="isDynamic">New <see cref="DbgModule.IsDynamic"/> value</param>
 /// <param name="isInMemory">New <see cref="DbgModule.IsInMemory"/> value</param>
 /// <param name="isOptimized">New <see cref="DbgModule.IsOptimized"/> value</param>
 /// <param name="order">New <see cref="DbgModule.Order"/> value</param>
 /// <param name="timestamp">New <see cref="DbgModule.Timestamp"/> value</param>
 /// <param name="version">New <see cref="DbgModule.Version"/> value</param>
 public abstract void Update(UpdateOptions options, bool isExe = false, ulong address = 0, uint size = 0, DbgImageLayout imageLayout = 0, string?name = null, string?filename = null, bool isDynamic = false, bool isInMemory = false, bool?isOptimized = null, int order = 0, DateTime?timestamp = null, string?version = null);
Ejemplo n.º 12
0
 /// <summary>
 /// Updates <see cref="DbgModule.ImageLayout"/>
 /// </summary>
 /// <param name="imageLayout">New value</param>
 public void UpdateImageLayout(DbgImageLayout imageLayout) => Update(UpdateOptions.ImageLayout, imageLayout: imageLayout);
Ejemplo n.º 13
0
        Func <DmdLazyMetadataBytes> CreateNormalGetMetadataDelegate(ClosedListenerCollection closedListenerCollection, DbgImageLayout imageLayout)
        {
            Debug.Assert(!isDynamic);

            var moduleAddressTmp = moduleAddress;
            var moduleSizeTmp    = moduleSize;
            var engine           = this.engine;
            var runtime          = objectFactory.Runtime;
            var filename         = monoModule.FullyQualifiedName;

            return(() => {
                DbgRawMetadata rawMd = null;
                try {
                    if (moduleAddressTmp != 0 && moduleSizeTmp != 0)
                    {
                        rawMd = engine.RawMetadataService.Create(runtime, imageLayout == DbgImageLayout.File, moduleAddressTmp, (int)moduleSizeTmp);
                    }
                    else if (File.Exists(filename))
                    {
                        rawMd = engine.RawMetadataService.Create(runtime, true, File.ReadAllBytes(filename));
                    }
                    else
                    {
                        //TODO:
                        rawMd = engine.RawMetadataService.Create(runtime, imageLayout == DbgImageLayout.File, Array.Empty <byte>());
                    }
                    closedListenerCollection.Closed += (s, e) => rawMd.Release();
                    return new DmdLazyMetadataBytesPtr(rawMd.Address, (uint)rawMd.Size, rawMd.IsFileLayout);
                }
                catch {
                    rawMd?.Release();
                    throw;
                }
            });
        }
Ejemplo n.º 14
0
 Func <DmdLazyMetadataBytes> CreateGetMetadataDelegate(ClosedListenerCollection closedListenerCollection, DbgImageLayout imageLayout)
 {
     if (isDynamic)
     {
         return(CreateDynamicGetMetadataDelegate());
     }
     else
     {
         return(CreateNormalGetMetadataDelegate(closedListenerCollection, imageLayout));
     }
 }