public static bool IsELF(this BinaryAnalyzerContext target) { ELFBinary ret = target.Binary as ELFBinary; if (ret == null) { return(false); } return(true); }
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); }
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); }
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); } }
// 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); } }
// 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); }
public abstract AnalysisApplicability CanAnalyzeElf(ELFBinary target, Sarif.PropertiesDictionary policy, out string reasonForNotAnalyzing);