Ejemplo n.º 1
0
        public ActionResult Index(HttpPostedFileBase file)
        {
            // max of 25 MB
            if (file.ContentLength > 0 && file.ContentLength < ((1024 * 1024) * 25))
            {
                var add = new ScanItemAdd();

                add.FileName = Path.GetFileName(file.FileName);
                add.Data     = new byte[file.ContentLength];

                // Read the file into memory
                file.InputStream.Read(add.Data, 0, add.Data.Length);

                // Get md5 hash
                add.MD5 = BerzerkAPI.Analyzers.MD5.FromByteArray(add.Data);

                // try to scan the object
                var result = man.ScanItemAdd(add);

                if (result != null)
                {
                    return(RedirectToAction("Result", new { id = result.Id }));
                }
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 2
0
        public ScanItemBase ScanItemAdd(ScanItemAdd add)
        {
            // Scan the file data
            var scan = BerzerkAPI.Analyzers.PatternAnalyzer.AnalyzeByteArray(add.Data, this.Signatures);

            // get the result
            if (scan != null)
            {
                add.Result = scan.Definition;
            }
            else
            {
                add.Result = "Clean";
            }


            // Add the item to the db
            var created = ds.ScanItem.Add(AutoMapper.Mapper.Map <ScanItem>(add));

            ds.SaveChanges();

            // return null or the results
            return((created == null) ? null : AutoMapper.Mapper.Map <ScanItemBase>(created));
        }