2015-12-04 15:47:52 +01:00
|
|
|
/**
|
2016-09-11 22:20:15 +02:00
|
|
|
* Author......: See docs/credits.txt
|
2015-12-04 15:47:52 +01:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
2023-01-30 14:41:12 +00:00
|
|
|
#ifndef HC_SHARED_H
|
|
|
|
#define HC_SHARED_H
|
2016-09-05 21:47:26 +02:00
|
|
|
|
2016-12-24 00:40:40 +01:00
|
|
|
#include <stdarg.h>
|
2016-09-08 14:11:35 +02:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2016-09-05 21:47:26 +02:00
|
|
|
#include <unistd.h>
|
2016-09-28 23:53:46 +02:00
|
|
|
#include <time.h>
|
2016-09-29 00:25:36 +02:00
|
|
|
#include <fcntl.h>
|
2017-03-19 15:11:41 +01:00
|
|
|
#include <ctype.h>
|
2018-07-31 16:18:45 +02:00
|
|
|
#include <math.h>
|
2019-07-13 00:20:41 +02:00
|
|
|
|
2019-06-21 21:56:38 +02:00
|
|
|
#include "zlib.h"
|
2019-07-13 00:20:41 +02:00
|
|
|
#include "filehandling.h"
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2018-09-01 14:09:24 +02:00
|
|
|
#if defined (_WIN)
|
|
|
|
#include <winsock2.h> // needed for select()
|
|
|
|
#else
|
|
|
|
#include <sys/select.h>
|
|
|
|
#endif
|
|
|
|
|
2020-05-12 08:54:26 +02:00
|
|
|
int sort_by_string_sized (const void *p1, const void *p2);
|
|
|
|
int sort_by_stringptr (const void *p1, const void *p2);
|
2020-05-11 11:52:36 +02:00
|
|
|
|
2017-02-23 10:39:17 +01:00
|
|
|
bool overflow_check_u32_add (const u32 a, const u32 b);
|
|
|
|
bool overflow_check_u32_mul (const u32 a, const u32 b);
|
|
|
|
bool overflow_check_u64_add (const u64 a, const u64 b);
|
|
|
|
bool overflow_check_u64_mul (const u64 a, const u64 b);
|
2017-02-22 16:33:23 +01:00
|
|
|
|
2016-09-20 17:04:31 +02:00
|
|
|
bool is_power_of_2 (const u32 v);
|
|
|
|
|
2016-09-08 10:01:49 +02:00
|
|
|
u32 get_random_num (const u32 min, const u32 max);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2016-09-08 10:01:49 +02:00
|
|
|
u32 mydivc32 (const u32 dividend, const u32 divisor);
|
|
|
|
u64 mydivc64 (const u64 dividend, const u64 divisor);
|
|
|
|
|
2016-09-24 21:44:43 +02:00
|
|
|
char *filename_from_filepath (char *filepath);
|
|
|
|
|
2016-09-30 17:41:40 +02:00
|
|
|
void naive_replace (char *s, const char key_char, const char replace_char);
|
|
|
|
void naive_escape (char *s, size_t s_max, const char key_char, const char escape_char);
|
2015-12-04 15:47:52 +01:00
|
|
|
|
2019-04-02 18:39:42 +02:00
|
|
|
__attribute__ ((format (printf, 2, 3))) int hc_asprintf (char **strp, const char *fmt, ...);
|
2016-12-24 00:40:40 +01:00
|
|
|
|
2019-06-17 17:35:23 +02:00
|
|
|
void setup_environment_variables (const folder_config_t *folder_config);
|
2016-10-30 10:55:27 -07:00
|
|
|
void setup_umask (void);
|
2016-09-28 23:53:46 +02:00
|
|
|
void setup_seeding (const bool rp_gen_seed_chgd, const u32 rp_gen_seed);
|
|
|
|
|
2016-11-16 10:22:57 +01:00
|
|
|
void hc_qsort_r (void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg);
|
|
|
|
void *hc_bsearch_r (const void *key, const void *base, size_t nmemb, size_t size, int (*compar) (const void *, const void *, void *), void *arg);
|
|
|
|
|
2017-01-27 11:46:45 +01:00
|
|
|
bool hc_path_is_file (const char *path);
|
|
|
|
bool hc_path_is_directory (const char *path);
|
2023-01-19 15:54:26 +00:00
|
|
|
bool hc_path_is_fifo (const char *path);
|
2017-01-27 11:46:45 +01:00
|
|
|
bool hc_path_is_empty (const char *path);
|
|
|
|
bool hc_path_exist (const char *path);
|
|
|
|
bool hc_path_read (const char *path);
|
|
|
|
bool hc_path_write (const char *path);
|
2017-01-28 00:08:12 +01:00
|
|
|
bool hc_path_create (const char *path);
|
2018-07-30 13:23:48 +02:00
|
|
|
bool hc_path_has_bom (const char *path);
|
2017-01-27 11:46:45 +01:00
|
|
|
|
2017-03-19 15:11:41 +01:00
|
|
|
bool hc_string_is_digit (const char *s);
|
2021-06-29 20:42:22 +02:00
|
|
|
int hc_string_bom_size (const u8 *s);
|
2017-03-19 15:11:41 +01:00
|
|
|
|
2017-06-02 10:08:19 +02:00
|
|
|
void hc_string_trim_trailing (char *s);
|
|
|
|
void hc_string_trim_leading (char *s);
|
|
|
|
|
2023-08-18 16:10:45 -07:00
|
|
|
int hc_get_processor_count (void);
|
2019-11-02 10:29:34 +01:00
|
|
|
|
2017-10-10 11:30:20 +02:00
|
|
|
bool hc_same_files (char *file1, char *file2);
|
|
|
|
|
2018-02-08 19:13:29 +01:00
|
|
|
u32 hc_strtoul (const char *nptr, char **endptr, int base);
|
|
|
|
u64 hc_strtoull (const char *nptr, char **endptr, int base);
|
|
|
|
|
2018-02-11 10:56:08 +01:00
|
|
|
u32 power_of_two_ceil_32 (const u32 v);
|
|
|
|
u32 power_of_two_floor_32 (const u32 v);
|
|
|
|
|
2018-02-13 13:20:29 +01:00
|
|
|
u32 round_up_multiple_32 (const u32 v, const u32 m);
|
|
|
|
u64 round_up_multiple_64 (const u64 v, const u64 m);
|
|
|
|
|
2018-12-06 14:02:10 +01:00
|
|
|
void hc_strncat (u8 *dst, const u8 *src, const size_t n);
|
2018-07-24 13:55:23 +02:00
|
|
|
|
2020-02-19 10:35:44 +01:00
|
|
|
const u8 *hc_strchr_next (const u8 *input_buf, const int input_len, const u8 separator);
|
|
|
|
const u8 *hc_strchr_last (const u8 *input_buf, const int input_len, const u8 separator);
|
|
|
|
|
2018-07-31 16:18:45 +02:00
|
|
|
int count_char (const u8 *buf, const int len, const u8 c);
|
|
|
|
float get_entropy (const u8 *buf, const int len);
|
|
|
|
|
2018-09-01 13:19:29 +02:00
|
|
|
int select_read_timeout (int sockfd, const int sec);
|
|
|
|
int select_write_timeout (int sockfd, const int sec);
|
|
|
|
|
2018-10-18 11:20:01 +02:00
|
|
|
int select_read_timeout_console (const int sec);
|
|
|
|
|
2018-12-19 13:43:45 +01:00
|
|
|
const char *strparser (const u32 parser_status);
|
2019-01-12 15:05:33 +01:00
|
|
|
const char *strhashcategory (const u32 hash_category);
|
|
|
|
const char *stroptitype (const u32 opti_type);
|
2018-12-19 13:43:45 +01:00
|
|
|
|
2019-02-14 09:53:29 +01:00
|
|
|
bool generic_salt_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, const u8 *in_buf, const int in_len, u8 *out_buf, int *out_len);
|
2019-02-14 10:52:24 +01:00
|
|
|
int generic_salt_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, const u8 *in_buf, const int in_len, u8 *out_buf);
|
2019-01-10 20:51:38 +01:00
|
|
|
|
2021-12-20 13:19:40 +01:00
|
|
|
int input_tokenizer (const u8 *input_buf, const int input_len, hc_token_t *token);
|
2018-12-19 13:43:45 +01:00
|
|
|
|
2023-11-09 15:04:32 +00:00
|
|
|
int extract_dynamicx_hash (const u8 *input_buf, const int input_len, u8 **output_buf, int *output_len);
|
2023-11-08 14:43:45 +00:00
|
|
|
|
2021-12-24 17:30:49 +01:00
|
|
|
#if defined (__APPLE__)
|
|
|
|
bool is_apple_silicon (void);
|
|
|
|
#endif
|
|
|
|
|
2022-08-07 20:36:08 +00:00
|
|
|
char *file_to_buffer (const char *filename);
|
|
|
|
|
2023-01-30 14:41:12 +00:00
|
|
|
#endif // HC_SHARED_H
|