1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-22 08:08:10 +00:00

Prepare file_to_buffer() for later use

This commit is contained in:
jsteube 2022-08-07 20:36:08 +00:00
parent 51b1744805
commit 7668ec5865
2 changed files with 33 additions and 0 deletions

View File

@ -107,4 +107,6 @@ int input_tokenizer (const u8 *input_buf, const int input_len, hc_token_t *token
bool is_apple_silicon (void);
#endif
char *file_to_buffer (const char *filename);
#endif // _SHARED_H

View File

@ -1397,3 +1397,34 @@ bool is_apple_silicon (void)
}
#endif // __APPLE__
char *file_to_buffer (const char *filename)
{
HCFILE fp;
if (hc_fopen (&fp, filename, "r") == true)
{
struct stat st;
memset (&st, 0, sizeof (st));
if (hc_fstat (&fp, &st))
{
hc_fclose (&fp);
return NULL;
}
char *buffer = malloc (st.st_size + 1);
const size_t nread = hc_fread (buffer, 1, st.st_size, &fp);
hc_fclose (&fp);
buffer[nread] = 0;
return buffer;
}
return NULL;
}