94 lines
2.1 KiB
C++
94 lines
2.1 KiB
C++
#include "stdafx.h"
|
|
#include "LockReadWriteTool.h"
|
|
#include "base64.h"
|
|
#include <string>
|
|
|
|
#ifdef _DEBUG
|
|
#undef THIS_FILE
|
|
static char THIS_FILE[]=__FILE__;
|
|
#define new DEBUG_NEW
|
|
#endif
|
|
|
|
#pragma comment(linker, "/NODEFAULTLIB:libc.lib")
|
|
#pragma comment(linker, "/NODEFAULTLIB:libcmt.lib")
|
|
|
|
char g_UserPin [] = "12345678";
|
|
bool CLockReadWriteTool::ReadLock(std::string& strData)
|
|
{
|
|
/*int i = 0,iNum = 0;
|
|
int nFlag = 0;
|
|
BYTE buffer[_ALL_PRODUCTS_LEN]; // 用户缓冲区
|
|
|
|
DONGLE_INFO *pDongleInfo = NULL;
|
|
DONGLE_HANDLE hDongle = NULL;
|
|
DWORD dwRet = 0;
|
|
int nRemainCount = 0;
|
|
BYTE* pbuffer = NULL;
|
|
|
|
dwRet = Dongle_Enum(NULL,&iNum);
|
|
for (i = 0; i < iNum;i++)
|
|
{
|
|
dwRet = Dongle_Open(&hDongle, i);
|
|
if (dwRet == DONGLE_SUCCESS)
|
|
{
|
|
//判断是否是写锁的许可锁
|
|
strData.assign(1,'\0');
|
|
if (!IsPermissionLock(hDongle,nFlag,strData)) //不是许可锁
|
|
{
|
|
break;
|
|
}
|
|
//是许可锁关闭
|
|
dwRet = Dongle_Close(hDongle);
|
|
}
|
|
}
|
|
|
|
if (i == iNum)//没有找到
|
|
{
|
|
memset(buffer,0,_ALL_PRODUCTS_LEN);
|
|
return false;
|
|
}
|
|
|
|
//验证用户PIN码
|
|
nRemainCount = 0;
|
|
dwRet = Dongle_VerifyPIN(hDongle, FLAG_USERPIN, g_UserPin, &nRemainCount);
|
|
if (dwRet != DONGLE_SUCCESS)
|
|
{
|
|
dwRet = Dongle_Close(hDongle);
|
|
return false;
|
|
}
|
|
|
|
dwRet = Dongle_LEDControl(hDongle,LED_ON);
|
|
|
|
BYTE bDataSec[_ALL_PRODUCTS_LEN];//数据区总大小8k
|
|
memset(bDataSec,0,_ALL_PRODUCTS_LEN);
|
|
|
|
//读数据文件验证写入正确
|
|
pbuffer = new BYTE[_ALL_PRODUCTS_LEN];
|
|
memset(pbuffer,0,_ALL_PRODUCTS_LEN);
|
|
|
|
dwRet = Dongle_ReadFile(hDongle, 0x0001, 0, pbuffer, _ALL_PRODUCTS_LEN);
|
|
if (dwRet != DONGLE_SUCCESS)
|
|
{
|
|
dwRet = Dongle_Close(hDongle);
|
|
delete[] pbuffer;
|
|
return false;
|
|
}
|
|
|
|
int nOutDataLen = _ALL_PRODUCTS_LEN;
|
|
char szBuffer[_ALL_PRODUCTS_LEN];
|
|
memset(szBuffer,0,_ALL_PRODUCTS_LEN);
|
|
memcpy(szBuffer,pbuffer,nOutDataLen);
|
|
|
|
strData.assign(szBuffer);
|
|
|
|
dwRet = Dongle_LEDControl(hDongle,LED_OFF);
|
|
Dongle_Close(hDongle);
|
|
delete[] pbuffer;
|
|
return true;*/
|
|
return false;
|
|
}
|
|
|
|
bool CLockReadWriteTool::IsPermissionLock(DONGLE_HANDLE hDongle,int& nFlag,std::string& strData)
|
|
{
|
|
return false;
|
|
} |