Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

main.vb 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. ' main.vb SNF-SDK-WIN VB 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 = "..\..\..\snf_engine.xml" ' For "Any CPU" platform.
  89. 'Const ConfigurationPath As String = "..\..\..\..\snf_engine.xml" ' For "x86" or "x64" platforms.
  90. Const IPToTest As UInt32 = &HC22384E ' Same as IP 12.34.56.78
  91. Const SampleMessage As String = _
  92. "Received: from mx-out.example.com [12.34.56.78] (HELO Somebody)\r\n" + _
  93. " by mx-in.example.com (nosuchserver v1.0) for nobody@example.com\r\n" + _
  94. "From: <somebody@example.com>\r\n" + _
  95. "To: <nobody@example.com>\r\n" + _
  96. "Subject: Nothing to see here\r\n" + _
  97. "\r\n" + _
  98. "So this is the big thing that's not here to see.\r\n" + _
  99. "I thought it would be more interesting than this.\r\n" + _
  100. "\r\n" + _
  101. "_M\r\n" + _
  102. ".\r\n"
  103. '' Here is a simple example. Startup, exercise the API, shut down.
  104. '' Note that we're doing this in a very "C" style becuase the DLL API is C
  105. Dim Result As Integer = 0
  106. Result = startupSNF(ConfigurationPath)
  107. 'Result = startupSNFAuthenticated( _
  108. ' ConfigurationPath, _
  109. ' LicenseID, _
  110. ' Authentication)
  111. Console.WriteLine("Started with config " + ConfigurationPath + " Result: " + Result.ToString("D"))
  112. ' IP tests can be done asynchrounously - they do not have to be part of any particular scan.
  113. Result = testIP(IPToTest)
  114. Console.WriteLine("IP test result: " + Result.ToString("D"))
  115. Dim IPReputation As Double = getIPReputation(IPToTest)
  116. Console.WriteLine("IP Reputation: " + IPReputation.ToString())
  117. ' Messgae scans happen in a scan, read, close cycle as shown inside this loop.
  118. Const NumberOfScans As Integer = 10
  119. For i As Integer = 0 To NumberOfScans
  120. ' Show how the IP reputation changes over time.
  121. IPReputation = getIPReputation(IPToTest)
  122. Console.WriteLine("IP Reputation: " + IPReputation.ToString())
  123. ' Scan a message from a buffer.
  124. Dim SetupTime As Integer = 12
  125. Dim ScanHandle As Integer = 0
  126. Dim MsgBuffer As New StringBuilder
  127. MsgBuffer.Append(SampleMessage)
  128. ScanHandle = scanBuffer(MsgBuffer, MsgBuffer.Length(), "TestMessage", SetupTime)
  129. Console.WriteLine("Scan Handle: " + ScanHandle.ToString("D"))
  130. ' Retrieve the X-Headers for the scan.
  131. Dim XHeadersBuffer As IntPtr = IntPtr.Zero
  132. Dim XHeadersLength As Int32
  133. Dim XHeaders As String
  134. Dim ScanResult As Integer = 0
  135. ScanResult = getScanXHeaders(ScanHandle, XHeadersBuffer, XHeadersLength)
  136. XHeaders = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(XHeadersBuffer, XHeadersLength)
  137. ' Close the scan.
  138. Result = closeScan(ScanHandle)
  139. Console.WriteLine("Scan Close Result: " + Result.ToString("D"))
  140. ' X- headers were captured in a string BEFORE closing the scan so we can
  141. ' use them here.
  142. Console.WriteLine("Scan result code: " + ScanResult.ToString("D"))
  143. Console.WriteLine("Scan X- headers: " + XHeaders)
  144. Next i
  145. ' Now that all scanning is done we shut down.
  146. Result = shutdownSNF()
  147. End Sub
  148. End Module