105 lines
3.5 KiB
C#
105 lines
3.5 KiB
C#
using SqlSugar;
|
|||
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.Linq;
|
||
|
|
using System.Runtime.InteropServices;
|
||
|
|
using System.Text;
|
||
|
|
using System.Threading.Tasks;
|
||
|
|
using static System.Net.Mime.MediaTypeNames;
|
||
|
|
|
||
|
|
namespace SuperDogTest
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// 超级狗辅助类
|
||
|
|
/// </summary>
|
||
|
|
public static class SuperDogHelper
|
||
|
|
{
|
||
|
|
/// <summary>
|
||
|
|
/// 加载dll
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="DllName"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
[DllImport("kernel32.dll")]
|
||
|
|
public extern static IntPtr LoadLibrary(string DllName);
|
||
|
|
/// <summary>
|
||
|
|
/// 释放dll
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="hModule"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
|
||
|
|
[DllImport("kernel32")]
|
||
|
|
public extern static bool FreeLibrary(IntPtr hModule);
|
||
|
|
/// <summary>
|
||
|
|
/// 获取dll中的方法句柄
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="hModule"></param>
|
||
|
|
/// <param name="ProcName"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
|
||
|
|
[DllImport("kernel32.dll")]
|
||
|
|
public extern static IntPtr GetProcAddress(IntPtr hModule, string ProcName);
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 查找加密狗委托
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="Count"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||
|
|
public delegate int VikeyFindType(ref int Count);
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 读取加密狗数据委托
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="Index"></param>
|
||
|
|
/// <param name="Addr"></param>
|
||
|
|
/// <param name="Length"></param>
|
||
|
|
/// <param name="buffer"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||
|
|
public delegate int VikeyReadDataType(int Index, int Addr, int Length, StringBuilder buffer);
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 管理员登录加密狗委托
|
||
|
|
/// </summary>
|
||
|
|
/// <param name="Index"></param>
|
||
|
|
/// <param name="AdminPassword"></param>
|
||
|
|
/// <returns></returns>
|
||
|
|
[UnmanagedFunctionPointer(CallingConvention.StdCall)]
|
||
|
|
public delegate int VikeyAdminLoginType(int Index, string AdminPassword);
|
||
|
|
|
||
|
|
/// <summary>
|
||
|
|
/// 加密狗句柄
|
||
|
|
/// </summary>
|
||
|
|
private static IntPtr VikeyHandle;
|
||
|
|
/// <summary>
|
||
|
|
/// 查找加密狗
|
||
|
|
/// </summary>
|
||
|
|
public static VikeyFindType VikeyFind { get; private set; }
|
||
|
|
/// <summary>
|
||
|
|
/// 加密狗管理员登录
|
||
|
|
/// </summary>
|
||
|
|
public static VikeyAdminLoginType VikeyAdminLogin { get; private set; }
|
||
|
|
/// <summary>
|
||
|
|
/// 加密狗读取数据
|
||
|
|
/// </summary>
|
||
|
|
public static VikeyReadDataType VikeyReadData { get; private set; }
|
||
|
|
static SuperDogHelper()
|
||
|
|
{
|
||
|
|
if (IntPtr.Size == 4)
|
||
|
|
{
|
||
|
|
VikeyHandle = LoadLibrary("ViKey32.dll");
|
||
|
|
}
|
||
|
|
else if (IntPtr.Size == 8)
|
||
|
|
{
|
||
|
|
VikeyHandle = LoadLibrary("ViKey64.dll");
|
||
|
|
}
|
||
|
|
else
|
||
|
|
return;
|
||
|
|
|
||
|
|
VikeyFind = Marshal.GetDelegateForFunctionPointer<VikeyFindType>(GetProcAddress(VikeyHandle, "VikeyFind"));
|
||
|
|
VikeyAdminLogin = Marshal.GetDelegateForFunctionPointer<VikeyAdminLoginType>(GetProcAddress(VikeyHandle, "VikeyAdminLogin"));
|
||
|
|
VikeyReadData = Marshal.GetDelegateForFunctionPointer<VikeyReadDataType>(GetProcAddress(VikeyHandle, "VikeyReadData"));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|