Exemple #1
0
        public BinaryDetail CreateBinaryDetail(FileInfo binaryFileInfo)
        {
            if (string.IsNullOrEmpty(binaryFileInfo.Directory.FullName))
            {
                throw new InvalidOperationException(
                          "Directory can't be null or empty.");
            }

            if (!Directory.Exists(binaryFileInfo.Directory.FullName))
            {
                throw new InvalidOperationException(
                          string.Format(CultureInfo.CurrentCulture,
                                        "Directory not found {0}",
                                        binaryFileInfo.Directory.FullName));
            }

            var childDomain = BuildChildDomain(
                AppDomain.CurrentDomain);

            try
            {
                var bd         = new BinaryDetail(binaryFileInfo);
                var loaderType = typeof(BinaryDetailPopulator);
                if (loaderType.Assembly != null)
                {
                    var loader =
                        (BinaryDetailPopulator)childDomain.CreateInstanceFrom(
                            loaderType.Assembly.Location,
                            loaderType.FullName).Unwrap();

                    try
                    {
                        loader.LoadAssembly(
                            binaryFileInfo.FullName);

                        bd = loader.PopulateBinaryDetail(bd);
                    }
                    catch (Exception e)
                    {
                        bd.Error = e.Message;
                    }
                }

                return(bd);
            }
            finally
            {
                AppDomain.Unload(childDomain);
            }
        }
Exemple #2
0
            internal BinaryDetail PopulateBinaryDetail(BinaryDetail binaryDetail)
            {
                var directory = new DirectoryInfo(binaryDetail.FileInfo.DirectoryName);

                ResolveEventHandler resolveEventHandler =
                    (s, e) =>
                {
                    return(OnReflectionOnlyResolve(
                               e, directory));
                };

                AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve
                    += resolveEventHandler;

                var reflectionOnlyAssembly =
                    AppDomain.CurrentDomain.ReflectionOnlyGetAssemblies().First();

                binaryDetail.ImageRuntimeVersion = reflectionOnlyAssembly.ImageRuntimeVersion;
                binaryDetail.AssemblyVersion     = reflectionOnlyAssembly.GetName().Version.ToString();

                PortableExecutableKinds peKind;
                ImageFileMachine        machine;

                reflectionOnlyAssembly.ManifestModule.GetPEKind(out peKind, out machine);
                binaryDetail.PEKind           = peKind;
                binaryDetail.ImageFileMachine = machine;

                var pe = reflectionOnlyAssembly.GetName().ProcessorArchitecture;

                binaryDetail.ProcessorArchitecture = pe;

                binaryDetail.TargetFrameworkAttribute   = GetCustomAttributeValue(reflectionOnlyAssembly, typeof(TargetFrameworkAttribute));
                binaryDetail.AssemblyCompanyAttribute   = GetCustomAttributeValue(reflectionOnlyAssembly, typeof(AssemblyCompanyAttribute));
                binaryDetail.AssemblyCopyrightAttribute = GetCustomAttributeValue(reflectionOnlyAssembly, typeof(AssemblyCopyrightAttribute));

                AppDomain.CurrentDomain.ReflectionOnlyAssemblyResolve
                    -= resolveEventHandler;

                return(binaryDetail);
            }