public static Table Sum(List <Table> list) { var groups = new Dictionary <string, List <TransparencyStats> >(); var sum = new Table(); foreach (var table in list) { foreach (var row in table.Rows) { List <TransparencyStats> group; if (!groups.TryGetValue(row.Key, out group)) { var srow = new Row(); srow.Key = row.Key; sum.Rows.Add(srow); groups[row.Key] = group = new List <TransparencyStats>(); } group.Add(row.Stats); } } foreach (var row in sum.Rows) { row.Stats = TransparencyStats.Sum(groups[row.Key]); } return(sum); }
public static byte[] ExtractorNormalized(string key, SampleFingerprint fp) { return(PersistentCache.Get(Path.Combine("normalized-extractor-transparency-files", key), ExtractorPath(key, fp), () => { return SerializationUtils.Normalize(TransparencyStats.ExtractorRow(fp, key).Mime, Extractor(key, fp)); })); }
public static Table Of(string key, string mime, byte[] data) { var row = new Row(); row.Key = key; row.Stats = TransparencyStats.Of(mime, data); var table = new Table(); table.Rows.Add(row); return(table); }
public static TransparencyStats Of(string mime, byte[] data) { var stats = new TransparencyStats(); stats.Mime = mime; stats.Count = 1; stats.Size = data.Length; var normalized = SerializationUtils.Normalize(mime, data); stats.SizeNormalized = normalized.Length; stats.Hash = DataHash.Of(normalized); return(stats); }
static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .WriteTo.Console(outputTemplate: "{Level:u1} {Message:lj}{NewLine}{Exception}") .CreateLogger(); if (args.Length != 1) { return; } switch (args[0]) { case "extractor-transparency-stats": TransparencyStats.Report(TransparencyStats.ExtractorTable()); break; } }
public static TransparencyStats Sum(List <TransparencyStats> list) { var sum = new TransparencyStats(); sum.Mime = list[0].Mime; var hash = new DataHash(); foreach (var stats in list) { sum.Count += stats.Count; sum.Size += stats.Size; sum.SizeNormalized += stats.SizeNormalized; hash.Add(stats.Hash); } sum.Hash = hash.Compute(); return(sum); }
static void Main(string[] args) { Log.Logger = new LoggerConfiguration() .WriteTo.Console(outputTemplate: "{Message:lj}{NewLine}{Exception}") .CreateLogger(); if (args.Length < 1) { return; } switch (args[0]) { case "footprint": TemplateFootprint.Report(); break; case "accuracy": ScalarAccuracy.Report(); break; case "extractor-transparency-stats": TransparencyStats.Report(TransparencyStats.ExtractorTable()); break; case "extractor-transparency-files": if (args.Length < 2) { return; } TransparencyFile.Extractor(args[1]); break; case "normalized-extractor-transparency-files": if (args.Length < 2) { return; } TransparencyFile.ExtractorNormalized(args[1]); break; } }
static string ExtractorPath(string key, SampleFingerprint fp) { return(fp.Path + Extension(TransparencyStats.ExtractorRow(fp, key).Mime)); }
public void Add(TransparencyStats stats) { Count += stats.Count; Size += stats.Size; Hasher.AppendData(stats.Hash); }