Advanced options

Top  Previous  Next

 

--encoding <encoding>

 

Specify a target character encoding for ruby 1.9.x and 2.x code. This option does not make any sense for Ruby 1.8. RubyEncoder compiles source Ruby files to a binary representation, as a result 'magic comments' cannot be used for specifying character encoding of source files as they are read on the 'running' stage, not during compilation. Please use this RubyEncoder option when you are encoding files that have 'magic comments' in the code for specifying the character encoding.

 

Example 1: --encoding UTF-8

Example 2: --encoding ISO-8859-1

 

Since version 2.5 of RubyEncoder the default encoding if UTF-8 if not specified.

 

 

--rails

 

Enables Rails compatibility which lets you encode all Rails *.rb files (you can encode only pure Ruby files with RubyEncoder). Normally you can encode only application controllers, model and helper files. Other files if encoded would not work under Rails if the Rails compatibility mode was not used. Using this option makes an internal CRC check weaker for a bit. This is done to let Rails engine use eval() for loading protected files.

 

 

-n

 

Don't integrate dynamic loader.You may use this option if you don't want to include the default starter code into protected scripts. Scripts encoded using this option will not be able to automatically find and load an appropriate RubyEncoder loader and you have to start an appropriate loader before running the encoded script. This option is useful if you have multiple encoded files and want to start the RubyEncoder loader manually from your code maybe from the custom folder before running the protected files. When starting loaders manually you may either 'require' the loader.rb helper file which is available along with binary loaders or you may load the binary loader directly.  

 

Note: if you select this option then "Loader not found error code" option (-j) has no effect (as the code is placed inside the default dynamic loader code).

 

 

-p "code"    

Prepend header code. You may put any code to be inserted BEFORE the protected scripts code. This code WILL NOT BE ENCODED. This should be syntactically correct Ruby code. Of course, it may by Ruby comments starting with a # symbol.  This option is usually used for including copyrights into protected scripts. Also this option is used to put a custom error handler code into protected scripts (see --catch option). You should prepend all special characters including double quote characters with a back slash if you want to include them into the code (  "  becomes  \"  ).

 

Example 1:

 

>rubyencoder -p "# My protected script. Copyright by My Name" file.rb

 

Example 2:

 

> rubyencoder -p "puts \"My protected script. Copyright by My Name\";" file.rb

 

All user {constants} that are defined in locking options will be replaced in the header code. Also some standard RubyEncoder constants may be used:

 

       {RG_DATE} - current date i.e. date of encoding

       {RG_LICENSEE} - RubyEncoder license owner from the RubyEncoder license file

 

       It works in the same way also for licgen and do replacements for custom text if it is used. See details

 

 

-j "code"    

By default a RubyEncoder protected script will generate an exception with the following message when the RubyEncoder Loader is not installed:

 

Ruby script '...' is protected by RubyEncoder and requires the RubyEncoder loader. Please visit the http://www.rubyencoder.com/loaders/ RubyEncoder site to download the required loader and unpack it into '.../rgloader/' directory to run this protected script. (RuntimeError)

 

It is possible for you to change the default loader error behavior. This option allows you to change the default error action of the protected script if it cannot find or load an appropriate RubyEncoder Loader file. You may use any Ruby code here and it will be executed as a replacement to the default RubyEncoder  loader exception. This code WILL NOT BE ENCODED. You should prepend all all special characters including double quote characters with a back slash if you want to include them into the code ( "  becomes \" ). If you want you may load the required RubyEncoder Loader with "require" directive from a non-standard directory instead of printing an error message.

 

Example:

 

> rubyencoder -j "puts \"Loader is not found. Call 123-456-7890 for support\"; exit(1);" hello.rb

 

The encoded script will have the defined code as unencoded:

 

# RubyEncoder v1.0                                                                                

_d = _d0 = File.expand_path(File.dirname(__FILE__)); while 1 do _f = _d + '/rgloader/loader.rb'; bre

ak if File.exist?(_f); _d1 = File.dirname(_d); if _d1 == _d then                                  

puts "Loader is not found. Call 123-456-7890 for support"; exit(1);                                

break; else _d = _d1; end; end; require _f; RGLoader::load('AAEAAAAEaAAAAIAAAAAA/6vBQ2j8ivZCR3gVFB15

Hr/Y90fXBYLdnQDavAjb9qL66uNG0QBaN4Uk9NrqUbHzhv/WHM97yUQkyjHsiD9nsMr9JiGEavcQ5tAIbHD1/1xoxia2TOrPle4V

e8+H+3odwWqOIjks94QLEgAAAGAAAAB75w3qzOZQCmvQDuOs+G9ZVhz0GbAy1oT4injTT83Iijyj0iubOUfKRn2+frb7QOm3dEXG

qgUtKkGzz2yaCE0T9yV1V0ZtZv4RKezGy1UJdYtDb41rK0t8S9FRLBYnwAYAAAAA');

 

Now a test run without a required RubyEncoder Loader installed:

 

>ruby hello.rb

 

Loader is not found. Call 123-456-7890 for support

 

 

Prepend header code and Loader error code may be loaded from a file

                         

Prepend header code option -p and Loader error code option -j may load the source from a file. Use @filename as a parameter for -p or -j. We suggest to use this option if you need to add some complex code. It is easier to edit this code in a separate file than writing it in command line as an option.

 

Example:

>rubyencoder -p @prepend.rb -j @loadererr.rb file.rb

 

 

--stop-on-error

 

Stop on compiler errors. This option instructs the encoder to stop encoding at first critical error. This may be useful if you have many files in the project and there is a risk of missing errors and leaving some files unencoded because of it.

 

Note: Even if this option is off error messages will be printed to console during encoding.

 

 

-a <YYYYMMDDhhmmss>

 

This options lets you encode only changed files detected by file modification date. Only files that have been modified after the specified date will be encoded.