]> git.sesse.net Git - freerainbowtables/blobdiff - Client Applications/rcracki_mt/Public.cpp
Merge branch 'master' of git@gitorious.org:freerainbowtables-applications/freerainbow...
[freerainbowtables] / Client Applications / rcracki_mt / Public.cpp
index 41a95155ec9f47c41bf25630d5bf70aa69148481..941331ba7443b0393e3c87d24e0ffdd5e60a5b49 100644 (file)
@@ -129,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
@@ -170,7 +172,7 @@ bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
        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
+       for(uint32 i = 0; i < vParts.size(); i++)\r
        {\r
                tCharset stCharset;\r
                vector<string> vParts2;\r
@@ -184,6 +186,55 @@ bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
        }\r
        return true;\r
 }\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
+       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
+               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
+#endif\r
 bool ReadLinesFromFile(string sPathName, vector<string>& vLine)\r
 {\r
        vLine.clear();\r
@@ -191,7 +242,7 @@ bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
        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
@@ -303,9 +354,9 @@ string HexToStr(const unsigned char* pData, int nLen)
        return sRet;\r
 }\r
 \r
-uint64 GetAvailPhysMemorySize()\r
+unsigned long GetAvailPhysMemorySize()\r
 {\r
-#if defined(_WIN32)\r
+#ifdef _WIN32\r
        MEMORYSTATUS ms;\r
        GlobalMemoryStatus(&ms);\r
        return ms.dwAvailPhys;\r
@@ -335,10 +386,11 @@ string GetApplicationPath()
        GetModuleFileName(NULL, fullPath, FILENAME_MAX);\r
 #else\r
        char szTmp[32];\r
-       // XXX linux/proc file system dependen\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
@@ -352,13 +404,12 @@ string GetApplicationPath()
        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