Smart Card Shell

Build-in Shell Commands

The full potential of the shell can be explored using JavaScript expressions, which are evaluated immediately. Only a few commands are provided by the shell object, whereas the majority of functions are in the scripting classes.

help

Display a short help in interactive mode

q | quit

Terminate shell.

r | reset

Reset card in reader and display Answer to Reset returned by card.

a | apdu(String apdu)

Send APDU to card. The argument apdu must be a string that contains in hexadecimal encoding the concatenation of CLA|INS|P1|P2|Lc|Data|Le

print(...)

All arguments passed to the print() function are converted using the toString() method and are concatenated with a trailing blank. The resulting string is printed with a '\n' appended.

If the object is of type ByteString, then a hexadecimal dump is generated.

load(String filename)

Load, compile and execute ECMA script.

Unless an absolute file name is given, the path is relative to the location of the script in which the function is called. See Locating Files for details.

launch(String moduleid)

Locate the module with moduleid and launch as main module. All modules referenced using require() will be maintained in the main module.

defineClass(String classfilename)

Load Java class file and define new ECMA class constructor in script runtime. The Java class must be derived from org.mozilla.javascript.ScriptableObject.

assert(condition, message)

The condition argument is evaluated. If the result is false, then an exception is thrown with message. This is useful for test script.

Extending Shell Commands

When an expression entered on the command line is evaluated to be a function and no arguments are given, then the function is called with the result of the last evaluation. Shell commands can therefore be extended by simply defining a function in ECMA Script (e.g. as part of a startup script).

Example: Define a function do()

function mydo(last) {
  print("mydo() called with " + last);
}

Now when you enter "mydo" in the shell, this evaluates to a function object, which is then called with the result of the last evaluation.

>"Hello World";
Hello World
>mydo
mydo() called with Hello World
>