Click here to Skip to main content
11,721,385 members (79,845 online)
Click here to Skip to main content

Locking shareware functions

, 18 Sep 2003 CPOL 63.5K 775 33
Rate this:
Please Sign up or sign in to vote.
This article describes how to lock some functions in a shareware product. Users can unlock them only after obtaining keyfile

Introduction

If you're shareware programmer, you may need to lock some functions of your product from unauthorized access. Problem is that hackers can unlock these functions without your permission. Smile | :) In this article I'll show how to lock shareware functions and to reduce of risk of a hacker cracking your product.

Background

Basic idea is that we call hidden shareware functions by its address, which we pass to user in key file. In this case, hacker can't crack the program because he cannot determine the necessary address of a protected function. In the provided demo project, the address of function is stored in an open kind ( pass.txt file), but nothing hinders you to encrypt this address by user's hard disk serial number, for example.

The required Steps

  1. Let's find out the address of the function:
    // somewhere in program body our shareware function lives 
    void HiddenPaintFunc(DWORD pv,DWORD pp)
    
    {
        //...
    }
    
    
    BOOL CSharewareDialog::OnInitDialog()
    {
    //
    // let's find out its address. It can be done with debugger, 
    // or simply like this:
    
    CString strAddress;
    strAddress.Format("0x%X",HiddenPaintFunc);
    AfxMessageBox(strAddress);// this string need to be commented  
                              // after obtaining an address
    ...
  2. Create a key file in hex editor and write an address to it ( don't forget about the return order - for example: 00401602 -> 02164000)
  3. At last, instead of a customary function call, we write the following :
    void CSharewareDialog::INeedCallLockedFunction(CDC*pDC)
    {
                  FILE*pFile=NULL;
      pFile=fopen("C:\\pass.txt","r");// open key file
      if(pFile){
                  DWORD dwHidden=0;
      fread((void*)&dwHidden,4,4,pFile);
      fclose(pFile);
      if(dwHidden){
      try{
         DWORD dwParam=(DWORD)pDC;
         DWORD dwParam2=(DWORD)this;
        
        __asm{
        
        xor ebx,ebx
        mov ebx,dwParam // pass some parameters
        push ebx
        mov ebx,dwParam2
        push ebx
        call dwHidden    // address of function we've got from key file
                         // if key file is wrong - jump to anywhere
    
      }
    
    
    
      }
      catch(...){
    
        AfxMessageBox("You must register this program.");
    
      }
      }
      else
      {
    
            AfxMessageBox("You must register this program.");
    
      }
      }
       else
      {
    
            AfxMessageBox("You must register this program.");
    
      }       
    
    }
  4. That's all.

Notes

It is necessary to keep track of the address of the shareware function, as it may be changed from build to build.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

va_dev
Software Developer
Russian Federation Russian Federation
Professional Windows/Java Mobile/Web-applications developer since 2000.

You may also be interested in...

Comments and Discussions

 
GeneralImproving Pin
winx26-Jan-06 21:30
memberwinx26-Jan-06 21:30 
General:-) nice Pin
MREBI24-Sep-03 4:49
memberMREBI24-Sep-03 4:49 
Generalgood try, but too easy to crack Pin
TekCat23-Sep-03 21:20
memberTekCat23-Sep-03 21:20 
Questionwhat ? Pin
Anonymous20-Sep-03 1:39
sussAnonymous20-Sep-03 1:39 
AnswerRe: what ? Pin
John M. Drescher20-Sep-03 5:35
memberJohn M. Drescher20-Sep-03 5:35 
GeneralRe: what ? Pin
Colin Angus Mackay3-Dec-03 14:39
memberColin Angus Mackay3-Dec-03 14:39 
John M. Drescher wrote:
there is a possibility of the code not being where you would expect

I'm sure there is a compiler option that allows the developer to set the base address of the application. So would this be much of an issue.

--Colin Mackay--

"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)


GeneralRe: what ? Pin
John M. Drescher3-Dec-03 15:00
memberJohn M. Drescher3-Dec-03 15:00 
GeneralNot sure if this such a good idea Pin
Brian Shifrin20-Sep-03 1:25
memberBrian Shifrin20-Sep-03 1:25 
GeneralRe: Not sure if this such a good idea Pin
CyberSky20-Sep-03 9:56
memberCyberSky20-Sep-03 9:56 
GeneralRe: Not sure if this such a good idea Pin
Anatoly Ivasyuk20-Sep-03 10:02
memberAnatoly Ivasyuk20-Sep-03 10:02 
GeneralAvoid AfxMessageBox... Pin
Stephane Rodriguez.18-Sep-03 23:22
memberStephane Rodriguez.18-Sep-03 23:22 
QuestionOpen file in text mode?? Pin
Anonymous18-Sep-03 23:20
sussAnonymous18-Sep-03 23:20 
GeneralBuffer overflow Pin
Anonymous18-Sep-03 23:16
sussAnonymous18-Sep-03 23:16 
GeneralTurns out to be the same as every cracking problem Pin
Anonymous18-Sep-03 23:12
sussAnonymous18-Sep-03 23:12 
GeneralCrashes in debug mode. Pin
WREY18-Sep-03 20:50
memberWREY18-Sep-03 20:50 
GeneralA good try, but not foolproof. Pin
WREY18-Sep-03 20:20
memberWREY18-Sep-03 20:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.150901.1 | Last Updated 19 Sep 2003
Article Copyright 2003 by va_dev
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid