VC++生成序列号和简单注册机实例
在成品软件中,软件注册是必需的,在VC++中,如何实现程序注册功能呢?今天发一下VC++生成程序序
列号和注册机程序的代码,或许是个参考
一、生成程序序列号的具体实现:
HCURSOR CJiemishuoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CJiemishuoDlg::OnButton1()
{
DWORD num;
UpdateData(1);
num=m_jms;
num^=0x1999aa98;
if(num==m_gkh)
MessageBox("ok"); //提示解密正确
CFile ff;
if(!ff.Open("play.exe",CFile::modeWrite))
return;
CString str;
str.Format("%10d",m_jms);
MessageBox(str);
ff.Seek(-10,CFile::end);
ff.Write(str,10);//添加到play.exe尾部
ff.Close();
}
void CJiemishuoDlg::OnButton2()
{
//功能:得到解密匙.
UpdateData(1);
long aa=m_gkh^0x1999aa98;
m_jms=aa;
UpdateData(0);
}
void CJiemishuoDlg::OnAdd()
{
DWORD num;
UpdateData(1);
num=m_jms;
num^=0x1999aa98;
if(num==m_gkh)
MessageBox("ok"); //提示解密匙正确
CFile ff;
if(!ff.Open("play.exe",CFile::modeWrite))
return;
CString str;
str.Format("%10d",m_jms);
MessageBox(str);
ff.SeekToEnd();
ff.Write(str,10);//改写解密匙
ff.Close();
}
二、简单注册机的实现:
void CZhuCeJiDlg::OnJieMi()
{
//在你要加密的文件play.exe末部改写解密匙.
long num;
UpdateData(1);
num=m_jms;
num^=0x1999aa98;
if(num==m_gkh)
MessageBox("ok");//提示解密匙正确
CFile ff;
if(!ff.Open("play.exe",CFile::modeWrite))
return;
CString str;
str.Format("%10d",m_jms);
MessageBox(str);
ff.Seek(-10,CFile::end);
ff.Write(str,10); //改写解密匙
ff.Close();
}
http://www.codefans.net/articles/1437.shtml
========
http://www.newxing.com/Code/VC/zfcl/1386.html
VC 根据序列号生成注册码示例
========
http://blog.csdn.net/A8572785/article/details/7644342
加密解密-TraceMe—注册机
写了个TraceMe的注册机
unsigned char Table[8] = {0xC, 0xA, 0x13, 0x9,0xC,0xB,0xA,0x8};
unsigned long GenRegCode(CHAR * name, int len)
{
CString temp;
int i, j;
unsigned long ID =0;
for(i=3,j=0; i<len; i++,j++)
{
if(j>7)
j=0;
ID+=name[i]*Table[j];
}
return ID;
}
void CTraceMeDlg::OnRegist()
{
// TODO: Add your control notification handler code here
CString str1;
CString test;
unsigned long str2;
char* buf;
GetDlgItemText(IDC_Name,str1);
buf = (LPSTR)(LPCTSTR)str1;
str2 = GenRegCode(buf,strlen(str1));
test.Format("%ld",str2);
SetDlgItemText(IDC_ID, test);
}
http://download.csdn.net/download/dancer8th/1862601
在成品软件中,软件注册是必需的,在VC++中,如何实现程序注册功能呢?今天发一下VC++生成程序序
列号和注册机程序的代码,或许是个参考
一、生成程序序列号的具体实现:
HCURSOR CJiemishuoDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CJiemishuoDlg::OnButton1()
{
DWORD num;
UpdateData(1);
num=m_jms;
num^=0x1999aa98;
if(num==m_gkh)
MessageBox("ok"); //提示解密正确
CFile ff;
if(!ff.Open("play.exe",CFile::modeWrite))
return;
CString str;
str.Format("%10d",m_jms);
MessageBox(str);
ff.Seek(-10,CFile::end);
ff.Write(str,10);//添加到play.exe尾部
ff.Close();
}
void CJiemishuoDlg::OnButton2()
{
//功能:得到解密匙.
UpdateData(1);
long aa=m_gkh^0x1999aa98;
m_jms=aa;
UpdateData(0);
}
void CJiemishuoDlg::OnAdd()
{
DWORD num;
UpdateData(1);
num=m_jms;
num^=0x1999aa98;
if(num==m_gkh)
MessageBox("ok"); //提示解密匙正确
CFile ff;
if(!ff.Open("play.exe",CFile::modeWrite))
return;
CString str;
str.Format("%10d",m_jms);
MessageBox(str);
ff.SeekToEnd();
ff.Write(str,10);//改写解密匙
ff.Close();
}
二、简单注册机的实现:
void CZhuCeJiDlg::OnJieMi()
{
//在你要加密的文件play.exe末部改写解密匙.
long num;
UpdateData(1);
num=m_jms;
num^=0x1999aa98;
if(num==m_gkh)
MessageBox("ok");//提示解密匙正确
CFile ff;
if(!ff.Open("play.exe",CFile::modeWrite))
return;
CString str;
str.Format("%10d",m_jms);
MessageBox(str);
ff.Seek(-10,CFile::end);
ff.Write(str,10); //改写解密匙
ff.Close();
}
http://www.codefans.net/articles/1437.shtml
========
http://www.newxing.com/Code/VC/zfcl/1386.html
VC 根据序列号生成注册码示例
========
http://blog.csdn.net/A8572785/article/details/7644342
加密解密-TraceMe—注册机
写了个TraceMe的注册机
unsigned char Table[8] = {0xC, 0xA, 0x13, 0x9,0xC,0xB,0xA,0x8};
unsigned long GenRegCode(CHAR * name, int len)
{
CString temp;
int i, j;
unsigned long ID =0;
for(i=3,j=0; i<len; i++,j++)
{
if(j>7)
j=0;
ID+=name[i]*Table[j];
}
return ID;
}
void CTraceMeDlg::OnRegist()
{
// TODO: Add your control notification handler code here
CString str1;
CString test;
unsigned long str2;
char* buf;
GetDlgItemText(IDC_Name,str1);
buf = (LPSTR)(LPCTSTR)str1;
str2 = GenRegCode(buf,strlen(str1));
test.Format("%ld",str2);
SetDlgItemText(IDC_ID, test);
}
========
程序初始化时调用
BOOL CMySoftApp::InitInstance()
{
AfxEnableControlContainer();
if(!IsRegisterOK())
return FALSE;
......
BOOL CMySoftApp::IsRegisterOK()
{
DWORD dwVolumeSerialNumber,dwUserID,dwDecodeNumber;
DWORD dwMask=87654321; //运算子,随便设定
DWORD dwKey=0x20080808; //密钥码,设成自己好记、别人不知的
CString strUserID,strRegCode;
char str[200];
int str_len=200;
// 将硬盘序列号与运算子异或后做为用户号
::GetVolumeInformation("C:\\",NULL,NULL,&dwVolumeSerialNumber,NULL,NULL,NULL,NULL);
dwUserID=dwVolumeSerialNumber^dwMask;
strUserID.Format("%8d",dwUserID);
// 正确的注册码应为16进制形式=(10进制的dwUserID转16进制后)^(16进制的密钥码)
// 开发者可利用科学型计算器,根据用户报知的用户号直接算出注册码返回给用户
// 先直接从操作系统的win.ini读取注册码
if( ::GetProfileString("MySoft","RegCode","",str,str_len)!=0 )
{
strRegCode=str;
// 验证注册码
dwDecodeNumber=strtoul(strRegCode,NULL,16);
dwDecodeNumber^=dwKey; //解密钥
dwDecodeNumber^=dwMask; //还原硬盘序列号
if(dwDecodeNumber==dwVolumeSerialNumber) //注册成功
return TRUE;
}
// 如果上面读取的注册码不对或没有,再通过对话框取注册码
for(;;)
{
CDlgRegister dlg;
dlg.m_strUserID=strUserID;
if(dlg.DoModal()==IDOK)
{
strRegCode=dlg.m_strRegCode;
delete dlg;
// 验证注册码
dwDecodeNumber=strtoul(strRegCode,NULL,16);
dwDecodeNumber^=dwKey; //解密钥
dwDecodeNumber^=dwMask; //还原硬盘序列号
if(dwDecodeNumber==dwVolumeSerialNumber) //注册成功
{
// 将通过的注册信息保存到操作系统的win.ini,以备以后直接读取
::WriteProfileString("MySoft","UserID",strUserID);
::WriteProfileString("MySoft","RegCode",strRegCode);
return TRUE;
}
else
AfxMessageBox("注册码错误! 请重试输入或向开发者索取本机注册码!");
}
else
{
delete dlg;
break;
}
}
return FALSE; //注册失败
}
http://download.csdn.net/download/dancer8th/1862601