Beispiel #1
0
        /// <summary>
        /// Get the compilers used to create an ELF binary.
        /// </summary>
        /// <param name="elf">ELF binary</param>
        /// <returns>List of compiler tools from the .comment section</returns>
        internal static ELFCompiler[] GetELFCompilers(IELF elf)
        {
            ISection commentSection = elf.Sections.Where(s => s.Name == ".comment").FirstOrDefault();

            if (commentSection != null)
            {
                try
                {
                    string[] commentData = NullTermAsciiToStrings(commentSection.GetContents());
                    var      compilers   = new ELFCompiler[commentData.Length];
                    for (int i = 0; i < commentData.Length; i++)
                    {
                        compilers[i] = new ELFCompiler(commentData[i]);
                    }
                    return(compilers);
                }
                // Catch cases when the .comment section is not formatted the way we expect it to be.
                catch (Exception ex) when(ex is ArgumentException || ex is ArgumentNullException)
                {
                    return(new ELFCompiler[] { new ELFCompiler(string.Empty) });
                }
            }
            else
            {
                return(new ELFCompiler[] { new ELFCompiler(string.Empty) });
            }
        }
Beispiel #2
0
        public void ELFCompiler_ConstructorHandlesKnownInputs(string compilerString, ELFCompilerType expectedType, string expectedVersion)
        {
            ELFCompiler compiler = new ELFCompiler(compilerString);

            compiler.Compiler.Should().Be(expectedType);
            compiler.Version.Should().Be(new Version(expectedVersion));
        }