コード例 #1
0
        public static bool IsELF(this BinaryAnalyzerContext target)
        {
            ELFBinary ret = target.Binary as ELFBinary;

            if (ret == null)
            {
                return(false);
            }
            return(true);
        }
コード例 #2
0
        public static ELFBinary ELFBinary(this BinaryAnalyzerContext target)
        {
            ELFBinary ret = target.Binary as ELFBinary;

            if (ret == null)
            {
                // Attempted to cast a binary target to a '{0}', but was unable to.  This indicates a programmer error in rules evaluating that sort of target.
                throw new InvalidOperationException(string.Format(SdkResources.IllegalBinaryCast, "ELFBinary"));
            }
            return(ret);
        }
コード例 #3
0
        public override AnalysisApplicability CanAnalyzeElf(ELFBinary target, Sarif.PropertiesDictionary policy, out string reasonForNotAnalyzing)
        {
            IELF elf = target.ELF;

            if (elf.Type == FileType.Core || elf.Type == FileType.None || elf.Type == FileType.Relocatable)
            {
                reasonForNotAnalyzing = reasonForNotAnalyzing = MetadataConditions.ElfIsCoreNoneOrObject;
                return(AnalysisApplicability.NotApplicableToSpecifiedTarget);
            }

            reasonForNotAnalyzing = null;
            return(AnalysisApplicability.ApplicableToSpecifiedTarget);
        }
コード例 #4
0
 public sealed override AnalysisApplicability CanAnalyze(BinaryAnalyzerContext context, out string reasonForNotAnalyzing)
 {
     if (context.IsELF())
     {
         ELFBinary target = context.ELFBinary();
         return(CanAnalyzeElf(target, context.Policy, out reasonForNotAnalyzing));
     }
     else
     {
         reasonForNotAnalyzing = MetadataConditions.ImageIsNotElf;
         return(AnalysisApplicability.NotApplicableToSpecifiedTarget);
     }
 }
コード例 #5
0
 // We may want to consider changing this to an extension/plugin model rather than a hardcoded list of supported binary parsers.
 // However, for now this will do.
 public static IBinary GetBinaryFromFile(Uri uri, string symbolPath = null, string localSymbolDirectories = null)
 {
     if (PEBinary.CanLoadBinary(uri))
     {
         return(new PEBinary(uri, symbolPath, localSymbolDirectories));
     }
     else if (ELFBinary.CanLoadBinary(uri))
     {
         return(new ELFBinary(uri));
     }
     else
     {
         return(null);
     }
 }
コード例 #6
0
 // We may want to consider changing this to an extension/plugin model rather than a hardcoded list of supported binary parsers.
 // However, for now this will do.
 public static IBinary GetBinaryFromFile(Uri uri)
 {
     if (PEBinary.CanLoadBinary(uri))
     {
         return(new PEBinary(uri));
     }
     else if (ELFBinary.CanLoadBinary(uri))
     {
         return(new ELFBinary(uri));
     }
     else
     {
         return(null);
     }
 }
コード例 #7
0
        public override AnalysisApplicability CanAnalyzeElf(ELFBinary target, Sarif.PropertiesDictionary policy, out string reasonForNotAnalyzing)
        {
            IELF elf = target.ELF;

            if (elf.Type == FileType.Core || elf.Type == FileType.None || elf.Type == FileType.Relocatable)
            {
                reasonForNotAnalyzing = MetadataConditions.ElfIsCoreNoneOrObject;
                return(AnalysisApplicability.NotApplicableToSpecifiedTarget);
            }

            // We check for "any usage of non-gcc" as a default/standard compilation with clang leads to [GCC, Clang]
            // either because it links with a gcc-compiled object (cstdlib) or the linker also reading as GCC.
            // This has a potential for a False Negative if teams are using GCC and other tools.
            if (target.Compilers.Any(c => c.Compiler != ELFCompilerType.GCC))
            {
                reasonForNotAnalyzing = MetadataConditions.ElfNotBuiltWithGcc;
                return(AnalysisApplicability.NotApplicableToSpecifiedTarget);
            }

            reasonForNotAnalyzing = null;
            return(AnalysisApplicability.ApplicableToSpecifiedTarget);
        }
コード例 #8
0
 public abstract AnalysisApplicability CanAnalyzeElf(ELFBinary target, Sarif.PropertiesDictionary policy, out string reasonForNotAnalyzing);