diff -urpN bleed2/src/dmg2john.c bleed/src/dmg2john.c --- bleed2/src/dmg2john.c 2013-03-19 11:55:30.151000000 -0500 +++ bleed/src/dmg2john.c 2013-03-19 11:59:23.518000000 -0500 @@ -27,7 +27,6 @@ #include #include #include -#include #include #include #include @@ -37,6 +36,7 @@ #include "stdint.h" #include "gladman_fileenc.h" #include "filevault.h" +#include "misc.h" #define ntohll(x) (((uint64_t) ntohl((x) >> 32)) | (((uint64_t) ntohl((uint32_t) ((x) & 0xFFFFFFFF))) << 32)) diff -urpN bleed2/src/misc.c bleed/src/misc.c --- bleed2/src/misc.c 2013-03-19 11:55:30.404000000 -0500 +++ bleed/src/misc.c 2013-03-19 11:54:27.609000000 -0500 @@ -18,6 +18,7 @@ #include #include "logger.h" +#include "params.h" #ifdef HAVE_MPI #include "john-mpi.h" @@ -184,3 +185,59 @@ char *strupr(char *s) return s; } #endif + +// For used in jtr_basename_r function. We need to handle separator chars differently +// in unix vs Win32(DOS). +#if defined _WIN32 || defined __WIN32__ || defined _MSC_VER || defined __DJGPP__ || defined __CYGWIN32__ || defined __MINGW32__ +#define SEP_CHAR(c) ((c)=='/'||(c)=='\\') +#else +#define SEP_CHAR(c) ((c)=='/') +#endif + + +char *jtr_basename_r(const char *name, char *buf) { + char *base, *p; + int something=0; + + // if name was null, or the string was null, then return a '.' char. + if (!name || name[0]==0) return "."; + + strcpy(buf, name); + base = buf; + + // deal with 'possible' drive letter in Win32/DOS type systems. +#if defined _WIN32 || defined __WIN32__ || defined _MSC_VER || defined __DJGPP__ || defined __CYGWIN32__ || defined __MINGW32__ + if (strlen(base)>1 && + ((base[0] >= 'A' && base[0] <= 'Z')||(base[0] >= 'a' && base[0] <= 'z')) && + base[1] == ':') + base += 2; + if (base[0]==0) return "."; +#endif + + p = base; + while (*p) { + if (SEP_CHAR(*p)) { + if (p[1] && !SEP_CHAR(p[1])) + base = p+1; + } + else + something = 1; + ++p; + } + if (!something) { + base = &base[strlen(base)-1]; + } else if (strlen(base)) { + p = &base[strlen(base)-1]; + while (SEP_CHAR(*p) && p >= base) { + *p = 0; + --p; + } + if (base[0]==0) return "."; + } + return (char*)base; +} + +char *jtr_basename(const char *name) { + static char buf[PATH_BUFFER_SIZE+1]; + return jtr_basename_r(name, buf); +} diff -urpN bleed2/src/misc.h bleed/src/misc.h --- bleed2/src/misc.h 2013-03-19 11:55:30.406000000 -0500 +++ bleed/src/misc.h 2013-03-19 11:58:26.169000000 -0500 @@ -66,6 +66,45 @@ extern int strnzcpyn(char *dst, const ch extern char *strnzcat(char *dst, const char *src, int size); /* + * Portable basename() function. DO NOT USE basename(). Use this + * proper working equivelent. The _r version is thread safe. In the + * _r version, pass in a buffer that is at least strlen(name)+1 bytes + * long, however, PATH_BUFFER_SIZE+1 can also be used. + * + * here is what defined: + * if name is null, or points to a null string (0 byte), then a '.' is returned. + * if name is all / chars (or \ chars), then a single / (or \) is returned. + * DOS drive letters are ignored. + * / or \ chars are properly handled. + * Trailing / (or \) are removed, IF there was real path data in there. + * + * here are some examples: + * jtr_basename("/user/lib") == lib + * jtr_basename("/user/") == user + * jtr_basename("/") == / + * jtr_basename("//") == / + * jtr_basename("///") == / + * jtr_basename("//user//lib//") == lib + * jtr_basename("c:\\txt.doc") == txt.doc + * jtr_basename("c:txt.doc") == txt.doc + * jtr_basename("c:b/c\\txt.doc/")== txt.doc + * jtr_basename("c:\\txt.doc\\") == txt.doc + * jtr_basename("c:") == . + * jtr_basename("") == . + * jtr_basename(NULL) == . + * jtr_basename("\\user\\lib") == lib + * jtr_basename("\\user\\") == user + * jtr_basename("\\") == \ + * jtr_basename("\\\\") == \ + * jtr_basename("one") == one + */ +extern char *jtr_basename(const char *name); +extern char *jtr_basename_r(const char *name, char *buf); +#undef basename +#define basename(a) jtr_basename(a) + + +/* * Converts a string to lowercase. */ #ifndef _MSC_VER diff -urpN bleed2/src/rar2john.c bleed/src/rar2john.c --- bleed2/src/rar2john.c 2013-03-19 11:55:30.806000000 -0500 +++ bleed/src/rar2john.c 2013-03-19 12:00:51.277000000 -0500 @@ -49,7 +49,6 @@ #include #include #include -#include #include "misc.h" #include "common.h"