pp_lfalias()

Creates a redundant alias to an open License File

Applies to:

Win32, Win64

Syntax-VB:

Declare Function pp_lfalias(ByVal handle As Long, ByVal filename As String, ByVal flags As Long, ByVal lftype As Long, ByVal password As String, ByRef newesthandle As Long) As Long

Syntax-C:

LONG pp_lfalias(PPLFHANDLE handle, LPSTR filename, LONG flags, LONG type, LPSTR password, LPPPLFHANDLE newesthandle)

Arguments:

<handle> is the handle to the License File previously open with pp_lfopen()

<filename> is the name of the redundant License File to open. Refer to pp_lfopen() for syntax of this parameter.

<flags> is a parameter with available options, defined as:

Flag

Value

Description

LFALIAS_VERIFY_CHECKSUM

1

Verifies the integrity of the license file.

LFALIAS_FIND_RECENT

2

If License Files are different, determines which License File has a later last used date and time.

LFALIAS_OVERWRITE_OLDER

4

If License Files are different, overwrites the older License File with the contents of the new one as determined by the last used date and time.

LFALIAS_CREATE_MISSING

8

Creates alias License File automatically if missing.

LFALIAS_SCATTER

16

Please see Description section below.

LFOPEN_AS32BIT

128

Causes 64-bit applications to open system and registry based license files/aliases using 32-bit locations (SysWOW64 and Wow6432Node respectively).

LFALIAS_SCATTER_BACK

2147483648

Please see Description section below.

<lftype> is the License File type to open. Refer to pp_lfopen() for syntax of this parameter.

<password> is your unique password to use with this file. A minimum of 3 and maximum of 124 characters is allowed for a password.

<newesthandle> is the buffer to place the handle of the more recent of the two License Files if the flag LFALIAS_FIND_RECENT is used. If the files are the same, the value of 0 will be returned in this parameter; otherwise, a handle to the newest file (the one that was written last) will be returned, based upon the last used date and time fields. Set this parameter to 0 if you do not wish to obtain the newest handle.

Returns:

Refer to pp_errorstr() for a table of possible return codes and their meaning. Typically, PP_SUCCESS [1] (alias file was opened) or ERR_ALIAS_FILE_DOES_NOT_MATCH [68] (License Files do not match and LFALIAS_OVERWRITE_OLDER was not specified) is returned.

Description:

This is an extremely powerful function to help maintain License File Aliases or redundant License Files to help prevent tampering with your license data such as usage, expiration dates, and last used dates. The first step is to open the master or primary License File. Once a handle is obtained, pp_lfalias() can be called to open a redundant copy. The redundant copy is automatically created if missing when using the LFALIAS_CREATE_MISSING flag.

Once the alias file is opened, if the flag LFALIAS_VERIFY_CHECKSUM is specified, the internal checksums will be compared. If this flag is not specified and neither of the flags LFALIAS_FIND_RECENT and LFALIAS_OVERWRITE_OLDER are used, the function will return PP_SUCCESS no matter what is contained in the alias License File. The first function that writes to the License File will automatically force the contents of the alias file to be the same as the primary file.

If the files are different and the flag LFALIAS_FIND_RECENT is specified, the License File fields VAR_LAST_DATE and VAR_LAST_TIME are compared. The handle to the one that was written to last will be returned in the parameter <newesthandle>. If the date and time values are the same, the value of <handle> is returned. This can be used if you want to inspect the contents of the alias handle in the event it is more recent.

CAUTION
Only write to the License File using the primary License File as indicated by the <handle> parameter. The <newesthandle> parameter is provided to read values from the most recent file. Writing to the License File using the <newesthandle> will not write to the primary License File. Use the flag LFALIAS_OVERWRITE_OLDER to synchronize all copies with the newest data.

If the files are different and the flag LFALIAS_FIND_RECENT and LFALIAS_OVERWRITE_OLDER are specified, the License File fields VAR_LAST_DATE and VAR_LAST_TIME are compared. The one that is more recent will be copied into the one that is less recent. If the date and time values are the same, the contents of the primary License File will be copied into the alias License File. All License Files will then contain the same exact data.

It is not necessary to call pp_lfclose() for the handle contained in <newesthandle>. Simply call pp_lfclose() for the master or primary handle and all aliases will automatically be closed as well.

The LF_ALIAS_SCATTER (or LF_ALIAS_SCATTER_BACK)  flag is designed to make it more difficult for crackers to monitor the registry locations where the alias files are located with products such as RegMon or Process Monitor. When pp_lfalias is called with this flag set the function will read values from the registry and write them directly back to their original location. At a random time during this process the actual alias file will be read or created. You must specify the number of read/writes the function will perform if this flag is set. This is specified by preceding the filename string parameter with a number inside two colons. For example, to read/write 2000 existing registry locations the filename parameter would be set to :2000::LM:Software\Widget:License

Note: In versions of Protection PLUS earlier than 4.4.1.0, only :LM: is supported with the scatter flag.  Version 4.4.1.0 and later support :LM: and :CU:.  When :LM: is used, the scatter is done in HKEY_LOCAL_MACHINE\Software\Classes\CLSID.  Otherwise, if :CU: is used, the scatter is done in HKEY_CURRENT_USER\Software\Classes\CLSID.

If you are using the :LM: or :CU: shortcuts you must include both surrounding semicolons for both entries. Therefore, when using :LM: the entry would contain two semicolons between the number of scattered aliases and the LM (:2000::LM:).

This functionality has been extensively tested. On a Pentium 1Ghz machine a number of 1000 read/writes takes less than a second.

Refer to License File Alias for a description of the typical modes of this function.

Example:

' Open License File c:\test1.ini and set up

' aliases to c:\test2.ini and c:\test3.ini.

' Uses a flag value of 15 which includes the

' LFALIAS_VERIFY_CHECKSUM, LFALIAS_FIND_RECENT,

' LFALIAS_OVERWRITE_OLDER, and

' LFALIAS_CREATE_MISSING flags.

 

Dim lfhandle As Long

 

pp_lfopen "c:\test1.ini", LF_CREATE_MISSING, LF_FILE, "password", lfhandle

 

pp_lfalias lfhandle, "c:\test2.ini", 15, LF_FILE, "password", 0

 

pp_lfalias lfhandle, "c:\test3.ini", 15, LF_FILE, "password", 0

 

. . . [code here] . . .

 

' Aliases are automatically closed after the master

pp_lfclose lfhandle

See Also:

PP_LFOPEN()