Skip to content

Commit 7599c6c

Browse files
committed
added:memory write and read key file
1 parent 24bde9d commit 7599c6c

File tree

5 files changed

+108
-0
lines changed

5 files changed

+108
-0
lines changed

XEngine_Module/XEngine_Verification/Verification_Define.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,8 @@ extern "C" bool Verification_XAuthKey_FileRead(VERIFICATION_XAUTHKEY* pSt_XAuthI
520520
备注:无论解析操作是否成功,此函数在结束的时候都需要调用,用来更新CDKEY使用信息.特别是秒数和天数版本
521521
*********************************************************************/
522522
extern "C" bool Verification_XAuthKey_FileWrite(VERIFICATION_XAUTHKEY* pSt_XAuthInfo, LPCXSTR lpszKeyFile, LPCXSTR lpszKeyPass = NULL);
523+
extern "C" bool Verification_XAuthKey_MemoryRead(VERIFICATION_XAUTHKEY* pSt_XAuthInfo, LPCXSTR lpszMSGBuffer, int nMSGLen, LPCXSTR lpszKeyPass = NULL);
524+
extern "C" bool Verification_XAuthKey_MemoryWrite(VERIFICATION_XAUTHKEY* pSt_XAuthInfo, XCHAR* ptszMSGBuffer, int* pInt_MSGLen, LPCXSTR lpszKeyPass = NULL);
523525
/********************************************************************
524526
函数名称:Verification_XAuthKey_KeyParse
525527
函数功能:解析CDKEY内容,判断是否超时

XEngine_Module/XEngine_Verification/Verification_XAuth/Verification_XAuthKey.cpp

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,99 @@ bool CVerification_XAuthKey::Verification_XAuthKey_FileWrite(VERIFICATION_XAUTHK
178178

179179
return true;
180180
}
181+
bool CVerification_XAuthKey::Verification_XAuthKey_MemoryRead(VERIFICATION_XAUTHKEY* pSt_XAuthInfo, LPCXSTR lpszMSGBuffer, int nMSGLen, LPCXSTR lpszKeyPass /* = NULL */)
182+
{
183+
Verification_IsErrorOccur = false;
184+
185+
int nRet = nMSGLen;
186+
XCHAR tszDECodecBuffer[4096] = {};
187+
XCHAR tszENCodecBuffer[4096] = {};
188+
189+
memcpy(tszENCodecBuffer, lpszMSGBuffer, nMSGLen);
190+
191+
if (NULL == lpszKeyPass)
192+
{
193+
//读取
194+
if (!Verification_XAuthKey_ReadMemory(tszENCodecBuffer, nRet, pSt_XAuthInfo))
195+
{
196+
return false;
197+
}
198+
}
199+
else
200+
{
201+
//解密
202+
if (!Cryption_XCrypto_Decoder(tszENCodecBuffer, &nRet, tszDECodecBuffer, lpszKeyPass))
203+
{
204+
Verification_IsErrorOccur = true;
205+
Verification_dwErrorCode = Cryption_GetLastError();
206+
return false;
207+
}
208+
//读取
209+
if (!Verification_XAuthKey_ReadMemory(tszDECodecBuffer, nRet, pSt_XAuthInfo))
210+
{
211+
return false;
212+
}
213+
}
214+
215+
if (ENUM_VERIFICATION_MODULE_SERIAL_TYPE_DAY == pSt_XAuthInfo->st_AuthRegInfo.enSerialType)
216+
{
217+
XENGINE_LIBTIME st_SysTime = {};
218+
XENGINE_LIBTIME st_EndTime = {};
219+
BaseLib_Time_GetSysTime(&st_SysTime);
220+
BaseLib_Time_StrToTime(pSt_XAuthInfo->st_AuthRegInfo.tszStartTime, &st_EndTime);
221+
if ((st_EndTime.wYear != st_SysTime.wYear) || (st_EndTime.wMonth != st_SysTime.wMonth) || (st_EndTime.wDay != st_SysTime.wDay))
222+
{
223+
pSt_XAuthInfo->st_AuthRegInfo.nHasTime--;
224+
_xstprintf(pSt_XAuthInfo->st_AuthRegInfo.tszLeftTime, _X("%lld"), pSt_XAuthInfo->st_AuthRegInfo.nHasTime);
225+
BaseLib_Time_TimeToStr(pSt_XAuthInfo->st_AuthRegInfo.tszStartTime);
226+
}
227+
}
228+
else
229+
{
230+
BaseLib_Time_TimeToStr(pSt_XAuthInfo->st_AuthRegInfo.tszStartTime);
231+
}
232+
pSt_XAuthInfo->st_AuthAppInfo.nExecTime++;
233+
return true;
234+
}
235+
bool CVerification_XAuthKey::Verification_XAuthKey_MemoryWrite(VERIFICATION_XAUTHKEY* pSt_XAuthInfo, XCHAR* ptszMSGBuffer, int* pInt_MSGLen, LPCXSTR lpszKeyPass /* = NULL */)
236+
{
237+
Verification_IsErrorOccur = false;
238+
239+
int nSize = 0;
240+
XCHAR tszDECodecBuffer[4096] = {};
241+
//更新使用时间
242+
if (ENUM_VERIFICATION_MODULE_SERIAL_TYPE_SECOND == pSt_XAuthInfo->st_AuthRegInfo.enSerialType)
243+
{
244+
XCHAR tszTimeEnd[64] = {};
245+
__int64x nUsedTime = 0;
246+
247+
BaseLib_Time_TimeToStr(tszTimeEnd);
248+
BaseLib_TimeSpan_GetForStr(pSt_XAuthInfo->st_AuthRegInfo.tszStartTime, tszTimeEnd, &nUsedTime, ENUM_XENGINE_BASELIB_TIME_TYPE_SECOND);
249+
pSt_XAuthInfo->st_AuthRegInfo.nHasTime -= nUsedTime;
250+
_xstprintf(pSt_XAuthInfo->st_AuthRegInfo.tszLeftTime, _X("%lld"), pSt_XAuthInfo->st_AuthRegInfo.nHasTime);
251+
}
252+
//准备数据
253+
if (!Verification_XAuthKey_WriteMemory(tszDECodecBuffer, &nSize, pSt_XAuthInfo))
254+
{
255+
return false;
256+
}
257+
//写数据
258+
if (NULL == lpszKeyPass)
259+
{
260+
memcpy(ptszMSGBuffer, tszDECodecBuffer, nSize);
261+
}
262+
else
263+
{
264+
if (!Cryption_XCrypto_Encoder(tszDECodecBuffer, &nSize, (XBYTE*)ptszMSGBuffer, lpszKeyPass))
265+
{
266+
Verification_IsErrorOccur = true;
267+
Verification_dwErrorCode = Cryption_GetLastError();
268+
return false;
269+
}
270+
}
271+
*pInt_MSGLen = nSize;
272+
return true;
273+
}
181274
/********************************************************************
182275
函数名称:Verification_XAuthKey_KeyParse
183276
函数功能:解析CDKEY内容,判断是否超时

XEngine_Module/XEngine_Verification/Verification_XAuth/Verification_XAuthKey.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ class CVerification_XAuthKey
1919
public:
2020
bool Verification_XAuthKey_FileRead(VERIFICATION_XAUTHKEY* pSt_XAuthInfo, LPCXSTR lpszKeyFile, LPCXSTR lpszKeyPass = NULL);
2121
bool Verification_XAuthKey_FileWrite(VERIFICATION_XAUTHKEY* pSt_XAuthInfo, LPCXSTR lpszKeyFile, LPCXSTR lpszKeyPass = NULL);
22+
bool Verification_XAuthKey_MemoryRead(VERIFICATION_XAUTHKEY* pSt_XAuthInfo, LPCXSTR lpszMSGBuffer, int nMSGLen, LPCXSTR lpszKeyPass = NULL);
23+
bool Verification_XAuthKey_MemoryWrite(VERIFICATION_XAUTHKEY* pSt_XAuthInfo, XCHAR* ptszMSGBuffer, int* pInt_MSGLen, LPCXSTR lpszKeyPass = NULL);
24+
public:
2225
bool Verification_XAuthKey_KeyParse(VERIFICATION_XAUTHKEY* pSt_XAuthInfo);
2326
bool Verification_XAuthKey_KeyInit(VERIFICATION_XAUTHKEY* pSt_XAuthInfo);
2427
bool Verification_XAuthKey_KeySerial(XCHAR* ptszSerialStr, int nCount, int nType);

XEngine_Module/XEngine_Verification/XEngine_Verification.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ EXPORTS
1717

1818
Verification_XAuthKey_FileRead
1919
Verification_XAuthKey_FileWrite
20+
Verification_XAuthKey_MemoryRead
21+
Verification_XAuthKey_MemoryWrite
2022
Verification_XAuthKey_KeyParse
2123
Verification_XAuthKey_KeyInit
2224
Verification_XAuthKey_KeySerial

XEngine_Module/XEngine_Verification/pch.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ extern "C" bool Verification_XAuthKey_FileWrite(VERIFICATION_XAUTHKEY* pSt_XAuth
8989
{
9090
return m_XAuthKeyVerification.Verification_XAuthKey_FileWrite(pSt_XAuthInfo, lpszKeyFile, lpszKeyPass);
9191
}
92+
extern "C" bool Verification_XAuthKey_MemoryRead(VERIFICATION_XAUTHKEY* pSt_XAuthInfo, LPCXSTR lpszMSGBuffer, int nMSGLen, LPCXSTR lpszKeyPass)
93+
{
94+
return m_XAuthKeyVerification.Verification_XAuthKey_MemoryRead(pSt_XAuthInfo, lpszMSGBuffer, nMSGLen, lpszKeyPass);
95+
}
96+
extern "C" bool Verification_XAuthKey_MemoryWrite(VERIFICATION_XAUTHKEY* pSt_XAuthInfo, XCHAR* ptszMSGBuffer, int* pInt_MSGLen, LPCXSTR lpszKeyPass)
97+
{
98+
return m_XAuthKeyVerification.Verification_XAuthKey_MemoryWrite(pSt_XAuthInfo, ptszMSGBuffer, pInt_MSGLen, lpszKeyPass);
99+
}
92100
extern "C" bool Verification_XAuthKey_KeyParse(VERIFICATION_XAUTHKEY* pSt_XAuthInfo)
93101
{
94102
return m_XAuthKeyVerification.Verification_XAuthKey_KeyParse(pSt_XAuthInfo);

0 commit comments

Comments
 (0)