Skip to content

Commit ae5a709

Browse files
committed
Formats: Colorize warnings and/or use _ONCE macros
1 parent f405c6a commit ae5a709

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+224
-306
lines changed

src/7z_common_plug.c

Lines changed: 27 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ struct fmt_tests sevenzip_tests[] = {
101101

102102
sevenzip_salt_t *sevenzip_salt;
103103

104-
#define YEL "\x1b[0;33m"
105-
#define NRM "\x1b[0m"
106-
107104
int sevenzip_trust_padding;
108105

109106
static char *comp_type[16] = { "stored", "LZMA1", "LZMA2", "PPMD", NULL, NULL, "BZIP2", "DEFLATE" };
@@ -140,23 +137,23 @@ int sevenzip_valid(char *ciphertext, struct fmt_main *self)
140137
&& type != 128) {
141138
if (john_main_process && !warned[type]) {
142139
warned[type] = 1;
143-
fprintf(stderr, YEL "Warning: Not loading files with unsupported compression type %s (0x%02x)\n" NRM,
140+
fprintf_color(color_warning, stderr, "Warning: Not loading files with unsupported compression type %s (0x%02x)\n",
144141
comp_type[c_type] ? comp_type[c_type] : "(unknown)", type);
145142
#if !HAVE_LIBBZ2
146143
if (type == 6)
147-
fprintf(stderr, YEL "Rebuild with libbz2 to get support for that type.\n" NRM);
144+
fprintf_color(color_warning, stderr, "Rebuild with libbz2 to get support for that type.\n");
148145
#endif
149146
#if !HAVE_LIBZ
150147
if (type == 7)
151-
fprintf(stderr, YEL "Rebuild with libz (zlib) to get support for that type.\n" NRM);
148+
fprintf_color(color_warning, stderr, "Rebuild with libz (zlib) to get support for that type.\n");
152149
#endif
153150
}
154151
goto err;
155152
}
156153
if (john_main_process && !ldr_in_pot && !self_test_running &&
157154
options.verbosity > VERB_DEFAULT && !warned[type]) {
158155
warned[type] = 1;
159-
fprintf(stderr, YEL "Saw file(s) with compression type %s%s%s (0x%02x)\n" NRM,
156+
fprintf_color(color_notice, stderr, "Saw file(s) with compression type %s%s%s (0x%02x)\n",
160157
precomp_type[p_type], p_type ? "+" : "", comp_type[c_type], type);
161158
}
162159
if ((p = strtokm(NULL, "$")) == NULL) /* NumCyclesPower */
@@ -174,11 +171,8 @@ int sevenzip_valid(char *ciphertext, struct fmt_main *self)
174171
goto err;
175172
len = atoi(p);
176173
if (len > 0 && strstr(self->params.label, "-opencl")) {
177-
static int warned;
178-
179-
if (!warned++)
180-
fprintf(stderr, YEL "%s: Warning: Not loading hashes with salt due to optimizations. Please report!\n" NRM,
181-
self->params.label);
174+
if (!ldr_in_pot && john_main_process)
175+
WARN_ONCE(color_warning, stderr, "%s: Warning: Not loading hashes with salt due to optimizations. Please report!\n", self->params.label);
182176
goto err;
183177
}
184178
if (len > 16)
@@ -355,7 +349,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
355349

356350
#if DEBUG
357351
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
358-
fprintf(stderr, "\nType %02x (%s%s%s) AES length %zu, packed len %zu, pad size %d, crc len %zu\n",
352+
fprintf_color(color_notice, stderr, "\nType %02x (%s%s%s) AES length %zu, packed len %zu, pad size %d, crc len %zu\n",
359353
sevenzip_salt->type, precomp_type[p_type] ? precomp_type[p_type] : "",
360354
p_type ? "+" : "",
361355
comp_type[c_type] ? comp_type[c_type] : "(unknown)",
@@ -379,12 +373,11 @@ int sevenzip_decrypt(unsigned char *derived_key)
379373
if (buf[i] != 0) {
380374
#if DEBUG
381375
if (!benchmark_running && options.verbosity >= VERB_DEBUG) {
382-
fprintf(stderr, YEL "Early padding check failed, ");
376+
fprintf_color(color_warning, stderr, "Early padding check failed, ");
383377
dump_stderr_msg("padding", buf + 16 - pad_size, pad_size);
384-
fprintf(stderr, NRM);
385378
}
386379
if (sevenzip_salt->type == 0x80)
387-
fprintf(stderr, YEL "We don't have data for complete decryption\n");
380+
WARN_ONCE(color_warning, stderr, "We don't have data for complete decryption\n");
388381
break;
389382
#else
390383
return 0;
@@ -395,13 +388,13 @@ int sevenzip_decrypt(unsigned char *derived_key)
395388
}
396389
#if DEBUG
397390
if (!nbytes && !benchmark_running && options.verbosity >= VERB_DEBUG)
398-
fprintf(stderr, "Early padding check passed\n");
391+
fprintf_color(color_notice, stderr, "Early padding check passed\n");
399392
else
400393
nbytes = 0;
401-
#else
394+
if (self_test_running)
395+
#endif
402396
if (sevenzip_salt->type == 0x80) /* We only have truncated data */
403397
return 1;
404-
#endif
405398
}
406399

407400
/* Complete decryption */
@@ -417,9 +410,8 @@ int sevenzip_decrypt(unsigned char *derived_key)
417410
if (out[i] != 0) {
418411
#if DEBUG
419412
if (!benchmark_running && options.verbosity >= VERB_DEBUG) {
420-
fprintf(stderr, YEL "Full data padding check failed, ");
413+
fprintf_color(color_warning, stderr, "Full data padding check failed, ");
421414
dump_stderr_msg("padding", out + sevenzip_salt->aes_length - pad_size, pad_size);
422-
fprintf(stderr, NRM);
423415
}
424416
break;
425417
#else
@@ -431,7 +423,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
431423
}
432424
#if DEBUG
433425
if (!nbytes && !benchmark_running && options.verbosity >= VERB_DEBUG)
434-
fprintf(stderr, "Padding check passed\n");
426+
fprintf_color(color_notice, stderr, "Padding check passed\n");
435427
#endif
436428
}
437429

@@ -456,7 +448,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
456448
out_size == crc_len) {
457449
#if DEBUG
458450
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
459-
fprintf(stderr, "LZMA decoding passed, %zu/%zu -> %zu/%zu, props %02x%02x%02x%02x\n",
451+
fprintf_color(color_notice, stderr, "LZMA decoding passed, %zu/%zu -> %zu/%zu, props %02x%02x%02x%02x\n",
460452
in_size, sevenzip_salt->packed_size, out_size, crc_len, sevenzip_salt->decoder_props[0],
461453
sevenzip_salt->decoder_props[1], sevenzip_salt->decoder_props[2], sevenzip_salt->decoder_props[3]);
462454
#endif
@@ -465,7 +457,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
465457
} else {
466458
#if DEBUG
467459
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
468-
fprintf(stderr, YEL "LZMA decoding failed, %zu/%zu -> %zu/%zu, props %02x%02x%02x%02x\n" NRM,
460+
fprintf_color(color_warning, stderr, "LZMA decoding failed, %zu/%zu -> %zu/%zu, props %02x%02x%02x%02x\n",
469461
in_size, sevenzip_salt->packed_size, out_size, crc_len, sevenzip_salt->decoder_props[0],
470462
sevenzip_salt->decoder_props[1], sevenzip_salt->decoder_props[2], sevenzip_salt->decoder_props[3]);
471463
#endif
@@ -488,15 +480,15 @@ int sevenzip_decrypt(unsigned char *derived_key)
488480
out_size == crc_len) {
489481
#if DEBUG
490482
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
491-
fprintf(stderr, "LZMA2 decoding passed, %zu/%zu -> %zu/%zu, props %02x\n",
483+
fprintf_color(color_notice, stderr, "LZMA2 decoding passed, %zu/%zu -> %zu/%zu, props %02x\n",
492484
in_size, sevenzip_salt->packed_size, out_size, crc_len, sevenzip_salt->decoder_props[0]);
493485
#endif
494486
MEM_FREE(out);
495487
out = new_out;
496488
} else {
497489
#if DEBUG
498490
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
499-
fprintf(stderr, YEL "LZMA2 decoding failed, %zu/%zu -> %zu/%zu, props %02x\n" NRM,
491+
fprintf_color(color_warning, stderr, "LZMA2 decoding failed, %zu/%zu -> %zu/%zu, props %02x\n",
500492
in_size, sevenzip_salt->packed_size, out_size, crc_len, sevenzip_salt->decoder_props[0]);
501493
#endif
502494
MEM_FREE(new_out);
@@ -526,7 +518,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
526518
if (ret == BZ_STREAM_END) {
527519
#if DEBUG
528520
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
529-
fprintf(stderr, "BZIP2 decoding passed, %zu/%zu -> %zu/%zu\n",
521+
fprintf_color(color_notice, stderr, "BZIP2 decoding passed, %zu/%zu -> %zu/%zu\n",
530522
sevenzip_salt->packed_size - inf_stream.avail_in, sevenzip_salt->packed_size,
531523
crc_len - inf_stream.avail_out, crc_len);
532524
#endif
@@ -535,7 +527,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
535527
} else {
536528
#if DEBUG
537529
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
538-
fprintf(stderr, YEL "BZIP2 decoding failed, %zu/%zu -> %zu/%zu\n" NRM,
530+
fprintf_color(color_warning, stderr, "BZIP2 decoding failed, %zu/%zu -> %zu/%zu\n",
539531
sevenzip_salt->packed_size - inf_stream.avail_in, sevenzip_salt->packed_size,
540532
crc_len - inf_stream.avail_out, crc_len);
541533
#endif
@@ -564,7 +556,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
564556
if (ret == Z_STREAM_END) {
565557
#if DEBUG
566558
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
567-
fprintf(stderr, "DEFLATE decoding passed, %zu/%zu -> %zu/%zu\n",
559+
fprintf_color(color_notice, stderr, "DEFLATE decoding passed, %zu/%zu -> %zu/%zu\n",
568560
sevenzip_salt->packed_size - inf_stream.avail_in, sevenzip_salt->packed_size,
569561
crc_len - inf_stream.avail_out, crc_len);
570562
#endif
@@ -573,7 +565,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
573565
} else {
574566
#if DEBUG
575567
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
576-
fprintf(stderr, YEL "DEFLATE decoding failed, %zu/%zu -> %zu/%zu\n" NRM,
568+
fprintf_color(color_warning, stderr, "DEFLATE decoding failed, %zu/%zu -> %zu/%zu\n",
577569
sevenzip_salt->packed_size - inf_stream.avail_in, sevenzip_salt->packed_size,
578570
crc_len - inf_stream.avail_out, crc_len);
579571
#endif
@@ -586,7 +578,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
586578
if (p_type) {
587579
#if DEBUG
588580
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
589-
fprintf(stderr, "Decoding %s, props %02x\n", precomp_type[p_type], sevenzip_salt->preproc_props);
581+
fprintf_color(color_notice, stderr, "Decoding %s, props %02x\n", precomp_type[p_type], sevenzip_salt->preproc_props);
590582
#endif
591583
if (p_type == 1) {
592584
uint32_t state;
@@ -596,10 +588,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
596588
}
597589
else if (p_type == 2) {
598590
if (!benchmark_running && options.verbosity >= VERB_DEFAULT) {
599-
static int warned;
600-
601-
if (!warned++)
602-
fprintf(stderr, YEL "Can't decode BCJ2, so skipping CRC check" NRM);
591+
WARN_ONCE(color_warning, stderr, "Can't decode BCJ2, so skipping CRC check");
603592
}
604593
goto exit_good;
605594
}
@@ -620,7 +609,7 @@ int sevenzip_decrypt(unsigned char *derived_key)
620609
Delta_Decode(state, sevenzip_salt->preproc_props + 1, out, crc_len);
621610
#if DEBUG
622611
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
623-
fprintf(stderr, YEL "DELTA decoding can't fail so result unknown\n" NRM);
612+
fprintf_color(color_notice, stderr, "DELTA decoding can't fail so result unknown\n");
624613
#endif
625614
}
626615
}
@@ -636,13 +625,13 @@ int sevenzip_decrypt(unsigned char *derived_key)
636625
if (ccrc == sevenzip_salt->crc) {
637626
#if DEBUG
638627
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
639-
fprintf(stderr, "CRC check passed (%08x)\n", ccrc);
628+
fprintf_color(color_notice, stderr, "CRC check passed (%08x)\n", ccrc);
640629
#endif
641630
goto exit_good;
642631
}
643632
#if DEBUG
644633
if (!benchmark_running && options.verbosity >= VERB_DEBUG)
645-
fprintf(stderr, YEL "CRC failed, %08x vs %08x\n" NRM, ccrc, sevenzip_salt->crc);
634+
fprintf_color(color_warning, stderr, "CRC failed, %08x vs %08x\n", ccrc, sevenzip_salt->crc);
646635
#endif
647636

648637
exit_bad:

src/LM_fmt.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,14 +124,12 @@ static void init(struct fmt_main *self)
124124
fmt_LM.params.max_keys_per_crypt = DES_bs_max_kpc;
125125
#endif
126126

127-
static int warned;
128-
if (!warned && options.target_enc > CP_DOS_HI && !options.listconf &&
127+
if (options.target_enc > CP_DOS_HI && !options.listconf &&
129128
sizeof(tests) / sizeof(tests[0]) > 16) {
130-
fprintf_color(color_warning, stderr,
129+
WARN_ONCE(color_warning, stderr,
131130
"Warning: LM formats incompatible with %s encoding, disabling some tests\n",
132131
cp_id2name(options.target_enc));
133132
tests[16].ciphertext = NULL; // Truncates the array after 16 entries
134-
warned = 1;
135133
}
136134
}
137135

src/argon2_fmt_plug.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -272,11 +272,11 @@ static void set_salt(void *salt)
272272
static int allocate(uint8_t **memory, size_t size)
273273
{
274274
if (THREAD_NUMBER < 0 || THREAD_NUMBER > NUM_THREADS) {
275-
fprintf(stderr, "Error: Argon2: Thread number %d out of range\n", THREAD_NUMBER);
275+
fprintf_color(color_error, stderr, "Error: Argon2: Thread number %d out of range\n", THREAD_NUMBER);
276276
goto fail;
277277
}
278278
if (thread_mem[THREAD_NUMBER].used) {
279-
fprintf(stderr, "Error: Argon2: Thread %d: Memory allocated twice\n", THREAD_NUMBER);
279+
fprintf_color(color_error, stderr, "Error: Argon2: Thread %d: Memory allocated twice\n", THREAD_NUMBER);
280280
goto fail;
281281
}
282282

@@ -299,15 +299,15 @@ static int allocate(uint8_t **memory, size_t size)
299299
static void deallocate(uint8_t *memory, size_t size)
300300
{
301301
if (THREAD_NUMBER < 0 || THREAD_NUMBER > NUM_THREADS) {
302-
fprintf(stderr, "Error: Argon2: Thread number %d out of range\n", THREAD_NUMBER);
302+
fprintf_color(color_error, stderr, "Error: Argon2: Thread number %d out of range\n", THREAD_NUMBER);
303303
return;
304304
}
305305

306306
if (!thread_mem[THREAD_NUMBER].used)
307-
fprintf(stderr, "Error: Argon2: Thread %d: Freed memory not in use\n", THREAD_NUMBER);
307+
fprintf_color(color_error, stderr, "Error: Argon2: Thread %d: Freed memory not in use\n", THREAD_NUMBER);
308308

309309
if (thread_mem[THREAD_NUMBER].region.aligned_size < size)
310-
fprintf(stderr, "Error: Argon2: Thread %d: Freeing incorrect size %zu, was %zu\n",
310+
fprintf_color(color_error, stderr, "Error: Argon2: Thread %d: Freeing incorrect size %zu, was %zu\n",
311311
THREAD_NUMBER, size, thread_mem[THREAD_NUMBER].region.aligned_size);
312312

313313
thread_mem[THREAD_NUMBER].used = 0;
@@ -343,7 +343,7 @@ static int crypt_all(int *pcount, struct db_salt *salt)
343343
error_code = argon2_ctx(&context, saved_salt.type);
344344
if (error_code != ARGON2_OK) {
345345
failed = -1;
346-
fprintf(stderr, "Error: Argon2 failed: %s\n", argon2_error_message(error_code));
346+
fprintf_color(color_error, stderr, "Error: Argon2 failed: %s\n", argon2_error_message(error_code));
347347
#ifndef _OPENMP
348348
break;
349349
#endif
@@ -352,7 +352,7 @@ static int crypt_all(int *pcount, struct db_salt *salt)
352352

353353
if (failed) {
354354
#ifdef _OPENMP
355-
fprintf(stderr, "Error: Argon2 failed in some threads\n");
355+
fprintf_color(color_error, stderr, "Error: Argon2 failed in some threads\n");
356356
#endif
357357
error();
358358
}

src/armory_fmt_plug.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ static void init(struct fmt_main *self)
125125
* calls that take a const pointer.
126126
*/
127127
if (!(secp256k1_ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN))) {
128-
fprintf(stderr, "Failed to create secp256k1 context\n");
129-
error();
128+
error_msg("Failed to create secp256k1 context\n");
130129
}
131130
}
132131

@@ -439,12 +438,10 @@ static int crypt_all(int *pcount, struct db_salt *salt)
439438
if (failed) {
440439
#ifdef _OPENMP
441440
if (failed < 0) {
442-
fprintf(stderr, "OpenMP thread number out of range\n");
443-
error();
441+
error_msg("OpenMP thread number out of range\n");
444442
}
445443
#endif
446-
fprintf(stderr, "Memory allocation failed: %s\n", strerror(failed));
447-
error();
444+
error_msg("Memory allocation failed: %s\n", strerror(failed));
448445
}
449446

450447
return cracked ? count : 0;

src/as400_ssha1_fmt_plug.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ john_register_one(&fmt_AS400_ssha1);
4646
#include "options.h"
4747
#include "unicode.h"
4848
#include "base64_convert.h"
49+
#include "john.h"
4950

5051
#define FORMAT_LABEL "as400-ssha1"
5152
#define FORMAT_NAME "AS400-SaltedSHA1"
@@ -150,14 +151,12 @@ static int our_valid(char *ciphertext, struct fmt_main *self)
150151
if (strlen(&ciphertext[FORMAT_TAG_LEN + 2 * BINARY_SIZE + 1]) > 10)
151152
return 0;
152153
if (options.input_enc == UTF_8 && !valid_utf8((UTF8*)ciphertext)) {
153-
static int error_shown = 0;
154154
#ifdef HAVE_FUZZ
155155
if (options.flags & (FLG_FUZZ_CHK | FLG_FUZZ_DUMP_CHK))
156156
return 0;
157157
#endif
158-
if (!error_shown)
159-
fprintf(stderr, "%s: Input file is not UTF-8. Please use --input-enc to specify a codepage.\n", self->params.label);
160-
error_shown = 1;
158+
if (john_main_process)
159+
WARN_ONCE(color_error, stderr, "%s: Input file is not UTF-8. Please use --input-enc to specify a codepage.\n", self->params.label);
161160
return 0;
162161
}
163162
return pDynamic->methods.valid(Convert(Conv_Buf, ciphertext), pDynamic);

src/bestcrypt_ve_fmt_plug.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ john_register_one(&fmt_bestcrypt_ve);
3131
#endif
3232

3333
#include "arch.h"
34+
#include "john.h"
3435
#include "misc.h"
3536
#include "common.h"
3637
#include "formats.h"
@@ -229,7 +230,8 @@ static int valid(char *ciphertext, struct fmt_main *self)
229230
if (atoi(p) != 8 && atoi(p) != 9 && atoi(p) != 10 && atoi(p) != 11 && atoi(p) != 15)
230231
goto err;
231232
if (atoi(p) == 11) {
232-
fprintf(stderr, "Warning: " FORMAT_LABEL ": RC6 encryption not supported yet!\n");
233+
if (john_main_process && !ldr_in_pot)
234+
fprintf_color(color_warning, stderr, "Warning: " FORMAT_LABEL ": RC6 encryption not supported yet!\n");
233235
goto err;
234236
}
235237
if ((p = strtokm(NULL, "$")) == NULL) // salt
@@ -401,11 +403,11 @@ static int crypt_all(int *pcount, struct db_salt *salt)
401403
if (failed) {
402404
#ifdef _OPENMP
403405
if (failed < 0) {
404-
fprintf(stderr, "OpenMP thread number out of range\n");
406+
fprintf_color(color_error, stderr, "OpenMP thread number out of range\n");
405407
error();
406408
}
407409
#endif
408-
fprintf(stderr, "scrypt failed: %s\n", strerror(failed));
410+
fprintf_color(color_error, stderr, "scrypt failed: %s\n", strerror(failed));
409411
error();
410412
}
411413

src/bitshares_fmt_plug.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ static int crypt_all(int *pcount, struct db_salt *salt)
300300
any_cracked |= 1;
301301

302302
if (memcmp(km, out_full, 4) != 0) {
303-
fprintf(stderr, "Warning: " FORMAT_LABEL ": Good padding, but bad checksum"
303+
fprintf_color(color_warning, stderr, "Warning: " FORMAT_LABEL ": Good padding, but bad checksum"
304304
" (corrupted data or false positive?) - will keep guessing\n");
305305
fmt_bitshares.params.flags |= FMT_NOT_EXACT;
306306
}

0 commit comments

Comments
 (0)