You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

main.vb 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. ' main.vb SNF-SDK-WIN CPP OEM Demonstration Code
  2. ' Copyright (C) 2009 ARM Research Labs, LLC
  3. '
  4. ' This app simply exercises the API provided by snfmultidll.
  5. Imports System.Runtime.InteropServices
  6. Imports System.Text
  7. Module SNFMultiDLLExample
  8. #Region "DLL Imports"
  9. ' Location of SNFMulti.dll.
  10. Const SNFMULTI_DLL As String = "..\..\..\64bitDll\SNFMulti.dll" ' Set CPU type to "Any CPU"
  11. 'Const SNFMULTI_DLL As String = "..\..\..\..\64bitDll\SNFMulti.dll" ' Set CPU type to "x64"
  12. 'Const SNFMULTI_DLL As String = "..\..\..\32bitDll\SNFMulti.dll" ' Set CPU type to "x86"
  13. 'int setThrottle(int Threads); /* Set scan thread limit. */
  14. 'int startupSNF(char* Path); /* Start SNF with configuration. */
  15. 'int startupSNFAuthenticated(char* Path, char* Lic, char* Auth); /* Start SNF with conf & auth. */
  16. 'int shutdownSNF(); /* Shutdown SNF. */
  17. 'int testIP(unsigned long int IPToCheck); /* Test the IP for a GBUdb range. */
  18. 'double getIPReputation(unsigned long int IPToCheck); /* Get reputation figure for IP. */
  19. 'int scanBuffer(unsigned char* Bfr, int Length, char* Name, int Setup); /* Scan msgBuffer, name, setup time. */
  20. 'int scanFile(char* FilePath, int Setup); /* Scan msgFile, setup time. */
  21. 'int getScanXHeaders(int ScanHandle, char** Bfr, int* Length); /* Get result & XHeaders. */
  22. 'int getScanXMLLog(int ScanHandle, char** Bfr, int* Length); /* Get result & XML Log. */
  23. 'int getScanClassicLog(int ScanHandle, char** Bfr, int* Length); /* Get result & Classic Log. */
  24. 'int getScanResult(int ScanHandle); /* Get just the scan result. */
  25. 'int closeScan(int ScanHandle); /* Close the scan result. */
  26. 'Set scan thread limit
  27. <DllImport(SNFMULTI_DLL, EntryPoint:="setThrottle", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
  28. Public Function setThrottle(ByVal Threads As Int32) As Int32
  29. End Function
  30. 'Startup
  31. <DllImport(SNFMULTI_DLL, EntryPoint:="startupSNF", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
  32. Public Function startupSNF(ByVal PathToConfigurationFile As String) As Int32
  33. End Function
  34. 'Start SNF with conf & auth.
  35. <DllImport(SNFMULTI_DLL, EntryPoint:="startupSNFAuthenticated", CharSet:=CharSet.Ansi, _
  36. CallingConvention:=CallingConvention.Winapi)> _
  37. Public Function startupSNFAuthenticated( _
  38. ByVal Path As String, _
  39. ByVal Lic As String, _
  40. ByVal Auth As String) As Int32
  41. End Function
  42. 'Shutdown
  43. <DllImport(SNFMULTI_DLL, EntryPoint:="shutdownSNF", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
  44. Public Function shutdownSNF() As Int32
  45. End Function
  46. 'Test IP
  47. <DllImport(SNFMULTI_DLL, EntryPoint:="testIP", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
  48. Public Function testIP(ByVal IPToCheck As UInt32) As Int32
  49. End Function
  50. 'getIPReputation
  51. <DllImport(SNFMULTI_DLL, EntryPoint:="getIPReputation", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
  52. Public Function getIPReputation(ByVal IPToCheck As UInt32) As Double
  53. End Function
  54. 'ScanBuffer - returns scannerhandle
  55. <DllImport(SNFMULTI_DLL, EntryPoint:="scanBuffer", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
  56. Public Function scanBuffer(ByVal MsgBfr As StringBuilder, ByVal MsgBfrLen As Int32, ByVal MsgID As String, ByVal SetupTime As Int32) As Int32
  57. End Function
  58. 'ScanFile
  59. <DllImport(SNFMULTI_DLL, EntryPoint:="scanFile", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
  60. Public Function scanFile(ByVal FilePath As String, ByVal Setup As Int32) As Int32
  61. End Function
  62. 'GetScanXHeaders - use scannerhandle returned from previous - returns ScanResult Code
  63. <DllImport(SNFMULTI_DLL, EntryPoint:="getScanXHeaders", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
  64. Public Function getScanXHeaders(ByVal ScannerHandle As Int32, ByRef HeadersPtr As IntPtr, ByRef HeadersLength As Int32) As Int32
  65. End Function
  66. 'GetScanXMLLog - Get result & XML Log
  67. <DllImport(SNFMULTI_DLL, EntryPoint:="getScanXMLLog", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
  68. Public Function getScanXMLLog(ByVal ScannerHandle As Int32, ByRef LogPtr As IntPtr, ByRef LogLength As Int32) As Int32
  69. End Function
  70. 'GetScanClassicLog - Get result & Classic Log
  71. <DllImport(SNFMULTI_DLL, EntryPoint:="getScanClassicLog", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
  72. Public Function getScanClassicLog(ByVal ScannerHandle As Int32, ByRef LogPtr As IntPtr, ByRef LogLength As Int32) As Int32
  73. End Function
  74. 'GetScanResult - Get just the scan result
  75. <DllImport(SNFMULTI_DLL, EntryPoint:="getScanResult", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
  76. Public Function getScanResult(ByVal ScannerHandle As Int32) As Int32
  77. End Function
  78. 'Close Scan
  79. <DllImport(SNFMULTI_DLL, EntryPoint:="closeScan", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
  80. Public Function closeScan(ByVal ScannerHandle As Int32) As Int32
  81. End Function
  82. #End Region
  83. Sub Main()
  84. ' Setup the basics we need to run this test.
  85. 'Const LicenseID As String = "licensid" ' SNF License ID can be passed
  86. 'Const Authentication As String = "authentication" ' directly or read from the
  87. ' configuration. OEMs go direct!
  88. Const ConfigurationPath As String = "c:\snf\snf_engine.xml"
  89. Const IPToTest As UInt32 = &HC22384E ' Same as IP 12.34.56.78
  90. Const SampleMessage As String = _
  91. "Received: from mx-out.example.com [12.34.56.78] (HELO Somebody)\r\n" + _
  92. " by mx-in.example.com (nosuchserver v1.0) for nobody@example.com\r\n" + _
  93. "From: <somebody@example.com>\r\n" + _
  94. "To: <nobody@example.com>\r\n" + _
  95. "Subject: Nothing to see here\r\n" + _
  96. "\r\n" + _
  97. "So this is the big thing that's not here to see.\r\n" + _
  98. "I thought it would be more interesting than this.\r\n" + _
  99. "\r\n" + _
  100. "_M\r\n" + _
  101. ".\r\n"
  102. '' Here is a simple example. Startup, exercise the API, shut down.
  103. '' Note that we're doing this in a very "C" style becuase the DLL API is C
  104. Dim Result As Integer = 0
  105. Result = startupSNF(ConfigurationPath)
  106. 'Result = startupSNFAuthenticated( _
  107. ' ConfigurationPath, _
  108. ' LicenseID, _
  109. ' Authentication)
  110. Console.WriteLine("Started with config " + ConfigurationPath + " Result: " + Result.ToString("D"))
  111. ' IP tests can be done asynchrounously - they do not have to be part of any particular scan.
  112. Result = testIP(IPToTest)
  113. Console.WriteLine("IP test result: " + Result.ToString("D"))
  114. Dim IPReputation As Double = getIPReputation(IPToTest)
  115. Console.WriteLine("IP Reputation: " + IPReputation.ToString())
  116. ' Messgae scans happen in a scan, read, close cycle as shown inside this loop.
  117. Const NumberOfScans As Integer = 10
  118. For i As Integer = 0 To NumberOfScans
  119. ' Show how the IP reputation changes over time.
  120. IPReputation = getIPReputation(IPToTest)
  121. Console.WriteLine("IP Reputation: " + IPReputation.ToString())
  122. ' Scan a message from a buffer.
  123. Dim SetupTime As Integer = 12
  124. Dim ScanHandle As Integer = 0
  125. Dim MsgBuffer As New StringBuilder
  126. MsgBuffer.Append(SampleMessage)
  127. ScanHandle = scanBuffer(MsgBuffer, MsgBuffer.Length(), "TestMessage", SetupTime)
  128. Console.WriteLine("Scan Handle: " + ScanHandle.ToString("D"))
  129. ' Retrieve the X-Headers for the scan.
  130. Dim XHeadersBuffer As IntPtr = IntPtr.Zero
  131. Dim XHeadersLength As Int32
  132. Dim XHeaders As String
  133. Dim ScanResult As Integer = 0
  134. ScanResult = getScanXHeaders(ScanHandle, XHeadersBuffer, XHeadersLength)
  135. XHeaders = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(XHeadersBuffer, XHeadersLength)
  136. ' Close the scan.
  137. Result = closeScan(ScanHandle)
  138. Console.WriteLine("Scan Close Result: " + Result.ToString("D"))
  139. ' X- headers were captured in a string BEFORE closing the scan so we can
  140. ' use them here.
  141. Console.WriteLine("Scan result code: " + ScanResult.ToString("D"))
  142. Console.WriteLine("Scan X- headers: " + XHeaders)
  143. Next i
  144. ' Now that all scanning is done we shut down.
  145. Result = shutdownSNF()
  146. End Sub
  147. End Module