|
Introduction
After your applications are developed normally with VC++. You should protect
your codes unless your software is free.But the Cracker can crack your codes
always,the main reason about the software application cracked is that it can be
debuged by some programme debug tools,then it can be analysed statically and
dynamically.So when your application is running,and if it can prevent all
debuger tool from being executed normally,then it's almost impossible to be cracked
without a debugger.In order to do this,you must study how the debugger works and to
find how to prevent them from working,AntiDebugLIB can help you finish these heavy works and protect
your codes from being cracked.
A sample code is released in this article to show the usage of AntiDebugLIB.
How does it work?
1. AntiDebugLIB V2.3 offers some functions which need license and use the same function definition as in c++ .
2. AntiDebugLIB V2.3 offers custom function and encryption macro function,they can helps software developers encrypt their codes rapidly.
3. AntiDebugLIB V2.3 offers a powerful PE Protector tool--Eagle Protector V2.3 .
After your applications are developed normally with VC++,only four steps left as follows:
Step 1
Replace the c++ function with AntiDebugLIB's function simply in your non-sharing codes or key codes.
Show example
#ifndef _ANTIDEBUG
strcpy(buffer,mess);
#else
GJ_strcpy(buffer,mess);
#endifStep 2
Use AntiDebug LIB's custom functions to create self-engendered function codes.
Step 3
Insert AntiDebug LIB's encryption macros to mark regions of codes that need to be encrypted.
Step 4
Rebuild project and encrypt the release PE file with Eagle Protector V2.3.
1.AntiDebugLIB Files
File Name
Comment
antidebug.h Function Library's header file. antidebug.lib Function Library file.(included in ADL_Register.EXE) gjglly.sys AntiDebugLIB driver file. included in ADL_Register.EXE) ADL_Register.EXE AntiDebugLIB License generation tool and PE file protection tool. AntiDebugLib.CHM AntiDebugLIB help file.
2.Programme Developing EnvironmentOS: Windows XP/2003/Vista/2008/7 (X86)
IDE:Microsoft Visual Studio 2008 / C++Builder / Delphi / VB6.0.3.Illustration
The follow steps will start from scratch to create a demo project to demonstrate usage of AntiDebugLIB.You can download “antidebug_demo” here firstly, rebuild it directly and get the first impression.You should refer to the article "How to build antidebug_demo project?" to solve the building problems.
3.1 Programme Design
(1) Open “Microsoft Visual Studio 2008”,select “File | New | Project” menu command ,popup “New Project” window,select Project types:“Visual C++ | MFC”,select Templates:“Visual Studio installed templates |MFC Application”,confirm the project's name is “antidebug_demo”,and select directory.
(2) In the popup “MFC Application AppWinzard - Application Type” dialog box,select the type of application to “Single document”.
(3) The follow steps,keep the default setting,at last click [Finish] button.
(4) Add two menu command:"Display Hello World !" and "Display Hello AntiDebug !"
Show illustration
(5) Map menu command function by Event Handler Wizard:
void CAntidebug_demoDoc::OnDisplayHelloWorld().
void CAntidebug_demoDoc::OnDisplayHelloAntidebug().Insert the following code:
Show Code
//File: antidebug_demoDoc.cpp
//Antidebug LIB Demo Code
void CAntidebug_demoDoc::OnDisplayHelloWorld() //share function
{
// TODO: Add your command handler code here
char mess[]="Hello World !";
char buffer[100];
strcpy(buffer,mess);
AfxMessageBox(buffer);
}
void CAntidebug_demoDoc::OnDisplayHelloAntidebug() //no share function
{
// TODO: Add your command handler code here
char mess[]="Hello Antidebug !";
char buffer[100];
strcpy(buffer,mess);
AfxMessageBox(buffer);
}
//Antidebug LIB Demo Code
(6) After finished,antidebug_demo can display two MessageBox :"Hello World ! " and "Hello AntiDebug ! ",it's free and no License.
3.2 Encrypte Programme
(1) Copy antidebug.h and antidebug.lib into the antidebug_demo project directory(\antidebug_demo\).
(2) Select “Project | Protertys” menu command,Only set "Win32 Release" .
Add "antidebug.lib setupapi.lib NETAPI32.LIB" into Linker's input Additional Dependencies edit box.Show illustration
Set "Buffer Security Check" to "NO(/GS)" .
Show illustration
Set "Data Execution Prevention(DEP)" to "Default" or "Image is not compatible with DEP(/NXCOMPAT:NO)".Show illustration
Set "Randomized Base Address" to "Disable Image Randomization ".
Show illustration
Set "UAC Execution Level " to "requireAdministrator".
Show illustration
(3) Add codes into antidebug_demoDoc.h file:
Show Code
//#####################################################################
//Antidebug LIB Demo Code#ifndef _DEBUG //If define _DEBUG,we don't use the AntiDebugLIB in order to debug the program.
#include "antidebug.h"
#define _ANTIDEBUG //If define _ANTIDEBUG,the no shared functions can't be debugged.#define _TRIAL_VERSION //If define _TRIAL_VERSION,we use the AntiDebugLIB's demo function,
// and use Eagle Protector Trial Version to encrypt the antidebug_demo.exe.
//If no define _TRIAL_VERSION,we use the registered version function of AntiDebugLIB,
// and use Eagle Protector Registered Version to encrypt the antidebug_demo.exe.
//This is very important ! You mustn't cross them.//If define _TRIAL_VERSION,and use Eagle Protector Trial Version to encrypt the antidebug_demo.exe,
//all encryption macro will be ignored.
// That means only Registered Version supports the encryption macro.
#endif//Antidebug LIB Demo Code
//#####################################################################
(4) Add codes into antidebug_demoDoc.cpp file:
Show Code
/////////////////////////////////////////////////////////////////////////////
// CAntidebug_demoDoc construction/destructionCAntidebug_demoDoc::CAntidebug_demoDoc()
{
// TODO: add one-time construction code here
//#####################################################################
//Antidebug LIB Demo Code#ifdef _ANTIDEBUG
GJ_ENCRYPT_CODE_START //$$$$$$$$$$$$$$$$$$$$$$$$$$$ ENCRYPTION MACRO START
if(GJ_Install_AntiDebugLIB())
{
AfxMessageBox("Install AntiDebugLIB Successfully !"); //Here it is only a demo code,you should use "//" to clear it.
}
else
{
AfxMessageBox("Install AntiDebugLIB Unsuccessfully !"); //Here it is only a demo code,you should use "//" to clear it.
}
#ifdef _TRIAL_VERSION
char antidebug_userid[]=
"088A8EA376ECBE1F141F83C99946A068BE7681469A4157CDE99E2EECEF6133054E50DC281402D4F0A361D9486804ADFE";
//antidebug_userid is generated by AntideBug LIB REGISTER programme.
//Here is the antidebug demo userid.
char antidebug_licence_filename[]="antidebuglib_demo.lic";
//antidebuglib_demo.lic is generated by AntideBug LIB REGISTER programme(ADL_Register.EXE).
//Here is the antidebug demo license.
//antidebuglib_demo.lic is in the current directory.#else
char antidebug_userid[]="**********************************your userid goes here******************************************";
//antidebug_userid is generated by AntideBug LIB REGISTER programme.
char antidebug_licence_filename[]="antidebuglib.lic";
//antidebuglib.lic is generated by AntideBug LIB REGISTER programme(ADL_Register.EXE).
#endif
BYTE append_data[]={'1','2','3','4','5','6'}; //AntiDebug LIB provides two kinds of version: Ultimate and Professional Version.
//Only Ultimate Version can use appending datas to generate license file.
//
//If no appending datas(e.g. hardware serial number or programme code fingerprint
//data generated by MD5.) are supplied or AntiDebug LIB's Version is Professional,
//set antidebug_licence_filename=NULL,antidebug_append_data_len=0.
//
//The format of appending data file can be found in the help document.It is very simple:
//Just save all datas to a file.//When generate the demo license by AntideBug LIB REGISTER programme,
// please use antidebug_append.dat in the current directory(\antidebug_demo).UINT antidebug_append_data_len=6; //MAX_LENGTH<300
if(!GJ_IsAntidebugWorking())
{
MessageBox(NULL,
"AntiDebug LIB DRIVER isn't installed or started,
Antidebug_demo programme will EXIT !",
"Antidebug Demo",MB_ICONINFORMATION
);
//Here it is only a demo code,you should use "//" to clear it.
ExitProcess(0);
};
#ifdef _TRIAL_VERSION
GJ_OpenAntidebug_demo(antidebug_userid,
antidebug_licence_filename,
antidebug_append_data_len,
append_data
);
#else
GJ_OpenAntidebug(antidebug_userid,
antidebug_licence_filename,
antidebug_append_data_len,
append_data
);
#endif
//TEST IF REGISTER OK
//Not only the GJ_add function but also the others can do the same thing.
int a=1;
int b=2;
int c=a+b;
#ifdef _TRIAL_VERSION
a=GJ_add_demo(a,b);
#else
a=GJ_add(a,b);
#endif
if(a==c)
{
AntiDebug_Reg_OK=TRUE;
AfxMessageBox("Register Successfully !"); //Here it is only a demo code,you should use "//" to clear it.
}
else
{
AntiDebug_Reg_OK=FALSE;
AfxMessageBox("Register Unsuccessfully !"); //Here it is only a demo code,you should use "//" to clear it.
}
//TEST IF REGISTER OK
GJ_ENCRYPT_CODE_END //$$$$$$$$$$$$$$$$$$$$$$$$$$$ ENCRYPTION MACRO END
#endif
//Antidebug LIB Demo Code
//#####################################################################}
CAntidebug_demoDoc::~CAntidebug_demoDoc()
{
//#####################################################################
//Antidebug LIB Demo Code#ifdef _ANTIDEBUG
#ifdef _TRIAL_VERSION
GJ_CloseAntidebug_demo();
#else
GJ_CloseAntidebug();
#endif
GJ_Remove_AntiDebugLIB();
GJ_MACRO_END //This MACRO should be executed only once
#endif
//Antidebug LIB Demo Code
//#####################################################################
}
(5) Revise non-sharing function code .
Show Code
//File:antidebug_demoDoc.cpp
void CAntidebug_demoDoc::OnDisplayHelloAntidebug() //non-sharing function
{
// TODO: Add your command handler code here#ifdef _ANTIDEBUG
if(AntiDebug_Reg_OK)
{
#endifchar mess[]="Hello Antidebug !";
char buffer[100];#ifndef _ANTIDEBUG
strcpy(buffer,mess);
#else
#ifdef _TRIAL_VERSION
GJ_strcpy_demo(buffer,mess);
#else
GJ_strcpy(buffer,mess);
#endif
#endif
AfxMessageBox(buffer);
#ifdef _ANTIDEBUG
}
else
{
AfxMessageBox("Only registered user can use this function !");
}#endif
}
(6) Select “Build | Rdbuild Solution” menu command to encrypt the antidebug_demo.Now,if you want to display "Hello AntiDebug !" MessageBox,must have the License which is generated by ADL_register.exe.
(7) Custom Function
As to the very important key codes ,we recommend you strongly to use AntiDebugLIB's custom function to create self-engendered functions quickly,then the key codes become a secret except you.
There are three functions offered by AntiDebugLIB can do this job:
GJ_encrypt_custom_function.
GJ_load_custom_founction.
GJ_free_custom_founction.GJ_encrypt_custom_function (or GJ_encrypt_custom_function_demo) is only used in another private project,the custom function is debuged and encrypted in that project.When GJ_encrypt_custom_function (or GJ_encrypt_custom_function_demo) return TRUE,it will generate "founction_name.h" file.The encrypted code of custom function is included in it.Then include this header file into the releasing project,invoke GJ_load_custom_founction (or GJ_load_custom_founction_demo) to decrypt the custom function code and execute,when the custom function is not invoked again,invoke GJ_free_custom_founction to clear the code of custom function.
Now,we create another project named custom_function_demo in the same way just like antidebug_demo project does. The void __stdcall custom_function(...) function is the function that we want to encrypt.We can invoke void encrypt_custom_function() function to encrypt it and get a custom_function.h file which includes the encrypted code of custom_function(...).
Show void __stdcall custom_function() and void encrypt_custom_function() Code
After we get the custom_function.h,we insert the clause #include "..\\antidebug_demo\\custom_function_demo\\custom_function.h" into antidebug_demoDoc.cpp which belongs to antidebug_demo project.
//File: custom_function_demoDoc.cpp
//#####################################################################
//Antidebug LIB Demo Code//The custom_function is the name of custom function,the function must be relocation code.
//
//1:Only use local variable,don't use global variable,static variable,and constant string variable.
//2:If custom_function wants to invoke a function,the pointer of the function should be passed to it.
//
//in a word, the custom function must be relocation code.void __stdcall custom_function(int x,
int y,
char* str_a,
char* str_b,
void* (__cdecl *_memcpy )( void *dest, const void *src, size_t count ),
int (__cdecl *_sprintf )( char *buffer, const char *format, ... ),
void* (__cdecl *_malloc )( size_t size ),
void (__cdecl *_free )( void *memblock ),
size_t (__cdecl *_strlen )( const char *string ),
int (__stdcall* _MessageBox)(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)
)
{
char* pTemp;
int str_a_len=_strlen(str_a);
int str_b_len=_strlen(str_b);
pTemp=(char*)_malloc(str_a_len+str_b_len+20);if(x>y)
{
//_sprintf(pTemp,"%s%s",str_a,str_b); error:constant string variable
_memcpy(pTemp,str_a,str_a_len);
_memcpy(pTemp+str_a_len,str_b,str_b_len);
pTemp[str_a_len+str_b_len]=0;//_MessageBox(NULL,pTemp,"",MB_OK); error:constant string variable
_MessageBox(NULL,pTemp,str_a,MB_OK);
}
else
{
//_sprintf(pTemp,"%s%s",str_b,str_a); error:constant string variable
_memcpy(pTemp,str_b,str_b_len);
_memcpy(pTemp+str_b_len,str_a,str_a_len);
pTemp[str_a_len+str_b_len]=0;//_MessageBox(NULL,pTemp,"",MB_OK); error:constant string variable
_MessageBox(NULL,pTemp,str_b,MB_OK);
}for(int i=0;i<10;i++)
{
int j=1;
j^=i;
}_free(pTemp);
}void __stdcall custom_function_END() //In order to calculate the length of custom function,
// custom_function_END function must follow on the heels of custom_function.
{
}#ifdef _ANTIDEBUG
void encrypt_custom_function()
{
void ( __stdcall *_custom_function)( int x,
int y,
char* str_a,
char* str_b,
void* (__cdecl *_memcpy )( void *dest, const void *src, size_t count ),
int (__cdecl *_sprintf )( char *buffer, const char *format, ... ),
void* (__cdecl *_malloc )( size_t size ),
void (__cdecl *_free )( void *memblock ),
size_t (__cdecl *_strlen )( const char *string ),
int (__stdcall* _MessageBox)(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)
);
void ( __stdcall *_custom_function_END)();
unsigned int n_custom_function_size;
char* function_name="custom_function";
_custom_function=custom_function;
_custom_function_END=custom_function_END;
n_custom_function_size=abs((INT)_custom_function_END-(INT)_custom_function)+1; //calculate the length of custom function
#ifdef _TRIAL_VERSION
BOOL nstatus=GJ_encrypt_custom_function_demo((BYTE*)_custom_function,n_custom_function_size,function_name);
#else
BOOL nstatus=GJ_encrypt_custom_function((BYTE*)_custom_function,n_custom_function_size,function_name);
#endif
if(nstatus)
{
AfxMessageBox("The custom function is encrypted successfully ! The encrypted code is included in custom_function.h file.");
}
else
{
AfxMessageBox("The custom function is encrypted unsuccessfully !");
}}
#endif
//Antidebug LIB Demo Code
//#####################################################################Show custom_function.h Code
//custom_function.h
//Created by AntiDebug LIB
//Http://www.antidebuglib.com
unsigned char custom_function_00001_code[]="\
\xa5\x3f\x84\x0b\x63\x23\x34\x9f\xc1\x51\xc5\xb7\x21\xbb\x13\xe8\x4a\x77\xaa\x2a\
\x1e\xfc\x89\xfc\x54\x0f\x48\xfc\x50\x45\xfb\xbe\x28\xe6\x65\x53\x2f\xc5\x16\x4c\
\x84\xd6\x67\x9d\xbf\x49\x1b\x48\x64\x5d\xe7\xe9\x18\x14\x8b\xed\xed\x51\xd7\x75\
\x5b\x2e\xc2\x55\x96\x25\x07\xa8\x40\x6c\xb7\x3e\x52\xdd\x3f\x0c\x81\x44\x8b\xd0\
\xce\x7d\xa3\x49\x02\x0f\x8d\xbb\xeb\x9f\x48\xed\x09\xa7\xae\x30\x41\x7b\xc1\xaa\
\xb7\xbd\x91\xdd\xe8\xe8\xe5\xd4\x65\xae\xa7\xb3\x8a\x03\x21\x11\x08\xd7\x32\xcb\
\xf9\x60\x94\x49\x8e\xc4\xbe\x1a\xcb\x25\xbc\xa9\x49\x69\x8c\x56\x8e\x12\xc1\x83\
\x71\x84\xa9\xb4\xd3\x76\x8f\x5d\x03\xfc\x47\xfe\xc8\x8a\x2e\x59\x88\x98\x72\x90\
\xa5\x2f\xd5\x13\x0c\x00\x2b\x66\x66\x2b\x66\x66\x2b\x66\x66\x2b\x66\x66\x2b\x66\
\xe1";
#define custom_function_00001_code_LEN 181#define custom_function_ARRAY_NUM 1
#define custom_function_CODE_LEN 181
Show CUSTOM FUNCTION TEST Code
//File: antidebug_demoDoc.cpp
//Antidebug LIB Demo Code 2: CUSTOM FUNCTION TEST
#ifdef _ANTIDEBUG
//Explanation:custom_function is the name of custom function.
//The custom_function.h head file is generated by the custom_function_demo Project.
#include "..\\antidebug_demo\\custom_function_demo\\custom_function.h"
#define _founc(x) custom_function_##x##_code
#define _founc_len(x) custom_function_##x##_code_LEN
unsigned char* p_custom_function;
//1: Load custom function.
// First assemble cryptograph of custom function into one buffer,
// then invoke GJ_load_custom_function_demo(BYTE* custom_function_code,int custom_function_length).
void Load_custom_function()
{
int code_len=custom_function_CODE_LEN;
unsigned char* pcode=(unsigned char*)malloc(code_len*sizeof(unsigned char));
if(pcode==NULL)
{
#ifdef _DEBUG
AfxMessageBox("Memory used up!");
#endif
return;
}
GJ_ENCRYPT_CODE_WITH_LIC_START //$$$$$$$$$$$$$$$$$$$$$$$$$$$ ENCRYPTION MACRO START
int p;
int hp=0;
for(int k=1;k<=custom_function_ARRAY_NUM;k++){
switch (k){
//The number of case equal to custom_function_ARRAY_NUM defined in custom_function.h.
case 1:
for(p=0;p<_founc_len(00001);p++) pcode[hp+p]=_founc(00001)[p];
hp=hp+p;
break;
/*
case 2:
for(p=0;p<_founc_len(00002);p++) pcode[hp+p]=_founc(00002)[p];
hp=hp+p;
break;
case 3:
for(p=0;p<_founc_len(00003);p++) pcode[hp+p]=_founc(00003)[p];
hp=hp+p;
break;
case 4:
for(p=0;p<_founc_len(00004);p++) pcode[hp+p]=_founc(00004)[p];
hp=hp+p;
break;
*/
default:
break;
}
}
#ifdef _TRIAL_VERSION
p_custom_function=GJ_load_custom_function_demo(pcode,code_len);
#else
p_custom_function=GJ_load_custom_function(pcode,code_len);
#endif
free(pcode);
GJ_ENCRYPT_CODE_WITH_LIC_END //$$$$$$$$$$$$$$$$$$$$$$$$$$$ ENCRYPTION MACRO END
}
//2:Execute the custom function.
void Run_custom_function()
{
GJ_ENCRYPT_CODE_WITH_LIC_START //$$$$$$$$$$$$$$$$$$$$$$$$$$$ ENCRYPTION MACRO START
int x=1;
int y=2;
char str_a[]=" HELLO CUSTOM_FOUNCTION ! ";
char str_b[]=" Hello Custom_function ! ";
void* (__cdecl *_memcpy )( void *dest, const void *src, size_t count );
int (__cdecl *_sprintf )( char *buffer, const char *format, ... );
void* (__cdecl *_malloc )( size_t size );
void (__cdecl *_free )( void *memblock );
size_t (__cdecl *_strlen )( const char *string );
int (__stdcall* _MessageBox)(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType);
_memcpy=memcpy;
_sprintf=sprintf;
_malloc=malloc;
_free=free;
_strlen=strlen;
_MessageBox=MessageBox;
void ( __stdcall *_custom_function)( int x,
int y,
char* str_a,
char* str_b,
void* (__cdecl *_memcpy )( void *dest, const void *src, size_t count ),
int (__cdecl *_sprintf )( char *buffer, const char *format, ... ),
void* (__cdecl *_malloc )( size_t size ),
void (__cdecl *_free )( void *memblock ),
size_t (__cdecl *_strlen )( const char *string ),
int (__stdcall* _MessageBox)(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)
);
_custom_function=(void ( __stdcall *)(int x,
int y,
char* str_a,
char* str_b,
void* (__cdecl *_memcpy )( void *dest, const void *src, size_t count ),
int (__cdecl *_sprintf )( char *buffer, const char *format, ... ),
void* (__cdecl *_malloc )( size_t size ),
void (__cdecl *_free )( void *memblock ),
size_t (__cdecl *_strlen )( const char *string ),
int (__stdcall* _MessageBox)(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)
)) p_custom_function; _custom_function( x,
y,
str_a,
str_b,
_memcpy,
_sprintf,
_malloc,
_free,
_strlen,
_MessageBox
);
GJ_ENCRYPT_CODE_WITH_LIC_END //$$$$$$$$$$$$$$$$$$$$$$$$$$$ ENCRYPTION MACRO END
}//3:Unload the custom function.
void Free_custom_function()
{
#ifdef _TRIAL_VERSION
GJ_free_custom_function_demo(p_custom_function,custom_function_CODE_LEN);
#else
GJ_free_custom_function(p_custom_function,custom_function_CODE_LEN);
#endif
}
#endif
void CAntidebug_demoDoc::OnCustomFunctionTest() //no shared function
{
// TODO: Add your command handler code here
#ifdef _ANTIDEBUG
if(AntiDebug_Reg_OK)
{
//GJ_ENCRYPT_CODE_WITH_LIC_START //$$$$$$$$$$$$$$$$$$$$$$$$$$$ ENCRYPTION MACRO START
//NOTE: Don't use ENCRYPTION MACRO here,because MACRO NESTING will occur !
// If you do use it,the effect will be similar to the MACRO GJ_ONCE_CODE.This code will be executed only once.
Load_custom_function(); //Load
Run_custom_function(); //Execute
Free_custom_function(); //Unload
//GJ_ENCRYPT_CODE_WITH_LIC_END //$$$$$$$$$$$$$$$$$$$$$$$$$$$ ENCRYPTION MACRO END
}
else
{
AfxMessageBox("Only registered user can use this function !");
}
#endif}
For more information please refer to Atidebug_demo demo programme and Programming Self-generating Code for Windows Applications. .(8) Encryption Macro
There are four encryption macros to help the developers encrypt their code rapidly.
Only Registered Version supports the encryption macro.
GJ_MACRO_INIT GJ_MACRO_END GJ_ONCE_CODE_START GJ_ONCE_CODE_END GJ_ENCRYPT_CODE_START GJ_ENCRYPT_CODE_END GJ_ENCRYPT_CODE_WITH_LIC_START GJ_ENCRYPT_CODE_WITH_LIC_END
Show GJ_MACRO_INIT, GJ_MACRO_END Example Code
//File: antidebug_demo.cpp
CAntidebug_demoApp::CAntidebug_demoApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance//#####################################################################
//Antidebug LIB Demo Code#ifdef _ANTIDEBUG
GJ_MACRO_INIT //This MACRO should be executed only once.
#endif
//Antidebug LIB Demo Code
//#####################################################################}
// antidebug_demoDoc.cpp
CAntidebug_demoDoc::~CAntidebug_demoDoc()
{
//#####################################################################
//Antidebug LIB Demo Code#ifdef _ANTIDEBUG
#ifdef _TRIAL_VERSION
GJ_CloseAntidebug_demo();
#else
GJ_CloseAntidebug();
#endif
GJ_Remove_AntiDebugLIB();
GJ_MACRO_END //This MACRO should be executed only once
#endif
//Antidebug LIB Demo Code
//#####################################################################
}
Show GJ_ONCE_CODE_START,GJ_ONCE_CODE_END Example Code
//File: antidebug_demo.cpp
BOOL CAntidebug_demoApp::InitInstance()
{//#####################################################################
//Antidebug LIB Demo Code#ifdef _ANTIDEBUG
GJ_ONCE_CODE_START
#endif
//Antidebug LIB Demo Code
//#####################################################################AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CAntidebug_demoDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CAntidebug_demoView));
AddDocTemplate(pDocTemplate);// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);//#####################################################################
//Antidebug LIB Demo Code#ifdef _ANTIDEBUG
GJ_ONCE_CODE_END
#endif
//Antidebug LIB Demo Code
//#####################################################################// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();//#####################################################################
//Antidebug LIB Demo CodeGetCurrentDirectory(MAX_PATH,szCurrentDir);
//Antidebug LIB Demo Code
//#####################################################################return TRUE;
}
Show GJ_ENCRYPT_CODE_START,GJ_ENCRYPT_CODE_END Example Code
//File: antidebug_demoDoc.cpp
/////////////////////////////////////////////////////////////////////////////
// CAntidebug_demoDoc construction/destructionCAntidebug_demoDoc::CAntidebug_demoDoc()
{
// TODO: add one-time construction code here
//#####################################################################
//Antidebug LIB Demo Code#ifdef _ANTIDEBUG
GJ_ENCRYPT_CODE_START //$$$$$$$$$$$$$$$$$$$$$$$$$$$ ENCRYPTION MACRO START
if(GJ_Install_AntiDebugLIB())
{
AfxMessageBox("Install AntiDebugLIB Successfully !"); //Here it is only a demo code,you should use "//" to clear it.
}
else
{
AfxMessageBox("Install AntiDebugLIB Unsuccessfully !"); //Here it is only a demo code,you should use "//" to clear it.
}
#ifdef _TRIAL_VERSION
char antidebug_userid[]="088A8EA376ECBE1F141F83C99946A068BE7681469A4157CDE99E2EECEF6133054E50DC281402D4F0A361D9486804ADFE";
//antidebug_userid is generated by AntideBug LIB REGISTER programme.
//Here is the antidebug demo userid.
char antidebug_licence_filename[]="antidebuglib_demo.lic";
//antidebuglib_demo.lic is generated by AntideBug LIB REGISTER programme(ADL_Register.EXE).
//Here is the antidebug demo license.
//antidebuglib_demo.lic is in the current directory.#else
char antidebug_userid[]="**********************************your userid goes here******************************************";
//antidebug_userid is generated by AntideBug LIB REGISTER programme.
char antidebug_licence_filename[]="antidebuglib.lic";
//antidebuglib.lic is generated by AntideBug LIB REGISTER programme(ADL_Register.EXE).
#endif
BYTE append_data[]={'1','2','3','4','5','6'}; //AntiDebug LIB provides two kinds of version: Ultimate and Professional Version.
//Only Ultimate Version can use appending datas to generate license file.
//
//If no appending datas(e.g. hardware serial number or programme code fingerprint
//data generated by MD5.) are supplied or AntiDebug LIB's Version is Professional,
//set antidebug_licence_filename=NULL,antidebug_append_data_len=0.
//
//The format of appending data file can be found in the help document.It is very simple:
//Just save all datas to a file.//When generate the demo license by AntideBug LIB REGISTER programme,
// please use antidebug_append.dat in the current directory(\antidebug_demo).UINT antidebug_append_data_len=6; //MAX_LENGTH<300
if(!GJ_IsAntidebugWorking())
{
MessageBox(NULL,
"AntiDebug LIB DRIVER isn't installed or started,
Antidebug_demo programme will EXIT !",
"Antidebug Demo",MB_ICONINFORMATION
);
//Here it is only a demo code,you should use "//" to clear it.
ExitProcess(0);
};
#ifdef _TRIAL_VERSION
GJ_OpenAntidebug_demo(antidebug_userid,
antidebug_licence_filename,
antidebug_append_data_len,
append_data
);
#else
GJ_OpenAntidebug(antidebug_userid,
antidebug_licence_filename,
antidebug_append_data_len,
append_data
);
#endif
//TEST IF REGISTER OK
//Not only the GJ_add function but also the others can do the same thing.
int a=1;
int b=2;
int c=a+b;
#ifdef _TRIAL_VERSION
a=GJ_add_demo(a,b);
#else
a=GJ_add(a,b);
#endif
if(a==c)
{
AntiDebug_Reg_OK=TRUE;
AfxMessageBox("Register Successfully !"); //Here it is only a demo code,you should use "//" to clear it.
}
else
{
AntiDebug_Reg_OK=FALSE;
AfxMessageBox("Register Unsuccessfully !"); //Here it is only a demo code,you should use "//" to clear it.
}
//TEST IF REGISTER OK
GJ_ENCRYPT_CODE_END //$$$$$$$$$$$$$$$$$$$$$$$$$$$ ENCRYPTION MACRO END
#endif
//Antidebug LIB Demo Code
//#####################################################################}
Show GJ_ENCRYPT_CODE_WITH_LIC_START,GJ_ENCRYPT_CODE_WITH_LIC_END Example Code
// antidebug_demoDoc.cpp
//Antidebug LIB Demo Code 2: CUSTOM FUNCTION TEST
#ifdef _ANTIDEBUG
//Explanation:custom_function is the name of custom function.
//The custom_function.h head file is generated by the custom_function_demo Project.#include "..\\antidebug_demo\\custom_function_demo\\custom_function.h"
#define _founc(x) custom_function_##x##_code
#define _founc_len(x) custom_function_##x##_code_LENunsigned char* p_custom_function;
//1: Load custom function.
// First assemble cryptograph of custom function into one buffer,
// then invoke GJ_load_custom_function_demo(BYTE* custom_function_code,int custom_function_length).void Load_custom_function()
{
int code_len=custom_function_CODE_LEN;
unsigned char* pcode=(unsigned char*)malloc(code_len*sizeof(unsigned char));if(pcode==NULL)
{
#ifdef _DEBUG
AfxMessageBox("Memory used up!");
#endifreturn;
}GJ_ENCRYPT_CODE_WITH_LIC_START //$$$$$$$$$$$$$$$$$$$$$$$$$$$ ENCRYPTION MACRO START
int p;
int hp=0;for(int k=1;k<=custom_function_ARRAY_NUM;k++){
switch (k){
//The number of case equal to custom_function_ARRAY_NUM defined in custom_function.h.
case 1:
for(p=0;p<_founc_len(00001);p++) pcode[hp+p]=_founc(00001)[p];
hp=hp+p;
break;
/*
case 2:
for(p=0;p<_founc_len(00002);p++) pcode[hp+p]=_founc(00002)[p];
hp=hp+p;
break;
case 3:
for(p=0;p<_founc_len(00003);p++) pcode[hp+p]=_founc(00003)[p];
hp=hp+p;
break;
case 4:
for(p=0;p<_founc_len(00004);p++) pcode[hp+p]=_founc(00004)[p];
hp=hp+p;
break;
*/
default:
break;
}
}
#ifdef _TRIAL_VERSION
p_custom_function=GJ_load_custom_function_demo(pcode,code_len);
#else
p_custom_function=GJ_load_custom_function(pcode,code_len);
#endif
free(pcode);
GJ_ENCRYPT_CODE_WITH_LIC_END //$$$$$$$$$$$$$$$$$$$$$$$$$$$ ENCRYPTION MACRO END
}
//2:Execute the custom function.
void Run_custom_function()
{GJ_ENCRYPT_CODE_WITH_LIC_START //$$$$$$$$$$$$$$$$$$$$$$$$$$$ ENCRYPTION MACRO START
int x=1;
int y=2;
char str_a[]=" HELLO CUSTOM_FOUNCTION ! ";
char str_b[]=" Hello Custom_function ! ";void* (__cdecl *_memcpy )( void *dest, const void *src, size_t count );
int (__cdecl *_sprintf )( char *buffer, const char *format, ... );
void* (__cdecl *_malloc )( size_t size );
void (__cdecl *_free )( void *memblock );
size_t (__cdecl *_strlen )( const char *string );
int (__stdcall* _MessageBox)(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType);_memcpy=memcpy;
_sprintf=sprintf;
_malloc=malloc;
_free=free;
_strlen=strlen;
_MessageBox=MessageBox;void ( __stdcall *_custom_function)( int x,
int y,
char* str_a,
char* str_b,
void* (__cdecl *_memcpy )( void *dest, const void *src, size_t count ),
int (__cdecl *_sprintf )( char *buffer, const char *format, ... ),
void* (__cdecl *_malloc )( size_t size ),
void (__cdecl *_free )( void *memblock ),
size_t (__cdecl *_strlen )( const char *string ),
int (__stdcall* _MessageBox)(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)
);
_custom_function=(void ( __stdcall *)(int x,
int y,
char* str_a,
char* str_b,
void* (__cdecl *_memcpy )( void *dest, const void *src, size_t count ),
int (__cdecl *_sprintf )( char *buffer, const char *format, ... ),
void* (__cdecl *_malloc )( size_t size ),
void (__cdecl *_free )( void *memblock ),
size_t (__cdecl *_strlen )( const char *string ),
int (__stdcall* _MessageBox)(HWND hWnd, LPCTSTR lpText, LPCTSTR lpCaption, UINT uType)
)) p_custom_function;_custom_function( x,
y,
str_a,
str_b,
_memcpy,
_sprintf,
_malloc,
_free,
_strlen,
_MessageBox
);GJ_ENCRYPT_CODE_WITH_LIC_END //$$$$$$$$$$$$$$$$$$$$$$$$$$$ ENCRYPTION MACRO END
}
//3:Unload the custom function.
void Free_custom_function()
{
#ifdef _TRIAL_VERSIONGJ_free_custom_function_demo(p_custom_function,custom_function_CODE_LEN);
#else
GJ_free_custom_function(p_custom_function,custom_function_CODE_LEN);
#endif
}
#endif
void CAntidebug_demoDoc::OnCustomFunctionTest() //no shared function
{
// TODO: Add your command handler code here#ifdef _ANTIDEBUG
if(AntiDebug_Reg_OK)
{//GJ_ENCRYPT_CODE_WITH_LIC_START //$$$$$$$$$$$$$$$$$$$$$$$$$$$ ENCRYPTION MACRO START
//NOTE: Don't use ENCRYPTION MACRO here,because MACRO NESTING will occur !
// If you do use it,the effect will be similar to the MACRO GJ_ONCE_CODE.This code will be executed only once.Load_custom_function(); //Load
Run_custom_function(); //Execute
Free_custom_function(); //Unload//GJ_ENCRYPT_CODE_WITH_LIC_END //$$$$$$$$$$$$$$$$$$$$$$$$$$$ ENCRYPTION MACRO END
}
else
{
AfxMessageBox("Only registered user can use this function !");
}#endif
}
Show Usage of Encryption Macro
For more information please refer to Atidebug_demo demo programme.
(9) Insert some essential codes into Antidebug_demo's about dialog window for user to create the Serial Number expediently.
Show Code
//File: antidebug_demo.cpp
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App Aboutclass CAboutDlg : public CDialog
{
public:
CAboutDlg();//#####################################################################
//Antidebug LIB Demo Codechar adl_sn[1024];
char* szCurrentDir;
BOOL OnInitDialog();//Antidebug LIB Demo Code
//#####################################################################// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
afx_msg void OnSnCopy();
afx_msg void OnLicBrowse();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};// App command to run the dialog
void CAntidebug_demoApp::OnAppAbout()
{
CAboutDlg aboutDlg;//#####################################################################
//Antidebug LIB Demo CodeaboutDlg.szCurrentDir=szCurrentDir;
//Antidebug LIB Demo Code
//#####################################################################aboutDlg.DoModal();
}/////////////////////////////////////////////////////////////////////////////
// CAntidebug_demoApp message handlersBOOL CAboutDlg::OnInitDialog()
{//#####################################################################
//Antidebug LIB Demo Code#ifdef _ANTIDEBUG
CDialog::OnInitDialog();
if(GJ_IsAntidebugWorking())
{
char version[]="2.3.0.0"; //Don't use any other string ! This is the AntiDebugLIB interior Version.
char username[]="AntiDebug_Demo";
GJ_Create_ADL_Serial_Number(version,username,NULL,adl_sn);
CEdit* pedit=(CEdit*) GetDlgItem(IDC_EDIT_SN);
pedit->SetWindowText(adl_sn);
}
return true;
#elsereturn true;
#endif
//Antidebug LIB Demo Code
//#####################################################################}
void CAboutDlg::OnSnCopy()
{
// TODO: Add your control notification handler code here//#####################################################################
//Antidebug LIB Demo CodeHANDLE hData;
LPSTR lpData;//Allocate memory and copy the string to it
if (!(hData=GlobalAlloc(GMEM_MOVEABLE, (DWORD)strlen(adl_sn)+1)))
{
return;
}
if (!(lpData = (char *)GlobalLock(hData)))
{
return;
}
strcpy(lpData, adl_sn);GlobalUnlock(hData);
// Clear the current contents of the clipboard, and set the data handle to the new string.
if (OpenClipboard())
{
EmptyClipboard();
SetClipboardData(CF_TEXT, hData);
CloseClipboard();
}
GlobalFree (hData);//Antidebug LIB Demo Code
//#####################################################################}
void CAboutDlg::OnLicBrowse()
{
// TODO: Add your control notification handler code here//#####################################################################
//Antidebug LIB Demo CodeCFileDialog dlg(TRUE,"lic","",OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT,"(*.lic) |*.lic| All Files (*.*) |*.*|",NULL);
if(dlg.DoModal()==IDOK)
{
CString adl_license_file_name=dlg.GetPathName();char newfilename[MAX_PATH];
char filename[MAX_PATH];char* pszSlash = strrchr(adl_license_file_name.GetBuffer(5), '\\');
strcpy(filename,pszSlash);int eee=sprintf(newfilename,"%s",szCurrentDir);
sprintf(newfilename+eee,"%s",filename);if(CopyFile(adl_license_file_name.GetBuffer(5),newfilename,FALSE))
{
char mes[1024];
eee=sprintf(mes,"<%s> is copyed to <%s> successfully ! AntiDebug_demo should be restarted ! ",filename+1,szCurrentDir);
MessageBox(mes,"ADL_LICENSE",MB_OK|MB_ICONINFORMATION);
CEdit* pedit=(CEdit*)GetDlgItem(IDC_EDIT_ADL_LIC_MES);
pedit->SetWindowText(mes);
}
}
SetCurrentDirectory(szCurrentDir);//Antidebug LIB Demo Code
//#####################################################################
}
(10) At last antidebug_demo.exe should be Encrypted by Eagle Protector.
Finally,Antidebug_demo can display three MessageBox :one free "Hello World ! " MessageBox, two non-free "Hello AntiDebug ! "and "Hello Cuntom function ! "MessageBox.
Now,you can distribute trial versions of your applications with gjglly.sys securely.4.Gengerate License
(1) Paste the Serial Number copyed from user's antidebug_demo's about dialog window into the ADL Register Serial Number Edit box.
(2) Select antidebug_append.dat file for Appending Data.
(3) Click <Generate ADL DEMO LICENSE> button.
(4) Save As the LICENSE data into antidebuglib_demo.lic file and email it to the user.5.End
Above-mentioned antidebug_demo programme demonstrates the basic process and frame about how to use AntiDebug LIB to encrypt and protect application. If you have any technical problems using AntiDebug LIB or need a special feature to be included in a next release, please feel free to contact us at support@antidebuglib.com,MSN:
.Please visit our forum and leave your most valuable comments and suggestions. You can download the latest version of our products from http://www.antidebuglib.com.















