コード例 #1
0
 private static bool IsARM(this System.Runtime.InteropServices.Architecture arch)
 {
     if (arch == System.Runtime.InteropServices.Architecture.Arm)
     {
         return(true);
     }
     if (arch == System.Runtime.InteropServices.Architecture.Arm64)
     {
         return(true);
     }
     return(false);
 }
コード例 #2
0
        private static Architecture ConvertArchitecture(System.Runtime.InteropServices.Architecture architecture)
        {
            switch (architecture)
            {
            case System.Runtime.InteropServices.Architecture.Arm:
                return(Architecture.Arm);

            case System.Runtime.InteropServices.Architecture.Arm64:
                return(Architecture.Arm64);

            case System.Runtime.InteropServices.Architecture.X86:
                return(Architecture.X86);

            case System.Runtime.InteropServices.Architecture.X64:
                return(Architecture.Amd64);

            default:
                return(Architecture.None);
            }
        }
コード例 #3
0
        public async Task <object> GetChanges([FromRoute(Name = "branch")] string updateBranch,
                                              [FromQuery(Name = "version")] string urlVersion,
                                              [FromQuery(Name = "os")] OperatingSystem operatingSystem,
                                              [FromQuery(Name = "runtimeVer")] string urlRuntimeVersion,
                                              [FromQuery(Name = "runtime")] Runtime runtime = Runtime.DotNet,
                                              [FromQuery(Name = "arch")] Architecture arch  = Architecture.X64)
        {
            Response.Headers[HeaderNames.CacheControl] = GetCacheControlHeader(DateTime.UtcNow);

            var updateFiles = await _updateFileService.Find(updateBranch, operatingSystem, runtime, arch, false, 5, urlVersion, urlRuntimeVersion);

            var response = new List <UpdatePackage>();

            foreach (var updateFile in updateFiles)
            {
                var           update        = updateFile.Update.Value;
                UpdateChanges updateChanges = null;

                if (update.New.Count != 0 || update.Fixed.Count != 0)
                {
                    updateChanges = new UpdateChanges
                    {
                        New   = update.New,
                        Fixed = update.Fixed
                    };
                }

                response.Add(new UpdatePackage
                {
                    Version     = update.Version,
                    ReleaseDate = update.ReleaseDate,
                    Filename    = updateFile.Filename,
                    Url         = updateFile.Url,
                    Changes     = updateChanges,
                    Hash        = updateFile.Hash,
                    Branch      = update.Branch.ToString().ToLower()
                });
            }

            return(response);
        }
コード例 #4
0
        public bool InputArchitectureMatchesDisassemblerArchitecture()
        {
            System.Runtime.InteropServices.Architecture val = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture;
            switch (Machine)
            {
            case Machine.Amd64:
                return(val == System.Runtime.InteropServices.Architecture.X64);

            case Machine.I386:
                return(val == System.Runtime.InteropServices.Architecture.X86);

            case Machine.Arm64:
                return(val == System.Runtime.InteropServices.Architecture.Arm64);

            case Machine.ArmThumb2:
                return(val == System.Runtime.InteropServices.Architecture.Arm);

            default:
                return(false);
            }
        }
コード例 #5
0
        public async Task <object> GetUpdateFile([FromRoute(Name = "branch")] string updateBranch,
                                                 [FromQuery(Name = "version")] string urlVersion,
                                                 [FromQuery(Name = "os")] OperatingSystem operatingSystem,
                                                 [FromQuery(Name = "runtime")] Runtime runtime,
                                                 [FromQuery(Name = "arch")] Architecture arch,
                                                 [FromQuery(Name = "installer")] bool installer = false)
        {
            Response.Headers[HeaderNames.CacheControl] = GetCacheControlHeader(DateTime.UtcNow);

            UpdateFileEntity updateFile;

            if (urlVersion != null)
            {
                if (!Version.TryParse(urlVersion, out var _))
                {
                    return(new
                    {
                        ErrorMessage = "Invalid version number specified."
                    });
                }

                updateFile = await _updateFileService.Find(urlVersion, updateBranch, operatingSystem, runtime, arch, installer);
            }
            else
            {
                var updateFiles = await _updateFileService.Find(updateBranch, operatingSystem, runtime, arch, installer, 1);

                updateFile = updateFiles.FirstOrDefault();
            }

            if (updateFile == null)
            {
                return(new
                {
                    ErrorMessage = $"Update file for {updateBranch}-{urlVersion} not found."
                });
            }

            return(RedirectPermanent(updateFile.Url));
        }
コード例 #6
0
 // TODO: Fix R2RDump issue where an R2R image cannot be dissassembled with the x86 CoreDisTools
 // For the short term, we want to error out with a decent message explaining the unexpected error
 // Issue #19564: https://github.com/dotnet/coreclr/issues/19564
 public bool DisassemblerArchitectureSupported()
 {
     System.Runtime.InteropServices.Architecture val = System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture;
     return(val != System.Runtime.InteropServices.Architecture.X86);
 }
コード例 #7
0
        public async Task <object> GetUpdates([FromRoute(Name = "branch")] string updateBranch,
                                              [FromQuery(Name = "version")] string urlVersion,
                                              [FromQuery(Name = "os")] OperatingSystem operatingSystem,
                                              [FromQuery(Name = "runtime")] Runtime runtime,
                                              [FromQuery(Name = "runtimeVer")] string urlRuntimeVersion,
                                              [FromQuery(Name = "arch")] Architecture arch,
                                              [FromQuery(Name = "active")] bool activeInstall = true)
        {
            Response.Headers[HeaderNames.CacheControl] = GetCacheControlHeader(DateTime.UtcNow);

            // Check given version
            if (!Version.TryParse(urlVersion, out var version))
            {
                return(new
                {
                    ErrorMessage = "Invalid version number specified."
                });
            }

            var userAgentInfo = new UserAgentInfo(Request.Headers["User-Agent"].ToString());

            // Dont' send metrics for dev/debug instances
            if (version.Major < 10)
            {
                var remoteIpAddress = Request.HttpContext.Connection.RemoteIpAddress;

                Metrics.Write("userstats",
                              new Dictionary <string, object>
                {
                    { "source", remoteIpAddress }
                },
                              new Dictionary <string, string>
                {
                    { "program", _project },
                    { "requestApp", userAgentInfo.App ?? "Unknown" },
                    { "branch", updateBranch },
                    { "version", urlVersion },
                    { "os", operatingSystem.ToString() },
                    { "osName", userAgentInfo.Name ?? "Unknown" },
                    { "osVersion", userAgentInfo.OsVersion ?? "Unknown" },
                    { "runtime", runtime.ToString() },
                    { "runtimeVersion", urlRuntimeVersion },
                    { "arch", arch.ToString() },
                    { "activeinstall", activeInstall.ToString() }
                });
            }

            var files = await _updateFileService.Find(updateBranch, operatingSystem, runtime, arch, false, 1, urlVersion, urlRuntimeVersion);

            var updateFile = files.FirstOrDefault();

            if (updateFile == null)
            {
                return(new UpdatePackageContainer
                {
                    Available = false
                });
            }

            var update = updateFile.Update.Value;

            // Compare given version and update version
            var updateVersion = new Version(update.Version);

            if (updateVersion.CompareTo(version) <= 0)
            {
                return(new UpdatePackageContainer
                {
                    Available = false
                });
            }

            // Get the update changes
            UpdateChanges updateChanges = null;

            if (update.New.Count != 0 || update.Fixed.Count != 0)
            {
                updateChanges = new UpdateChanges
                {
                    New   = update.New,
                    Fixed = update.Fixed
                };
            }

            return(new UpdatePackageContainer
            {
                Available = true,
                UpdatePackage = new UpdatePackage
                {
                    Version = update.Version,
                    ReleaseDate = update.ReleaseDate,
                    Filename = updateFile.Filename,
                    Url = updateFile.Url,
                    Changes = updateChanges,
                    Hash = updateFile.Hash,
                    Branch = update.Branch.ToString().ToLower(),
                    Runtime = updateFile.Runtime.ToString().ToLower()
                }
            });
        }
コード例 #8
0
        public static void SetSource(dynamic p)
        {
            if (p == null)
            {
                throw new ArgumentNullException(nameof(p));
            }

            SourcePath = PathResolver.Build((string)p.Source);
            if (!SourcePath[SourcePath.Length - 1].Equals(System.IO.Path.DirectorySeparatorChar))
            {
                SourcePath += System.IO.Path.DirectorySeparatorChar;
            }
            SettingsFilePath = SourcePath + FilePath.Build("root", "settings.json");
            BasePath         = SourcePath;// + $"base{System.IO.Path.DirectorySeparatorChar}";
            RootPath         = BasePath + $"root{System.IO.Path.DirectorySeparatorChar}";
            ResourcePath     = BasePath + $"res{System.IO.Path.DirectorySeparatorChar}";
            FeatureSetPath   = p.FeaturesSet == null ? null : (string)p.FeaturesSet;
            Features         = new System.Collections.Generic.Dictionary <string, Feature>();
            if (FeatureSetPath != null)
            {
                ProcessorArchitecture arch = Assembly.GetExecutingAssembly().GetName().ProcessorArchitecture;
                if (arch == ProcessorArchitecture.MSIL)
                {
                    System.Runtime.InteropServices.Architecture osarch = System.Runtime.InteropServices.RuntimeInformation.OSArchitecture;
                    arch = osarch == System.Runtime.InteropServices.Architecture.Arm ? ProcessorArchitecture.Arm :
                           osarch == System.Runtime.InteropServices.Architecture.X64 ? ProcessorArchitecture.Amd64 :
                           osarch == System.Runtime.InteropServices.Architecture.X86 ? ProcessorArchitecture.X86 : ProcessorArchitecture.X86;
                }
                dynamic features = Newtonsoft.Json.JsonConvert.DeserializeObject(System.IO.File.ReadAllText(FeatureSetPath + "config.json"));
                foreach (dynamic feature in features)
                {
                    ProcessorArchitecture featureArch = GetArchitecture(((string)feature.Architecture).Trim(), arch);
                    if (!arch.Equals(featureArch))
                    {
                        if (arch == ProcessorArchitecture.Amd64 && featureArch == ProcessorArchitecture.X86)
                        {
                            ;
                        }
                        else if ((arch == ProcessorArchitecture.Amd64 || arch == ProcessorArchitecture.X86) && Environment.Is64BitProcess)
                        {
                            ;
                        }
                        else
                        {
                            ErrorLogger.Warn("[Settings] : Feature '" + (string)feature.Name + "' Unknown architecture '" + arch + "', feature dropped >> " + featureArch.ToString());
                            continue;
                        }
                    }


                    Feature f = new()
                    {
                        Name = (string)feature.Name,
                        Path = FeatureSetPath + (string)feature.Name + System.IO.Path.DirectorySeparatorChar + (
                            featureArch == ProcessorArchitecture.Amd64 ? "x64" + System.IO.Path.DirectorySeparatorChar :
                            featureArch == ProcessorArchitecture.X86 ? "x86" + System.IO.Path.DirectorySeparatorChar :
                            featureArch == ProcessorArchitecture.Arm ? "arm" + System.IO.Path.DirectorySeparatorChar : null
                            ),
                        TargetName           = (string)feature.Target,
                        RequireServerIOFocus = (bool)feature.RequireServerIOFocus,
                        WaitForExit          = (bool)feature.WaitForExit
                    };

                    f.TargetExcutable = f.Path + f.TargetName;

                    if (!System.IO.File.Exists(f.TargetExcutable) || f.Path == null)
                    {
                        ErrorLogger.Warn("[Settings] : Feature '" + (string)feature.Name + "' Target file not found, won't be available");
                        continue;
                    }
                    if (!(bool)feature.Enabled)
                    {
                        continue;
                    }
                    if (Features.ContainsKey(f.Name))
                    {
                        ErrorLogger.Warn("[Settings] : Feature '" + (string)feature.Name + "' already defined. duplicates ignored");
                        continue;
                    }

                    Features.Add(f.Name, f);
                }

                if (!Features.ContainsKey("cpython"))
                {
                    throw new Exception("Cannot initialize feature-set without cpython");
                }
            }
        }