AmsiSession Class
- Supported on windows10.0.10240
Represents an AMSI session that correlates multiple scan requests within the same context.
[SupportedOSPlatform("windows10.0.10240")]
public sealed class AmsiSession : IDisposableExample
using var context = AmsiContext.Create("MyApplication");
// The scans of a session are correlated, e.g. the fragments of a script
using var session = context.CreateSession();
Assert.False(session.IsMalware("Hello world", "file1.txt"));
Assert.True(session.IsMalware(@"X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*", "file2.txt"));- Implements
Methods
| Name | Description |
|---|---|
| Dispose() | |
| IsMalware(byte[], string) | Scans a byte buffer for malware within this session. |
| IsMalware(string, string) | Scans a string for malware within this session. |
| Scan(byte[], string) | Scans a byte buffer for malware within this session. |
| Scan(string, string) | Scans a string for malware within this session. |
Dispose()
AmsiSession.cspublic void Dispose()No documentation is available.
IsMalware overloads
IsMalware(byte[], string)
AmsiSession.csScans a byte buffer for malware within this session.
Parameters
payloadbyte[]- The byte buffer to scan.
contentNamestring- The name or identifier of the content being scanned.
Returns
bool true if the content is detected as malware; otherwise, false.
Exceptions
COMException- Thrown when the scan operation fails.
ObjectDisposedException- Thrown when the session or its context has been disposed.
Remarks
Content blocked by administrator policy is not reported as malware. Use AmsiSession.Scan and AmsiResultExtensions.ShouldBlock to cover that case.
IsMalware(string, string)
AmsiSession.csScans a string for malware within this session.
Parameters
payloadstring- The string content to scan.
contentNamestring- The name or identifier of the content being scanned.
Returns
bool true if the content is detected as malware; otherwise, false.
Exceptions
COMException- Thrown when the scan operation fails.
ObjectDisposedException- Thrown when the session or its context has been disposed.
Remarks
Content blocked by administrator policy is not reported as malware. Use AmsiSession.Scan and AmsiResultExtensions.ShouldBlock to cover that case.
Scan overloads
Scan(byte[], string)
AmsiSession.csScans a byte buffer for malware within this session.
public AmsiResult Scan(byte[] payload, string contentName)Parameters
payloadbyte[]- The byte buffer to scan.
contentNamestring- The name or identifier of the content being scanned.
Returns
AmsiResult The result reported by the antimalware provider.
Exceptions
COMException- Thrown when the scan operation fails.
ObjectDisposedException- Thrown when the session or its context has been disposed.
Scan(string, string)
AmsiSession.csScans a string for malware within this session.
public AmsiResult Scan(string payload, string contentName)Parameters
payloadstring- The string content to scan.
contentNamestring- The name or identifier of the content being scanned.
Returns
AmsiResult The result reported by the antimalware provider.
Exceptions
COMException- Thrown when the scan operation fails.
ObjectDisposedException- Thrown when the session or its context has been disposed.