]> git.sesse.net Git - freerainbowtables/blobdiff - Client Applications/rcracki_mt/Public.cpp
Fix typo: Seperate -> Separate.
[freerainbowtables] / Client Applications / rcracki_mt / Public.cpp
index 0aba1a8943311706202a6cbef4afde7d8f340e0f..3c66a5f3bc642349315da7688dd0cfac67347a80 100644 (file)
@@ -5,9 +5,9 @@
  * 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
+ * Copyright 2009, 2010, 2011 James Nobis <frt@quelrod.net>\r
  *\r
- * This file is part of racrcki_mt.\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
  * along with rcracki_mt.  If not, see <http://www.gnu.org/licenses/>.\r
  */\r
 \r
-#ifdef _WIN32\r
-       #pragma warning(disable : 4786 4267 4018)\r
+#if defined(_WIN32) && !defined(__GNUC__)\r
+       #pragma warning(disable : 4786)\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
@@ -40,8 +44,8 @@
  \r
        struct timezone\r
        {\r
-               int  tz_minuteswest; /* minutes W of Greenwich */\r
-               int  tz_dsttime;     /* type of dst correction */\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
@@ -125,11 +129,13 @@ timeval sub_timeofday( timeval tv2, timeval tv )
        return final;\r
 }\r
 \r
-unsigned int GetFileLen(FILE* file)\r
+long GetFileLen(FILE* file)\r
 {\r
-       long int pos = ftell(file);\r
+       // XXX on x86/x86_64 linux returns long\r
+       // 32-bit this is a problem if the file is > (2^31-1) bytes\r
+       long pos = ftell(file);\r
        fseek(file, 0, SEEK_END);\r
-       long int len = ftell(file);\r
+       long len = ftell(file);\r
        fseek(file, pos, SEEK_SET);\r
 \r
        return len;\r
@@ -147,8 +153,9 @@ string TrimString(string s)
 \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
+               if (s[s.size() - 1] == ' ' || s[s.size() - 1] == '\t' ||\r
+                   s[s.size() - 1] == '\r' || s[s.size() - 1] == '\n')\r
+                       s.resize(s.size() - 1);\r
                else\r
                        break;\r
        }\r
@@ -161,33 +168,42 @@ bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
        if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset\r
                return false;\r
 \r
-       UINT4 nEnd = (int) sCharset.rfind(')');\r
-       UINT4 nStart = (int) sCharset.rfind('(');\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
+       SeparateString(sChar, ",", vParts);\r
+       for(uint32 i = 0; i < vParts.size(); i++)\r
        {\r
                tCharset stCharset;\r
                vector<string> vParts2;\r
-               SeperateString(vParts[i], "#", vParts2);\r
+               SeparateString(vParts[i], "#", vParts2);\r
                stCharset.sName = vParts2[0];\r
                vector<string> vParts3;\r
-               SeperateString(vParts2[1], "-", vParts3);\r
+               SeparateString(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
+#ifdef BOINC\r
+bool boinc_ReadLinesFromFile(string sPathName, vector<string>& vLine)\r
 {\r
        vLine.clear();\r
+       char input_path[512];\r
+       boinc_resolve_filename(sPathName.c_str(), input_path, sizeof(input_path));\r
+       FILE *file = boinc_fopen(input_path, "rb");\r
+       if (!file) {\r
+               fprintf(stderr,\r
+                       "Couldn't find input file, resolved name %s.\n", input_path\r
+               );\r
+               exit(-1);\r
+       }\r
 \r
-       FILE* file = fopen(sPathName.c_str(), "rb");\r
        if (file != NULL)\r
        {\r
-               unsigned int len = GetFileLen(file);\r
+               long len = GetFileLen(file);\r
                char* data = new char[len + 1];\r
                fread(data, 1, len, file);\r
                data[len] = '\0';\r
@@ -202,8 +218,8 @@ bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
                                content[i] = '\n';\r
                }\r
 \r
-               int n;\r
-               while ((n = content.find("\n", 0)) != -1)\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
@@ -219,6 +235,45 @@ bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
 \r
        return true;\r
 }\r
+#endif\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
+               long 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
+               string::iterator n = content.begin();\r
+               string::iterator line_end;\r
+               for ( ;; ) {\r
+                       line_end = find(n, content.end(), '\n');\r
+\r
+                       string line(n, line_end);\r
+                       line = TrimString(line);\r
+                       if (line != "")\r
+                               vLine.push_back(line);\r
+\r
+                       if (line_end == content.end()) {\r
+                               break;\r
+                       }\r
+                       n = line_end + 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
@@ -234,15 +289,15 @@ bool writeResultLineToFile(string sOutputFile, string sHash, string sPlain, stri
                return false;\r
 }\r
 \r
-bool SeperateString(string s, string sSeperator, vector<string>& vPart)\r
+bool SeparateString(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
-               int n = s.find(sSeperator[i]);\r
-               if (n != -1)\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
@@ -299,7 +354,7 @@ string HexToStr(const unsigned char* pData, int nLen)
        return sRet;\r
 }\r
 \r
-uint64 GetAvailPhysMemorySize()\r
+unsigned long GetAvailPhysMemorySize()\r
 {\r
 #ifdef _WIN32\r
        MEMORYSTATUS ms;\r
@@ -331,29 +386,30 @@ string GetApplicationPath()
        GetModuleFileName(NULL, fullPath, FILENAME_MAX);\r
 #else\r
        char szTmp[32];\r
+       // XXX linux/proc file system dependent\r
        sprintf(szTmp, "/proc/%d/exe", getpid());\r
        int bytes = readlink(szTmp, fullPath, FILENAME_MAX);\r
-       if(bytes >= 0)\r
+\r
+       if( bytes >= 0 )\r
                fullPath[bytes] = '\0';\r
 #endif\r
 \r
        string sApplicationPath = fullPath;\r
 #ifdef _WIN32\r
-       int nIndex = sApplicationPath.find_last_of('\\');\r
+       string::size_type nIndex = sApplicationPath.find_last_of('\\');\r
 #else\r
-       int nIndex = sApplicationPath.find_last_of('/');\r
+       string::size_type nIndex = sApplicationPath.find_last_of('/');\r
 #endif\r
 \r
-       if (nIndex != -1)\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
+       uint32 i;\r
        for (i = 0; i < sHash.size() / 2; i++)\r
        {\r
                string sSub = sHash.substr(i * 2, 2);\r