File: shared.h

package info (click to toggle)
hashcat 7.1.2%2Bds1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 75,920 kB
  • sloc: lisp: 627,107; ansic: 431,312; perl: 30,157; cpp: 11,400; sh: 5,250; python: 2,504; makefile: 1,188
file content (134 lines) | stat: -rw-r--r-- 4,376 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
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
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/**
 * Author......: See docs/credits.txt
 * License.....: MIT
 */

#ifndef HC_SHARED_H
#define HC_SHARED_H

#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <time.h>
#include <fcntl.h>
#include <ctype.h>
#include <math.h>

#include "zlib.h"
#include "filehandling.h"

#if defined (_WIN)
#include <winsock2.h> // needed for select()
#else
#include <sys/select.h>
#endif

#ifndef __MINGW_PRINTF_FORMAT
#define __MINGW_PRINTF_FORMAT printf
#endif

int sort_by_string_sized (const void *p1, const void *p2);
int sort_by_stringptr    (const void *p1, const void *p2);

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);

bool is_power_of_2 (const u32 v);
u32 smallest_repeat_double (const u32 v);

u32 get_random_num (const u32 min, const u32 max);

u32 mydivc32 (const u32 dividend, const u32 divisor);
u64 mydivc64 (const u64 dividend, const u64 divisor);

char *filename_from_filepath (char *filepath);

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);

__attribute__ ((format (__MINGW_PRINTF_FORMAT, 2, 3))) int hc_asprintf (char **strp, const char *fmt, ...);

void setup_environment_variables (const folder_config_t *folder_config, const user_options_t *user_options);
void setup_umask (void);
void setup_seeding (const bool rp_gen_seed_chgd, const u32 rp_gen_seed);

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);

bool hc_path_is_file (const char *path);
bool hc_path_is_directory (const char *path);
bool hc_path_is_fifo (const char *path);
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);
bool hc_path_create (const char *path);
bool hc_path_has_bom (const char *path);

bool hc_string_is_digit (const char *s);
int  hc_string_bom_size (const u8 *s);

void hc_string_trim_trailing (char *s);
void hc_string_trim_leading (char *s);

int hc_get_processor_count (void);

bool hc_same_files (char *file1, char *file2);

u32 hc_strtoul  (const char *nptr, char **endptr, int base);
u64 hc_strtoull (const char *nptr, char **endptr, int base);

u32 power_of_two_ceil_32  (const u32 v);
u32 power_of_two_floor_32 (const u32 v);

u32 round_up_multiple_32 (const u32 v, const u32 m);
u64 round_up_multiple_64 (const u64 v, const u64 m);

void hc_strncat (u8 *dst, const u8 *src, const size_t n);

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);

int count_char (const u8 *buf, const int len, const u8 c);
float get_entropy (const u8 *buf, const int len);

int select_read_timeout  (int sockfd, const int sec);
int select_write_timeout (int sockfd, const int sec);

int select_read_timeout_console (const int sec);

const char *strparser (const u32 parser_status);
const char *strhashcategory (const u32 hash_category);
const char *stroptitype (const u32 opti_type);

bool generic_salt_decode (MAYBE_UNUSED const hashconfig_t *hashconfig, const u8 *in_buf, const int in_len, u8 *out_buf, int *out_len);
int  generic_salt_encode (MAYBE_UNUSED const hashconfig_t *hashconfig, const u8 *in_buf, const int in_len, u8 *out_buf);

int input_tokenizer (const u8 *input_buf, const int input_len, hc_token_t *token);

int extract_dynamicx_hash (const u8 *input_buf, const int input_len, u8 **output_buf, int *output_len);

int get_current_arch();

#if defined (__APPLE__)
bool is_apple_silicon (void);
#endif

char *file_to_buffer (const char *filename);

bool check_file_suffix (const char *file, const char *suffix);
bool remove_file_suffix (char *file, const char *suffix);

int suppress_stderr (void);
void restore_stderr (int saved_fd);

bool get_free_memory (u64 *free_mem);

u32 previous_power_of_two (const u32 x);
u32 next_power_of_two (const u32 x);

#endif // HC_SHARED_H