In the practice of developing software, the software is usually divided into several editions: the ①release;②demo;③anti_copy:④register;⑤dog version. Release is a normal unrestricted release, the latter several copyrighted versions, where the demo version is a limited time or feature version; Anti_copy is an anti-copy version that only the installed version can use, and when implemented, the installer places a dynamic library under the specified path. The program runs to verify that the file exists; Register version is the user by providing software developer registration code, generated by the software provider registration code, return to the user, that is, through the software provided by the registration code verification mechanism to achieve the opening of software system functions The dog version implements the copyright protection of the software through the hardware dongle.
1 Limitation of the software part function
The first step is to empty the function implementation function of the menu in the function menu of the software, so that when the function is executed, a prompt dialog box is displayed or nothing is moved. The second option is to set the menu's properties to grayed out or inactive for convenience, so that when the system is running, the menu item will be dimmed or not activated. This method is simple, but if you open the executable file directly with Visual C + +, you can remove the gray or non-active state, and then remove the limitations of the software part of the function.
2 Limit Software trial time
This article describes the time-of-day restriction method for recording times.
2.1 Setting three time variables
起始时间:int nYear0,nMonth0,nDate0; 终止时间:int nYear,nMonth,nDate;
2.2 Assigning values to the above variables at first run time
对于当前时间:
SYSTEMTIME stcur;
2.GetSystemTnne (&stcur);
3.nyearcufstcur.wyear.nmonthcur=stcur.wmonth;
4.ndatecur=stcur.wday;
The assignment of the start time and end time is to write the current time and the preset period to a file the first time the program is run, and then compare the two times with the current system time to determine if the software expires or if the trial time expires:
View sourceprint?01.string sfn= "C:\muxuanshe.sys";
02.FII. E *fp=fopen (SFn, "RB");
03.{
Ndateo=ndatecur;
Nyear0=n yearcur;
Nmontho=nmonthcur;
NDATE=NDATE0;
NYEAR=NYEAR0;
nmonth=nmonth0+1;
if (nmonth>12) {
nmonth-=12;
nycar++;
}//straddling calculates the start time, the expiration time, and the current time and the number of bytes of the file in turn C:\muxuanshe sys
14.}
2.3 Compare time
Each time the runtime compares the current time to the file record, there are two cases, one is to determine whether to advance the system system time:
if (Isprctime (NYEAR0,NMONTH0,NDATE0) | | Ispretime (Nyear01d,nmo Nthold,ndateojd)) where Nyearold,nmonthold,ndateold is the last run time:
View Sourceprint?01.bool jsovertime (int nyear,int nmonth,int ndate)
02.{
SYSTEMTIME St;
Getsysten/rime (&ST);
if (st.wyear>nyear)
return TRUE;
else if (st.wyearnmonth)
return TRUE;
else if (st.wmonth==nmonth&&st.wday>ndate)
return TRUE;
return FALSF;
12.}
If you move the machine time forward, it will terminate the time Nyear=l and write to C:\muxuanshe.sys, the software terminates the operation later!
Another case is for the normal remaining time-to-ask calculation: Isovertime (nyear,nmonth,ndate), which is not described in detail, see Sample code for implementation.
Here the method is mainly to note that the storage time of the file to be confidential, if you know the time to store the location, then the time limit is easy to be relieved. It is also possible to store time in other, more secure ways, such as in the registry.
3 Implement software registration according to machine code
Machine code refers to the computer hardware (CPU, network number, hard disk) related serial number, such as hard disk serial number, MAC address, etc., the person who writes the software commonly used machine code as the basis of generating software serial number, the purpose is to distinguish users, to ensure that their software use controlled, the following by reading the user computer hard disk volume serial number, After the conversion of certain encryption algorithm, return to the user a product registration code, because the hard disk volume serial number is unique, the product registration code provided is also unique, the user uses the registration code through the verification to obtain the full functionality of the software.
In the author's programming practice found that sometimes due to the use of the function is not correct, often can not correctly get the serial number of the hard disk, here on this issue discussed.
3.1 Incorrect serial number
The computer hard disk volume serial number obtained by using getvolumelnformation is not the correct unique serial number:
View Sourceprint?01.void Cwjgisapp::register ()
02.{
DWORD VolumeSerialNumber;
GetVolumeInformation ("C: \", null,null,&volumeseriainumber,null,null,null,null);
Char charvolumeserialnumber[l0];
Itoa (volumeserlalnumber,charvoiumeserialnumber,10);
CString strtemp;
Strtemp.format ("%s", Charvolumeserialnumber);
09.}
The sequence number obtained by the function changes after the hard disk is formatted.
3.2 Getting the serial number of the hard drive correctly
Get the hard drive serial number code as follows:
View sourceprint?01.
Read-like HDD serial number function
char* cgethdserial::gethdserial ()
{
M_buffer[0]= ' \ n ';
Get the current operating system version
osVersionInfo osversioninfo;
osversioninfo.dwosversioninfosize = sizeof (OSVERSIONINFO);
GetVersionEx (&osversioninfo);
if (osversioninfo.dwplatformld! = ver_platform_win32_nt)
{
Read hard drive serial number under Windows 9x/me
WORD M_WWIN9XL ' hdserial[256];
Win9xreadhdserial (m_wwin9xhdserial);
strcpy (M_buffer, Wordtochar (M _wwin9xhdserial, 10, 19));
}
Else
{
Windows NT/2000/XP read hard drive sequence bow
DWORD m_wwinnthdserial[256];
Determine if there is a SCSI hard drive
if (! Winntreadidehdserial (m_wwinnthdserial))
Winntreadscsihdserial (m_wwinnthdserial);
strcpy (M_buffer,dwordtochar (m_wwinnthdserial,10, 19));
}
return m_buffer;
}
Read IDE hard drive serial number under Windows nt/2000/xp
BOOL cgethdscriai::winntreadidehdserial (dword* buffer)
{
BYTE jdoutcmd [sizeof (Sendcmdoutparams) +idfntify_buffer_size-1];
BOOL bflag = FALSE;
int drive = 0;
Char drivename[256];
HANDLE hphysicaldriveloctl=0;
Sprintf (DriveName, "\.\physicaldrive%d", drive);
Administrator permissions are required to create files under Windows nt/2000/xp
Hphysicaldriveioctl=createfile (drivename,generic_read| Generic_write,
39.file_share_read| File_share_write,null,open_existing,0,null);
if (Hphysicaldriveioctl!=invalid_handle_value)
{
Getversionoutparams Versionparams;
DWORD cbbytesreturned=0;
Get the I/O controller version of the drive
Memser ((void*) &versionparams,0,sizeof (versionparams));
if (DeviceIoControl (Hphysicaldriveioctl,ioctl_get_version,null,
48.0,&versionpaiams,sizeof (Versionparams), sizeof (Versionparams),
&cbbytesreturned,null))
{
if (versionparams.bidedevicemap>0)
{
BYTE bidcmd=0;//ide or ATAPI recognition command
Sendcmdinparams Scip;
If the drive is an optical drive, use the command Ide_atapi_identify,command,
56. Otherwise use the command ide_ata_identify to read the drive information
Bidcmd= (versionparams.bidedevicemap?drive&0x10)?
58.ide_atapi_identify:ide_ata_identify;
memset (&scip,0,sizeof (SCIP));
memset (idoutcmd,0,sizeof (idoutcmd));
Get drive information
if (Winntgetidehdinfo (Hphysicaldriveloctl,&scip, (psendcmdoutparms) &
64.IDOUTCMD, (Byte) Bidcmd, (byte) drive,&cbbytesreturned))
{
int m=0;
USHORTpldsector= (USHORT) ((psendcmdoutparams) idoutcmd)->bbuffer;
for (m=0;m<256;m++)
BUFFER[M]=PIDSECTOR[M];
Bflag=true; Read hard disk information successfully
}
}
}
CloseHandle (HPHYSICALDRIYEIOCTL); Close handle
}
Return Bflag;
}
4 software copyright Protection method invocation
When the program is initialized, different software protection methods are called according to the actual needs, as follows:
View Sourceprint?01.bool g_nsofttype=0;//0,relese;1,demo;2 anti_copy;3 Dog;
02.BOOL ctestapp::initinstance ()
03.{
if (g_nsofttype==1) {
if (Demoisovertime ())
return FALSE;
}
else if (g_nsofttype==2) {
if (! Isinstalledsoft ())
return FALSE;
}
else if (g_nsofttype==3) {
if (! Dog ()) {
AfxMessageBox ("You do not have a software dog installed, please purchase genuine software.") \ n \ nyou are sorry ... ");
return flase;
}
}
if (!g_bdemo) {
CCommandLineInfo Cmdinfo;
ParseCommandLine (Cmdinfo);
}
22.}
The above simply introduces the method of implementing software copyright protection in Visual C + +, obviously, the protection effectiveness from high to low in turn is the hardware dog method version, registration code registration method, function limit method, time limit method, the user can choose according to the actual needs of the work.
How to use VC + + to limit software functionality