Selaa lähdekoodia

Added VS2018VBSample.

master
adeniz 4 vuotta sitten
vanhempi
commit
f7a5f18f86

+ 29
- 0
VS2019VBSample/README Näytä tiedosto

@@ -0,0 +1,29 @@
README file for the VS 2019 VB sample project

Copyright (c) 2009, 2020 ARM Research Laboratories

This README file gives an overview of the VS 2019 VB sample project.

This project links the sample VB file VBSample\main.cpp with the
SNFMulti DLL library.

To build this application:

1) Open VS2019VBSample\VS2019VBSample.sln with VS 2019.

2) Select "Any CPU", "x64" or "x86" for the platform.

3) In the project, open main.vb.

4) Modify the initial value of ConfigurationPath as necessary to
specify the location of the SNFServer configuration file. The
defaults assume that the configuration file name is
"snf_engine.xml", and is located in the same directory as the
VS2019VBSample.sln.

5) Modify the initial value of SNFMULTI_DLL as necessary to specify
the location of the SNFMulti.dll file.

6) Build.

7) Run.

+ 37
- 0
VS2019VBSample/VS2019VBSample.sln Näytä tiedosto

@@ -0,0 +1,37 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30309.148
MinimumVisualStudioVersion = 10.0.40219.1
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "VS2019VBSample", "VS2019VBSample.vbproj", "{098C5C9D-C82B-4DE0-85A4-B288C4CD6DF0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{098C5C9D-C82B-4DE0-85A4-B288C4CD6DF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{098C5C9D-C82B-4DE0-85A4-B288C4CD6DF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{098C5C9D-C82B-4DE0-85A4-B288C4CD6DF0}.Debug|x64.ActiveCfg = Debug|x64
{098C5C9D-C82B-4DE0-85A4-B288C4CD6DF0}.Debug|x64.Build.0 = Debug|x64
{098C5C9D-C82B-4DE0-85A4-B288C4CD6DF0}.Debug|x86.ActiveCfg = Debug|x86
{098C5C9D-C82B-4DE0-85A4-B288C4CD6DF0}.Debug|x86.Build.0 = Debug|x86
{098C5C9D-C82B-4DE0-85A4-B288C4CD6DF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{098C5C9D-C82B-4DE0-85A4-B288C4CD6DF0}.Release|Any CPU.Build.0 = Release|Any CPU
{098C5C9D-C82B-4DE0-85A4-B288C4CD6DF0}.Release|x64.ActiveCfg = Release|x64
{098C5C9D-C82B-4DE0-85A4-B288C4CD6DF0}.Release|x64.Build.0 = Release|x64
{098C5C9D-C82B-4DE0-85A4-B288C4CD6DF0}.Release|x86.ActiveCfg = Release|x86
{098C5C9D-C82B-4DE0-85A4-B288C4CD6DF0}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {65A49697-9E47-40A8-B1C8-C3841B3C04F5}
EndGlobalSection
EndGlobal

+ 121
- 0
VS2019VBSample/VS2019VBSample.vbproj Näytä tiedosto

@@ -0,0 +1,121 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProjectGuid>{098C5C9D-C82B-4DE0-85A4-B288C4CD6DF0}</ProjectGuid>
<OutputType>Exe</OutputType>
<StartupObject>
</StartupObject>
<RootNamespace>VS2019VBSample</RootNamespace>
<AssemblyName>ConsoleApplication</AssemblyName>
<FileAlignment>512</FileAlignment>
<MyType>Console</MyType>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<TargetFrameworkProfile>Client</TargetFrameworkProfile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|x86' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<OutputPath>bin\Debug\</OutputPath>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<DebugType>pdbonly</DebugType>
<DefineDebug>false</DefineDebug>
<DefineTrace>true</DefineTrace>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<PlatformTarget>x86</PlatformTarget>
</PropertyGroup>
<PropertyGroup>
<OptionExplicit>On</OptionExplicit>
</PropertyGroup>
<PropertyGroup>
<OptionCompare>Binary</OptionCompare>
</PropertyGroup>
<PropertyGroup>
<OptionStrict>Off</OptionStrict>
</PropertyGroup>
<PropertyGroup>
<OptionInfer>On</OptionInfer>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<OutputPath>bin\Debug\</OutputPath>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|AnyCPU'">
<DefineTrace>true</DefineTrace>
<OutputPath>bin\Release\</OutputPath>
<Optimize>true</Optimize>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<DefineDebug>true</DefineDebug>
<DefineTrace>true</DefineTrace>
<OutputPath>bin\x64\Debug\</OutputPath>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<DefineTrace>true</DefineTrace>
<OutputPath>bin\x64\Release\</OutputPath>
<Optimize>true</Optimize>
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Deployment" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
</ItemGroup>
<ItemGroup>
<Import Include="Microsoft.VisualBasic" />
<Import Include="System" />
<Import Include="System.Collections" />
<Import Include="System.Collections.Generic" />
<Import Include="System.Data" />
<Import Include="System.Diagnostics" />
<Import Include="System.Linq" />
<Import Include="System.Xml.Linq" />
</ItemGroup>
<ItemGroup>
<Compile Include="main.vb" />
</ItemGroup>
<ItemGroup>
<Folder Include="My Project\" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.Targets" />
<ProjectExtensions>
<VisualStudio AllowExistingFolder="true" />
</ProjectExtensions>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>

+ 3
- 0
VS2019VBSample/VS2019VBSample.vbproj.user Näytä tiedosto

@@ -0,0 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
</Project>

+ 202
- 0
VS2019VBSample/main.vb Näytä tiedosto

@@ -0,0 +1,202 @@
' main.vb SNF-SDK-WIN CPP OEM Demonstration Code
' Copyright (C) 2009 ARM Research Labs, LLC
'
' This app simply exercises the API provided by snfmultidll.

Imports System.Runtime.InteropServices
Imports System.Text

Module SNFMultiDLLExample

#Region "DLL Imports"

' Location of SNFMulti.dll.
Const SNFMULTI_DLL As String = "..\..\..\64bitDll\SNFMulti.dll" ' Set CPU type to "Any CPU"
'Const SNFMULTI_DLL As String = "..\..\..\..\64bitDll\SNFMulti.dll" ' Set CPU type to "x64"
'Const SNFMULTI_DLL As String = "..\..\..\32bitDll\SNFMulti.dll" ' Set CPU type to "x86"

'int setThrottle(int Threads); /* Set scan thread limit. */
'int startupSNF(char* Path); /* Start SNF with configuration. */
'int startupSNFAuthenticated(char* Path, char* Lic, char* Auth); /* Start SNF with conf & auth. */
'int shutdownSNF(); /* Shutdown SNF. */
'int testIP(unsigned long int IPToCheck); /* Test the IP for a GBUdb range. */
'double getIPReputation(unsigned long int IPToCheck); /* Get reputation figure for IP. */
'int scanBuffer(unsigned char* Bfr, int Length, char* Name, int Setup); /* Scan msgBuffer, name, setup time. */
'int scanFile(char* FilePath, int Setup); /* Scan msgFile, setup time. */
'int getScanXHeaders(int ScanHandle, char** Bfr, int* Length); /* Get result & XHeaders. */
'int getScanXMLLog(int ScanHandle, char** Bfr, int* Length); /* Get result & XML Log. */
'int getScanClassicLog(int ScanHandle, char** Bfr, int* Length); /* Get result & Classic Log. */
'int getScanResult(int ScanHandle); /* Get just the scan result. */
'int closeScan(int ScanHandle); /* Close the scan result. */


'Set scan thread limit
<DllImport(SNFMULTI_DLL, EntryPoint:="setThrottle", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
Public Function setThrottle(ByVal Threads As Int32) As Int32
End Function

'Startup
<DllImport(SNFMULTI_DLL, EntryPoint:="startupSNF", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
Public Function startupSNF(ByVal PathToConfigurationFile As String) As Int32
End Function

'Start SNF with conf & auth.
<DllImport(SNFMULTI_DLL, EntryPoint:="startupSNFAuthenticated", CharSet:=CharSet.Ansi, _
CallingConvention:=CallingConvention.Winapi)> _
Public Function startupSNFAuthenticated( _
ByVal Path As String, _
ByVal Lic As String, _
ByVal Auth As String) As Int32
End Function

'Shutdown
<DllImport(SNFMULTI_DLL, EntryPoint:="shutdownSNF", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
Public Function shutdownSNF() As Int32
End Function

'Test IP
<DllImport(SNFMULTI_DLL, EntryPoint:="testIP", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
Public Function testIP(ByVal IPToCheck As UInt32) As Int32
End Function

'getIPReputation
<DllImport(SNFMULTI_DLL, EntryPoint:="getIPReputation", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
Public Function getIPReputation(ByVal IPToCheck As UInt32) As Double
End Function

'ScanBuffer - returns scannerhandle
<DllImport(SNFMULTI_DLL, EntryPoint:="scanBuffer", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
Public Function scanBuffer(ByVal MsgBfr As StringBuilder, ByVal MsgBfrLen As Int32, ByVal MsgID As String, ByVal SetupTime As Int32) As Int32
End Function

'ScanFile
<DllImport(SNFMULTI_DLL, EntryPoint:="scanFile", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
Public Function scanFile(ByVal FilePath As String, ByVal Setup As Int32) As Int32
End Function

'GetScanXHeaders - use scannerhandle returned from previous - returns ScanResult Code
<DllImport(SNFMULTI_DLL, EntryPoint:="getScanXHeaders", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
Public Function getScanXHeaders(ByVal ScannerHandle As Int32, ByRef HeadersPtr As IntPtr, ByRef HeadersLength As Int32) As Int32
End Function

'GetScanXMLLog - Get result & XML Log
<DllImport(SNFMULTI_DLL, EntryPoint:="getScanXMLLog", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
Public Function getScanXMLLog(ByVal ScannerHandle As Int32, ByRef LogPtr As IntPtr, ByRef LogLength As Int32) As Int32
End Function

'GetScanClassicLog - Get result & Classic Log
<DllImport(SNFMULTI_DLL, EntryPoint:="getScanClassicLog", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
Public Function getScanClassicLog(ByVal ScannerHandle As Int32, ByRef LogPtr As IntPtr, ByRef LogLength As Int32) As Int32
End Function

'GetScanResult - Get just the scan result
<DllImport(SNFMULTI_DLL, EntryPoint:="getScanResult", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
Public Function getScanResult(ByVal ScannerHandle As Int32) As Int32
End Function

'Close Scan
<DllImport(SNFMULTI_DLL, EntryPoint:="closeScan", CharSet:=CharSet.Ansi, CallingConvention:=CallingConvention.Winapi)> _
Public Function closeScan(ByVal ScannerHandle As Int32) As Int32
End Function

#End Region

Sub Main()

' Setup the basics we need to run this test.

'Const LicenseID As String = "licensid" ' SNF License ID can be passed
'Const Authentication As String = "authentication" ' directly or read from the
' configuration. OEMs go direct!
Const ConfigurationPath As String = "c:\Program Files\snf\snf_engine.xml"


Const IPToTest As UInt32 = &HC22384E ' Same as IP 12.34.56.78

Const SampleMessage As String = _
"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"

'' Here is a simple example. Startup, exercise the API, shut down.
'' Note that we're doing this in a very "C" style becuase the DLL API is C

Dim Result As Integer = 0

Result = startupSNF(ConfigurationPath)

'Result = startupSNFAuthenticated( _
' ConfigurationPath, _
' LicenseID, _
' Authentication)

Console.WriteLine("Started with config " + ConfigurationPath + " Result: " + Result.ToString("D"))

' IP tests can be done asynchrounously - they do not have to be part of any particular scan.

Result = testIP(IPToTest)
Console.WriteLine("IP test result: " + Result.ToString("D"))

Dim IPReputation As Double = getIPReputation(IPToTest)
Console.WriteLine("IP Reputation: " + IPReputation.ToString())

' Messgae scans happen in a scan, read, close cycle as shown inside this loop.

Const NumberOfScans As Integer = 10
For i As Integer = 0 To NumberOfScans

' Show how the IP reputation changes over time.

IPReputation = getIPReputation(IPToTest)
Console.WriteLine("IP Reputation: " + IPReputation.ToString())

' Scan a message from a buffer.

Dim SetupTime As Integer = 12
Dim ScanHandle As Integer = 0
Dim MsgBuffer As New StringBuilder
MsgBuffer.Append(SampleMessage)
ScanHandle = scanBuffer(MsgBuffer, MsgBuffer.Length(), "TestMessage", SetupTime)


Console.WriteLine("Scan Handle: " + ScanHandle.ToString("D"))

' Retrieve the X-Headers for the scan.

Dim XHeadersBuffer As IntPtr = IntPtr.Zero
Dim XHeadersLength As Int32
Dim XHeaders As String

Dim ScanResult As Integer = 0
ScanResult = getScanXHeaders(ScanHandle, XHeadersBuffer, XHeadersLength)
XHeaders = System.Runtime.InteropServices.Marshal.PtrToStringAnsi(XHeadersBuffer, XHeadersLength)

' Close the scan.

Result = closeScan(ScanHandle)

Console.WriteLine("Scan Close Result: " + Result.ToString("D"))

' X- headers were captured in a string BEFORE closing the scan so we can
' use them here.

Console.WriteLine("Scan result code: " + ScanResult.ToString("D"))
Console.WriteLine("Scan X- headers: " + XHeaders)

Next i

' Now that all scanning is done we shut down.

Result = shutdownSNF()

End Sub

End Module

Loading…
Peruuta
Tallenna