Friday, April 16, 2010

Using Activelock

Activelock is an open source software licensing and copy protection component for windows applications. Its source is available in VB6 and VB.NET.

Prerequisites
Visual Studio 6 with SP6
MSXML 4
Visual Studio 2008
IIS with ASP.NET configured (only for testing web integration)

Version used
Activelock 3.6.0.3
Visual Studio 6 with SP6
.NET framework 3.5
Visual Studio 2008 Express edition
IIS on Windows XP (IIS 5.1)


Installation
  1. Download the VB6 and VB2008 core dlls and source code packages from the activelock website, activelocksoftware.com
  2. Run the setup programs to install the activelock files

Customizing the VB6 dll
  1. Copy the contents of the dll source folder C:\Program Files\Activelock_VB6_3.6\Activelock3.6 for VB6 to your own folder e.g. C:\MyLock
  2. Copy the contents of the test application folder C:\Program Files\Activelock_VB6_3.6\ALTestApp3.6 for VB6 to your own folder e.g. C:\MyLock TestApp
  3. Using the code in the C:\MyLock folder, open the file ActiveLock3.vbp
  4. Save the project with a different name e.g. MyLock.vbp
  5. Change the name of the project under project properties e.g. MyLock
  6. Right click on the project and click on the properties menu
  7. Clear the help file text box
  8. Change the project description text box e.g. MyLock
  9. In the make tab, change the version number e.g. 1.0.0
  10. Change the application title e.g MyLock
  11. Change all the items under version information as desired
  12. Open a code window and replace all occurrences of the string ActiveLock3 with e.g. MyLock. Ensure the Find whole word only option is selected.
  13. In activelock.cls, change the value of the AL_REGISTRY_HIVE$ constant
  14. In activelock.cls, modify the ValidateShortKey procedure. Comment out the section referring to alcrypto, only leaving the automatic registration code. If you don't want the short key to be tied to a specific computer, comment out the line fprint = modHardware.GetFingerprint()
  15. In activelock.cls, modify the IactiveLock_InstallationCode Get procedure. Don't pass the fingerprint to the GenerateShortSerial function. This is also only if the short key isn't required to be tied to a specific computer
  16. Make any other customizations as required
  17. Add a reference to the Microsoft WMI Scripting V1.1 Library
  18. If you don't have MDAC 2.8, remove the existing reference and select the reference for the highest version of Microsoft ActiveX Data Objects Library you have.
  19. Compile the dll, giving it a different name e.g MyLock.dll
  20. Select the project properties, and under the component tab, set version compatibility to binary compatibility, referencing the dll just compiled.
  21. Compile the dll again.
  22. Close the project.

Customizing the key generator
  1. Using the code in the C:\MyLock folder, open the file Alugen.vbp
  2. Save the project with a different name e.g. MyGenerator.vbp
  3. Change the name of the project e.g. MyGenerator
  4. Open a code window and replace all occurrences of the string ActiveLock3 with the same name used in the dll e.g. MyLock
  5. Under project references, remove the reference to the ActiveLock Object Library 3.6 and add a reference to the modified dll you've compiled e.g MyLock.dll.
  6. Build the exe, giving it a different name e.g. MyGenerator.exe
  7. Close the project

Customizing the test application
  1. Using the code in the C:\MyLock TestApp folder, open the file ALVB6Sample.vbp.
  2. Save the project with a different name e.g. MyLockTestApp.vbp
  3. Open a code window and replace all occurrences of the string ActiveLock3 with the same name used in the dll e.g. MyLock
  4. Under project references, remove the reference to the ActiveLock Object Library 3.6 and add a reference to the modified dll you've compiled.
  5. In the form_load procedure of frmMain, comment out the line with CheckForResources
  6. In the form_load procedure of frmMain, modify the software password e.g. .SoftwarePassword="pass"
  7. In the form_load procedure of frmMain, modify the licence key type to .LicenseKeyType = alsShortKeyMD5. Only if a short key will be used
  8. Build the exe, giving it a different name e.g. MyLockTestApp.exe
  9. Close the project

Generating an installation code
  • Create a new project and add two text boxes to it, txtUser and txtInstallCode
  • Add a reference to the modified dll, MyLock.dll
  • Open a code window and paste the following code
Option Explicit

Private ActiveLock As DVTransManager.IActiveLock
Private WithEvents ActiveLockEventSink As ActiveLockEventNotifier

Private Sub Form_Load()
    InitializeActiveLock
End Sub

Private Sub txtUser_Change()
    txtInstallCode.Text = ActiveLock.InstallationCode(txtUser.Text)
    
    On Error GoTo 0
    Exit Sub
End Sub

Private Sub InitializeActiveLock()
    Set ActiveLock = DVTransManager.NewInstance()
    
    Set ActiveLockEventSink = ActiveLock.EventNotifier
    
    With ActiveLock
        .SoftwareName = "ALVB6Sample"
        .SoftwareVersion = "3.6"
        .SoftwarePassword = "pass"
        .SoftwareCode = "RSA1024BgIAAAAkAABSU0ExAAQAAAEAAQCBcwKp9p1rkQhZyxTeREh9EM273wBqpODS+KLkeu/xn/Q0+w8uhBQfZq8f/sdRfL+S5LIBItOv0okG42mKcaNk0mRoSoJkUPMrRp43j8nAKVCmRrD7pZ1Do3uHM4SjydLY0omeK8vOCyZ2WldYy0IxwgQjNqMHLuG1rCg1DR4+5g=="
        
        .LicenseKeyType = alsShortKeyMD5
        .LockType = lockNone
    End With
   
    ActiveLock.Init
End Sub

  • Run the program and in the txtUser text box, type in "test"
  • Copy the installation code displayed

Generate and test a licence key
  1. Run MyGenerator.exe
  2. In the licence keygen tab, make sure the product is ALVB6Sample – 3.6
  3. Paste the installation code in the installation code text box
  4. In the user name text box, type in "user"
  5. Click on the Generate button to generate the licence key
  6. Run MyLockTestApp.exe
  7. In the user name text box, type in "user"
  8. In the installation code text box, paste the installation code used in the key generator
  9. In the liberation key text box, paste the licence key generated by the key generator
  10. Click on the Register button
  11. Registration should be successful, indicating that you have successfully created a licence key and had it verified.

Using with a new product
  1. For your own custom application, you start by creating a new product in the key generator.
  2. Type in a name and version for your product and click on the Generate button to generate the product codes. The codes are a public/private key-pair with the Vcode being the public key, and the Gcode the private key. The codes are specific to a particular product name and version combination
  3. Click on Add to product list to add the new product to the list of known products
  4. The source code in the test application can be used as a guide for your own windows application. Further customization would be required e.g to include different product details, and apply custom stealth measures if desired.


Customizing the VB.NET version
To customize the VB.NET version of Activelock, download and install the corresponding VB.NET package and make code changes in the same places as the VB6 version.
The product codes, installation codes and licence keys [liberation keys] generated by the VB.NET and VB6 versions are not the same. This means a licence key generated by the VB.NET key generator will not be valid when an attempt to register the licence is made from the VB6 component and vice versa.


Web integration for the VB6 version
One may require to automate licence key generation and distribution through a website. If your windows application is using the VB6 component to verify licence keys, you'll need to generate keys using the VB6 key generator.
  1. Download and install the VB6 version of Activelock
  2. Copy the following files from C:\Program Files\Activelock_VB6_3.6\Activelock3.6 for VB6 to your own folder e.g. C:\MyWebGenerator. modActiveLock.bas, modALUGEN.bas and modWindowsVersion.bas.
  3. Open the VB6 IDE and create a new ActiveX DLL project
  4. Give the project a name e.g. MyWebGenerator and change the name of the default class e.g WebGenerator and save the project to the folder you created e.g. C:\MyWebGenerator
  5. Add the module files to the project
  6. Open the project file Alugen.vbp from C:\Program Files\Activelock_VB6_3.6\Activelock3.6 for VB6
  7. Create a public function in you class e.g. GenerateLicenceKey and use code from the cmdKeyGen_Click procedure of the Alugen project to implement the licence key generation as per your requirements.
  8. Declare a private class variable for the Activelock object and use the InitActiveLock procedure from frmMain in the Class_Initialize method.
  9. Add a project reference to the VB6 Activelock dll, perhaps one which you've modified and compiled.
  10. Compile your new dll e.g. MyWebGenerator.dll

Using the VB6 key generation dll in an ASP.NET website
  1. Set up an IIS server that can serve ASP.NET pages
  2. Copy MyWebGenerator.dll to the web server, if it's on a different machine, e.g to a folder C:\Components
  3. Register MyWebGenerator.dll on the web server
  4. Use the tlbimp.exe utility that comes with the .NET framework to create a runtime callable wrapper for the ActiveX dll you've just compiled. This is to allow you to use the functions of the dll from a .NET development environment just like it was a .NET component.
  5. Search for the file tlbimp.exe on the machine and copy it to C:\Components
  6. Open a command prompt window and navigate to C:\Components
  7. Run tlbimp giving a new name for the .NET wrapper. The syntax to use would be something like tlbimp MyWebGenerator.dll /out:MyWebGeneratorRCW.dll /verbose
  8. Create a new website project e.g using Visual Web Developer Express edition
  9. Under the Website | Add Reference menu, browse and add a reference to the wrapper dll MyWebGeneratorRCW.dll
  10. Use the ildasm.exe utility that comes with the .NET framework to confirm the name of the namespace, class and methods in the wrapper dll you've just created. Run ildasm and open the MyWebGeneratorRCW.dll. The namespace is the name of the node directly under the MANIFEST node. Classes are blue nodes and interfaces are blue nodes with an I.
  11. Add a line in your webpage to import the wrapper namespace as indicated by ildasm e.g <%@ Import Namespace="MyWebGeneratorRCW" %>
  12. Instantiate and use the methods in your dll as you would any .NET component in ASP.NET.


Web integration for the VB.NET version
Create a .NET dll using code from the VB.NET ALUGEN, just like is done for the VB6 version. Since ASP.NET will use the .NET dlls without having to jump any hoops, add a reference to this dll and use as required.

5 comments:

  1. Is it possible to statically link to activelock3 so the activelock3.dll file is not necessary? Activelock3.dll works great, but I'm in need of copy protection for an application that must be run from a single .exe file (e.g. where a setup program along with registering dll files cannot be used).

    ReplyDelete
  2. I don't know if this is possible.

    ReplyDelete
  3. Great Job with ActiveLock!!!

    ReplyDelete
  4. Hi
    I'm working through your help above in VB6 but when I try to run the test vbp, I get "User-defined type not defined"
    I tried Project/References and linking ActiveLock and scripting, but still the same (and MDAC 2.8)
    Objects/Browser shows MyLock with the relevant calls, etc.
    What am I doing wrong?
    Regards
    Tony

    ReplyDelete
  5. Not sure what's going wrong, but that error seems to be something about wrong/invalid references.

    ReplyDelete