How to use

Command Line

DonQuixote のコマンドラインの様式は以下の通りです.いくつかのオプショ ンを受け取り,jar, zip, クラスファイルを引数に取ります.加えて,--processor オプションで Available Processors 以下にあるプロセッサ \(processor\) を複数指定し,引数に渡されたクラス群にどのような処理を施す のかを決定します.

--destination オプションを指定するか,dumper プロセッサを指定すること で,所定の場所に変換されたクラスファイルが出力されます.また,--launch オプションを指定することで,変換されたクラスを直接実行させることも可能 です.

 -n,--plugin-dir <DIR>             set plugin directory
 -D <property=value>               Use value for given property.  Property name formatted by 
                                   ``${alias name of processor}.${property name}.''
                                   For example, ``example'' processor which alias name is
                                   n``example1'' has property ``property1.''
                                   Then, ``example1.property1=propertyvalue.''
                                   Alias name can be specified in processor option.
 -L,--license                      print DonQuixote LICENSE
 -V,--version                      print DonQuixote version
 -d,--destination <DEST>           set output directory of processed
                                   classes. If this option is specified,
                                   dumper processor is added by
                                   DonQuixote runtime.
 -h,--help                         print this message
 -l,--launch <CLASS_NAME>          launch the target class. If this option is specified,
                                   launcher processor is added by DonQuixote runtime.
 -p,--processor <PROCESSOR_NAME>   Specify certain bytecode processors and
                                   alias name of processor in ``${alias name}=${processor name}.''
                                   If alias name is not specified such as ``processor name,''
                                   alias name will set same as processor name.
 -s,--summary <DESTINATION>        Set output of Summary object.  Default
                                   is ``<stdout>'' which means standard output.
                                   This option allows ``<stdout>,'' ``<stderr>,'' 
                                   ``/dev/null,''a nd file names.
 -V,--version                      print DonQuixote version
 -d,--destination <DEST>           set output directory of processed
                                   classes. If this option is specified,
                                   dumper processor is added by DonQuixote runtime.
 -h,--help                         print this message
 -l,--launch <CLASS_NAME>          launch the target class. If this option
                                   is specified, launcher processor is added by DonQuixote runtime.
 -p,--processor <PROCESSOR_NAME>   Specify certain bytecode processors and alias name of processor
                                   in ``${alias name}=${processor name}.''  If alias name is not
                                   specified such as ``processor name,'' alias name will set same
                                   as processor name.

Available Processor:
        disassembler: Disassemble given classes
        holder: Hold most recent target for testing.
        verifier: Verify given classes
        typecounter: Count types
        dumper: Dump given classes.
        launcher: Launch class

デフォルトの Processor は上記の disassembler, holder, verifier, typecounter, dumper, launcher の 6 つですが,以下の Processor登録処理を行うことで,自由に追加するこ とが可能です.

プロセッサの指定

適用するプロセッサ(難読化処理器)はコマンドラインオプションの -p もし くは --processor を使って指定することができます.実行する処理器の名前 を以下のように -p,--processor の後ろに書いて指定します.

$ java -jar /path/to/runtime-x.x.jar --processor dumper classes....

また,プロセッサの指定の際に,プロセッサに別名(エイリアス名)を与える ことが可能です.エイリアス名を指定しない場合は自動的にプロセッサ名がエ イリアス名に指定されます.

例えば,以下のように dumper プロセッサに testdumper, realdumper と別 のエイリアス名を指定することができ,同じプロセッサの別のインスタンスを 区別して扱うことが可能になります.

/path/to/runtime-x.x.jar --processor testdumper=dumper --processor realdumper=dumper classes....

プロセッサへの引数の渡し方

各プロセッサは引数を受け取るものも存在します.それらのプロセッサにコ マンドラインから引数を渡すには -D オプションを利用します.例えば, dumper プロセッサは引数 destination を持ちます.デフォルトの値はカレン トディレクトリを表す "." ですが,DonQuixote のコマンドラインオプション で以下のように -D dumper.destination=dest とすることで,dumper プロセッ サの引数 destination に dest という値が渡されます.

$ java -jar /path/to/runtime-x.x.jar -D dumper.destination=dest --processor dumper classes....

このように,「プロセッサのエイリアス名.オプション名=値」という形式で プロセッサに値を渡すことが可能です.

また,各プロセッサが持つ引数が何か分からない場合は --processor オプショ ンでプロセッサ名を指定し,かつ,--help オプションも与えることで,プロ セッサのヘルプを表示させることが可能です.

 $ java -jar /path/to/runtime-x.x.jar --processor dumper --help
 ---------- dumper ----------
 Dump given classes.
 Authors
         Haruaki TAMADA
 Properties:
         Name: destination
         Default Value: .
         Description: Dump destination

How to register processors

新たなプラグインの作成については, Rocinante をご覧ください. ここでは,作成されたプラグインを DonQuixote に認識させる方法について述 べます.

プラグインを認識させる方法は以下の 3 通りあります.いずれの場合も,プ ラグイン jar ファイルを特定のディレクトリに置くことで認識されます.ま た,プラグイン jar ファイルが依存する jar ファイルがある場合は,jar ファ イル内の MANIFEST.MF の Class-Path エントリで指定しておく必要がありま す.このときの相対パスの基点はプラグイン jar ファイルが置かれているディ レクトリとなります.

コマンドラインで指定

最初に,コマンドラインで DonQuixote に認識させる方法について述べます. DonQuixote の実行環境には --plugin-dir というオプションが備わっていま す.そのオプションの引数にディレクトリを与えると,DonQuixote はそのディ レクトリをプラグインが置かれているディレクトリであると認識し,プラグイ ンをロードします.--plugin-dir オプションは複数個指定することが可能で す.また,コンマで区切ることも可能です.

環境変数で指定

環境変数 DONQUIXOTE_PLUGIN_DIR が定義されている場合,そのディレクトリ を暗黙的に --plugin-dir に与えられたものと認識し,DonQuixote はそのディ レクトリからプラグインの検索,ロードを行います.

runtime-x.x.jar と同じディレクトリに置く

runtime-x.x.jar と同じディレクトリにプラグイン jar ファイルを置いてお くと,自動的に認識されますが,システムが提供するプラグインと,ユーザが 提供するプラグインと(将来的にはシステム的にも)区別するため,推奨しませ ん.