Ejemplo n.º 1
0
        public static bool IsELF(this BinaryAnalyzerContext target)
        {
            ELFBinary ret = target.Binary as ELFBinary;

            if (ret == null)
            {
                return(false);
            }
            return(true);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 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);
     }
 }
        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);
        }
Ejemplo n.º 8
0
 public abstract AnalysisApplicability CanAnalyzeElf(ELFBinary target, Sarif.PropertiesDictionary policy, out string reasonForNotAnalyzing);