How to use VC + + to limit software functionality

Source: Internet
Author: User
Tags ide hard drive

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.{

    1. Ndateo=ndatecur;

    2. Nyear0=n yearcur;

    3. Nmontho=nmonthcur;

    4. NDATE=NDATE0;

    5. NYEAR=NYEAR0;

    6. nmonth=nmonth0+1;

    7. if (nmonth>12) {

    8. nmonth-=12;

    9. nycar++;

    10. }//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.{

    1. SYSTEMTIME St;

    2. Getsysten/rime (&ST);

    3. if (st.wyear>nyear)

    4. return TRUE;

    5. else if (st.wyearnmonth)

    6. return TRUE;

    7. else if (st.wmonth==nmonth&&st.wday>ndate)

    8. return TRUE;

    9. 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.{

    1. DWORD VolumeSerialNumber;

    2. GetVolumeInformation ("C: \", null,null,&volumeseriainumber,null,null,null,null);

    3. Char charvolumeserialnumber[l0];

    4. Itoa (volumeserlalnumber,charvoiumeserialnumber,10);

    5. CString strtemp;

    6. 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

  1. char* cgethdserial::gethdserial ()

  2. {

  3. M_buffer[0]= ' \ n ';

  4. Get the current operating system version

  5. osVersionInfo osversioninfo;

  6. osversioninfo.dwosversioninfosize = sizeof (OSVERSIONINFO);

  7. GetVersionEx (&osversioninfo);

  8. if (osversioninfo.dwplatformld! = ver_platform_win32_nt)

  9. {

  10. Read hard drive serial number under Windows 9x/me

  11. WORD M_WWIN9XL ' hdserial[256];

  12. Win9xreadhdserial (m_wwin9xhdserial);

  13. strcpy (M_buffer, Wordtochar (M _wwin9xhdserial, 10, 19));

  14. }

  15. Else

  16. {

  17. Windows NT/2000/XP read hard drive sequence bow

  18. DWORD m_wwinnthdserial[256];

  19. Determine if there is a SCSI hard drive

  20. if (! Winntreadidehdserial (m_wwinnthdserial))

  21. Winntreadscsihdserial (m_wwinnthdserial);

  22. strcpy (M_buffer,dwordtochar (m_wwinnthdserial,10, 19));

  23. }

  24. return m_buffer;

  25. }

  26. Read IDE hard drive serial number under Windows nt/2000/xp

  27. BOOL cgethdscriai::winntreadidehdserial (dword* buffer)

  28. {

  29. BYTE jdoutcmd [sizeof (Sendcmdoutparams) +idfntify_buffer_size-1];

  30. BOOL bflag = FALSE;

  31. int drive = 0;

  32. Char drivename[256];

  33. HANDLE hphysicaldriveloctl=0;

  34. Sprintf (DriveName, "\.\physicaldrive%d", drive);

  35. Administrator permissions are required to create files under Windows nt/2000/xp

  36. Hphysicaldriveioctl=createfile (drivename,generic_read| Generic_write,
    39.file_share_read| File_share_write,null,open_existing,0,null);

  37. if (Hphysicaldriveioctl!=invalid_handle_value)

  38. {

  39. Getversionoutparams Versionparams;

  40. DWORD cbbytesreturned=0;

  41. Get the I/O controller version of the drive

  42. Memser ((void*) &versionparams,0,sizeof (versionparams));

  43. if (DeviceIoControl (Hphysicaldriveioctl,ioctl_get_version,null,
    48.0,&versionpaiams,sizeof (Versionparams), sizeof (Versionparams),

  44. &cbbytesreturned,null))

  45. {

  46. if (versionparams.bidedevicemap>0)

  47. {

  48. BYTE bidcmd=0;//ide or ATAPI recognition command

  49. Sendcmdinparams Scip;

  50. 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

  51. Bidcmd= (versionparams.bidedevicemap?drive&0x10)?
    58.ide_atapi_identify:ide_ata_identify;

  52. memset (&scip,0,sizeof (SCIP));

  53. memset (idoutcmd,0,sizeof (idoutcmd));

  54. Get drive information

  55. if (Winntgetidehdinfo (Hphysicaldriveloctl,&scip, (psendcmdoutparms) &
    64.IDOUTCMD, (Byte) Bidcmd, (byte) drive,&cbbytesreturned))

  56. {

  57. int m=0;

  58. USHORTpldsector= (USHORT) ((psendcmdoutparams) idoutcmd)->bbuffer;

  59. for (m=0;m<256;m++)

  60. BUFFER[M]=PIDSECTOR[M];

  61. Bflag=true; Read hard disk information successfully

  62. }

  63. }

  64. }

  65. CloseHandle (HPHYSICALDRIYEIOCTL); Close handle

  66. }

  67. Return Bflag;

  68. }
    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.{

    1. if (g_nsofttype==1) {

    2. if (Demoisovertime ())

    3. return FALSE;

    4. }

    5. else if (g_nsofttype==2) {

    6. if (! Isinstalledsoft ())

    7. return FALSE;

    8. }

    9. else if (g_nsofttype==3) {

    10. if (! Dog ()) {

    11. AfxMessageBox ("You do not have a software dog installed, please purchase genuine software.") \ n \ nyou are sorry ... ");

    12. return flase;

    13. }

    14. }

    15. if (!g_bdemo) {

    16. CCommandLineInfo Cmdinfo;

    17. ParseCommandLine (Cmdinfo);

    18. }
      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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.