-/*\r
- * rcracki_mt is a multithreaded implementation and fork of the original \r
- * RainbowCrack\r
- *\r
- * Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>\r
- * Copyright Martin Westergaard Jørgensen <martinwj2005@gmail.com>\r
- * Copyright 2009, 2010 Daniël Niggebrugge <niggebrugge@fox-it.com>\r
- * Copyright 2009, 2010 James Nobis <frt@quelrod.net>\r
- *\r
- * This file is part of rcracki_mt.\r
- *\r
- * rcracki_mt is free software: you can redistribute it and/or modify\r
- * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation, version 2 of the License.\r
- *\r
- * rcracki_mt is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with rcracki_mt. If not, see <http://www.gnu.org/licenses/>.\r
- */\r
-\r
-#if defined(_WIN32) && !defined(__GNUC__)\r
- #pragma warning(disable : 4786 4267 4018)\r
-#endif\r
-\r
-#include "Public.h"\r
-\r
-#ifdef _WIN32\r
- #include <windows.h>\r
-#endif\r
-\r
-#if defined(_WIN32) && !defined(__GNUC__)\r
- #include <windows.h>\r
- #include <time.h>\r
-\r
- #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)\r
- #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64\r
- #else\r
- #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL\r
- #endif\r
- \r
- struct timezone\r
- {\r
- int tz_minuteswest; /* minutes W of Greenwich */\r
- int tz_dsttime; /* type of dst correction */\r
- };\r
- \r
- int gettimeofday(struct timeval *tv, struct timezone *tz)\r
- {\r
- // Define a structure to receive the current Windows filetime\r
- FILETIME ft;\r
- \r
- // Initialize the present time to 0 and the timezone to UTC\r
- unsigned __int64 tmpres = 0;\r
- static int tzflag = 0;\r
- \r
- if (NULL != tv)\r
- {\r
- GetSystemTimeAsFileTime(&ft);\r
- \r
- // The GetSystemTimeAsFileTime returns the number of 100 nanosecond \r
- // intervals since Jan 1, 1601 in a structure. Copy the high bits to \r
- // the 64 bit tmpres, shift it left by 32 then or in the low 32 bits.\r
- tmpres |= ft.dwHighDateTime;\r
- tmpres <<= 32;\r
- tmpres |= ft.dwLowDateTime;\r
- \r
- // Convert to microseconds by dividing by 10\r
- tmpres /= 10;\r
- \r
- // The Unix epoch starts on Jan 1 1970. Need to subtract the difference \r
- // in seconds from Jan 1 1601.\r
- tmpres -= DELTA_EPOCH_IN_MICROSECS;\r
- \r
- // Finally change microseconds to seconds and place in the seconds value. \r
- // The modulus picks up the microseconds.\r
- tv->tv_sec = (long)(tmpres / 1000000UL);\r
- tv->tv_usec = (long)(tmpres % 1000000UL);\r
- }\r
- \r
- if (NULL != tz)\r
- {\r
- if (!tzflag)\r
- {\r
- _tzset();\r
- tzflag++;\r
- }\r
- \r
- // Adjust for the timezone west of Greenwich\r
- tz->tz_minuteswest = _timezone / 60;\r
- tz->tz_dsttime = _daylight;\r
- }\r
- \r
- return 0;\r
- }\r
-\r
-#elif defined(__APPLE__) || \\r
- ((defined(__unix__) || defined(unix)) && !defined(USG))\r
-\r
- #include <sys/param.h>\r
-\r
- #if defined(BSD)\r
- #include <sys/sysctl.h>\r
- #elif defined(__linux__)\r
- #include <sys/sysinfo.h>\r
- #else\r
- #error Unsupported Operating System\r
- #endif\r
-#endif\r
-\r
-//////////////////////////////////////////////////////////////////////\r
-\r
-timeval sub_timeofday( timeval tv2, timeval tv )\r
-{\r
- timeval final;\r
-\r
- final.tv_usec = tv2.tv_usec - tv.tv_usec;\r
- final.tv_sec = tv2.tv_sec - tv.tv_sec;\r
-\r
- if ( final.tv_usec < 0 )\r
- {\r
- final.tv_usec += 1000000;\r
- --final.tv_sec;\r
- }\r
-\r
- return final;\r
-}\r
-\r
-unsigned int GetFileLen(FILE* file)\r
-{\r
- long int pos = ftell(file);\r
- fseek(file, 0, SEEK_END);\r
- long int len = ftell(file);\r
- fseek(file, pos, SEEK_SET);\r
-\r
- return len;\r
-}\r
-\r
-string TrimString(string s)\r
-{\r
- while (s.size() > 0)\r
- {\r
- if (s[0] == ' ' || s[0] == '\t')\r
- s = s.substr(1);\r
- else\r
- break;\r
- }\r
-\r
- while (s.size() > 0)\r
- {\r
- if (s[s.size() - 1] == ' ' || s[s.size() - 1] == '\t')\r
- s = s.substr(0, s.size() - 1);\r
- else\r
- break;\r
- }\r
-\r
- return s;\r
-}\r
-bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)\r
-{\r
- // Example: hybrid(mixalpha-numeric-all-space#1-6,numeric#1-4)\r
- if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset\r
- return false;\r
-\r
- string::size_type nEnd = sCharset.rfind(')');\r
- string::size_type nStart = (int) sCharset.rfind('(');\r
- string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1);\r
- vector<string> vParts;\r
- SeperateString(sChar, ",", vParts);\r
- for(UINT4 i = 0; i < vParts.size(); i++)\r
- {\r
- tCharset stCharset;\r
- vector<string> vParts2;\r
- SeperateString(vParts[i], "#", vParts2);\r
- stCharset.sName = vParts2[0];\r
- vector<string> vParts3;\r
- SeperateString(vParts2[1], "-", vParts3);\r
- stCharset.nPlainLenMin = atoi(vParts3[0].c_str());\r
- stCharset.nPlainLenMax = atoi(vParts3[1].c_str());\r
- vCharset.push_back(stCharset);\r
- }\r
- return true;\r
-}\r
-bool ReadLinesFromFile(string sPathName, vector<string>& vLine)\r
-{\r
- vLine.clear();\r
-\r
- FILE* file = fopen(sPathName.c_str(), "rb");\r
- if (file != NULL)\r
- {\r
- unsigned int len = GetFileLen(file);\r
- char* data = new char[len + 1];\r
- fread(data, 1, len, file);\r
- data[len] = '\0';\r
- string content = data;\r
- content += "\n";\r
- delete [] data;\r
-\r
- unsigned int i;\r
- for (i = 0; i < content.size(); i++)\r
- {\r
- if (content[i] == '\r')\r
- content[i] = '\n';\r
- }\r
-\r
- string::size_type n;\r
- while ((n = content.find("\n", 0)) != string::npos)\r
- {\r
- string line = content.substr(0, n);\r
- line = TrimString(line);\r
- if (line != "")\r
- vLine.push_back(line);\r
- content = content.substr(n + 1);\r
- }\r
-\r
- fclose(file);\r
- }\r
- else\r
- return false;\r
-\r
- return true;\r
-}\r
-\r
-bool writeResultLineToFile(string sOutputFile, string sHash, string sPlain, string sBinary)\r
-{\r
- FILE* file = fopen(sOutputFile.c_str(), "a");\r
- if (file!=NULL)\r
- {\r
- string buffer = sHash + ":" + sPlain + ":" + sBinary + "\n";\r
- fputs (buffer.c_str(), file);\r
- fclose (file);\r
- return true;\r
- }\r
- else\r
- return false;\r
-}\r
-\r
-bool SeperateString(string s, string sSeperator, vector<string>& vPart)\r
-{\r
- vPart.clear();\r
-\r
- unsigned int i;\r
- for (i = 0; i < sSeperator.size(); i++)\r
- {\r
- string::size_type n;\r
- if ( (n = s.find(sSeperator[i])) != string::npos)\r
- {\r
- vPart.push_back(s.substr(0, n));\r
- s = s.substr(n + 1);\r
- }\r
- else\r
- {\r
- printf("not found: %c\n", sSeperator[i]);\r
- printf("s: %s\n", s.c_str());\r
- return false;\r
- }\r
- }\r
- vPart.push_back(s);\r
-\r
- return true;\r
-}\r
-\r
-string uint64tostr(uint64 n)\r
-{\r
- char str[32];\r
-\r
-#ifdef _WIN32\r
- sprintf(str, "%I64u", n);\r
-#else\r
- sprintf(str, "%llu", n);\r
-#endif\r
-\r
- return str;\r
-}\r
-\r
-string uint64tohexstr(uint64 n)\r
-{\r
- char str[32];\r
-\r
-#ifdef _WIN32\r
- sprintf(str, "%016I64x", n);\r
-#else\r
- sprintf(str, "%016llx", n);\r
-#endif\r
-\r
- return str;\r
-}\r
-\r
-string HexToStr(const unsigned char* pData, int nLen)\r
-{\r
- string sRet;\r
- int i;\r
- for (i = 0; i < nLen; i++)\r
- {\r
- char szByte[3];\r
- sprintf(szByte, "%02x", pData[i]);\r
- sRet += szByte;\r
- }\r
-\r
- return sRet;\r
-}\r
-\r
-uint64 GetAvailPhysMemorySize()\r
-{\r
-#if defined(_WIN32)\r
- MEMORYSTATUS ms;\r
- GlobalMemoryStatus(&ms);\r
- return ms.dwAvailPhys;\r
-#elif defined(BSD)\r
- int mib[2] = { CTL_HW, HW_PHYSMEM };\r
- uint64 physMem;\r
- //XXX warning size_t isn't portable\r
- size_t len;\r
- len = sizeof(physMem);\r
- sysctl(mib, 2, &physMem, &len, NULL, 0);\r
- return physMem;\r
-#elif defined(__linux__)\r
- struct sysinfo info;\r
- sysinfo(&info);\r
- return ( info.freeram + info.bufferram ) * (unsigned long) info.mem_unit;\r
-#else\r
- return 0;\r
- #error Unsupported Operating System\r
-#endif\r
-}\r
-\r
-string GetApplicationPath()\r
-{\r
- char fullPath[FILENAME_MAX];\r
-\r
-#ifdef _WIN32\r
- GetModuleFileName(NULL, fullPath, FILENAME_MAX);\r
-#else\r
- char szTmp[32];\r
- // XXX linux/proc file system dependen\r
- sprintf(szTmp, "/proc/%d/exe", getpid());\r
- int bytes = readlink(szTmp, fullPath, FILENAME_MAX);\r
- if(bytes >= 0)\r
- fullPath[bytes] = '\0';\r
-#endif\r
-\r
- string sApplicationPath = fullPath;\r
-#ifdef _WIN32\r
- string::size_type nIndex = sApplicationPath.find_last_of('\\');\r
-#else\r
- string::size_type nIndex = sApplicationPath.find_last_of('/');\r
-#endif\r
-\r
- if ( nIndex != string::npos )\r
- sApplicationPath = sApplicationPath.substr(0, nIndex+1);\r
-\r
- //printf ("\n\nDebug: The application directory is %s\n", sApplicationPath.c_str());\r
- return sApplicationPath;\r
-}\r
-\r
-void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)\r
-{\r
- UINT4 i;\r
- for (i = 0; i < sHash.size() / 2; i++)\r
- {\r
- string sSub = sHash.substr(i * 2, 2);\r
- int nValue;\r
- sscanf(sSub.c_str(), "%02x", &nValue);\r
- pHash[i] = (unsigned char)nValue;\r
- }\r
-\r
- nHashLen = (int) sHash.size() / 2;\r
-}\r
-\r
-void Logo()\r
-{\r
- printf("RainbowCrack (improved, multi-threaded) - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");\r
- printf("by Martin Westergaard <martinwj2005@gmail.com>\n");\r
- printf("multi-threaded and enhanced by neinbrucke (version 0.6.3)\n");\r
- printf("http://www.freerainbowtables.com/\n");\r
- printf("original code by Zhu Shuanglei <shuanglei@hotmail.com>\n");\r
- printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");\r
-}\r
-\r
-// XXX nmap is GPL2, will check newer releases regarding license\r
-// Code comes from nmap, used for the linux implementation of kbhit()\r
-#ifndef _WIN32\r
-\r
-static int tty_fd = 0;\r
-struct termios saved_ti;\r
-\r
-int tty_getchar()\r
-{\r
- int c, numChars;\r
-\r
- if (tty_fd && tcgetpgrp(tty_fd) == getpid()) {\r
- c = 0;\r
- numChars = read(tty_fd, &c, 1);\r
- if (numChars > 0) return c;\r
- }\r
-\r
- return -1;\r
-}\r
-\r
-void tty_done()\r
-{\r
- if (!tty_fd) return;\r
-\r
- tcsetattr(tty_fd, TCSANOW, &saved_ti);\r
-\r
- close(tty_fd);\r
- tty_fd = 0;\r
-}\r
-\r
-void tty_init()\r
-{\r
- struct termios ti;\r
-\r
- if (tty_fd)\r
- return;\r
-\r
- if ((tty_fd = open("/dev/tty", O_RDONLY | O_NONBLOCK)) < 0) return;\r
-\r
- tcgetattr(tty_fd, &ti);\r
- saved_ti = ti;\r
- ti.c_lflag &= ~(ICANON | ECHO);\r
- ti.c_cc[VMIN] = 1;\r
- ti.c_cc[VTIME] = 0;\r
- tcsetattr(tty_fd, TCSANOW, &ti);\r
-\r
- atexit(tty_done);\r
-}\r
-\r
-void tty_flush(void)\r
-{\r
- tcflush(tty_fd, TCIFLUSH);\r
-}\r
-// end nmap code\r
-#endif\r
+/*
+ * rcracki_mt is a multithreaded implementation and fork of the original
+ * RainbowCrack
+ *
+ * Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+ * Copyright Martin Westergaard Jørgensen <martinwj2005@gmail.com>
+ * Copyright 2009, 2010 Daniël Niggebrugge <niggebrugge@fox-it.com>
+ * Copyright 2009, 2010 James Nobis <frt@quelrod.net>
+ *
+ * This file is part of rcracki_mt.
+ *
+ * rcracki_mt is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, version 2 of the License.
+ *
+ * rcracki_mt is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with rcracki_mt. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#if defined(_WIN32) && !defined(__GNUC__)
+ #pragma warning(disable : 4786 4267 4018)
+#endif
+
+#include "Public.h"
+
+#ifdef _WIN32
+ #include <windows.h>
+#endif
+
+#if defined(_WIN32) && !defined(__GNUC__)
+ #include <windows.h>
+ #include <time.h>
+
+ #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
+ #define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
+ #else
+ #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
+ #endif
+
+ struct timezone
+ {
+ int tz_minuteswest; /* minutes W of Greenwich */
+ int tz_dsttime; /* type of dst correction */
+ };
+
+ int gettimeofday(struct timeval *tv, struct timezone *tz)
+ {
+ // Define a structure to receive the current Windows filetime
+ FILETIME ft;
+
+ // Initialize the present time to 0 and the timezone to UTC
+ unsigned __int64 tmpres = 0;
+ static int tzflag = 0;
+
+ if (NULL != tv)
+ {
+ GetSystemTimeAsFileTime(&ft);
+
+ // The GetSystemTimeAsFileTime returns the number of 100 nanosecond
+ // intervals since Jan 1, 1601 in a structure. Copy the high bits to
+ // the 64 bit tmpres, shift it left by 32 then or in the low 32 bits.
+ tmpres |= ft.dwHighDateTime;
+ tmpres <<= 32;
+ tmpres |= ft.dwLowDateTime;
+
+ // Convert to microseconds by dividing by 10
+ tmpres /= 10;
+
+ // The Unix epoch starts on Jan 1 1970. Need to subtract the difference
+ // in seconds from Jan 1 1601.
+ tmpres -= DELTA_EPOCH_IN_MICROSECS;
+
+ // Finally change microseconds to seconds and place in the seconds value.
+ // The modulus picks up the microseconds.
+ tv->tv_sec = (long)(tmpres / 1000000UL);
+ tv->tv_usec = (long)(tmpres % 1000000UL);
+ }
+
+ if (NULL != tz)
+ {
+ if (!tzflag)
+ {
+ _tzset();
+ tzflag++;
+ }
+
+ // Adjust for the timezone west of Greenwich
+ tz->tz_minuteswest = _timezone / 60;
+ tz->tz_dsttime = _daylight;
+ }
+
+ return 0;
+ }
+
+#elif defined(__APPLE__) || \
+ ((defined(__unix__) || defined(unix)) && !defined(USG))
+
+ #include <sys/param.h>
+
+ #if defined(BSD)
+ #include <sys/sysctl.h>
+ #elif defined(__linux__)
+ #include <sys/sysinfo.h>
+ #else
+ #error Unsupported Operating System
+ #endif
+#endif
+
+//////////////////////////////////////////////////////////////////////
+
+timeval sub_timeofday( timeval tv2, timeval tv )
+{
+ timeval final;
+
+ final.tv_usec = tv2.tv_usec - tv.tv_usec;
+ final.tv_sec = tv2.tv_sec - tv.tv_sec;
+
+ if ( final.tv_usec < 0 )
+ {
+ final.tv_usec += 1000000;
+ --final.tv_sec;
+ }
+
+ return final;
+}
+
+unsigned int GetFileLen(FILE* file)
+{
+ long int pos = ftell(file);
+ fseek(file, 0, SEEK_END);
+ long int len = ftell(file);
+ fseek(file, pos, SEEK_SET);
+
+ return len;
+}
+
+string TrimString(string s)
+{
+ while (s.size() > 0)
+ {
+ if (s[0] == ' ' || s[0] == '\t')
+ s = s.substr(1);
+ else
+ break;
+ }
+
+ while (s.size() > 0)
+ {
+ if (s[s.size() - 1] == ' ' || s[s.size() - 1] == '\t')
+ s = s.substr(0, s.size() - 1);
+ else
+ break;
+ }
+
+ return s;
+}
+bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
+{
+ // Example: hybrid(mixalpha-numeric-all-space#1-6,numeric#1-4)
+ if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset
+ return false;
+
+ string::size_type nEnd = sCharset.rfind(')');
+ string::size_type nStart = (int) sCharset.rfind('(');
+ string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1);
+ vector<string> vParts;
+ SeperateString(sChar, ",", vParts);
+ for(UINT4 i = 0; i < vParts.size(); i++)
+ {
+ tCharset stCharset;
+ vector<string> vParts2;
+ SeperateString(vParts[i], "#", vParts2);
+ stCharset.sName = vParts2[0];
+ vector<string> vParts3;
+ SeperateString(vParts2[1], "-", vParts3);
+ stCharset.nPlainLenMin = atoi(vParts3[0].c_str());
+ stCharset.nPlainLenMax = atoi(vParts3[1].c_str());
+ vCharset.push_back(stCharset);
+ }
+ return true;
+}
+bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
+{
+ vLine.clear();
+
+ FILE* file = fopen(sPathName.c_str(), "rb");
+ if (file != NULL)
+ {
+ unsigned int len = GetFileLen(file);
+ char* data = new char[len + 1];
+ fread(data, 1, len, file);
+ data[len] = '\0';
+ string content = data;
+ content += "\n";
+ delete [] data;
+
+ unsigned int i;
+ for (i = 0; i < content.size(); i++)
+ {
+ if (content[i] == '\r')
+ content[i] = '\n';
+ }
+
+ string::size_type n;
+ while ((n = content.find("\n", 0)) != string::npos)
+ {
+ string line = content.substr(0, n);
+ line = TrimString(line);
+ if (line != "")
+ vLine.push_back(line);
+ content = content.substr(n + 1);
+ }
+
+ fclose(file);
+ }
+ else
+ return false;
+
+ return true;
+}
+
+bool writeResultLineToFile(string sOutputFile, string sHash, string sPlain, string sBinary)
+{
+ FILE* file = fopen(sOutputFile.c_str(), "a");
+ if (file!=NULL)
+ {
+ string buffer = sHash + ":" + sPlain + ":" + sBinary + "\n";
+ fputs (buffer.c_str(), file);
+ fclose (file);
+ return true;
+ }
+ else
+ return false;
+}
+
+bool SeperateString(string s, string sSeperator, vector<string>& vPart)
+{
+ vPart.clear();
+
+ unsigned int i;
+ for (i = 0; i < sSeperator.size(); i++)
+ {
+ string::size_type n;
+ if ( (n = s.find(sSeperator[i])) != string::npos)
+ {
+ vPart.push_back(s.substr(0, n));
+ s = s.substr(n + 1);
+ }
+ else
+ {
+ printf("not found: %c\n", sSeperator[i]);
+ printf("s: %s\n", s.c_str());
+ return false;
+ }
+ }
+ vPart.push_back(s);
+
+ return true;
+}
+
+string uint64tostr(uint64 n)
+{
+ char str[32];
+
+#ifdef _WIN32
+ sprintf(str, "%I64u", n);
+#else
+ sprintf(str, "%llu", n);
+#endif
+
+ return str;
+}
+
+string uint64tohexstr(uint64 n)
+{
+ char str[32];
+
+#ifdef _WIN32
+ sprintf(str, "%016I64x", n);
+#else
+ sprintf(str, "%016llx", n);
+#endif
+
+ return str;
+}
+
+string HexToStr(const unsigned char* pData, int nLen)
+{
+ string sRet;
+ int i;
+ for (i = 0; i < nLen; i++)
+ {
+ char szByte[3];
+ sprintf(szByte, "%02x", pData[i]);
+ sRet += szByte;
+ }
+
+ return sRet;
+}
+
+uint64 GetAvailPhysMemorySize()
+{
+#if defined(_WIN32)
+ MEMORYSTATUS ms;
+ GlobalMemoryStatus(&ms);
+ return ms.dwAvailPhys;
+#elif defined(BSD)
+ int mib[2] = { CTL_HW, HW_PHYSMEM };
+ uint64 physMem;
+ //XXX warning size_t isn't portable
+ size_t len;
+ len = sizeof(physMem);
+ sysctl(mib, 2, &physMem, &len, NULL, 0);
+ return physMem;
+#elif defined(__linux__)
+ struct sysinfo info;
+ sysinfo(&info);
+ return ( info.freeram + info.bufferram ) * (unsigned long) info.mem_unit;
+#else
+ return 0;
+ #error Unsupported Operating System
+#endif
+}
+
+string GetApplicationPath()
+{
+ char fullPath[FILENAME_MAX];
+
+#ifdef _WIN32
+ GetModuleFileName(NULL, fullPath, FILENAME_MAX);
+#else
+ char szTmp[32];
+ // XXX linux/proc file system dependen
+ sprintf(szTmp, "/proc/%d/exe", getpid());
+ int bytes = readlink(szTmp, fullPath, FILENAME_MAX);
+ if(bytes >= 0)
+ fullPath[bytes] = '\0';
+#endif
+
+ string sApplicationPath = fullPath;
+#ifdef _WIN32
+ string::size_type nIndex = sApplicationPath.find_last_of('\\');
+#else
+ string::size_type nIndex = sApplicationPath.find_last_of('/');
+#endif
+
+ if ( nIndex != string::npos )
+ sApplicationPath = sApplicationPath.substr(0, nIndex+1);
+
+ //printf ("\n\nDebug: The application directory is %s\n", sApplicationPath.c_str());
+ return sApplicationPath;
+}
+
+void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
+{
+ UINT4 i;
+ for (i = 0; i < sHash.size() / 2; i++)
+ {
+ string sSub = sHash.substr(i * 2, 2);
+ int nValue;
+ sscanf(sSub.c_str(), "%02x", &nValue);
+ pHash[i] = (unsigned char)nValue;
+ }
+
+ nHashLen = (int) sHash.size() / 2;
+}
+
+void Logo()
+{
+ printf("RainbowCrack (improved, multi-threaded) - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");
+ printf("by Martin Westergaard <martinwj2005@gmail.com>\n");
+ printf("multi-threaded and enhanced by neinbrucke (version 0.6.3)\n");
+ printf("http://www.freerainbowtables.com/\n");
+ printf("original code by Zhu Shuanglei <shuanglei@hotmail.com>\n");
+ printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");
+}
+
+// XXX nmap is GPL2, will check newer releases regarding license
+// Code comes from nmap, used for the linux implementation of kbhit()
+#ifndef _WIN32
+
+static int tty_fd = 0;
+struct termios saved_ti;
+
+int tty_getchar()
+{
+ int c, numChars;
+
+ if (tty_fd && tcgetpgrp(tty_fd) == getpid()) {
+ c = 0;
+ numChars = read(tty_fd, &c, 1);
+ if (numChars > 0) return c;
+ }
+
+ return -1;
+}
+
+void tty_done()
+{
+ if (!tty_fd) return;
+
+ tcsetattr(tty_fd, TCSANOW, &saved_ti);
+
+ close(tty_fd);
+ tty_fd = 0;
+}
+
+void tty_init()
+{
+ struct termios ti;
+
+ if (tty_fd)
+ return;
+
+ if ((tty_fd = open("/dev/tty", O_RDONLY | O_NONBLOCK)) < 0) return;
+
+ tcgetattr(tty_fd, &ti);
+ saved_ti = ti;
+ ti.c_lflag &= ~(ICANON | ECHO);
+ ti.c_cc[VMIN] = 1;
+ ti.c_cc[VTIME] = 0;
+ tcsetattr(tty_fd, TCSANOW, &ti);
+
+ atexit(tty_done);
+}
+
+void tty_flush(void)
+{
+ tcflush(tty_fd, TCIFLUSH);
+}
+// end nmap code
+#endif