Small improvement to debug logging code.
This commit is contained in:
parent
b0cd820fdf
commit
b654c89dbf
@ -40,6 +40,7 @@
|
||||
# endif
|
||||
#else
|
||||
# include <unistd.h>
|
||||
# include <syslog.h>
|
||||
# define STAT_T struct stat
|
||||
# define STAT(X,Y) stat((X),(Y))
|
||||
# define FSTAT(X,Y) fstat((X),(Y))
|
||||
@ -73,19 +74,17 @@ static void clear_cmdline_args(char *const acmdln, wchar_t *const wcmdln)
|
||||
if (len > 5U) wcscpy(wcmdln, L"slunk");
|
||||
}
|
||||
}
|
||||
static void set_translation_mode(FILE* const stream, const int utf8_mode)
|
||||
{
|
||||
_setmode(_fileno(stream), utf8_mode ? _O_U8TEXT : _O_BINARY);
|
||||
}
|
||||
#endif
|
||||
|
||||
void init_terminal(void)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX);
|
||||
set_translation_mode(stderr, 1);
|
||||
set_translation_mode(stdin, 0);
|
||||
_setmode(_fileno(stderr), _O_U8TEXT);
|
||||
_setmode(_fileno(stdin), _O_BINARY);
|
||||
clear_cmdline_args(_acmdln, _wcmdln);
|
||||
#else
|
||||
openlog("slunkcrypt", LOG_PID | LOG_CONS, LOG_USER);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,13 @@
|
||||
#ifndef INC_SLUNKCRYPT_COMPILER_H
|
||||
#define INC_SLUNKCRYPT_COMPILER_H
|
||||
|
||||
#ifdef _WIN32
|
||||
# define WIN32_LEAN_AND_MEAN 1
|
||||
# define _CRT_SECURE_NO_WARNINGS 1
|
||||
#else
|
||||
# define _GNU_SOURCE 1
|
||||
#endif
|
||||
|
||||
/* Intel(R) oneAPI DPC++/C++ Compiler */
|
||||
#if defined(__INTEL_LLVM_COMPILER) && (!defined(__GNUC__))
|
||||
# define __GNUC__ 4
|
||||
|
@ -10,31 +10,37 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/* syslog */
|
||||
#if defined(_WIN32)
|
||||
/* logging sub-system */
|
||||
#ifdef _WIN32
|
||||
# define WIN32_LEAN_AND_MEAN 1
|
||||
# include <Windows.h>
|
||||
#elif defined(__unix__) || defined(__HAIKU__)
|
||||
#else
|
||||
# include <syslog.h>
|
||||
#endif
|
||||
|
||||
void slunkcrypt_debug_write(const char* const text)
|
||||
void slunkcrypt_debug_write(const char* const message)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
OutputDebugStringA(text);
|
||||
#elif defined(__unix__) || defined(__HAIKU__)
|
||||
syslog(LOG_DEBUG, "%s", text);
|
||||
#ifdef _WIN32
|
||||
OutputDebugStringA(message);
|
||||
#else
|
||||
syslog(LOG_ALERT, "%s", message);
|
||||
#endif
|
||||
}
|
||||
|
||||
void slunkcrypt_debug_print(const char* const text, ...)
|
||||
void slunkcrypt_debug_print(const char* const message, ...)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
char buffer[100U];
|
||||
va_list ap;
|
||||
va_start(ap, text);
|
||||
if (vsnprintf(buffer, 100U, text, ap) > 0)
|
||||
#endif
|
||||
va_list args;
|
||||
va_start(args, message);
|
||||
#ifdef _WIN32
|
||||
if (vsnprintf(buffer, 100U, message, args) > 0)
|
||||
{
|
||||
slunkcrypt_debug_write(buffer);
|
||||
OutputDebugStringA(buffer);
|
||||
}
|
||||
va_end(ap);
|
||||
#else
|
||||
vsyslog(LOG_ALERT, message, args);
|
||||
#endif
|
||||
va_end(args);
|
||||
}
|
||||
|
@ -6,7 +6,14 @@
|
||||
#ifndef INC_SLUNKCRYPT_DEBUG_H
|
||||
#define INC_SLUNKCRYPT_DEBUG_H
|
||||
|
||||
void slunkcrypt_debug_write(const char *const text);
|
||||
void slunkcrypt_debug_print(const char *const text, ...);
|
||||
void slunkcrypt_debug_write(const char *const message);
|
||||
void slunkcrypt_debug_print(const char *const message, ...);
|
||||
|
||||
#define DBG_PRINTF(BUFF, FORMAT, ...) do \
|
||||
{ \
|
||||
const int _strlen = sprintf((BUFF), (FORMAT), __VA_ARGS__); \
|
||||
if (_strlen > 0) { BUFF += _strlen; } \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
#endif
|
||||
|
@ -3,16 +3,9 @@
|
||||
/* This work has been released under the CC0 1.0 Universal license! */
|
||||
/******************************************************************************/
|
||||
|
||||
#ifdef _WIN32
|
||||
# define WIN32_LEAN_AND_MEAN 1
|
||||
# define _CRT_SECURE_NO_WARNINGS 1
|
||||
#else
|
||||
# define _GNU_SOURCE 1
|
||||
#endif
|
||||
|
||||
/* Internal */
|
||||
#include "slunkcrypt.h"
|
||||
#include "compiler.h"
|
||||
#include "slunkcrypt.h"
|
||||
|
||||
/* CRT */
|
||||
#include <string.h>
|
||||
|
@ -3,16 +3,10 @@
|
||||
/* This work has been released under the CC0 1.0 Universal license! */
|
||||
/******************************************************************************/
|
||||
|
||||
#ifdef _WIN32
|
||||
# define _CRT_SECURE_NO_WARNINGS 1
|
||||
#else
|
||||
# define _GNU_SOURCE 1
|
||||
#endif
|
||||
|
||||
/* Internal */
|
||||
#include "compiler.h"
|
||||
#include "slunkcrypt.h"
|
||||
#include "debug.h"
|
||||
#include "compiler.h"
|
||||
#include "keygen.h"
|
||||
#include "initialize.h"
|
||||
#include "thread.h"
|
||||
@ -219,20 +213,20 @@ static int initialize_state(crypt_data_t *const data, const size_t thread_count,
|
||||
/* dump the final configuration */
|
||||
if (debug)
|
||||
{
|
||||
const rand_state_t *const rand_state = &data->thread_data[0].random;
|
||||
slunkcrypt_debug_print("cntr = %08X", data->thread_data[0].counter);
|
||||
slunkcrypt_debug_print("drbg = %08X %08X %08X %08X %08X %08X",
|
||||
data->thread_data[0].random.d, data->thread_data[0].random.v, data->thread_data[0].random.w,
|
||||
data->thread_data[0].random.x, data->thread_data[0].random.y, data->thread_data[0].random.z);
|
||||
slunkcrypt_debug_print("drbg = %08X %08X %08X %08X %08X %08X", rand_state->d, rand_state->v, rand_state->w, rand_state->x, rand_state->y, rand_state->z);
|
||||
for (r = 0U; r < 256U; ++r)
|
||||
{
|
||||
char text[775U];
|
||||
size_t off = sprintf(text, "[%02X] =", (unsigned)r);
|
||||
char message[775U] = { '\0' };
|
||||
char *ptr = message;
|
||||
DBG_PRINTF(ptr, "[%02X] =", (unsigned)r);
|
||||
for (i = 0U; i < 256U; ++i)
|
||||
{
|
||||
off += sprintf(text + off, " %02X", data->wheel[r][i]);
|
||||
DBG_PRINTF(ptr, " %02X", data->wheel[r][i]);
|
||||
}
|
||||
CHECK_ABORTED();
|
||||
slunkcrypt_debug_write(text);
|
||||
slunkcrypt_debug_write(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5,15 +5,9 @@
|
||||
|
||||
#ifndef SLUNKBUILD_NOTHREADS
|
||||
|
||||
#ifdef _WIN32
|
||||
# define _CRT_SECURE_NO_WARNINGS 1
|
||||
#else
|
||||
# define _GNU_SOURCE 1
|
||||
#endif
|
||||
|
||||
/* Internal */
|
||||
#include "thread.h"
|
||||
#include "compiler.h"
|
||||
#include "thread.h"
|
||||
|
||||
/* CRT */
|
||||
#include <stdlib.h>
|
||||
|
Loading…
Reference in New Issue
Block a user