2016-09-05 19:47:26 +00:00
|
|
|
/**
|
2016-09-11 20:20:15 +00:00
|
|
|
* Author......: See docs/credits.txt
|
2016-09-05 19:47:26 +00:00
|
|
|
* License.....: MIT
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
2016-10-10 09:03:11 +00:00
|
|
|
#include "types.h"
|
|
|
|
#include "event.h"
|
2016-09-05 19:47:26 +00:00
|
|
|
#include "memory.h"
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
void *hccalloc (hashcat_ctx_t *hashcat_ctx, const size_t nmemb, const size_t sz)
|
2016-09-05 19:47:26 +00:00
|
|
|
{
|
2016-10-10 09:03:11 +00:00
|
|
|
void *p = calloc (nmemb, sz);
|
2016-09-05 19:47:26 +00:00
|
|
|
|
|
|
|
if (p == NULL)
|
|
|
|
{
|
2016-10-11 08:55:02 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s", MSG_ENOMEM);
|
2016-09-05 19:47:26 +00:00
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
return (NULL);
|
2016-09-05 19:47:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
void *hcmalloc (hashcat_ctx_t *hashcat_ctx, const size_t sz)
|
2016-09-05 19:47:26 +00:00
|
|
|
{
|
2016-10-10 09:03:11 +00:00
|
|
|
void *p = malloc (sz);
|
2016-09-05 19:47:26 +00:00
|
|
|
|
|
|
|
if (p == NULL)
|
|
|
|
{
|
2016-10-11 08:55:02 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s", MSG_ENOMEM);
|
2016-09-05 19:47:26 +00:00
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
return (NULL);
|
2016-09-05 19:47:26 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
memset (p, 0, sz);
|
2016-09-05 19:47:26 +00:00
|
|
|
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
void *hcrealloc (hashcat_ctx_t *hashcat_ctx, void *ptr, const size_t oldsz, const size_t addsz)
|
2016-09-05 19:47:26 +00:00
|
|
|
{
|
2016-10-10 09:03:11 +00:00
|
|
|
void *p = realloc (ptr, oldsz + addsz);
|
2016-09-05 19:47:26 +00:00
|
|
|
|
|
|
|
if (p == NULL)
|
|
|
|
{
|
2016-10-11 08:55:02 +00:00
|
|
|
event_log_error (hashcat_ctx, "%s", MSG_ENOMEM);
|
2016-09-05 19:47:26 +00:00
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
return (NULL);
|
2016-09-05 19:47:26 +00:00
|
|
|
}
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
memset ((char *) p + oldsz, 0, addsz);
|
2016-09-05 19:47:26 +00:00
|
|
|
|
|
|
|
return (p);
|
|
|
|
}
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
char *hcstrdup (hashcat_ctx_t *hashcat_ctx, const char *s)
|
2016-09-05 19:47:26 +00:00
|
|
|
{
|
|
|
|
const size_t len = strlen (s);
|
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
char *b = (char *) hcmalloc (hashcat_ctx, len + 1);
|
|
|
|
|
2016-10-13 08:07:04 +00:00
|
|
|
if (b == NULL) return (NULL);
|
|
|
|
|
|
|
|
memcpy (b, s, len);
|
2016-09-05 19:47:26 +00:00
|
|
|
|
2016-10-10 09:03:11 +00:00
|
|
|
b[len] = 0;
|
2016-09-05 19:47:26 +00:00
|
|
|
|
|
|
|
return (b);
|
|
|
|
}
|
2016-10-10 09:03:11 +00:00
|
|
|
|
|
|
|
void hcfree (void *ptr)
|
|
|
|
{
|
|
|
|
if (ptr == NULL) return;
|
|
|
|
|
|
|
|
free (ptr);
|
|
|
|
}
|