Skip to content
Siorki edited this page Oct 27, 2018 · 6 revisions

Module Interface

The PackerData is used as the only interface between the different modules composing RegPack. It contains all the relevant data to compress the code provided as input; and records actions from modules it went through.

Upon executing RegPack, a PackerData is initialized with the provided input and default settings (not including options) and fed to the first module. Each module takes a PackerData as input, plus the user-defined options, and outputs one or several PackerData.

The contents of this structure, along with their initial and possible values, are described below.

name

When a module creates several branches, it outputs as many instances of PackerData, and names them according to the specificity of the branch. Since multiple modules may do this, branch names should be appended to the existing name. Names are not shown by default in the GUI.

Initial value is "" (empty string)

Names are currently given only by the module Hash contexts.

contents

This is the string to compress, that may be altered by all the preprocessing modules. If a module can not perform its action or assumes it to be ineffective, it leaves the contents unchanged.

Initial value is the input code.

log

The log records operations performed by the different modules. Even modules failing to modify the contents should log their actions. It is shown in the right column in the GUI.

Initial value is "" (empty string)

environment

This is the environment the unpacked code will be executed in. It is prepended directly to the evaluation call such as : with(Math)eval(_)

Initial value is "" (empty string)

The module Define environment may change it to "with(Math)"

packedCodeVarName

This is the name of the variable containing the packed code. It is unpacked in the same variable.

Initial value is _

The module Rename variables may change the name to any other one-letter variable.

interpreterCall

Contains the instruction that will be used to run the unpacked code provided as a string (contained in packedCodeVarName).

Initial value is eval(_).

The module Wrap with setInterval changes the value to setInterval(_,delay).
The module Rename variables may change the variable to match the value of packedCodeVarName.

wrappedInit

Contains a piece of code that will be executed within the unpacking routine, inside the join(pop()) or join(shift()) loop. Putting these instructions between the () even if pop() does not require any parameter saves one byte as no ; is required, compared to prepending them to the routine.

Initial value is "" (empty string).

The module Wrap with setInterval changes the value to time=0 with the appropriate name for the time variable.

initialDeclarationOffset

Represents the byte offset, from the beginning of the string, to the actual code that will be executed first after unpacking. This is usually the beginning of the code (offset zero), however refactoring may change this.

Initial value is zero.

The module Wrap with setInterval changes the value to the beginning of the conditional loop, immediately after the opening bracket.

containedStrings

Lists all the strings present in the input code. Each string is stored as an object in the array :

{   
    begin : 20 // offset to the opening delimiter, from the beginning of the input
    end : 30 // offset to the closing delimiter, from the beginning of the input
    delimiter : '"' // ASCII code of the delimiter : 34 for ", 39 for ', 96 for `
    characterCount : [] // integer array, showing how many other quotation characters are present in the string 
}

Initial value is [] (empty array). It is then filled by a preliminary phase of the module Quote strings.

containedTemplateLiterals

(since v5.0.2)

Lists all the templates literals ${....} in ES6 strings within the code, stored as an array :

{   
    begin : 36 // offset to the `{` in the opening delimiter, from the beginning of the input
    end : 45 // offset to the closing delimiter, from the beginning of the input
}

Initial value is [] (empty array). It is then filled by a preliminary phase of the module Quote strings.

packedStringDelimiter

Contains the string quote, either ', ", or `, which is used to wrap the packed string. The same quote is also used for the token string for the crusher output (packer output uses a RegExp delimited by /).

Initial value is "

The module Quote strings may change the value to either ' or `.

result

Stores the packed string.

Initial value is empty.
Crusher and Packer stages modify that value to the packed string.

Assembly of the unpacking routine

Elements of the PackerData are used to build the unpacking routine. The following examples illustrate how these elements are put together.

example 1 PackerData member used example 2
for(_= packedCodeVarName for(j=
"packedCode" packedStringDelimiter , result 'packedCode'
;G=/[tokens]/.exec(_);)with(_.split(G)) packedCodeVarName ;G=/[tokens]/.exec(j);)with(j.split(G)))
_=join(shift(t=0)); wrappedInit j=join(shift());
(empty) environment with(Math)
setInterval(_,20) interpreterCall eval(j)