123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- <html>
- <head>
- <title>C:\M\Projects\MessageSniffer\PKG-SNF-SDK-WIN_Work\PKG-SNF-SDK-WIN\CSSample\main.cs</title>
- <style>
- body { background-color: #ffffff; font-family: "Courier New"; font-size:10.0pt; font-style: normal; font-weight: normal; text-decoration: none; }
- .se2 { color: #000000; background-color: #ffffff; } /* Window Text */
- .se17 { color: #800080; background-color: #ffffff; } /* Keyword */
- .se19 { color: #000080; background-color: #ffffff; } /* Number */
- .se20 { color: #008080; background-color: #ffffff; } /* String */
- .se22 { color: #808000; background-color: #ffffff; } /* Preprocessor */
- .se23 { color: #800000; background-color: #ffffff; } /* Punctuation */
- .se25 { color: #000000; background-color: #ffffff; } /* Operator */
- .se28 { color: #000000; background-color: #ffffff; font-weight: bolder; } /* Function */
- .se49 { color: #008000; background-color: #ffffff; font-style: italic; } /* Comment */
- .se50 { color: #004080; background-color: #ffffff; font-style: italic; } /* Comment */
- .se55 { color: #000000; background-color: #ffffff; } /* Window Text */
- .se57 { color: #000080; background-color: #ffffff; } /* Number */
- </style>
- </head>
- <body>
- <pre>
- <span class="se49">// main.cs SNF-SDK-WIN C# OEM Demonstration Code</span>
- <span class="se49">// Copyright (C) 2009 ARM Research Labs, LLC</span>
- <span class="se49">//</span>
- <span class="se49">// This app simply exercises the API provided by snfmultidll.</span>
-
- <span class="se17">using</span><span class="se2"> </span><span class="se55">System</span><span class="se25">;</span>
- <span class="se17">using</span><span class="se2"> </span><span class="se55">System</span><span class="se2">.</span><span class="se55">Collections</span><span class="se2">.</span><span class="se55">Generic</span><span class="se25">;</span>
- <span class="se17">using</span><span class="se2"> </span><span class="se55">System</span><span class="se2">.</span><span class="se55">Linq</span><span class="se25">;</span>
- <span class="se17">using</span><span class="se2"> </span><span class="se55">System</span><span class="se2">.</span><span class="se55">Text</span><span class="se25">;</span>
- <span class="se17">using</span><span class="se2"> </span><span class="se55">System</span><span class="se2">.</span><span class="se55">IO</span><span class="se25">;</span>
- <span class="se17">using</span><span class="se2"> </span><span class="se55">System</span><span class="se2">.</span><span class="se55">Collections</span><span class="se25">;</span>
-
- <span class="se17">using</span><span class="se2"> </span><span class="se55">System</span><span class="se2">.</span><span class="se55">Runtime</span><span class="se2">.</span><span class="se55">InteropServices</span><span class="se25">;</span>
-
- <span class="se17">namespace</span><span class="se2"> </span><span class="se55">SNFMultiDLLExampleCsharp</span>
- <span class="se23">{</span>
- <span class="se2"> </span><span class="se17">class</span><span class="se2"> </span><span class="se55">SNFMultiDLLExample</span>
- <span class="se2"> </span><span class="se23">{</span>
-
- <span class="se22">#region</span><span class="se2"> </span><span class="se55">DLL</span><span class="se2"> </span><span class="se55">Imports</span>
- <span class="se2"> </span><span class="se49">// Location of SNFMulti.dll.</span>
- <span class="se2"> </span><span class="se17">const</span><span class="se2"> </span><span class="se17">string</span><span class="se2"> </span><span class="se55">SNFMULTI_DLL</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"..\\..\\..\\64bitDll\\SNFMulti.dll"</span><span class="se25">;</span><span class="se2"> </span><span class="se49">// Set CPU type to "Any CPU"</span>
- <span class="se2"> </span><span class="se49">//const string SNFMULTI_DLL = "..\\..\\..\\..\\64bitDll\\SNFMulti.dll"; // Set CPU type to "x64</span>
- <span class="se2"> </span><span class="se49">//const string SNFMULTI_DLL = "..\\..\\..\\..\\32bitDll\\SNFMulti.dll"; // Set CPU type to "x86"</span>
-
- <span class="se2"> </span><span class="se49">// int setThrottle(int Threads); /* Set scan thread limit. */</span>
- <span class="se2"> [</span><span class="se28">DllImport</span><span class="se2">(</span><span class="se55">SNFMULTI_DLL</span><span class="se2">, </span><span class="se55">CharSet</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CharSet</span><span class="se2">.</span><span class="se55">Auto</span><span class="se2">, </span><span class="se55">EntryPoint</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"setThrottle"</span><span class="se2">, </span><span class="se55">CallingConvention</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CallingConvention</span><span class="se2">.</span><span class="se55">Winapi</span><span class="se2">)]</span>
- <span class="se2"> </span><span class="se17">public</span><span class="se2"> </span><span class="se17">static</span><span class="se2"> </span><span class="se17">extern</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se28">setThrottle</span><span class="se2">(</span><span class="se17">int</span><span class="se2"> </span><span class="se55">throttle</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// int startupSNF(char* Path); /* Start SNF with configuration. */</span>
- <span class="se2"> [</span><span class="se28">DllImport</span><span class="se2">(</span><span class="se55">SNFMULTI_DLL</span><span class="se2">, </span><span class="se55">CharSet</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CharSet</span><span class="se2">.</span><span class="se55">Auto</span><span class="se2">, </span><span class="se55">EntryPoint</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"startupSNF"</span><span class="se2">, </span><span class="se55">CallingConvention</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CallingConvention</span><span class="se2">.</span><span class="se55">Winapi</span><span class="se2">)]</span>
- <span class="se2"> </span><span class="se17">public</span><span class="se2"> </span><span class="se17">static</span><span class="se2"> </span><span class="se17">extern</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se28">startupSNF</span><span class="se2">([</span><span class="se28">MarshalAs</span><span class="se2">(</span><span class="se55">UnmanagedType</span><span class="se2">.</span><span class="se55">LPStr</span><span class="se2">)] </span><span class="se17">string</span><span class="se2"> </span><span class="se55">Path</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// EXP int startupSNFAuthenticated(char* Path, char* Lic, char* Auth); /* Start SNF with conf & auth. */</span>
- <span class="se2"> [</span><span class="se28">DllImport</span><span class="se2">(</span><span class="se55">SNFMULTI_DLL</span><span class="se2">, </span><span class="se55">CharSet</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CharSet</span><span class="se2">.</span><span class="se55">Auto</span><span class="se2">, </span><span class="se55">EntryPoint</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"startupSNFAuthenticated"</span><span class="se2">,</span>
- <span class="se2"> </span><span class="se55">CallingConvention</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CallingConvention</span><span class="se2">.</span><span class="se55">Winapi</span><span class="se2">)]</span>
- <span class="se2"> </span><span class="se17">public</span><span class="se2"> </span><span class="se17">static</span><span class="se2"> </span><span class="se17">extern</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se28">startupSNFAuthenticated</span><span class="se2">(</span>
- <span class="se2"> [</span><span class="se28">MarshalAs</span><span class="se2">(</span><span class="se55">UnmanagedType</span><span class="se2">.</span><span class="se55">LPStr</span><span class="se2">)] </span><span class="se17">string</span><span class="se2"> </span><span class="se55">Path</span><span class="se2">,</span>
- <span class="se2"> [</span><span class="se28">MarshalAs</span><span class="se2">(</span><span class="se55">UnmanagedType</span><span class="se2">.</span><span class="se55">LPStr</span><span class="se2">)] </span><span class="se17">string</span><span class="se2"> </span><span class="se55">Lic</span><span class="se2">,</span>
- <span class="se2"> [</span><span class="se28">MarshalAs</span><span class="se2">(</span><span class="se55">UnmanagedType</span><span class="se2">.</span><span class="se55">LPStr</span><span class="se2">)] </span><span class="se17">string</span><span class="se2"> </span><span class="se55">Auth</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// int shutdownSNF(); /* Shutdown SNF. */</span>
- <span class="se2"> [</span><span class="se28">DllImport</span><span class="se2">(</span><span class="se55">SNFMULTI_DLL</span><span class="se2">, </span><span class="se55">CharSet</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CharSet</span><span class="se2">.</span><span class="se55">Auto</span><span class="se2">, </span><span class="se55">EntryPoint</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"shutdownSNF"</span><span class="se2">, </span><span class="se55">CallingConvention</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CallingConvention</span><span class="se2">.</span><span class="se55">Winapi</span><span class="se2">)]</span>
- <span class="se2"> </span><span class="se17">public</span><span class="se2"> </span><span class="se17">static</span><span class="se2"> </span><span class="se17">extern</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se28">shutdownSNF</span><span class="se2">()</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// int testIP(unsigned long int IPToCheck); /* Test the IP for a GBUdb range. */</span>
- <span class="se2"> [</span><span class="se28">DllImport</span><span class="se2">(</span><span class="se55">SNFMULTI_DLL</span><span class="se2">, </span><span class="se55">CharSet</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CharSet</span><span class="se2">.</span><span class="se55">Auto</span><span class="se2">, </span><span class="se55">EntryPoint</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"testIP"</span><span class="se2">, </span><span class="se55">CallingConvention</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CallingConvention</span><span class="se2">.</span><span class="se55">Winapi</span><span class="se2">)]</span>
- <span class="se2"> </span><span class="se17">public</span><span class="se2"> </span><span class="se17">static</span><span class="se2"> </span><span class="se17">extern</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se28">testIP</span><span class="se2">(</span><span class="se17">ulong</span><span class="se2"> </span><span class="se55">IPToCheck</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// double getIPReputation(unsigned long int IPToCheck); /* Get reputation figure for IP. */</span>
- <span class="se2"> [</span><span class="se28">DllImport</span><span class="se2">(</span><span class="se55">SNFMULTI_DLL</span><span class="se2">, </span><span class="se55">CharSet</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CharSet</span><span class="se2">.</span><span class="se55">Auto</span><span class="se2">, </span><span class="se55">EntryPoint</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"getIPReputation"</span><span class="se2">, </span><span class="se55">CallingConvention</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CallingConvention</span><span class="se2">.</span><span class="se55">Winapi</span><span class="se2">)]</span>
- <span class="se2"> </span><span class="se17">public</span><span class="se2"> </span><span class="se17">static</span><span class="se2"> </span><span class="se17">extern</span><span class="se2"> </span><span class="se17">double</span><span class="se2"> </span><span class="se28">getIPReputation</span><span class="se2">(</span><span class="se17">ulong</span><span class="se2"> </span><span class="se55">IPToCheck</span><span class="se2">)</span><span class="se25">;</span>
- <span class="se2"> </span>
-
- <span class="se2"> </span><span class="se49">// int scanBuffer(unsigned char* Bfr, int Length, char* Name, int Setup);/* Scan msgBuffer, name, setup time. */</span>
- <span class="se2"> [</span><span class="se28">DllImport</span><span class="se2">(</span><span class="se55">SNFMULTI_DLL</span><span class="se2">, </span><span class="se55">CharSet</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CharSet</span><span class="se2">.</span><span class="se55">Auto</span><span class="se2">, </span><span class="se55">EntryPoint</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"scanBuffer"</span><span class="se2">, </span><span class="se55">CallingConvention</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CallingConvention</span><span class="se2">.</span><span class="se55">Winapi</span><span class="se2">)]</span>
- <span class="se2"> </span><span class="se17">public</span><span class="se2"> </span><span class="se17">static</span><span class="se2"> </span><span class="se17">extern</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se28">scanBuffer</span><span class="se2">(</span>
- <span class="se2"> [</span><span class="se28">MarshalAs</span><span class="se2">(</span><span class="se55">UnmanagedType</span><span class="se2">.</span><span class="se55">LPStr</span><span class="se2">)] </span><span class="se17">string</span><span class="se2"> </span><span class="se55">Bfr</span><span class="se2">,</span>
- <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">Length</span><span class="se2">,</span>
- <span class="se2"> [</span><span class="se28">MarshalAs</span><span class="se2">(</span><span class="se55">UnmanagedType</span><span class="se2">.</span><span class="se55">LPStr</span><span class="se2">)] </span><span class="se17">string</span><span class="se2"> </span><span class="se55">Name</span><span class="se2">,</span>
- <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">Setup</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// int scanFile(char* FilePath, int Setup); /* Scan msgFile, setup time. */</span>
- <span class="se2"> [</span><span class="se28">DllImport</span><span class="se2">(</span><span class="se55">SNFMULTI_DLL</span><span class="se2">, </span><span class="se55">CharSet</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CharSet</span><span class="se2">.</span><span class="se55">Auto</span><span class="se2">, </span><span class="se55">EntryPoint</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"scanFile"</span><span class="se2">, </span><span class="se55">CallingConvention</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CallingConvention</span><span class="se2">.</span><span class="se55">Winapi</span><span class="se2">)]</span>
- <span class="se2"> </span><span class="se17">public</span><span class="se2"> </span><span class="se17">static</span><span class="se2"> </span><span class="se17">extern</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se28">scanFile</span><span class="se2">([</span><span class="se28">MarshalAs</span><span class="se2">(</span><span class="se55">UnmanagedType</span><span class="se2">.</span><span class="se55">LPStr</span><span class="se2">)] </span><span class="se17">string</span><span class="se2"> </span><span class="se55">Path</span><span class="se2">, </span><span class="se17">int</span><span class="se2"> </span><span class="se55">Setup</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// int getScanXHeaders(int ScanHandle, char** Bfr, int* Length); /* Get result & XHeaders. */</span>
- <span class="se2"> [</span><span class="se28">DllImport</span><span class="se2">(</span><span class="se55">SNFMULTI_DLL</span><span class="se2">, </span><span class="se55">CharSet</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CharSet</span><span class="se2">.</span><span class="se55">Auto</span><span class="se2">, </span><span class="se55">EntryPoint</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"getScanXHeaders"</span><span class="se2">, </span><span class="se55">CallingConvention</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CallingConvention</span><span class="se2">.</span><span class="se55">Winapi</span><span class="se2">)]</span>
- <span class="se2"> </span><span class="se17">public</span><span class="se2"> </span><span class="se17">static</span><span class="se2"> </span><span class="se17">extern</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se28">getScanXHeaders</span><span class="se2">(</span><span class="se17">int</span><span class="se2"> </span><span class="se55">ScanHandle</span><span class="se2">,</span>
- <span class="se2"> </span><span class="se17">out</span><span class="se2"> </span><span class="se55">IntPtr</span><span class="se2"> </span><span class="se55">Bfr</span><span class="se2">,</span>
- <span class="se2"> </span><span class="se17">out</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">Length</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// int getScanXMLLog(int ScanHandle, char** Bfr, int* Length); /* Get result & XML Log. */</span>
- <span class="se2"> [</span><span class="se28">DllImport</span><span class="se2">(</span><span class="se55">SNFMULTI_DLL</span><span class="se2">, </span><span class="se55">CharSet</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CharSet</span><span class="se2">.</span><span class="se55">Auto</span><span class="se2">, </span><span class="se55">EntryPoint</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"getScanXMLLog"</span><span class="se2">, </span><span class="se55">CallingConvention</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CallingConvention</span><span class="se2">.</span><span class="se55">Winapi</span><span class="se2">)]</span>
- <span class="se2"> </span><span class="se17">public</span><span class="se2"> </span><span class="se17">static</span><span class="se2"> </span><span class="se17">extern</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se28">getScanXMLLog</span><span class="se2">(</span><span class="se17">int</span><span class="se2"> </span><span class="se55">ScanHandle</span><span class="se2">,</span>
- <span class="se2"> </span><span class="se17">out</span><span class="se2"> </span><span class="se55">IntPtr</span><span class="se2"> </span><span class="se55">Bfr</span><span class="se2">,</span>
- <span class="se2"> </span><span class="se17">out</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">Length</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// int getScanClassicLog(int ScanHandle, char** Bfr, int* Length); /* Get result & Classic Log. */</span>
- <span class="se2"> [</span><span class="se28">DllImport</span><span class="se2">(</span><span class="se55">SNFMULTI_DLL</span><span class="se2">, </span><span class="se55">CharSet</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CharSet</span><span class="se2">.</span><span class="se55">Auto</span><span class="se2">, </span><span class="se55">EntryPoint</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"getScanClassicLog"</span><span class="se2">, </span><span class="se55">CallingConvention</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CallingConvention</span><span class="se2">.</span><span class="se55">Winapi</span><span class="se2">)]</span>
- <span class="se2"> </span><span class="se17">public</span><span class="se2"> </span><span class="se17">static</span><span class="se2"> </span><span class="se17">extern</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se28">getScanClassicLog</span><span class="se2">(</span><span class="se17">int</span><span class="se2"> </span><span class="se55">ScanHandle</span><span class="se2">,</span>
- <span class="se2"> </span><span class="se17">out</span><span class="se2"> </span><span class="se55">IntPtr</span><span class="se2"> </span><span class="se55">Bfr</span><span class="se2">,</span>
- <span class="se2"> </span><span class="se17">out</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">Length</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// int getScanResult(int ScanHandle); /* Get just the scan result. */</span>
- <span class="se2"> [</span><span class="se28">DllImport</span><span class="se2">(</span><span class="se55">SNFMULTI_DLL</span><span class="se2">, </span><span class="se55">CharSet</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CharSet</span><span class="se2">.</span><span class="se55">Auto</span><span class="se2">, </span><span class="se55">EntryPoint</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"getScanResult"</span><span class="se2">, </span><span class="se55">CallingConvention</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CallingConvention</span><span class="se2">.</span><span class="se55">Winapi</span><span class="se2">)]</span>
- <span class="se2"> </span><span class="se17">public</span><span class="se2"> </span><span class="se17">static</span><span class="se2"> </span><span class="se17">extern</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se28">getScanResult</span><span class="se2">(</span><span class="se17">int</span><span class="se2"> </span><span class="se55">ScanHandle</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// int closeScan(int ScanHandle); /* Close the scan result. */</span>
- <span class="se2"> [</span><span class="se28">DllImport</span><span class="se2">(</span><span class="se55">SNFMULTI_DLL</span><span class="se2">, </span><span class="se55">CharSet</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CharSet</span><span class="se2">.</span><span class="se55">Auto</span><span class="se2">, </span><span class="se55">EntryPoint</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"closeScan"</span><span class="se2">, </span><span class="se55">CallingConvention</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">CallingConvention</span><span class="se2">.</span><span class="se55">Winapi</span><span class="se2">)]</span>
- <span class="se2"> </span><span class="se17">public</span><span class="se2"> </span><span class="se17">static</span><span class="se2"> </span><span class="se17">extern</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se28">closeScan</span><span class="se2">(</span><span class="se17">int</span><span class="se2"> </span><span class="se55">ScanHandle</span><span class="se2">)</span><span class="se25">;</span>
-
-
- <span class="se22">#endregion</span>
-
- <span class="se2"> </span><span class="se17">static</span><span class="se2"> </span><span class="se17">void</span><span class="se2"> </span><span class="se28">Main</span><span class="se2">(</span><span class="se17">string</span><span class="se2">[] </span><span class="se55">args</span><span class="se2">)</span>
- <span class="se2"> </span><span class="se23">{</span>
- <span class="se2"> </span><span class="se50">//// Setup the basics we need to run this test.</span>
-
- <span class="se2"> </span><span class="se49">// const string LicenseID = "licensid"; // SNF License ID can be passed</span>
- <span class="se2"> </span><span class="se49">// const string Authentication = "authenticationxx"; // directly or read from the</span>
- <span class="se2"> </span><span class="se49">// configuration. OEMs go direct!</span>
- <span class="se2"> </span><span class="se17">const</span><span class="se2"> </span><span class="se17">string</span><span class="se2"> </span><span class="se55">ConfigurationPath</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">"..\\..\\snf_engine.xml"</span><span class="se25">;</span><span class="se2"> </span><span class="se49">// For "Any CPU" platform.</span>
- <span class="se2"> </span><span class="se49">//const string ConfigurationPath = "..\\..\\..\\snf_engine.xml"; // For "x86" or "x64" platforms.</span>
-
-
- <span class="se2"> </span><span class="se17">const</span><span class="se2"> </span><span class="se17">uint</span><span class="se2"> </span><span class="se55">IPToTest</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se57">0x0c22384e</span><span class="se25">;</span><span class="se2"> </span><span class="se49">// Same as IP 12.34.56.78</span>
-
- <span class="se2"> </span><span class="se17">const</span><span class="se2"> </span><span class="se17">string</span><span class="se2"> </span><span class="se55">SampleMessage</span><span class="se2"> </span><span class="se25">=</span>
- <span class="se2"> </span><span class="se20">"Received: from mx-out.example.com [12.34.56.78] (HELO Somebody)\r\n"</span><span class="se2"> </span><span class="se25">+</span>
- <span class="se2"> </span><span class="se20">" by mx-in.example.com (nosuchserver v1.0) for nobody@example.com\r\n"</span><span class="se2"> </span><span class="se25">+</span>
- <span class="se2"> </span><span class="se20">"From: <somebody@example.com>\r\n"</span><span class="se2"> </span><span class="se25">+</span>
- <span class="se2"> </span><span class="se20">"To: <nobody@example.com>\r\n"</span><span class="se2"> </span><span class="se25">+</span>
- <span class="se2"> </span><span class="se20">"Subject: Nothing to see here\r\n"</span><span class="se2"> </span><span class="se25">+</span>
- <span class="se2"> </span><span class="se20">"\r\n"</span><span class="se2"> </span><span class="se25">+</span>
- <span class="se2"> </span><span class="se20">"So this is the big thing that's not here to see.\r\n"</span><span class="se2"> </span><span class="se25">+</span>
- <span class="se2"> </span><span class="se20">"I thought it would be more interesting than this.\r\n"</span><span class="se2"> </span><span class="se25">+</span>
- <span class="se2"> </span><span class="se20">"\r\n"</span><span class="se2"> </span><span class="se25">+</span>
- <span class="se2"> </span><span class="se20">"_M\r\n"</span><span class="se2"> </span><span class="se25">+</span>
- <span class="se2"> </span><span class="se20">".\r\n"</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se50">//// Here is a simple example. Startup, exercise the API, shut down.</span>
- <span class="se2"> </span><span class="se50">//// Note that we're doing this in a very "C" style becuase the DLL API is C</span>
-
- <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">startupSNF</span><span class="se2">(</span><span class="se55">ConfigurationPath</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">//Result = startupSNFAuthenticated(</span>
- <span class="se2"> </span><span class="se49">// ConfigurationPath,</span>
- <span class="se2"> </span><span class="se49">// LicenseID,</span>
- <span class="se2"> </span><span class="se49">// Authentication);</span>
-
- <span class="se2"> </span><span class="se55">System</span><span class="se2">.</span><span class="se55">Console</span><span class="se2">.</span><span class="se28">WriteLine</span><span class="se2">(</span><span class="se20">"Started with config "</span><span class="se2"> </span><span class="se25">+</span><span class="se2"> </span><span class="se55">ConfigurationPath</span><span class="se2"> </span><span class="se25">+</span><span class="se2"> </span><span class="se20">" Result: "</span><span class="se2"> </span><span class="se25">+</span><span class="se2"> </span><span class="se55">Result</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// IP tests can be done asynchrounously - they do not have to be part of any particular scan.</span>
-
- <span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">testIP</span><span class="se2">(</span><span class="se55">IPToTest</span><span class="se2">)</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se55">System</span><span class="se2">.</span><span class="se55">Console</span><span class="se2">.</span><span class="se28">WriteLine</span><span class="se2">(</span><span class="se20">"IP test result: "</span><span class="se2"> </span><span class="se25">+</span><span class="se2"> </span><span class="se55">Result</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se17">double</span><span class="se2"> </span><span class="se55">IPReputation</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">getIPReputation</span><span class="se2">(</span><span class="se55">IPToTest</span><span class="se2">)</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se55">System</span><span class="se2">.</span><span class="se55">Console</span><span class="se2">.</span><span class="se28">WriteLine</span><span class="se2">(</span><span class="se20">"IP Reputation: "</span><span class="se2"> </span><span class="se25">+</span><span class="se2"> </span><span class="se55">IPReputation</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// Messgae scans happen in a scan, read, close cycle as shown inside this loop.</span>
-
- <span class="se2"> </span><span class="se17">const</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">NumberOfScans</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">10</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se17">for</span><span class="se2">(</span><span class="se17">int</span><span class="se2"> </span><span class="se55">i</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span><span class="se2"> </span><span class="se55">i</span><span class="se2"> </span><span class="se25"><</span><span class="se2"> </span><span class="se55">NumberOfScans</span><span class="se25">;</span><span class="se2"> </span><span class="se55">i</span><span class="se25">++</span><span class="se2">) </span><span class="se23">{</span>
-
- <span class="se2"> </span><span class="se49">// Show how the IP reputation changes over time.</span>
-
- <span class="se2"> </span><span class="se55">IPReputation</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">getIPReputation</span><span class="se2">(</span><span class="se55">IPToTest</span><span class="se2">)</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se55">System</span><span class="se2">.</span><span class="se55">Console</span><span class="se2">.</span><span class="se28">WriteLine</span><span class="se2">(</span><span class="se20">"IP Reputation: "</span><span class="se2"> </span><span class="se25">+</span><span class="se2"> </span><span class="se55">IPReputation</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// Scan a message from a buffer.</span>
-
- <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">SetupTime</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">12</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">ScanHandle</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se55">ScanHandle</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">scanBuffer</span><span class="se2">(</span><span class="se55">SampleMessage</span><span class="se2">, </span><span class="se55">SampleMessage</span><span class="se2">.</span><span class="se55">Length</span><span class="se2">, </span><span class="se20">"TestMessage"</span><span class="se2">, </span><span class="se55">SetupTime</span><span class="se2">)</span><span class="se25">;</span>
-
-
- <span class="se2"> </span><span class="se55">System</span><span class="se2">.</span><span class="se55">Console</span><span class="se2">.</span><span class="se28">WriteLine</span><span class="se2">(</span><span class="se20">"Scan Handle: "</span><span class="se2"> </span><span class="se25">+</span><span class="se2"> </span><span class="se55">ScanHandle</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// Retrieve the X-Headers for the scan.</span>
-
- <span class="se2"> </span><span class="se55">IntPtr</span><span class="se2"> </span><span class="se55">XHeadersPtr</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">IntPtr</span><span class="se2">.</span><span class="se55">Zero</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">XHeadersLength</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">ScanResult</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se55">ScanResult</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">getScanXHeaders</span><span class="se2">(</span><span class="se55">ScanHandle</span><span class="se2">, </span><span class="se17">out</span><span class="se2"> </span><span class="se55">XHeadersPtr</span><span class="se2">, </span><span class="se17">out</span><span class="se2"> </span><span class="se55">XHeadersLength</span><span class="se2">)</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se17">string</span><span class="se2"> </span><span class="se55">XHeaders</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se55">XHeaders</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se55">System</span><span class="se2">.</span><span class="se55">Runtime</span><span class="se2">.</span><span class="se55">InteropServices</span><span class="se2">.</span><span class="se55">Marshal</span><span class="se2">.</span><span class="se28">PtrToStringAnsi</span><span class="se2">(</span><span class="se55">XHeadersPtr</span><span class="se2">, </span><span class="se55">XHeadersLength</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// Close the scan.</span>
-
- <span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">closeScan</span><span class="se2">(</span><span class="se55">ScanHandle</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se55">System</span><span class="se2">.</span><span class="se55">Console</span><span class="se2">.</span><span class="se28">WriteLine</span><span class="se2">(</span><span class="se20">"Scan Close Result: "</span><span class="se2"> </span><span class="se25">+</span><span class="se2"> </span><span class="se55">Result</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se49">// X- headers were captured in a string BEFORE closing the scan so we can</span>
- <span class="se2"> </span><span class="se49">// use them here.</span>
-
- <span class="se2"> </span><span class="se55">System</span><span class="se2">.</span><span class="se55">Console</span><span class="se2">.</span><span class="se28">WriteLine</span><span class="se2">(</span><span class="se20">"Scan result code: "</span><span class="se2"> </span><span class="se25">+</span><span class="se2"> </span><span class="se55">ScanResult</span><span class="se2">)</span><span class="se25">;</span>
- <span class="se2"> </span><span class="se55">System</span><span class="se2">.</span><span class="se55">Console</span><span class="se2">.</span><span class="se28">WriteLine</span><span class="se2">(</span><span class="se20">"Scan X- headers: "</span><span class="se2"> </span><span class="se25">+</span><span class="se2"> </span><span class="se55">XHeaders</span><span class="se2">)</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se23">}</span>
-
- <span class="se2"> </span><span class="se49">// Now that all scanning is done we shut down.</span>
-
- <span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">shutdownSNF</span><span class="se2">()</span><span class="se25">;</span>
-
- <span class="se2"> </span><span class="se23">}</span>
- <span class="se2"> </span><span class="se23">}</span>
- <span class="se23">}</span>
- </pre>
- </body>
- </html>
|