Example #1
0
        public static T GetSection <T> (String machineName, MachineType machineType) where T : ConfigurationSection, ISupportRefresh
        {
            String sectionName = typeof(T).FullName;

            //section.AttachEnvironmentProperties(typeof(T));
            string sectionCacheKey = BuildCacheKey(sectionName, machineName, machineType.ToString());
            T      section         = (T)GetConfigurationSection(sectionCacheKey);

            if (section == null)
            {
                lock ( _sectionsLoaded )                 // Only lock if there was no settings available.
                {
                    // Because this is set inside the lock, there will only be one accessor to this value
                    // while the config is loading, so that way ConfigSection, ConfigElement and ConfigElementCollection
                    // can read the right values for the environment during their PostSerialize steps.
                    _machineType = machineType;
                    _machineName = machineName;

                    // Check it again, to prevent the race condition.
                    section = (T)GetConfigurationSection(sectionCacheKey);

                    if (section == null)                       // If it's still null, then we can go ahead and load it.
                    {
                        string configFile = GetConfigurationPath(CoreConfigFileName);

                        ExeConfigurationFileMap fileMap = new ExeConfigurationFileMap
                        {
                            ExeConfigFilename = configFile
                        };

                        System.Configuration.Configuration configuration = ConfigurationManager.OpenMappedExeConfiguration(fileMap, ConfigurationUserLevel.None);

                        try
                        {
                            section = (T)configuration.GetSection(sectionName);
                        }
                        catch (ConfigurationErrorsException ceEx)
                        {
                            ceEx.Data.Add("sectionName", sectionName);
                            //Logger.LogError( ceEx );
                            throw ceEx;
                        }

//#if DEBUG
//                        if ( ConfigManager.InternalLoggingEnabled )
//                        Logging.Logger.LogDebug( "RightPoint.Config.ConfigManager::GetSection<" + typeof( T ).Name + ">(): Section Loaded: " + sectionName + " type: " + ((section == null) ? "null" : section.GetType().Name) );
//#endif

                        UpdateConfigurationDictionary(sectionCacheKey, section);
                    }
                }
            }

            return(section);
        }
        private void button2_Click(object sender, EventArgs e)
        {
            lsect.Clear();
            FileStream fs = new FileStream("Sample_exe\\explorer.exe", FileMode.Open, FileAccess.Read, FileShare.Read);

            s = pe_hlp.ReadImDosHeader(fs);
            //считали из файла в структуру IMAGE_DOS_HEADER

            uint size_dos_stub = s.e_lfanew - s.e_lfarlc;//определили величину стаба

            byte[] stub = new byte[size_dos_stub];
            fs.Read(stub, 0, (int)size_dos_stub);//поместили в stub стаб

            nt_h = pe_hlp.ReadImNtHeaders(fs);
            //считали из файла в структуру IMAGE_NT_HEADERS
            //теперь указатель чтения на позиции начала секций
            DateTime dt = new DateTime(1970, 1, 1, 0, 0, 0);

            dt = dt.AddSeconds(nt_h.FileHeader.TimeDateStamp);

            MachineType mt  = (MachineType)nt_h.FileHeader.Machine;
            string      str = mt.ToString();

            //0x00006000+0x00400000

            for (int i = 0; i < (int)nt_h.FileHeader.NumberOfSections; i++)
            {
                IMAGE_SECTION_HEADER sc_h = new IMAGE_SECTION_HEADER();
                sc_h = pe_hlp.ReadImSecHeaders(fs);
                string section_name = Encoding.ASCII.GetString(sc_h.Name);
                lsect.Add(sc_h);
                //считали из файла в структуру IMAGE_SECTION_HEADER очередную секцию
            }

            //Итак, мы прочитали заголовки...
            uint align = nt_h.OptionalHeader.SizeOfHeaders - (uint)fs.Position;

            al_hzch = new byte[align];
            fs.Read(al_hzch, 0, (int)align);//почитали байты до начала секций
            //А мона было воспользоваться FileAlignment

            //Читаем все секции сразу (чем руковод.: SizeOfHeaders или позицией читателя?)
            ushort cnt_sc          = nt_h.FileHeader.NumberOfSections;
            uint   point_last_sect = (lsect[cnt_sc - 1].PointerToRawData + lsect[cnt_sc - 1].SizeOfRawData) - nt_h.OptionalHeader.SizeOfHeaders;

            al_sc = new byte[point_last_sect];
            fs.Read(al_sc, 0, (int)point_last_sect);//почитали до конца файла

            fs.Close();

            dosHeader1.PrintIDH(s);
            ntHeaders1.PrintINTH(nt_h);
            sections1.PrintSect(lsect);
        }
Example #3
0
        public virtual void LoadConfiguartionValuesIntoFields(String machineName, MachineType machineType)
        {
            foreach (FieldInfo fieldInfo in this.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
            {
                if ((fieldInfo.Attributes & FieldAttributes.Private) == FieldAttributes.Private)
                {
                    continue;
                }

                string fieldName = fieldInfo.Name;
                fieldName = Char.ToLower(fieldName[0]) + fieldName.Substring(1);

                Object val = null;

                String customKey = fieldName + "_" + machineName;
                if (this.Properties.Contains(customKey) &&
                    fieldInfo.FieldType.GetInterface(typeof(ISupportFieldValueLoading).Name) == null
                    /*&& fieldInfo.FieldType.IsSubclassOf( typeof( ConfigurationElementCollection ) ) == false*/)
                {
                    val = base[customKey];
                }

                customKey = fieldName + "_" + machineType.ToString();
                if (this.Properties.Contains(customKey) &&
                    fieldInfo.FieldType.GetInterface(typeof(ISupportFieldValueLoading).Name) == null
                    /*&& fieldInfo.FieldType.IsSubclassOf( typeof( ConfigurationElementCollection ) ) == false*/)
                {
                    val = base[customKey];
                }

                //if (val == null || (val is String && String.IsNullOrEmpty((String)val)))
                if (val == null || (val is ConfigurationElementCollection && ((ConfigurationElementCollection)val).Count == 0))
                {
                    val = base[fieldName];
                }

                if (fieldName == "key")
                {
                    if (val == null)
                    {
                        val = Guid.NewGuid().ToString();
                    }
                    else
                    {
                        val = val.ToString().ToLower();
                    }
                }

                fieldInfo.SetValue(this, val);
            }
        }
Example #4
0
 public override String ToString() =>
 String.Format("ID: {0}\nType: {1}\nMachine: {2}\nVersion: {3}\nEntryPoint: 0x{4:X8}\nPHOffset: 0x{5:X8}\nSHOffset: 0x{6:X8}\nFlags: 0x{7:X4}\nHeaderSize: 0x{8:X2}\nPHSize: 0x{9:X2}\nPHCount: 0x{10:X2}\nSHSize: 0x{11:X2}\nSHCount: 0x{12:X2}\nStringTable: 0x{13:X2}\n\n",
               BitConverter.ToString(Identification),
               Type.ToString(),
               MachineType.ToString(),
               Version.ToString(),
               EntryPoint,
               ProgramHeaderOffset,
               SectionHeaderOffset,
               Flags,
               HeaderSize,
               ProgramHeaderSize,
               ProgramHeaderCount,
               SectionHeaderSize,
               SectionHeaderCount,
               StringTable);
Example #5
0
 /// <summary>
 /// Prints the info.
 /// </summary>
 public void PrintInfo()
 {
     Console.WriteLine("--------------");
     Console.WriteLine("| Elf64 Info:");
     Console.WriteLine("--------------");
     Console.WriteLine();
     Console.WriteLine("Magic number equals 0x7F454C46: Yes");
     Console.WriteLine("Ident class:                    {0} ({1})", ((IdentClass)Ident[4]).ToString(), ((IdentClass)Ident[4]).ToString("x"));
     Console.WriteLine("Ident data:                     {0} ({1})", ((IdentData)Ident[4]).ToString(), ((IdentData)Ident[4]).ToString("x"));
     Console.WriteLine("FileType:                       {0}", Type.ToString());
     Console.WriteLine("Machine:                        {0}", Machine.ToString());
     Console.WriteLine("Version:                        {0}", Version.ToString());
     Console.WriteLine("Entry VirtualAddress:                  0x{0}", EntryAddress.ToString("x"));
     Console.WriteLine("ProgramHeaderOffset:            0x{0}", ProgramHeaderOffset.ToString("x"));
     Console.WriteLine("SectionHeaderOffset:            0x{0}", SectionHeaderOffset.ToString("x"));
     Console.WriteLine("Flags:                          0x{0}", Flags.ToString("x"));
     Console.WriteLine("Header size:                    0x{0}", ElfHeaderSize.ToString("x"));
     Console.WriteLine("ProgramHeaderEntrySize:         0x{0}", ProgramHeaderEntrySize.ToString("x"));
     Console.WriteLine("ProgramHeaderNumber:            0x{0}", ProgramHeaderNumber.ToString("x"));
     Console.WriteLine("SectionHeaderEntrySize:         0x{0}", SectionHeaderEntrySize.ToString("x"));
     Console.WriteLine("SectionHeaderNumber:            0x{0}", SectionHeaderNumber.ToString("x"));
     Console.WriteLine("SectionHeaderStringIndex:       0x{0}", SectionHeaderStringIndex.ToString("x"));
 }
        private static async Task ProcessUpdateAsync(UpdateData update, string pOutputFolder, MachineType MachineType, string Language = "", string Edition = "", bool WriteMetadata = true)
        {
            HashSet <CompDBXmlClass.PayloadItem> payloadItems       = new HashSet <CompDBXmlClass.PayloadItem>();
            HashSet <CompDBXmlClass.PayloadItem> bannedPayloadItems = new HashSet <CompDBXmlClass.PayloadItem>();
            HashSet <CompDBXmlClass.CompDB>      specificCompDBs    = new HashSet <CompDBXmlClass.CompDB>();

            string buildstr = "";
            IEnumerable <string> languages = null;

            int returnCode = 0;
            IEnumerable <CExtendedUpdateInfoXml.File> filesToDownload = null;

            bool getSpecific         = !string.IsNullOrEmpty(Language) && !string.IsNullOrEmpty(Edition);
            bool getSpecificLanguage = !string.IsNullOrEmpty(Language) && string.IsNullOrEmpty(Edition);

            Logging.Log("Gathering update metadata...");

            var compDBs = await update.GetCompDBsAsync();

            await Task.WhenAll(
                Task.Run(async() => buildstr  = await update.GetBuildStringAsync()),
                Task.Run(async() => languages = await update.GetAvailableLanguagesAsync()));

            CompDBXmlClass.Package editionPackPkg = compDBs.GetEditionPackFromCompDBs();
            string editionPkg = await update.DownloadFileFromDigestAsync(editionPackPkg.Payload.PayloadItem.PayloadHash);

            var plans = await Task.WhenAll(languages.Select(x => update.GetTargetedPlanAsync(x, editionPkg)));

            foreach (var plan in plans)
            {
                Logging.Log("");
                Logging.Log("Editions available for language: " + plan.LanguageCode);
                plan.EditionTargets.PrintAvailablePlan();
            }

            string name         = $"{buildstr.Replace(" ", $".{MachineType.ToString().ToLower()}fre.").Replace("(", "").Replace(")", "")}_{update.Xml.UpdateIdentity.UpdateID.Split("-")[^1]}";
Example #7
0
        private void BuildCTAC(
            OSSkuId ReportingSku,
            string ReportingVersion,
            MachineType MachineType,
            string FlightRing,
            string FlightingBranchName,
            string BranchReadinessLevel,
            string CurrentBranch,
            bool SyncCurrentVersionOnly,
            bool IsStore = false
            )
        {
            string content       = "Mainline";
            int    flightEnabled = FlightRing == "Retail" ? 0 : 1;
            string App           = IsStore ? "WU_STORE" : "WU_OS";

            string InstallType  = "Client";
            string ReportingPFN = "Client.OS.rs2";
            string DeviceFamily = "Windows.Desktop";

            if (ReportingSku == OSSkuId.Holographic)
            {
                InstallType  = "FactoryOS";
                ReportingPFN = "HOLOLENS.OS.rs2";
                DeviceFamily = "Windows.Holographic";
            }
            else if (ReportingSku == OSSkuId.Lite)
            {
                InstallType  = "FactoryOS";
                ReportingPFN = "WCOSDevice0.OS";
                DeviceFamily = "Windows.Core";
            }
            else if (ReportingSku == OSSkuId.Andromeda)
            {
                InstallType  = "FactoryOS";
                ReportingPFN = "WCOSDevice1.OS";
                DeviceFamily = "Windows.Core";
            }
            else if (ReportingSku == OSSkuId.HubOS)
            {
                InstallType  = "FactoryOS";
                ReportingPFN = "WCOSDevice2.OS";
                DeviceFamily = "Windows.Core";
            }
            else if (ReportingSku.ToString().Contains("Server", StringComparison.InvariantCultureIgnoreCase) && ReportingSku.ToString().Contains("Core", StringComparison.InvariantCultureIgnoreCase))
            {
                InstallType  = "Server Core";
                ReportingPFN = "Server.OS";
                DeviceFamily = "Windows.Server";
            }
            else if (ReportingSku.ToString().Contains("Server", StringComparison.InvariantCultureIgnoreCase) && !ReportingSku.ToString().Contains("Core", StringComparison.InvariantCultureIgnoreCase))
            {
                InstallType  = "Server";
                ReportingPFN = "Server.OS";
                DeviceFamily = "Windows.Server";
            }
            else if (ReportingSku == OSSkuId.PPIPro)
            {
                DeviceFamily = "Windows.Team";
            }

            DeviceAttributes = "E:IsContainerMgrInstalled=1&" +
                               $"FlightRing={FlightRing}&" +
                               "TelemetryLevel=3&" +
                               "HidOverGattReg=C:\\WINDOWS\\System32\\DriverStore\\FileRepository\\hidbthle.inf_amd64_0fc6b7cd4ccbc55c\\Microsoft.Bluetooth.Profiles.HidOverGatt.dll&" +
                               $"AppVer={ReportingVersion}&" +
                               "IsAutopilotRegistered=0&" +
                               "ProcessorIdentifier=GenuineIntel Family 23 Model 1 Stepping 1&" +
                               "OEMModel=System Product Name&" +
                               "ProcessorManufacturer=GenuineIntel&" +
                               "InstallDate=1577722757&" +
                               "OEMModelBaseBoard=CROSSHAIR VI HERO&" +
                               $"BranchReadinessLevel={BranchReadinessLevel}&" +
                               "DataExpDateEpoch_20H1=0&" +
                               "IsCloudDomainJoined=0&" +
                               "Bios=2019&" +
                               "DchuAmdGrfxVen=4098&" +
                               "IsDeviceRetailDemo=0&" +
                               $"FlightingBranchName={FlightingBranchName}&" +
                               "OSUILocale=en-US&" +
                               $"DeviceFamily={DeviceFamily}&" +
                               "UpgEx_20H1=Green&" +
                               $"WuClientVer={ReportingVersion}&" +
                               $"IsFlightingEnabled={flightEnabled}&" +
                               $"OSSkuId={(int)ReportingSku}&" +
                               "GStatus_20H1=2&" +
                               $"App={App}&" +
                               $"CurrentBranch={CurrentBranch}&" +
                               "InstallLanguage=en-US&" +
                               "OEMName_Uncleaned=System manufacturer&" +
                               $"InstallationType={InstallType}&" +
                               "AttrDataVer=98&" +
                               "IsEdgeWithChromiumInstalled=1&" +
                               "TimestampEpochString_20H1=1593425114&" +
                               $"OSVersion={ReportingVersion}&" +
                               "TencentType=1&" +
                               $"FlightContent={content}&" +
                               "Steam=URL%3Asteam%20protocol&" +
                               "Free=8to16&" +
                               "TencentReg=79 d0 01 d7 9f 54 d5 01&" +
                               "FirmwareVersion=7704&" +
                               "DchuAmdGrfxExists=1&" +
                               "SdbVer_20H1=2340&" +
                               $"OSArchitecture={MachineType.ToString().ToUpper()}&" +
                               "DefaultUserRegion=244&" +
                               "UpdateManagementGroup=2";

            if (ReportingSku == OSSkuId.EnterpriseS || ReportingSku == OSSkuId.EnterpriseSN)
            {
                DeviceAttributes += "&BlockFeatureUpdates=1";
            }

            if (ReportingSku == OSSkuId.Holographic)
            {
                DeviceAttributes += $"OneCoreFwV={ReportingVersion}" +
                                    $"OneCoreSwV={ReportingVersion}" +
                                    $"OneCoreManufacturerModelName=HoloLens" +
                                    $"OneCoreManufacturer=Microsoft Corporation" +
                                    $"OneCoreOperatorName=000-88";
            }
            else if (ReportingSku == OSSkuId.HubOS)
            {
                DeviceAttributes += $"OneCoreFwV={ReportingVersion}" +
                                    $"OneCoreSwV={ReportingVersion}" +
                                    $"OneCoreManufacturerModelName=Surface Hub 2X" +
                                    $"OneCoreManufacturer=Microsoft Corporation" +
                                    $"OneCoreOperatorName=000-88";
            }
            else if (ReportingSku == OSSkuId.Andromeda)
            {
                DeviceAttributes += $"OneCoreFwV={ReportingVersion}" +
                                    $"OneCoreSwV={ReportingVersion}" +
                                    $"OneCoreManufacturerModelName=Andromeda" +
                                    $"OneCoreManufacturer=Microsoft Corporation" +
                                    $"OneCoreOperatorName=000-88";
            }
            else if (ReportingSku == OSSkuId.Lite)
            {
                DeviceAttributes += $"OneCoreFwV={ReportingVersion}" +
                                    $"OneCoreSwV={ReportingVersion}" +
                                    $"OneCoreManufacturerModelName=Santorini" +
                                    $"OneCoreManufacturer=Microsoft Corporation" +
                                    $"OneCoreOperatorName=000-88";
            }

            CallerAttributes = "E:Interactive=1&IsSeeker=1&SheddingAware=1&";
            if (IsStore)
            {
                CallerAttributes = "Acquisition=1&Id=Acquisition%3BMicrosoft.WindowsStore_8wekyb3d8bbwe&";
            }
            else
            {
                CallerAttributes = "Id=UpdateOrchestrator&";
            }
            Products = "";
            if (!IsStore)
            {
                Products = $"PN={ReportingPFN}.{MachineType}&Branch={CurrentBranch}&PrimaryOSProduct=1&Repairable=1&V={ReportingVersion};";
            }

            this.SyncCurrentVersionOnly = SyncCurrentVersionOnly;
        }
Example #8
0
        public void LoadConfiguartionValuesIntoFields(String machineName, MachineType machineType)
        {
            FieldInfo customKeyFieldInfo = null;
            FieldInfo keyFieldInfo       = null;

            foreach (FieldInfo fieldInfo in this.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance))
            {
                if ((fieldInfo.Attributes & FieldAttributes.Private) == FieldAttributes.Private)
                {
                    continue;
                }

                string fieldName = fieldInfo.Name;
                fieldName = Char.ToLower(fieldName[0]) + fieldName.Substring(1);

                Object val = null;

                String customKey = fieldName + "_" + machineName;
                if (this.Properties.Contains(customKey)
                    //&& fieldInfo.FieldType.GetInterface( typeof( ISupportFieldValueLoading ).Name ) == null
                    /*&& fieldInfo.FieldType.IsSubclassOf( typeof( ConfigurationElementCollection ) ) == false*/)
                {
                    val = base[customKey];
                    if (val is ConfigElement && ((ConfigElement)val).IsDefault)
                    {
                        val = null;
                    }
                }

                if (String.IsNullOrEmpty(ConfigManager.Application) == false)
                {
                    customKey = fieldName + "_" + ConfigManager.Application;
                    if ((val == null || (val is String && String.IsNullOrEmpty(val as String)) ||
                         (val is CDataConfigElement && ((CDataConfigElement)val).Value == null) ||
                         (val is ConfigurationElementCollection && ((ConfigurationElementCollection)val).Count == 0)) &&
                        this.Properties.Contains(customKey) && fieldInfo.FieldType.GetInterface(typeof(ISupportFieldValueLoading).Name) == null)
                    {
                        val = base[customKey];
                    }
                }

                if (HttpContext.Current != null)
                {
                    try
                    {
                        foreach (WebHost webHost in ConfigManager.WebHosts)
                        {
                            if (HttpContext.Current.Request.Url.Host.Contains(webHost.WebHostPart))
                            {
                                customKey = fieldName + "_" + webHost.WebHostPart;
                                if ((val == null || (val is String && String.IsNullOrEmpty(val as String)) ||
                                     (val is CDataConfigElement && ((CDataConfigElement)val).Value == null) ||
                                     (val is ConfigurationElementCollection && ((ConfigurationElementCollection)val).Count == 0)) &&
                                    this.Properties.Contains(customKey) && fieldInfo.FieldType.GetInterface(typeof(ISupportFieldValueLoading).Name) == null)
                                {
                                    val = base[customKey];
                                }
                            }
                        }
                    }
                    catch (System.Web.HttpException)
                    {
                    }
                }

                customKey = fieldName + "_" + machineType.ToString();
                if ((val == null || (val is String && String.IsNullOrEmpty(val as String) ||
                                     (val is CDataConfigElement && ((CDataConfigElement)val).Value == null)) ||
                     (val is ConfigurationElementCollection && ((ConfigurationElementCollection)val).Count == 0)) &&
                    this.Properties.Contains(customKey) &&
                    (fieldInfo.FieldType.GetInterface(typeof(ISupportFieldValueLoading).Name) == null || fieldInfo.FieldType == typeof(CDataConfigElement))
                    /*&& fieldInfo.FieldType.IsSubclassOf( typeof( ConfigurationElementCollection ) ) == false*/)
                {
                    val = base[customKey];
                }

                //if (val == null || (val is String && String.IsNullOrEmpty((String)val)))
                if ((val == null || (val is String && String.IsNullOrEmpty(val as String)) ||
                     (val is CDataConfigElement && ((CDataConfigElement)val).Value == null) ||
                     (val is ConfigurationElementCollection && ((ConfigurationElementCollection)val).Count == 0)) &&
                    this.Properties.Contains(fieldName))
                {
                    val = base[fieldName];
                }

                if (fieldName == "key")
                {
                    if (val == null)
                    {
                        val = Guid.NewGuid().ToString();
                    }
                    else
                    {
                        val = val.ToString().ToLower();
                    }

                    keyFieldInfo = fieldInfo;
                }

                fieldInfo.SetValue(this, val);

                if (this is ConfigElementCollectionItem && fieldInfo.GetCustomAttributes(typeof(CustomKeyAttribute), true).Length > 0)
                {
                    customKeyFieldInfo = fieldInfo;
                }
            }

            // If the object being loaded is a config element collection item, and it has a custom key attribute on a field,
            // set the internal Key field value to match the value of the custom key field.
            if (this is ConfigElementCollectionItem && customKeyFieldInfo != null)
            {
                keyFieldInfo.SetValue(this, customKeyFieldInfo.GetValue(this));
            }
        }
Example #9
0
        public void LoadConfiguartionValuesIntoFields(String machineName, MachineType machineType)
        {
            foreach (FieldInfo fieldInfo in this.GetType().GetFields())
            {
                string fieldName = fieldInfo.Name;
                fieldName = Char.ToLower(fieldName[0]) + fieldName.Substring(1);

                Object val = null;

                String customKey = fieldName + "_" + machineName;
                if (this.Properties.Contains(customKey) &&
                    (fieldInfo.FieldType.Equals(typeof(CDataConfigElement)) || fieldInfo.FieldType.GetInterface(typeof(ISupportFieldValueLoading).Name) == null))
                {
                    val = base[customKey];
                }

                if (String.IsNullOrEmpty(ConfigManager.Application) == false)
                {
                    customKey = fieldName + "_" + ConfigManager.Application;
                    if ((val == null || (val is ConfigurationElementCollection && ((ConfigurationElementCollection)val).Count == 0) || (val is CDataConfigElement && ((CDataConfigElement)val).Value == null)) &&
                        this.Properties.Contains(customKey) &&
                        (fieldInfo.FieldType.Equals(typeof(CDataConfigElement)) || fieldInfo.FieldType.GetInterface(typeof(ISupportFieldValueLoading).Name) == null))
                    {
                        val = base[customKey];
                    }
                }


                if (HttpContext.Current != null)
                {
                    try
                    {
                        foreach (WebHost webHost in ConfigManager.WebHosts)
                        {
                            if (HttpContext.Current.Request.Url.Host.Contains(webHost.WebHostPart))
                            {
                                customKey = fieldName + "_" + webHost.WebHostPart;
                                if ((val == null || (val is ConfigurationElementCollection && ((ConfigurationElementCollection)val).Count == 0) || (val is CDataConfigElement && ((CDataConfigElement)val).Value == null)) &&
                                    this.Properties.Contains(customKey) &&
                                    (fieldInfo.FieldType.Equals(typeof(CDataConfigElement)) || fieldInfo.FieldType.GetInterface(typeof(ISupportFieldValueLoading).Name) == null))
                                {
                                    val = base[customKey];
                                }
                            }
                        }
                    }
                    catch (System.Web.HttpException)
                    {
                    }
                }

                customKey = fieldName + "_" + machineType.ToString();
                if ((val == null || (val is ConfigurationElementCollection && ((ConfigurationElementCollection)val).Count == 0) || (val is CDataConfigElement && ((CDataConfigElement)val).Value == null)) &&
                    this.Properties.Contains(customKey) &&
                    (fieldInfo.FieldType.Equals(typeof(CDataConfigElement)) || fieldInfo.FieldType.GetInterface(typeof(ISupportFieldValueLoading).Name) == null))
                {
                    val = base[customKey];
                }

                if ((val == null || (val is ConfigurationElementCollection && ((ConfigurationElementCollection)val).Count == 0) || (val is CDataConfigElement && ((CDataConfigElement)val).Value == null)) &&
                    this.Properties.Contains(fieldName))
                {
                    val = base[fieldName];
                }

                fieldInfo.SetValue(this, val);
            }
        }
Example #10
0
        private static int Main(string[] args)
        {
            var returnValue = false;

            if (args.Length == 0 || args.Length > 2)
            {
                PrintUsage();
                return(Convert.ToInt16(returnValue));
            }


            var fileName  = args[0];
            var beVerbose = !(args.Length == 2 && args[1] == "-S");


            if (File.Exists(fileName))
            {
                fileName = Path.GetFullPath(fileName);
                if (beVerbose)
                {
                    Console.WriteLine("");
                    Console.WriteLine("File          : {0}", Path.GetFileName(fileName));
                    Console.WriteLine("Path          : {0}", Path.GetDirectoryName(fileName));

                    var ver = FileVersionInfo.GetVersionInfo(fileName);
                    Console.WriteLine("File Version  : {0}", ver.FileVersion);
                }


                if (!IsDotNet(fileName, beVerbose))
                {
                    using FileStream fs   = new FileStream(fileName, FileMode.Open, FileAccess.Read);
                    using BinaryReader br = new BinaryReader(fs);

                    fs.Seek(0x3c, SeekOrigin.Begin);
                    Int32 peOffset = br.ReadInt32();
                    fs.Seek(peOffset, SeekOrigin.Begin);
                    UInt32 peHead      = br.ReadUInt32();
                    bool   hasPEHeader = (peHead == 0x00004550);
                    Console.WriteLine($"Has PE Header : {hasPEHeader}");

                    if (hasPEHeader)
                    {
                        MachineType mt          = (MachineType)(br.ReadUInt16());
                        string      machineType = mt switch
                        {
                            MachineType.IMAGE_FILE_MACHINE_AMD64 => "AMD64",
                            MachineType.IMAGE_FILE_MACHINE_I386 => "i386",
                            MachineType.IMAGE_FILE_MACHINE_IA64 => "IA64",
                            _ => mt.ToString(),
                        };
                        Console.WriteLine($"Machine Type  : {machineType}");

                        var buildDateTime = GetLinkerTimeStamp(fileName);
                        Console.WriteLine("Built on      : {0:G}", buildDateTime);
                        Console.WriteLine("A deterministic build will give");
                        Console.WriteLine("an incorrect value above.");
                    }
                }
                else
                {
                    if (beVerbose)
                    {
                        var assembly = Assembly.ReflectionOnlyLoadFrom(fileName);
                        Console.WriteLine($"CLR Version   : {assembly.ImageRuntimeVersion}");
                    }

                    var ass = Assembly.LoadFile(fileName);
                    foreach (var att in ass.GetCustomAttributes(false))
                    {
                        if (att.GetType() == Type.GetType("System.Diagnostics.DebuggableAttribute"))
                        {
                            var typedAttribute = (DebuggableAttribute)att;

                            var debugOuput =
                                (typedAttribute.DebuggingFlags & DebuggableAttribute.DebuggingModes.Default)
                                != DebuggableAttribute.DebuggingModes.None
                                    ? "Full"
                                    : "pdb-only";

                            //returnValue = typedAttribute.IsJITOptimizerDisabled;

                            if (beVerbose)
                            {
                                Console.WriteLine("Debuggable    : {0}",
                                                  (typedAttribute.DebuggingFlags & DebuggableAttribute.DebuggingModes.Default) ==
                                                  DebuggableAttribute.DebuggingModes.Default);
                                Console.WriteLine("JIT Optimized : {0}", !typedAttribute.IsJITOptimizerDisabled);
                                Console.WriteLine("Debug Output  : {0}", debugOuput);

                                var buildDateTime = GetBuildDateTime(fileName);
                                Console.WriteLine("Built on      : {0:G}", buildDateTime);
                            }


                            returnValue = typedAttribute.IsJITOptimizerDisabled;
                        }
                    }

                    ass.ManifestModule.GetPEKind(out var peKind, out var imageFileMachine);


                    if (beVerbose)
                    {
                        Console.WriteLine("PE Type       : {0}", peKind);
                        Console.WriteLine("Machine       : {0}", imageFileMachine);
                        Console.WriteLine("");
                    }
                }
            }


            return(Convert.ToInt16(returnValue));
        }
Example #11
0
        private static async Task ProcessUpdateAsync(UpdateData update, string pOutputFolder, MachineType MachineType, string Language = "", string Edition = "", bool WriteMetadata = true)
        {
            HashSet <CompDBXmlClass.PayloadItem> payloadItems       = new();
            HashSet <CompDBXmlClass.PayloadItem> bannedPayloadItems = new();
            HashSet <CompDBXmlClass.CompDB>      specificCompDBs    = new();

            string buildstr = "";
            IEnumerable <string> languages = null;

            int returnCode = 0;
            IEnumerable <CExtendedUpdateInfoXml.File> filesToDownload = null;

            bool getSpecific             = !string.IsNullOrEmpty(Language) && !string.IsNullOrEmpty(Edition);
            bool getSpecificLanguageOnly = !string.IsNullOrEmpty(Language) && string.IsNullOrEmpty(Edition);

            Logging.Log("Title: " + update.Xml.LocalizedProperties.Title);
            Logging.Log("Description: " + update.Xml.LocalizedProperties.Description);

#if DEBUG
            foreach (var file in update.Xml.Files.File.Select(x => UpdateUtils.GetFilenameForCEUIFile(x, payloadItems)).OrderBy(x => x))
            {
                Console.WriteLine(file);
            }
#endif

            Logging.Log("Gathering update metadata...");

            var compDBs = await update.GetCompDBsAsync();

            await Task.WhenAll(
                Task.Run(async() => buildstr  = await update.GetBuildStringAsync()),
                Task.Run(async() => languages = await update.GetAvailableLanguagesAsync()));

            buildstr ??= "";

            if (string.IsNullOrEmpty(buildstr) && update.Xml.LocalizedProperties.Title.Contains("(UUP-CTv2)"))
            {
                string unformattedBase = update.Xml.LocalizedProperties.Title.Split(" ")[0];
                buildstr = $"10.0.{unformattedBase.Split(".")[0]}.{unformattedBase.Split(".")[1]} ({unformattedBase.Split(".")[2]}.{unformattedBase.Split(".")[3]})";
            }
            else if (string.IsNullOrEmpty(buildstr))
            {
                buildstr = update.Xml.LocalizedProperties.Title;
            }

            string name = $"{buildstr.Replace(" ", ".").Replace("(", "").Replace(")", "")}_{MachineType.ToString().ToLower()}fre_{update.Xml.UpdateIdentity.UpdateID.Split("-")[^1]}";
Example #12
0
 public Environment this[MachineType machineType]
 {
     get { return(this[machineType.ToString()]); }
 }
Example #13
0
 public static string ToString(MachineType machineType)
 => machineType.ToString();
Example #14
0
        private void btnOk_Click(object sender, System.EventArgs e)
        {
            MachineType machineType = GetMachineType();

            byte [] encryptedMultiplexedData = GetEncryptedMultiplexedData(machineType);

            string machineName = Environment.MachineName;

            byte [] iv  = Cryptography.CryptoUtility.GenerateIvFromPassword(machineName);
            byte [] key = Configuration.PUBLIC_ENCRYPTION_KEY;

            byte[] decryptedKey = GetDecryptedKey(encryptedMultiplexedData, machineType);

            // Encrypt the prime key with the public encryption key using the machineName as
            // the IV.
            this._encryptedPrimeKey    = Cryptography.CryptoUtility.EncryptBytesToBytes(decryptedKey, key, iv);
            this._encryptedMachineType = Cryptography.CryptoUtility.EncryptStringToBytes(machineType.ToString(), key, iv);

            /*
             * using( RegistryKey rk = Registry.LocalMachine.CreateSubKey( Configuration.EVENTINVENTORY_REGISTRY_KEY ) )
             * {
             *      rk.SetValue( Configuration.EVENTINVENTORY_REGISTRY_VALUE_NAME_STRONG_KEY, encryptedKey );
             *      rk.SetValue( Configuration.EVENTINVENTORY_REGISTRY_VALUE_NAME_MACHINE_TYPE, encryptedMachineType );
             *
             *      rk.Close();
             * }
             */

            this.DialogResult = DialogResult.OK;
            this.Close();
        }