using System; using System.Runtime.InteropServices; using System.Text; namespace NetTunnelApp; public enum ProtoCryptoType { CRYPTO_NONE = 0, CRYPTO_BASE64 = 1, CRYPTO_AES128 = 2, CRYPTO_3DES = 3, CRYPTO_AES256 = 4 } public enum LogLevel { LOG_TRACE = 0, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_CRITICAL, LOG_OFF } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct NetCard { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 260)] public string Name; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 132)] public string Description; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)] public string IpAddr; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)] public string NetMask; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)] public string MacAddr; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct WgSvrConfig { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] public string Name; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string Address; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] public string PrivateKey; public int ListenPort; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] public string CliPubKey; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string AllowNet; } [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Ansi)] public struct WgCliConfig { [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] public string Name; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] public string PrivateKey; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 32)] public string Address; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)] public string SvrPubKey; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string AllowNet; [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)] public string ServerURL; } public class NetTunnelLib { [DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int CreateTunnel(String lpszMsg); [DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)] internal static extern IntPtr TestMessage(); [DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)] internal static extern Int32 Add(int a, int b); [DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int TunnelSDKInitEnv(String workDir); [DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void TunnelSDKUnInit(); [DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int SetProtocolEncryptType(ProtoCryptoType type, String pProKey); [DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void InitTunnelSDKLog(String pProKey, LogLevel level); [DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int FindWireguardExe(StringBuilder lpString, int maxSize); [DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int SetWireguardPath(String path); [DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int GenerateWireguardKeyPairs(StringBuilder wgPubKey, int maxPubKey, StringBuilder wgPrivKey, int MaxPrivKey); [DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int GetAllNICInfo(IntPtr netCard, ref int size); [DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int WireGuardCreateServerConfig(WgSvrConfig cfg); [DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int WireGuardCreateClientConfig(WgCliConfig cfg); [DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)] public static extern int WireGuardInstallServerService(bool install); //[DllImport("NetTunnelSDK.dll", CallingConvention = CallingConvention.Cdecl)] //public static extern int RunPipeCmd(String pszCmd, StringBuilder pszResultBuffer, int dwResultBufferSize); }