1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-29 19:38:18 +00:00
This commit is contained in:
jsteube 2016-09-07 12:45:08 +02:00
parent e13419a1b2
commit f9e1329ca9
5 changed files with 665 additions and 663 deletions

View File

@ -6,6 +6,8 @@
*/
#include <stdio.h>
#include <errno.h>
#include <dirent.h>
#include <unistd.h>
#ifdef _POSIX
@ -26,3 +28,7 @@ char *get_exec_path (void);
char *get_install_dir (const char *progname);
char *get_profile_dir (const char *homedir);
char *get_session_dir (const char *profile_dir);
int count_dictionaries (char **dictionary_files);
char **scan_directory (const char *path);

View File

@ -10,7 +10,6 @@
#define _SHARED_H
#include <errno.h>
#include <dirent.h>
#include <time.h>
#include <unistd.h>
#include <signal.h>
@ -21,9 +20,6 @@
*/
#ifdef _POSIX
//#include <pthread.h>
//#include <dlfcn.h>
//#include <limits.h>
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/sysctl.h>
@ -162,8 +158,6 @@ u64 mydivc64 (const u64 dividend, const u64 divisor);
void format_speed_display (double val, char *buf, size_t len);
void format_timer_display (struct tm *tm, char *buf, size_t len);
char **scan_directory (const char *path);
int count_dictionaries (char **dictionary_files);
char *stroptitype (const uint opti_type);
char *strstatus (const uint threads_status);

View File

@ -117,3 +117,115 @@ char *get_session_dir (const char *profile_dir)
return session_dir;
}
int count_dictionaries (char **dictionary_files)
{
if (dictionary_files == NULL) return 0;
int cnt = 0;
for (int d = 0; dictionary_files[d] != NULL; d++)
{
cnt++;
}
return (cnt);
}
char **scan_directory (const char *path)
{
char *tmp_path = mystrdup (path);
size_t tmp_path_len = strlen (tmp_path);
while (tmp_path[tmp_path_len - 1] == '/' || tmp_path[tmp_path_len - 1] == '\\')
{
tmp_path[tmp_path_len - 1] = 0;
tmp_path_len = strlen (tmp_path);
}
char **files = NULL;
int num_files = 0;
DIR *d = NULL;
if ((d = opendir (tmp_path)) != NULL)
{
#ifdef __APPLE__
struct dirent e;
for (;;)
{
memset (&e, 0, sizeof (e));
struct dirent *de = NULL;
if (readdir_r (d, &e, &de) != 0)
{
log_error ("ERROR: readdir_r() failed");
break;
}
if (de == NULL) break;
#else
struct dirent *de;
while ((de = readdir (d)) != NULL)
{
#endif
if ((strcmp (de->d_name, ".") == 0) || (strcmp (de->d_name, "..") == 0)) continue;
int path_size = strlen (tmp_path) + 1 + strlen (de->d_name);
char *path_file = (char *) mymalloc (path_size + 1);
snprintf (path_file, path_size + 1, "%s/%s", tmp_path, de->d_name);
path_file[path_size] = 0;
DIR *d_test;
if ((d_test = opendir (path_file)) != NULL)
{
closedir (d_test);
myfree (path_file);
}
else
{
files = (char **) myrealloc (files, num_files * sizeof (char *), sizeof (char *));
num_files++;
files[num_files - 1] = path_file;
}
}
closedir (d);
}
else if (errno == ENOTDIR)
{
files = (char **) myrealloc (files, num_files * sizeof (char *), sizeof (char *));
num_files++;
files[num_files - 1] = mystrdup (path);
}
files = (char **) myrealloc (files, num_files * sizeof (char *), sizeof (char *));
num_files++;
files[num_files - 1] = NULL;
myfree (tmp_path);
return (files);
}

View File

@ -1111,118 +1111,8 @@ void format_speed_display (double val, char *buf, size_t len)
}
}
char **scan_directory (const char *path)
{
char *tmp_path = mystrdup (path);
size_t tmp_path_len = strlen (tmp_path);
while (tmp_path[tmp_path_len - 1] == '/' || tmp_path[tmp_path_len - 1] == '\\')
{
tmp_path[tmp_path_len - 1] = 0;
tmp_path_len = strlen (tmp_path);
}
char **files = NULL;
int num_files = 0;
DIR *d = NULL;
if ((d = opendir (tmp_path)) != NULL)
{
#ifdef __APPLE__
struct dirent e;
for (;;)
{
memset (&e, 0, sizeof (e));
struct dirent *de = NULL;
if (readdir_r (d, &e, &de) != 0)
{
log_error ("ERROR: readdir_r() failed");
break;
}
if (de == NULL) break;
#else
struct dirent *de;
while ((de = readdir (d)) != NULL)
{
#endif
if ((strcmp (de->d_name, ".") == 0) || (strcmp (de->d_name, "..") == 0)) continue;
int path_size = strlen (tmp_path) + 1 + strlen (de->d_name);
char *path_file = (char *) mymalloc (path_size + 1);
snprintf (path_file, path_size + 1, "%s/%s", tmp_path, de->d_name);
path_file[path_size] = 0;
DIR *d_test;
if ((d_test = opendir (path_file)) != NULL)
{
closedir (d_test);
myfree (path_file);
}
else
{
files = (char **) myrealloc (files, num_files * sizeof (char *), sizeof (char *));
num_files++;
files[num_files - 1] = path_file;
}
}
closedir (d);
}
else if (errno == ENOTDIR)
{
files = (char **) myrealloc (files, num_files * sizeof (char *), sizeof (char *));
num_files++;
files[num_files - 1] = mystrdup (path);
}
files = (char **) myrealloc (files, num_files * sizeof (char *), sizeof (char *));
num_files++;
files[num_files - 1] = NULL;
myfree (tmp_path);
return (files);
}
int count_dictionaries (char **dictionary_files)
{
if (dictionary_files == NULL) return 0;
int cnt = 0;
for (int d = 0; dictionary_files[d] != NULL; d++)
{
cnt++;
}
return (cnt);
}
char *stroptitype (const uint opti_type)
{