Friday, October 21, 2011

copy protect in VB

// Visual Basic or MS Access Subroutine
'
' *** Visual Basic and MS Access Sample Code ***
'
' This code should work with MS Access and Visual Basic and FoxPro
' and any other Microsoft products that employ OLE Automation with
' their string types.
'
' The problem with MS Access and Visual Basic is something called
' OLE Automation (or just Automation now). This DLL handles OLE Automatation
' and Widestrings.
'
' This is sample code showing how to perform a CRC Check and Lock Check.
' Using this code approach will ensure that your application is very secure.
' All integrity checking is performed internally by the lock except for
' checking that the DLL has not been replaced. That is why you must add
' the CRC check for ZSSGLOCKOLE2.DLL.
'
' CRC CHECK:
' This routine calls the DLL function passing the Filename.
' The Hex Result SHOULD BE returned by the DLL. It will contain
' the actual CRC value of the filename. If it does not match the
' expected value then shutdown your application.
'
' Set the hex value to "4F2369A0". This is the current CRC for
' ZSSGLOCKOLE2.DLL (at least it is for the version V2.0 I checked.
' Check to ensure that your version is the same.
' You can use ShareGuard Locksmith Tools page CRC Check to find
' the actual hex value that you should pass.
'
' LOCK CHECK:
' This routine calls the DLL function passing the ShareGuard Lock parameters.
' The Reason Code SHOULD BE returned by the DLL. It will contain
' the status of the software. If it does not match the expected value then
' shutdown your application. Only reason code 0 is valid.
'
' Reason Codes:
' 0 - OK
' 1 - CRC Check failed, DLL Missing
' 2 - CRC Check failed, product modifed-incorrect version/tampered by user
' 3 - Invalid Registration
' 4 - Demo Expired

' 5 - Parameters missing or invalid - ZSSGL.EXE parms
' 6 - System Migrated to another computer
' 7 - ZSSGL.EXE program missing
'
' Do not forget to set the current directory to wherever ZSSGL.EXE and
' the DLLs reside.
'
Private Sub Command1_Click()

Option Compare Database
Option Explicit
Private Declare Function ShareGuardLock Lib "ZSSGLOCKOLE2.dll"
(ByVal FileName As String) As String
Private Declare Function CRC32FileCheck Lib "ZSSGCRCOLE2.dll"
(ByVal FileName As String) As String

' CRC Check Declaratives
Dim strFileName As String * 255
Dim strHexResult As String * 16 ' WideString returned
Const FILE_NAME As String = "ZSSGLOCK.DLL"
Const HEX_VALUE As String = "4F2369A0"
Const SW_SHOW As Integer = 1

' Lock Declaratives
Dim strLockParms As String * 255
Dim strResult As String * 1 ' WideString returned
' ShareGuard Lock Parameters generated by Locksmith on the Lock page
Const LOCK_PARMS As String = "ZSSGL.EXE /D /A030 /R030 /$0.00
/KDC97C8877E90E509 /LDA768175D525C0F8
/Hwww.zappersoftware.com /Msales@zappersoftware.com
/NWilliam_Bradshaw /OSample /PSAMPLE.EXE
/Uwww.zappersoftware.com/Sample/samplepurchase.php /TSample_Demo"
Const RETURN_OK As String = "0"

' Do not forget to set the current directory to wherver ZSSGL.EXE resides
strFileName = FILE_NAME
strHexResult = CRC32FileCheck(strFileName)
' If it is not correct then shutdown
' If it does match then the ZSSGL.EXE has NOT been modified by anybody.
if strHexResult = HEX_VALUE then
' Nobody has modified it so continue processing
' Display the CRC value for testing
MsgBox strHexResult ' Remove this line after testing
Else
' DO NOT Allow anybody to replace the ShareGuard Lock DLL
MsgBox "ERROR: Lock library program has been modified"
MsgBox strHexResult ' Remove this line after testing
' Shutdown your application...
End If

strLockParms = LOCK_PARMS
strResult = ShareGuardLock(strLockParms)
' If it is not a reason code of zero then shutdown
if strResult = RETURN_OK then
' Demo is still alive or this is a purchased version -
' allow user to continue
MsgBox strResult ' Remove this line after testing
Else
MsgBox "ERROR: Demo program expired or
system has been tampered with."
MsgBox strHexResult ' Remove this line after testing
' Shutdown your application...
End If
'
' You could test each return code and issue different
messages based upon the reason.

End Sub