5 * Command line interface for the tool
9 public function run(): void
11 $parser = $this->setupCliParser();
13 $result = $parser->parse();
14 } catch (\Exception $exc) {
15 $parser->displayError($exc->getMessage());
19 switch ($result->command_name) {
21 $cmd = new Command\Decrypt(
22 $result->command->args['epub'], $result->command->args['path'],
23 $result->command->options
28 $cmd = new Command\Deobfuscate(
29 $result->command->args['epub'], $result->command->args['path'],
30 $result->command->options
35 $cmd = new Command\ListContent(
36 $result->command->args['epub'], $result->command->options
41 $parser->displayError('Command name missing');
45 $logger = new Logger();
46 $logger->showInfo = $result->options['verbose'];
49 $cmd->logger = $logger;
51 } catch (\Exception $e) {
52 fwrite(STDERR, 'Error: ' . $e->getMessage() . "\n");
57 protected function setupCliParser(): \Console_Commandline
59 $parser = new \Console_CommandLine();
60 $parser->description = 'Encrypt and decrypt epub files';
61 $parser->version = 'fixme';
67 'long_name' => '--verbose',
68 'description' => 'Show more messages',
69 'action' => 'StoreTrue',
74 $ls = $parser->addCommand(
77 'description' => 'List files inside the .epub with'
78 . ' their encryption status' . "\n"
80 . "First column: E=encrypted, O=obfuscated\n"
82 . " RESOBF = EPUB Open Container Format (OCF) 3.2: Resource Obfuscation\n"
83 . " AES256 = XML Encryption Syntax and Processing, AES-256",
88 ['description' => '.epub file to inspect']
91 $decrypt = $parser->addCommand(
94 'description' => 'Decrypt encrypted files inside the epub file',
100 'short_name' => '-k',
101 'long_name' => '--key',
102 'description' => 'Hex-encoded encryption key',
103 'action' => 'StoreString',
110 'short_name' => '-k',
111 'long_name' => '--keyfile',
112 'description' => 'File containing encryption key',
113 'action' => 'StoreString',
120 'short_name' => '-a',
121 'long_name' => '--all',
122 'description' => 'Decrypt all encrypted files',
123 'action' => 'StoreTrue',
130 'short_name' => '-c',
131 'long_name' => '--stdout',
132 'description' => 'Send decrypted contents to stdout. Do not modify epub file.',
133 'action' => 'StoreTrue',
137 $decrypt->addArgument(
139 ['description' => '.epub file']
141 $decrypt->addArgument(
144 'description' => 'File paths inside the epub file',
150 $deobfuscate = $parser->addCommand(
153 'description' => 'Deobfuscate files inside the epub file',
156 $deobfuscate->addOption(
159 'short_name' => '-k',
160 'long_name' => '--key',
161 'description' => 'Hex-encoded obfuscation key',
162 'action' => 'StoreString',
166 $deobfuscate->addOption(
169 'short_name' => '-k',
170 'long_name' => '--keyfile',
171 'description' => 'File containing obfuscatino key',
172 'action' => 'StoreString',
176 $deobfuscate->addOption(
179 'short_name' => '-a',
180 'long_name' => '--all',
181 'description' => 'Deobfuscate all obfuscated files',
182 'action' => 'StoreTrue',
186 $deobfuscate->addOption(
189 'short_name' => '-c',
190 'long_name' => '--stdout',
191 'description' => 'Send deobfuscated contents to stdout. Do not modify epub file.',
192 'action' => 'StoreTrue',
196 $deobfuscate->addArgument(
198 ['description' => '.epub file']
200 $deobfuscate->addArgument(
203 'description' => 'File paths inside the epub file',