Add wrapping function for asprintf()

pull/933/head
jsteube 8 years ago
parent 72af615e8b
commit 6ece83760d

@ -6,6 +6,7 @@
#ifndef _SHARED_H #ifndef _SHARED_H
#define _SHARED_H #define _SHARED_H
#include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
@ -24,6 +25,8 @@ char *filename_from_filepath (char *filepath);
void naive_replace (char *s, const char key_char, const char replace_char); 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); void naive_escape (char *s, size_t s_max, const char key_char, const char escape_char);
void hc_asprintf (char **strp, const char *fmt, ...);
void hc_sleep_msec (const u32 msec); void hc_sleep_msec (const u32 msec);
void hc_sleep (const u32 sec); void hc_sleep (const u32 sec);

@ -9,6 +9,7 @@
#include "event.h" #include "event.h"
#include "dictstat.h" #include "dictstat.h"
#include "locking.h" #include "locking.h"
#include "shared.h"
int sort_by_dictstat (const void *s1, const void *s2) int sort_by_dictstat (const void *s1, const void *s2)
{ {
@ -46,7 +47,7 @@ int dictstat_init (hashcat_ctx_t *hashcat_ctx)
dictstat_ctx->base = (dictstat_t *) hccalloc (MAX_DICTSTAT, sizeof (dictstat_t)); dictstat_ctx->base = (dictstat_t *) hccalloc (MAX_DICTSTAT, sizeof (dictstat_t));
dictstat_ctx->cnt = 0; dictstat_ctx->cnt = 0;
asprintf (&dictstat_ctx->filename, "%s/hashcat.dictstat", folder_config->profile_dir); hc_asprintf (&dictstat_ctx->filename, "%s/hashcat.dictstat", folder_config->profile_dir);
FILE *fp = fopen (dictstat_ctx->filename, "ab"); FILE *fp = fopen (dictstat_ctx->filename, "ab");

@ -28,7 +28,7 @@ static int get_exec_path (char *exec_path, const size_t exec_path_sz)
char *tmp; char *tmp;
asprintf (&tmp, "/proc/%d/exe", getpid ()); hc_asprintf (&tmp, "/proc/%d/exe", getpid ());
const ssize_t len = readlink (tmp, exec_path, exec_path_sz - 1); const ssize_t len = readlink (tmp, exec_path, exec_path_sz - 1);
@ -221,7 +221,7 @@ char **scan_directory (const char *path)
char *path_file; char *path_file;
asprintf (&path_file, "%s/%s", tmp_path, de->d_name); hc_asprintf (&path_file, "%s/%s", tmp_path, de->d_name);
DIR *d_test; DIR *d_test;
@ -393,7 +393,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
#if defined (_WIN) #if defined (_WIN)
asprintf (&cpath, "%s\\OpenCL\\", shared_dir); hc_asprintf (&cpath, "%s\\OpenCL\\", shared_dir);
char *cpath_real = (char *) hcmalloc (HCBUFSIZ_TINY); char *cpath_real = (char *) hcmalloc (HCBUFSIZ_TINY);
@ -406,7 +406,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
#else #else
asprintf (&cpath, "%s/OpenCL/", shared_dir); hc_asprintf (&cpath, "%s/OpenCL/", shared_dir);
char *cpath_real = (char *) hcmalloc (PATH_MAX); char *cpath_real = (char *) hcmalloc (PATH_MAX);
@ -426,7 +426,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
{ {
char *tmp; char *tmp;
asprintf (&tmp, "TMP=%s", cpath_real); hc_asprintf (&tmp, "TMP=%s", cpath_real);
putenv (tmp); putenv (tmp);
} }
@ -450,7 +450,7 @@ int folder_config_init (hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const char *ins
char *kernels_folder; char *kernels_folder;
asprintf (&kernels_folder, "%s/kernels", profile_dir); hc_asprintf (&kernels_folder, "%s/kernels", profile_dir);
hc_mkdir (kernels_folder, 0700); hc_mkdir (kernels_folder, 0700);

@ -57,7 +57,7 @@ static char *hm_SYSFS_get_syspath_device (hashcat_ctx_t *hashcat_ctx, const int
char *syspath; char *syspath;
asprintf (&syspath, "%s/0000:%02x:%02x.%01x", SYS_BUS_PCI_DEVICES, device_param->pcie_bus, device_param->pcie_device, device_param->pcie_function); hc_asprintf (&syspath, "%s/0000:%02x:%02x.%01x", SYS_BUS_PCI_DEVICES, device_param->pcie_bus, device_param->pcie_device, device_param->pcie_function);
return syspath; return syspath;
} }

@ -50,7 +50,7 @@ int induct_ctx_init (hashcat_ctx_t *hashcat_ctx)
{ {
char *root_directory; char *root_directory;
asprintf (&root_directory, "%s/%s.%s", folder_config->session_dir, user_options->session, INDUCT_DIR); hc_asprintf (&root_directory, "%s/%s.%s", folder_config->session_dir, user_options->session, INDUCT_DIR);
if (rmdir (root_directory) == -1) if (rmdir (root_directory) == -1)
{ {
@ -62,7 +62,7 @@ int induct_ctx_init (hashcat_ctx_t *hashcat_ctx)
{ {
char *root_directory_mv; char *root_directory_mv;
asprintf (&root_directory_mv, "%s/%s.induct.%d", folder_config->session_dir, user_options->session, (int) time (NULL)); hc_asprintf (&root_directory_mv, "%s/%s.induct.%d", folder_config->session_dir, user_options->session, (int) time (NULL));
if (rename (root_directory, root_directory_mv) != 0) if (rename (root_directory, root_directory_mv) != 0)
{ {

@ -9,6 +9,7 @@
#include "event.h" #include "event.h"
#include "logfile.h" #include "logfile.h"
#include "locking.h" #include "locking.h"
#include "shared.h"
static int logfile_generate_id (void) static int logfile_generate_id (void)
{ {
@ -83,7 +84,7 @@ int logfile_init (hashcat_ctx_t *hashcat_ctx)
if (user_options->logfile_disable == true) return 0; if (user_options->logfile_disable == true) return 0;
asprintf (&logfile_ctx->logfile, "%s/%s.log", folder_config->session_dir, user_options->session); hc_asprintf (&logfile_ctx->logfile, "%s/%s.log", folder_config->session_dir, user_options->session);
logfile_ctx->subid = (char *) hcmalloc (HCBUFSIZ_TINY); logfile_ctx->subid = (char *) hcmalloc (HCBUFSIZ_TINY);
logfile_ctx->topid = (char *) hcmalloc (HCBUFSIZ_TINY); logfile_ctx->topid = (char *) hcmalloc (HCBUFSIZ_TINY);

@ -102,7 +102,7 @@ int loopback_write_open (hashcat_ctx_t *hashcat_ctx)
const u32 random_num = get_random_num (0, 9999); const u32 random_num = get_random_num (0, 9999);
asprintf (&loopback_ctx->filename, "%s/%s.%d_%u", induct_ctx->root_directory, LOOPBACK_FILE, (int) now, random_num); hc_asprintf (&loopback_ctx->filename, "%s/%s.%d_%u", induct_ctx->root_directory, LOOPBACK_FILE, (int) now, random_num);
FILE *fp = fopen (loopback_ctx->filename, "ab"); FILE *fp = fopen (loopback_ctx->filename, "ab");

@ -339,7 +339,7 @@ int outcheck_ctx_init (hashcat_ctx_t *hashcat_ctx)
if (user_options->outfile_check_dir == NULL) if (user_options->outfile_check_dir == NULL)
{ {
asprintf (&outcheck_ctx->root_directory, "%s/%s.%s", folder_config->session_dir, user_options->session, OUTFILES_DIR); hc_asprintf (&outcheck_ctx->root_directory, "%s/%s.%s", folder_config->session_dir, user_options->session, OUTFILES_DIR);
} }
else else
{ {

@ -99,7 +99,7 @@ int potfile_init (hashcat_ctx_t *hashcat_ctx)
{ {
potfile_ctx->fp = NULL; potfile_ctx->fp = NULL;
asprintf (&potfile_ctx->filename, "%s/hashcat.potfile", folder_config->profile_dir); hc_asprintf (&potfile_ctx->filename, "%s/hashcat.potfile", folder_config->profile_dir);
} }
else else
{ {

@ -49,7 +49,7 @@ static int check_running_process (hashcat_ctx_t *hashcat_ctx)
char *pidbin; char *pidbin;
asprintf (&pidbin, "/proc/%u/cmdline", rd->pid); hc_asprintf (&pidbin, "/proc/%u/cmdline", rd->pid);
FILE *fd = fopen (pidbin, "rb"); FILE *fd = fopen (pidbin, "rb");
@ -356,13 +356,13 @@ int restore_ctx_init (hashcat_ctx_t *hashcat_ctx, int argc, char **argv)
if (user_options->restore_file_path == NULL) if (user_options->restore_file_path == NULL)
{ {
asprintf (&restore_ctx->eff_restore_file, "%s/%s.restore", folder_config->session_dir, user_options->session); hc_asprintf (&restore_ctx->eff_restore_file, "%s/%s.restore", folder_config->session_dir, user_options->session);
asprintf (&restore_ctx->new_restore_file, "%s/%s.restore.new", folder_config->session_dir, user_options->session); hc_asprintf (&restore_ctx->new_restore_file, "%s/%s.restore.new", folder_config->session_dir, user_options->session);
} }
else else
{ {
restore_ctx->eff_restore_file = hcstrdup (user_options->restore_file_path); restore_ctx->eff_restore_file = hcstrdup (user_options->restore_file_path);
asprintf (&restore_ctx->new_restore_file, "%s.new", user_options->restore_file_path); hc_asprintf (&restore_ctx->new_restore_file, "%s.new", user_options->restore_file_path);
} }
restore_ctx->argc = argc; restore_ctx->argc = argc;

@ -99,6 +99,15 @@ void naive_escape (char *s, size_t s_max, const char key_char, const char escape
strncpy (s, s_escaped, s_max - 1); strncpy (s, s_escaped, s_max - 1);
} }
void hc_asprintf (char **strp, const char *fmt, ...)
{
va_list args;
va_start (args, fmt);
int rc __attribute__((unused));
rc = asprintf (strp, fmt, args);
va_end (args);
}
#if defined (_POSIX) #if defined (_POSIX)
int hc_stat (const char *pathname, hc_stat_t *buf) int hc_stat (const char *pathname, hc_stat_t *buf)
{ {

@ -15,6 +15,7 @@
#include "thread.h" #include "thread.h"
#include "opencl.h" #include "opencl.h"
#include "hashes.h" #include "hashes.h"
#include "shared.h"
static int sort_by_tuning_db_alias (const void *v1, const void *v2) static int sort_by_tuning_db_alias (const void *v1, const void *v2)
{ {
@ -69,7 +70,7 @@ int tuning_db_init (hashcat_ctx_t *hashcat_ctx)
char *tuning_db_file; char *tuning_db_file;
asprintf (&tuning_db_file, "%s/%s", folder_config->shared_dir, TUNING_DB_FILE); hc_asprintf (&tuning_db_file, "%s/%s", folder_config->shared_dir, TUNING_DB_FILE);
FILE *fp = fopen (tuning_db_file, "rb"); FILE *fp = fopen (tuning_db_file, "rb");

Loading…
Cancel
Save