public System.Web.Http.Results.JsonResult <List <BlockScanResult> > Post(int blockSize, HttpRequestMessage request)
        {
            var sample     = request.Content.ReadAsStringAsync().Result;
            var lines      = sample.Split(new [] { Environment.NewLine }, StringSplitOptions.None);
            var sub_sample = lines.Skip(0).Take(blockSize);
            var result     = new List <BlockScanResult>();
            var scanner    = new AntiMalwareScanInterface();
            var block      = 1;

            while (sub_sample.Count() != 0)
            {
                var tempSample      = string.Join("\r\n", sub_sample);
                var tempSampleBytes = Encoding.UTF8.GetBytes(tempSample);
                var scanResult      = scanner.CallAntimalwareScanInterface(tempSampleBytes);
                if (scanResult)
                {
                    result.Add(new BlockScanResult()
                    {
                        BlockNumber = block, BlockText = tempSample
                    });
                }

                sub_sample = lines.Skip(blockSize * block).Take(blockSize);
                block++;
            }

            return(Json(result));
        }
        public System.Web.Http.Results.JsonResult <bool> Post(HttpRequestMessage request)
        {
            var sample  = request.Content.ReadAsStringAsync().Result;
            var bytes   = Encoding.UTF8.GetBytes(sample);
            var scanner = new AntiMalwareScanInterface();
            var result  = scanner.CallAntimalwareScanInterface(bytes);

            return(Json(result));
        }
        public void RandomString_Is_Not_Detected()
        {
            //arange
            var sample        = RandomData.RandomString(10);
            var AMSI_Provider = new AntiMalwareScanInterface();

            //act
            var detection = AMSI_Provider.CallAntimalwareScanInterface(sample);

            //assert
            Assert.AreEqual(false, detection, "Sample should not be deteceted.");
        }
        public void EICAR_Is_Detected()
        {
            //arange
            var sample1       = @"X5O!P%@AP[4\PZX54(P^)7CC)7}$EIC";
            var sample2       = @"AR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*";
            var AMSI_Provider = new AntiMalwareScanInterface();

            //act
            var detection = AMSI_Provider.CallAntimalwareScanInterface(sample1 + sample2);

            //assert
            Assert.AreEqual(true, detection, "EICAR file should be detected");
        }
Exemplo n.º 5
0
        public List <int> ScanFile(string fileContents)
        {
            var detections = new List <int>();
            var AMSI_Hooks = new AntiMalwareScanInterface();

            var lineNum = 1;

            foreach (string line in new LineReader(() => new StringReader(fileContents)))
            {
                var result = AMSI_Hooks.CallAntimalwareScanInterface(line);
                if (result)
                {
                    detections.Add(lineNum);
                }
                lineNum++;
            }

            return(detections);
        }