public void AmsiStreamTest() { var fn = TestCaseSources.BmpFile; var app = "MyTestApp"; AmsiStream str = null; Assert.That(() => str = new(new FileInfo(fn), false) { AppName = app }, Throws.Nothing);
/// <summary>Scans a string for malware.</summary> /// <param name="str">The string to be scanned.</param> /// <param name="contentName">The filename, URL, unique script ID, or similar of the content being scanned.</param> /// <returns>The result of the scan.</returns> public static ScanResult Scan(string str, string contentName = null) { AMSI_RESULT result; if (Provider is null) { EnsureContext(); using SafeHAMSISESSION session = new(hCtx); AmsiScanString(session.Context, str, contentName, session, out result).ThrowIfFailed(); return(result.Convert()); } else { using AmsiStream stream = new AmsiStream(new SafeCoTaskMemString(str), false); Provider.Scan(stream, out result).ThrowIfFailed(); } return(result.Convert()); }