/// <summary>Opens a session within which multiple scan requests can be correlated.</summary> /// <param name="amsiContext">The handle of type HAMSICONTEXT that was initially received from AmsiInitialize.</param> /// <param name="amsiSession"> /// A handle of type HAMSISESSION that must be passed to all subsequent calls to the AMSI API within the session. /// </param> /// <returns>If this function succeeds, it returns <c>S_OK</c>. Otherwise, it returns an <c>HRESULT</c> error code.</returns> /// <remarks>When the app is finished with the session it must call AmsiCloseSession.</remarks> // https://docs.microsoft.com/en-us/windows/win32/api/amsi/nf-amsi-amsiopensession HRESULT AmsiOpenSession( [in] HAMSICONTEXT // amsiContext, [out] HAMSISESSION *amsiSession ); public static HRESULT AmsiOpenSession([In] HAMSICONTEXT amsiContext, out SafeHAMSISESSION amsiSession) { HRESULT hr = AmsiOpenSessionInternal(amsiContext, out HAMSISESSION h); amsiSession = hr.Succeeded ? new SafeHAMSISESSION((IntPtr)h, true) : new SafeHAMSISESSION(IntPtr.Zero, false); return(hr); }
/// <summary>Initializes a new instance of the <see cref="SafeHAMSISESSION"/> class.</summary> /// <param name="context">The context.</param> public SafeHAMSISESSION(HAMSICONTEXT context) : base() => Open(Context = context);
private static extern HRESULT AmsiOpenSessionInternal([In] HAMSICONTEXT amsiContext, out HAMSISESSION amsiSession);
public static extern void AmsiUninitialize(HAMSICONTEXT amsiContext);
public static extern HRESULT AmsiScanString(HAMSICONTEXT amsiContext, [MarshalAs(UnmanagedType.LPWStr)] string str, [Optional, MarshalAs(UnmanagedType.LPWStr)] string contentName, [In, Optional] HAMSISESSION amsiSession, out AMSI_RESULT result);
public static extern HRESULT AmsiScanBuffer([In] HAMSICONTEXT amsiContext, [In] IntPtr buffer, uint length, [Optional, MarshalAs(UnmanagedType.LPWStr)] string contentName, [In, Optional] HAMSISESSION amsiSession, out AMSI_RESULT result);
public static extern HRESULT AmsiNotifyOperation([In] HAMSICONTEXT amsiContext, [In] IntPtr buffer, [In] uint length, [Optional, MarshalAs(UnmanagedType.LPWStr)] string contentName, out AMSI_RESULT result);
public static extern void AmsiCloseSession([In] HAMSICONTEXT amsiContext, [In] HAMSISESSION amsiSession);