|
|
@ -5,6 +5,7 @@ using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
using System.Text; |
|
|
|
using System.Threading.Tasks; |
|
|
|
|
|
|
@ -14,6 +15,9 @@ namespace IPA.AntiMalware |
|
|
|
{ |
|
|
|
internal static WindowsCOMAntiMalware? TryInitialize() |
|
|
|
{ |
|
|
|
// Mono's COM interop *fundamentally doesn't work.*
|
|
|
|
// End of story.
|
|
|
|
#if false
|
|
|
|
try |
|
|
|
{ |
|
|
|
return new(); |
|
|
@ -22,18 +26,39 @@ namespace IPA.AntiMalware |
|
|
|
{ |
|
|
|
Logger.AntiMalware.Warn("Could not initialize COM-based antimalware engine:"); |
|
|
|
Logger.AntiMalware.Warn(e); |
|
|
|
return null; |
|
|
|
} |
|
|
|
#endif
|
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private readonly IAntimalware amInterface; |
|
|
|
|
|
|
|
private WindowsCOMAntiMalware() |
|
|
|
{ |
|
|
|
var amType = Type.GetTypeFromCLSID(AmsiConstants.CAntimalwareGuid, true); |
|
|
|
amInterface = (IAntimalware)Activator.CreateInstance(amType); |
|
|
|
var hr = CoCreateInstanceAM(AmsiConstants.CAntimalwareGuid, |
|
|
|
null, |
|
|
|
0x1 | 0x4 /* inproc server, local server */, |
|
|
|
AmsiConstants.IAntimalwareGuid, |
|
|
|
out var antimalware); |
|
|
|
Marshal.ThrowExceptionForHR(hr); |
|
|
|
|
|
|
|
amInterface = antimalware; |
|
|
|
} |
|
|
|
|
|
|
|
[DllImport("ole32", |
|
|
|
CallingConvention = CallingConvention.Winapi, |
|
|
|
ExactSpelling = true, |
|
|
|
PreserveSig = false, |
|
|
|
EntryPoint = "CoCreateInstance")] |
|
|
|
[DefaultDllImportSearchPaths(DllImportSearchPath.System32)] |
|
|
|
private static extern int CoCreateInstanceAM( |
|
|
|
[In] in Guid clsid, |
|
|
|
[In, MarshalAs(UnmanagedType.Interface)] object? unkOuter, |
|
|
|
[In] int dwClsContext, |
|
|
|
[In] in Guid iid, |
|
|
|
[Out, MarshalAs(UnmanagedType.Interface)] out IAntimalware @interface); |
|
|
|
|
|
|
|
|
|
|
|
private static ScanResult ScanResultFromAmsiResult(AmsiResult result) |
|
|
|
=> result switch |
|
|
|
{ |
|
|
|