Custom predefined constants

Top  Previous  Next

 

--const name=value

 

RubyEncoder lets you define custom named constants during the encoding process, or within the external script license. Constant name/value pairs are stored internally in the encrypted area of the protected script or the license. They may be used for custom script locking or any other actions if you need to store a custom value in the protected script or script license file and then read it from your protected Ruby code. Note, the values are store in the encrypted area and can't be modified by the users.

 

It is important to use quotes if your constant name or the value contains a space or other special symbols. You defines only one constant with one

--const option but you may add as many --const options as you need into the command line.

 

>rubyencoder --const "licensed_for=Robin Hood" myscript.rb

>licgen  --const "licensed_for=Robin Hood" script.lic

 

To get a predefined constant value from the protected Ruby code use RGLoader::get_const() method. This method is defined in the RubyEncoder loader.

RGLoader::get_const() will return a predefined RubyEncoder constant value or nil if the constant with the specified name is not defined. Constant names are case sensitive.

 

Note, as RGLoader::get_const() is a part of the loader API, it may be used only from protected files.

 

There are 5 predefined constants for any protected script:

 

RGLoader::get_const("encoder")

Returns the name of the encoder "RubyEncoder"

RGLoader::get_const("loader_version")

Returns the loader version number

RGLoader::get_const("encode_date")

Returns the UNIX timestamp when the script was encoded

RGLoader::get_const("license_date")

Returns the UNIX timestamp when the script license was created. It's may differ from "encode_date" when external script license is used

RGLoader::get_const("expire_date")

Returns script expiration date as UNIX timestamp if it's defined in the script license or internally via script binding options during encoding