123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
-
-
-
-
-
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Collections;
-
- using System.Runtime.InteropServices;
-
- namespace SNFMultiDLLExampleCsharp
- {
- class SNFMultiDLLExample
- {
-
- #region DLL Imports
-
- const string SNFMULTI_DLL = "..\\..\\..\\64bitDll\\SNFMulti.dll";
-
-
-
-
- [DllImport(SNFMULTI_DLL, CharSet = CharSet.Auto, EntryPoint = "setThrottle", CallingConvention = CallingConvention.Winapi)]
- public static extern int setThrottle(int throttle);
-
-
- [DllImport(SNFMULTI_DLL, CharSet = CharSet.Auto, EntryPoint = "startupSNF", CallingConvention = CallingConvention.Winapi)]
- public static extern int startupSNF([MarshalAs(UnmanagedType.LPStr)] string Path);
-
-
- [DllImport(SNFMULTI_DLL, CharSet = CharSet.Auto, EntryPoint = "startupSNFAuthenticated",
- CallingConvention = CallingConvention.Winapi)]
- public static extern int startupSNFAuthenticated(
- [MarshalAs(UnmanagedType.LPStr)] string Path,
- [MarshalAs(UnmanagedType.LPStr)] string Lic,
- [MarshalAs(UnmanagedType.LPStr)] string Auth);
-
-
- [DllImport(SNFMULTI_DLL, CharSet = CharSet.Auto, EntryPoint = "shutdownSNF", CallingConvention = CallingConvention.Winapi)]
- public static extern int shutdownSNF();
-
-
- [DllImport(SNFMULTI_DLL, CharSet = CharSet.Auto, EntryPoint = "testIP", CallingConvention = CallingConvention.Winapi)]
- public static extern int testIP(ulong IPToCheck);
-
-
- [DllImport(SNFMULTI_DLL, CharSet = CharSet.Auto, EntryPoint = "getIPReputation", CallingConvention = CallingConvention.Winapi)]
- public static extern double getIPReputation(ulong IPToCheck);
-
-
-
- [DllImport(SNFMULTI_DLL, CharSet = CharSet.Auto, EntryPoint = "scanBuffer", CallingConvention = CallingConvention.Winapi)]
- public static extern int scanBuffer(
- [MarshalAs(UnmanagedType.LPStr)] string Bfr,
- int Length,
- [MarshalAs(UnmanagedType.LPStr)] string Name,
- int Setup);
-
-
- [DllImport(SNFMULTI_DLL, CharSet = CharSet.Auto, EntryPoint = "scanFile", CallingConvention = CallingConvention.Winapi)]
- public static extern int scanFile([MarshalAs(UnmanagedType.LPStr)] string Path, int Setup);
-
-
- [DllImport(SNFMULTI_DLL, CharSet = CharSet.Auto, EntryPoint = "getScanXHeaders", CallingConvention = CallingConvention.Winapi)]
- public static extern int getScanXHeaders(int ScanHandle,
- out IntPtr Bfr,
- out int Length);
-
-
- [DllImport(SNFMULTI_DLL, CharSet = CharSet.Auto, EntryPoint = "getScanXMLLog", CallingConvention = CallingConvention.Winapi)]
- public static extern int getScanXMLLog(int ScanHandle,
- out IntPtr Bfr,
- out int Length);
-
-
- [DllImport(SNFMULTI_DLL, CharSet = CharSet.Auto, EntryPoint = "getScanClassicLog", CallingConvention = CallingConvention.Winapi)]
- public static extern int getScanClassicLog(int ScanHandle,
- out IntPtr Bfr,
- out int Length);
-
-
- [DllImport(SNFMULTI_DLL, CharSet = CharSet.Auto, EntryPoint = "getScanResult", CallingConvention = CallingConvention.Winapi)]
- public static extern int getScanResult(int ScanHandle);
-
-
- [DllImport(SNFMULTI_DLL, CharSet = CharSet.Auto, EntryPoint = "closeScan", CallingConvention = CallingConvention.Winapi)]
- public static extern int closeScan(int ScanHandle);
-
-
- #endregion
-
- static void Main(string[] args)
- {
-
-
-
-
-
- const string ConfigurationPath = "..\\..\\snf_engine.xml";
-
-
-
- const uint IPToTest = 0x0c22384e;
-
- const string SampleMessage =
- "Received: from mx-out.example.com [12.34.56.78] (HELO Somebody)\r\n" +
- " by mx-in.example.com (nosuchserver v1.0) for nobody@example.com\r\n" +
- "From: <somebody@example.com>\r\n" +
- "To: <nobody@example.com>\r\n" +
- "Subject: Nothing to see here\r\n" +
- "\r\n" +
- "So this is the big thing that's not here to see.\r\n" +
- "I thought it would be more interesting than this.\r\n" +
- "\r\n" +
- "_M\r\n" +
- ".\r\n";
-
-
-
-
- int Result = 0;
-
- Result = startupSNF(ConfigurationPath);
-
-
-
-
-
-
- System.Console.WriteLine("Started with config " + ConfigurationPath + " Result: " + Result);
-
-
-
- Result = testIP(IPToTest);
- System.Console.WriteLine("IP test result: " + Result);
-
- double IPReputation = getIPReputation(IPToTest);
- System.Console.WriteLine("IP Reputation: " + IPReputation);
-
-
-
- const int NumberOfScans = 10;
- for(int i = 0; i < NumberOfScans; i++) {
-
-
-
- IPReputation = getIPReputation(IPToTest);
- System.Console.WriteLine("IP Reputation: " + IPReputation);
-
-
-
- int SetupTime = 12;
- int ScanHandle = 0;
- ScanHandle = scanBuffer(SampleMessage, SampleMessage.Length, "TestMessage", SetupTime);
-
-
- System.Console.WriteLine("Scan Handle: " + ScanHandle);
-
-
-
- IntPtr XHeadersPtr = IntPtr.Zero;
- int XHeadersLength = 0;
- int ScanResult = 0;
- ScanResult = getScanXHeaders(ScanHandle, out XHeadersPtr, out XHeadersLength);
- string XHeaders;
- XHeaders = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(XHeadersPtr, XHeadersLength);
-
-
-
- Result = closeScan(ScanHandle);
-
- System.Console.WriteLine("Scan Close Result: " + Result);
-
-
-
-
- System.Console.WriteLine("Scan result code: " + ScanResult);
- System.Console.WriteLine("Scan X- headers: " + XHeaders);
-
- }
-
-
-
- Result = shutdownSNF();
-
- }
- }
- }
|