stegdoc 4.0.0 → 5.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -21
- package/README.md +200 -214
- package/package.json +59 -59
- package/src/commands/decode.js +485 -343
- package/src/commands/encode.js +567 -449
- package/src/commands/info.js +118 -114
- package/src/commands/verify.js +207 -204
- package/src/index.js +89 -87
- package/src/lib/compression.js +177 -115
- package/src/lib/crypto.js +172 -172
- package/src/lib/decoy-generator.js +306 -306
- package/src/lib/docx-handler.js +587 -161
- package/src/lib/docx-templates.js +355 -0
- package/src/lib/file-handler.js +113 -113
- package/src/lib/file-utils.js +160 -150
- package/src/lib/interactive.js +190 -190
- package/src/lib/log-generator.js +764 -0
- package/src/lib/metadata.js +151 -122
- package/src/lib/streams.js +197 -197
- package/src/lib/utils.js +227 -227
- package/src/lib/xlsx-handler.js +597 -416
- package/src/lib/xml-utils.js +115 -115
package/src/commands/verify.js
CHANGED
|
@@ -1,204 +1,207 @@
|
|
|
1
|
-
const path = require('path');
|
|
2
|
-
const chalk = require('chalk');
|
|
3
|
-
const ora = require('ora');
|
|
4
|
-
const { readDocxBase64 } = require('../lib/docx-handler');
|
|
5
|
-
const { readXlsxBase64 } = require('../lib/xlsx-handler');
|
|
6
|
-
const { validateMetadata, isMultiPart, isStreamingFormat } = require('../lib/metadata');
|
|
7
|
-
const { detectFormat, formatBytes } = require('../lib/utils');
|
|
8
|
-
const { decrypt, unpackEncryptionMeta, createDecryptStream } = require('../lib/crypto');
|
|
9
|
-
const { extractContent, findMultiPartFiles } = require('../lib/file-utils');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Verify that a file can be decoded without actually writing output
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
console.log(chalk.cyan(`
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
console.log(chalk.
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
const
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
1
|
+
const path = require('path');
|
|
2
|
+
const chalk = require('chalk');
|
|
3
|
+
const ora = require('ora');
|
|
4
|
+
const { readDocxBase64 } = require('../lib/docx-handler');
|
|
5
|
+
const { readXlsxBase64 } = require('../lib/xlsx-handler');
|
|
6
|
+
const { validateMetadata, isMultiPart, isStreamingFormat, isLogEmbedFormat } = require('../lib/metadata');
|
|
7
|
+
const { detectFormat, formatBytes } = require('../lib/utils');
|
|
8
|
+
const { decrypt, unpackEncryptionMeta, createDecryptStream } = require('../lib/crypto');
|
|
9
|
+
const { extractContent, findMultiPartFiles } = require('../lib/file-utils');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Verify that a file can be decoded without actually writing output
|
|
13
|
+
*/
|
|
14
|
+
async function verifyCommand(inputFile, options) {
|
|
15
|
+
const spinner = ora('Verifying file...').start();
|
|
16
|
+
const issues = [];
|
|
17
|
+
|
|
18
|
+
try {
|
|
19
|
+
const format = detectFormat(inputFile);
|
|
20
|
+
if (!format) {
|
|
21
|
+
throw new Error('Unknown file format. Supported formats: .xlsx, .docx');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
spinner.text = `Reading ${format.toUpperCase()} file...`;
|
|
25
|
+
|
|
26
|
+
let readResult;
|
|
27
|
+
if (format === 'xlsx') {
|
|
28
|
+
readResult = await readXlsxBase64(inputFile);
|
|
29
|
+
} else {
|
|
30
|
+
readResult = await readDocxBase64(inputFile);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const extracted = extractContent(readResult, format);
|
|
34
|
+
const metadata = extracted.metadata;
|
|
35
|
+
const encryptionMeta = extracted.encryptionMeta;
|
|
36
|
+
|
|
37
|
+
try {
|
|
38
|
+
validateMetadata(metadata);
|
|
39
|
+
spinner.succeed('Metadata valid');
|
|
40
|
+
} catch (e) {
|
|
41
|
+
issues.push(`Metadata: ${e.message}`);
|
|
42
|
+
spinner.warn('Metadata issues found');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const isEncrypted = metadata.encrypted || (encryptionMeta && encryptionMeta.length > 0);
|
|
46
|
+
const isV5 = isLogEmbedFormat(metadata);
|
|
47
|
+
const isV4 = !isV5 && isStreamingFormat(metadata);
|
|
48
|
+
|
|
49
|
+
// Check multi-part
|
|
50
|
+
const hasMultipleParts = isMultiPart(metadata) || metadata.partNumber !== null;
|
|
51
|
+
if (hasMultipleParts) {
|
|
52
|
+
spinner.text = 'Checking multi-part files...';
|
|
53
|
+
const inputDir = path.dirname(inputFile);
|
|
54
|
+
const allParts = findMultiPartFiles(inputDir, metadata.hash, format);
|
|
55
|
+
const totalParts = metadata.totalParts || allParts.length;
|
|
56
|
+
|
|
57
|
+
if (metadata.totalParts !== null && allParts.length !== metadata.totalParts) {
|
|
58
|
+
const missing = [];
|
|
59
|
+
const foundParts = new Set(allParts.map(p => p.partNumber));
|
|
60
|
+
for (let i = 1; i <= metadata.totalParts; i++) {
|
|
61
|
+
if (!foundParts.has(i)) missing.push(i);
|
|
62
|
+
}
|
|
63
|
+
issues.push(`Missing parts: ${missing.join(', ')}`);
|
|
64
|
+
spinner.warn(`Found ${allParts.length}/${metadata.totalParts} parts`);
|
|
65
|
+
} else {
|
|
66
|
+
spinner.succeed(`All ${totalParts} parts found`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// Check password for encrypted files
|
|
71
|
+
if (isEncrypted) {
|
|
72
|
+
if (!options.password) {
|
|
73
|
+
issues.push('File is encrypted but no password provided');
|
|
74
|
+
spinner.warn('Encryption check skipped (no password)');
|
|
75
|
+
} else {
|
|
76
|
+
spinner.text = 'Verifying decryption...';
|
|
77
|
+
try {
|
|
78
|
+
if (isV5) {
|
|
79
|
+
await verifyV5Encryption(extracted, options.password);
|
|
80
|
+
} else if (isV4) {
|
|
81
|
+
await verifyV4Encryption(inputFile, format, encryptionMeta, options.password);
|
|
82
|
+
} else {
|
|
83
|
+
await verifyV3Encryption(inputFile, format, metadata, extracted.encryptedContent, encryptionMeta, options.password);
|
|
84
|
+
}
|
|
85
|
+
spinner.succeed('Decryption password valid');
|
|
86
|
+
} catch (e) {
|
|
87
|
+
issues.push('Decryption failed - wrong password or corrupted data');
|
|
88
|
+
spinner.fail('Decryption check failed');
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// Summary
|
|
94
|
+
console.log();
|
|
95
|
+
|
|
96
|
+
if (issues.length === 0) {
|
|
97
|
+
console.log(chalk.green.bold('✓ File verification passed!'));
|
|
98
|
+
console.log(chalk.cyan(` Original file: ${metadata.originalFilename}`));
|
|
99
|
+
console.log(chalk.cyan(` Size: ${formatBytes(metadata.originalSize)}`));
|
|
100
|
+
console.log(chalk.cyan(` Encrypted: ${isEncrypted ? 'Yes' : 'No'}`));
|
|
101
|
+
console.log(chalk.cyan(` Compressed: ${metadata.compressed ? 'Yes' : 'No'}`));
|
|
102
|
+
|
|
103
|
+
let versionStr = 'v3 (legacy)';
|
|
104
|
+
if (isV5) versionStr = 'v5 (log-embed)';
|
|
105
|
+
else if (isV4) versionStr = 'v4 (streaming)';
|
|
106
|
+
console.log(chalk.cyan(` Format version: ${versionStr}`));
|
|
107
|
+
|
|
108
|
+
if (hasMultipleParts) {
|
|
109
|
+
const totalParts = metadata.totalParts || 'unknown';
|
|
110
|
+
console.log(chalk.cyan(` Parts: ${totalParts}`));
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
console.log();
|
|
114
|
+
console.log(chalk.green('File is ready to decode.'));
|
|
115
|
+
} else {
|
|
116
|
+
console.log(chalk.yellow.bold('⚠ Verification completed with issues:'));
|
|
117
|
+
console.log();
|
|
118
|
+
for (const issue of issues) {
|
|
119
|
+
console.log(chalk.yellow(` • ${issue}`));
|
|
120
|
+
}
|
|
121
|
+
console.log();
|
|
122
|
+
|
|
123
|
+
const hasBlockingIssue = issues.some(i =>
|
|
124
|
+
i.includes('Missing parts') ||
|
|
125
|
+
i.includes('Decryption failed') ||
|
|
126
|
+
i.includes('Metadata')
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
if (hasBlockingIssue) {
|
|
130
|
+
console.log(chalk.red('File cannot be decoded until issues are resolved.'));
|
|
131
|
+
process.exit(1);
|
|
132
|
+
} else {
|
|
133
|
+
console.log(chalk.yellow('File may still be decodable. Run decode to attempt.'));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
} catch (error) {
|
|
138
|
+
spinner.fail('Verification failed');
|
|
139
|
+
console.error(chalk.red(`Error: ${error.message}`));
|
|
140
|
+
process.exit(1);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Verify v5 log-embed encryption
|
|
146
|
+
*/
|
|
147
|
+
async function verifyV5Encryption(extracted, password) {
|
|
148
|
+
const { payloadBuffer, encryptionMeta } = extracted;
|
|
149
|
+
const { iv, salt, authTag } = unpackEncryptionMeta(encryptionMeta);
|
|
150
|
+
const decipher = createDecryptStream(password, iv, salt, authTag);
|
|
151
|
+
decipher.update(payloadBuffer);
|
|
152
|
+
decipher.final();
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Verify v4 per-part encryption
|
|
157
|
+
*/
|
|
158
|
+
async function verifyV4Encryption(inputFile, format, encryptionMeta, password) {
|
|
159
|
+
const { iv, salt, authTag } = unpackEncryptionMeta(encryptionMeta);
|
|
160
|
+
|
|
161
|
+
let readResult;
|
|
162
|
+
if (format === 'xlsx') {
|
|
163
|
+
readResult = await readXlsxBase64(inputFile);
|
|
164
|
+
} else {
|
|
165
|
+
readResult = await readDocxBase64(inputFile);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const { encryptedContent } = extractContent(readResult, format);
|
|
169
|
+
const binaryData = Buffer.from(encryptedContent, 'base64');
|
|
170
|
+
|
|
171
|
+
const decipher = createDecryptStream(password, iv, salt, authTag);
|
|
172
|
+
decipher.update(binaryData);
|
|
173
|
+
decipher.final();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/**
|
|
177
|
+
* Verify v3 shared encryption
|
|
178
|
+
*/
|
|
179
|
+
async function verifyV3Encryption(inputFile, format, metadata, encryptedContent, encryptionMeta, password) {
|
|
180
|
+
const { iv, salt, authTag } = unpackEncryptionMeta(encryptionMeta);
|
|
181
|
+
|
|
182
|
+
let fullContent = encryptedContent;
|
|
183
|
+
|
|
184
|
+
if (isMultiPart(metadata)) {
|
|
185
|
+
const inputDir = path.dirname(inputFile);
|
|
186
|
+
const allParts = findMultiPartFiles(inputDir, metadata.hash, format);
|
|
187
|
+
|
|
188
|
+
if (allParts.length === metadata.totalParts) {
|
|
189
|
+
const contentParts = [];
|
|
190
|
+
for (const part of allParts) {
|
|
191
|
+
let partResult;
|
|
192
|
+
if (format === 'xlsx') {
|
|
193
|
+
partResult = await readXlsxBase64(part.path);
|
|
194
|
+
} else {
|
|
195
|
+
partResult = await readDocxBase64(part.path);
|
|
196
|
+
}
|
|
197
|
+
const { encryptedContent: partContent } = extractContent(partResult, format);
|
|
198
|
+
contentParts.push(partContent);
|
|
199
|
+
}
|
|
200
|
+
fullContent = contentParts.join('');
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
decrypt(fullContent, password, iv, salt, authTag);
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
module.exports = verifyCommand;
|
package/src/index.js
CHANGED
|
@@ -1,87 +1,89 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const { program } = require('commander');
|
|
4
|
-
const chalk = require('chalk');
|
|
5
|
-
const encodeCommand = require('./commands/encode');
|
|
6
|
-
const decodeCommand = require('./commands/decode');
|
|
7
|
-
const infoCommand = require('./commands/info');
|
|
8
|
-
const verifyCommand = require('./commands/verify');
|
|
9
|
-
|
|
10
|
-
// CLI Configuration
|
|
11
|
-
program
|
|
12
|
-
.name('stegdoc')
|
|
13
|
-
.description('CLI tool to encode files into Office documents with AES-256 encryption')
|
|
14
|
-
.version('
|
|
15
|
-
|
|
16
|
-
// Encode command
|
|
17
|
-
program
|
|
18
|
-
.command('encode <file>')
|
|
19
|
-
.description('Encode a file into XLSX/DOCX format with compression and optional encryption')
|
|
20
|
-
.option('-o, --output-dir <dir>', 'Output directory for files', process.cwd())
|
|
21
|
-
.option('-s, --chunk-size <size>', 'Maximum size per output file (e.g., "5MB", "25MB")', '5MB')
|
|
22
|
-
.option('-f, --format <format>', 'Output format: xlsx (default) or docx', 'xlsx')
|
|
23
|
-
.option('-p, --password <password>', 'Encryption password (optional, but recommended)')
|
|
24
|
-
.option('--force', 'Overwrite existing files without asking')
|
|
25
|
-
.option('
|
|
26
|
-
.option('-
|
|
27
|
-
.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
.
|
|
41
|
-
.
|
|
42
|
-
.option('--
|
|
43
|
-
.option('-
|
|
44
|
-
.option('
|
|
45
|
-
.
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
.
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
.
|
|
72
|
-
.
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { program } = require('commander');
|
|
4
|
+
const chalk = require('chalk');
|
|
5
|
+
const encodeCommand = require('./commands/encode');
|
|
6
|
+
const decodeCommand = require('./commands/decode');
|
|
7
|
+
const infoCommand = require('./commands/info');
|
|
8
|
+
const verifyCommand = require('./commands/verify');
|
|
9
|
+
|
|
10
|
+
// CLI Configuration
|
|
11
|
+
program
|
|
12
|
+
.name('stegdoc')
|
|
13
|
+
.description('CLI tool to encode files into Office documents with AES-256 encryption')
|
|
14
|
+
.version('5.0.0');
|
|
15
|
+
|
|
16
|
+
// Encode command
|
|
17
|
+
program
|
|
18
|
+
.command('encode <file>')
|
|
19
|
+
.description('Encode a file into XLSX/DOCX format with compression and optional encryption')
|
|
20
|
+
.option('-o, --output-dir <dir>', 'Output directory for files', process.cwd())
|
|
21
|
+
.option('-s, --chunk-size <size>', 'Maximum size per output file (e.g., "5MB", "25MB")', '5MB')
|
|
22
|
+
.option('-f, --format <format>', 'Output format: xlsx (default) or docx', 'xlsx')
|
|
23
|
+
.option('-p, --password <password>', 'Encryption password (optional, but recommended)')
|
|
24
|
+
.option('--force', 'Overwrite existing files without asking')
|
|
25
|
+
.option('--legacy', 'Use v4 format (hidden sheet + gzip) for backward compatibility')
|
|
26
|
+
.option('--no-limit', 'Bypass DOCX 1 MB size limit (large files will produce huge documents)')
|
|
27
|
+
.option('-q, --quiet', 'Minimal output (for scripting)')
|
|
28
|
+
.option('-y, --yes', 'Skip interactive prompts, use defaults')
|
|
29
|
+
.action(async (file, options) => {
|
|
30
|
+
try {
|
|
31
|
+
await encodeCommand(file, options);
|
|
32
|
+
} catch (error) {
|
|
33
|
+
console.error(chalk.red(`Error: ${error.message}`));
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
// Decode command
|
|
39
|
+
program
|
|
40
|
+
.command('decode <file>')
|
|
41
|
+
.description('Decode and decrypt an XLSX/DOCX file back to original format')
|
|
42
|
+
.option('-o, --output <path>', 'Output file path (defaults to original filename)')
|
|
43
|
+
.option('-p, --password <password>', 'Decryption password (required for encrypted files)')
|
|
44
|
+
.option('--force', 'Overwrite existing files without asking')
|
|
45
|
+
.option('-q, --quiet', 'Minimal output (for scripting)')
|
|
46
|
+
.option('-y, --yes', 'Skip interactive prompts, fail if password needed')
|
|
47
|
+
.action(async (file, options) => {
|
|
48
|
+
try {
|
|
49
|
+
await decodeCommand(file, options);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error(chalk.red(`Error: ${error.message}`));
|
|
52
|
+
process.exit(1);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Info command
|
|
57
|
+
program
|
|
58
|
+
.command('info <file>')
|
|
59
|
+
.description('Show information about an encoded file without decoding')
|
|
60
|
+
.action(async (file, options) => {
|
|
61
|
+
try {
|
|
62
|
+
await infoCommand(file, options);
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error(chalk.red(`Error: ${error.message}`));
|
|
65
|
+
process.exit(1);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
// Verify command
|
|
70
|
+
program
|
|
71
|
+
.command('verify <file>')
|
|
72
|
+
.description('Verify that a file can be decoded without actually decoding')
|
|
73
|
+
.option('-p, --password <password>', 'Password to verify (optional)')
|
|
74
|
+
.action(async (file, options) => {
|
|
75
|
+
try {
|
|
76
|
+
await verifyCommand(file, options);
|
|
77
|
+
} catch (error) {
|
|
78
|
+
console.error(chalk.red(`Error: ${error.message}`));
|
|
79
|
+
process.exit(1);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
// Show help by default if no command is provided
|
|
84
|
+
if (!process.argv.slice(2).length) {
|
|
85
|
+
program.outputHelp();
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// Parse arguments
|
|
89
|
+
program.parse(process.argv);
|