📄 checkdarkidentity.cpp
字号:
// CheckDarkIdentity.cpp: implementation of the CCheckDarkIdentity class.
//作者:高越 邮箱:darkprince@v.cn
//QQ:1738387 (本人只接受技术探讨以及软件项目合作事宜,其他误扰)
//////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "CheckDarkIdentity.h"
#include "DPSocketModel.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#endif
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CCheckDarkIdentity::CCheckDarkIdentity()
{
m_strKey=DEFAULT_KEY;
m_strKeyDataFileName="";
}
CCheckDarkIdentity::~CCheckDarkIdentity()
{
}
BOOL CCheckDarkIdentity::CheckIndentityByIp(CString strGlobalIp)
{
CDPSocketModel clsSocket;
clsSocket.DPInitLibrary();
BOOL bResult=FALSE;
strGlobalIp.TrimLeft();strGlobalIp.TrimRight();
if(strGlobalIp.IsEmpty())
return bResult;
char name[255];
PHOSTENT hostinfo;
if( gethostname ( name, sizeof(name)) == 0)
{
if((hostinfo = gethostbyname(name)) != NULL)
{
for( int i = 0; hostinfo!= NULL && hostinfo->h_addr_list[i]!= NULL; i++ )
{
CString strReturn;
strReturn = inet_ntoa (*(struct in_addr *)(hostinfo->h_addr_list[i]));
if(strReturn==strGlobalIp)
return TRUE;
}
}
}
clsSocket.DPCleanupLibrary();
return bResult;
}
BOOL CCheckDarkIdentity::EncryptMem(BYTE* pSource,BYTE* pDst,DWORD dwLength)
{
if(pSource==NULL||pDst==NULL||dwLength<=0)
return FALSE;
BYTE* krypttext=NULL;
krypttext = pSource;
BYTE* pKey=NULL;
DWORD nKeySize=m_strKey.GetLength();
DWORD j=0;
int crypt;
for(DWORD i=0;i<dwLength;i++) // the encryption algoritm
{
crypt=krypttext[i]+m_strKey.GetAt(j);
if (crypt>255)
pDst[i]=(BYTE)(crypt-255);
else
pDst[i]=(BYTE)crypt;
if(j+1==nKeySize)
j=0;
else
j++;
}
return TRUE;
}
BOOL CCheckDarkIdentity::DecryptMem(BYTE* pSource,BYTE* pDst,DWORD dwLength)
{
if(pSource==NULL||pDst==NULL||dwLength<=0)
return FALSE;
BYTE *dekrypttext=pSource;
DWORD nKeySize=m_strKey.GetLength();
DWORD j=0;
int decrypt;
for(DWORD i=0; i<dwLength; i++) // the decryption algoritm
{
decrypt=dekrypttext[i]-m_strKey.GetAt(j);
if (decrypt<0)
pDst[i]=decrypt+255;
else
pDst[i]=decrypt;
if(j+1==nKeySize)
j=0;
else
j++;
}
return TRUE;
}
CString CCheckDarkIdentity::GetGUID(void)
{
GUID tagGUID;
HRESULT hr=CoCreateGuid(&tagGUID);
if(FAILED(hr))
return "";
unsigned char* pGUID;
UuidToString(&tagGUID,&pGUID);
CString strGUID=pGUID;
if(pGUID!=NULL)
RpcStringFree(&pGUID);
strGUID.MakeUpper();
return strGUID;
}
BOOL CCheckDarkIdentity::CheckIpIdentity(void)
{
char* pContent=NULL;
DWORD dwLength=0;
//没有取得内容
if(!GetKeyContent(&pContent,dwLength))
return FALSE;
char* pDst=new char[dwLength+1];
if(!DecryptMem((BYTE*)pContent,(BYTE*)pDst,dwLength))
{
delete []pContent;
delete []pDst;
return FALSE;
}
pDst[dwLength]='\0';
CString strLine=pDst;
delete []pDst;
delete []pContent;
pDst=NULL;
CString strServerIp="";
while(!strLine.IsEmpty())
{
int nStart=strLine.Find("-");
if(nStart>0)
{
strLine=strLine.Mid(nStart+1);
int nEnd=strLine.Find("-");
if(nEnd>0)
{
strServerIp+=strLine.Left(nEnd);
strServerIp+=".";
strLine=strLine.Mid(nEnd+1);
}
}
else
strLine="";
}
strServerIp=strServerIp.Left(strServerIp.GetLength()-1);
return(CheckIndentityByIp(strServerIp));
}
BOOL CCheckDarkIdentity::GetKeyContent(char** pContent,DWORD& dwLength)
{
BOOL bReturn=FALSE;
*pContent=NULL;
dwLength=0;
char arrBuffer[MAX_PATH];
GetWindowsDirectory(arrBuffer,MAX_PATH);
CString strPath=arrBuffer;
if(strPath.GetAt(strPath.GetLength()-1)!='\\')
strPath+='\\';
strPath+=m_strKeyDataFileName;
HANDLE hFile=::CreateFile(strPath, GENERIC_READ,0,NULL,
OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
if((HANDLE)hFile==INVALID_HANDLE_VALUE)
return bReturn;
DWORD dwFileLength=GetFileSize(hFile,NULL);
if((LONG)dwFileLength<=0)
{
CloseHandle(hFile);
return bReturn;
}
char* pFileBuf=new char[dwFileLength];
DWORD dwReadLength=0;
BOOL bResult=ReadFile(hFile,pFileBuf,dwFileLength,&dwReadLength,NULL);
CloseHandle(hFile);
if(!bResult)
{
delete []pFileBuf;
return bReturn;
}
*pContent=pFileBuf;
dwLength=dwFileLength;
bReturn=TRUE;
return bReturn;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -