]> git.sesse.net Git - freerainbowtables/blobdiff - Common/rt api/Public.cpp
64-bit fixes for distrrtgen
[freerainbowtables] / Common / rt api / Public.cpp
index 60d7072d8f5c590efa26f55b69fd17114bbe58c2..66e8ce46638521020d0dc13b4f76bd3c3e171403 100644 (file)
@@ -1,7 +1,26 @@
 /*
-   RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique.
-
-   Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
+ * freerainbowtables is a project for generating, distributing, and using
+ * perfect rainbow tables
+ *
+ * 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 freerainbowtables.
+ *
+ * freerainbowtables 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, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * freerainbowtables 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 freerainbowtables.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #ifdef _WIN32
@@ -9,7 +28,9 @@
 #endif
 
 #ifdef _WIN32
-#include "boinc_win.h"
+       #ifdef BOINC
+               #include "boinc_win.h"
+       #endif
 #else
 #include "config.h"
 #include <cstdio>
 #include <unistd.h>
 
 #endif
-#include "filesys.h"
-#include "boinc_api.h"
-
+#ifdef BOINC
+       #include "filesys.h"
+       #include "boinc_api.h"
+#endif
 #include "Public.h"
 
 #ifdef _WIN32
        #include <windows.h>
-#else
-       #include <sys/sysinfo.h>
+#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
 
 //////////////////////////////////////////////////////////////////////
@@ -69,12 +101,13 @@ 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;
-       size_t nEnd = sCharset.rfind(')');
-       size_t nStart = sCharset.rfind('(');
+
+       UINT4 nEnd = (int) sCharset.rfind(')');
+       UINT4 nStart = (int) sCharset.rfind('(');
        string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1);
        vector<string> vParts;
        SeperateString(sChar, ",", vParts);
-       for(int i = 0; i < vParts.size(); i++)
+       for(UINT4 i = 0; i < vParts.size(); i++)
        {
                tCharset stCharset;
                vector<string> vParts2;
@@ -88,18 +121,59 @@ bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
        }
        return true;
 }
+#ifdef BOINC
+bool boinc_ReadLinesFromFile(string sPathName, vector<string>& vLine)
+{
+       vLine.clear();
+       char input_path[512];
+       boinc_resolve_filename(sPathName.c_str(), input_path, sizeof(input_path));
+       FILE *file = boinc_fopen(input_path, "rb");
+       if (!file) {
+               fprintf(stderr,
+                       "Couldn't find input file, resolved name %s.\n", input_path
+               );
+               exit(-1);
+       }
+
+       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';
+               }
+
+               int n;
+               while ((n = content.find("\n", 0)) != -1)
+               {
+                       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;
+}
+#endif 
 bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
 {
        vLine.clear();
-    char input_path[512];
-    boinc_resolve_filename(sPathName.c_str(), input_path, sizeof(input_path));
-    FILE *file = boinc_fopen(input_path, "rb");
-    if (!file) {
-        fprintf(stderr,
-            "Couldn't find input file, resolved name %s.\n", input_path
-        );
-        exit(-1);
-    }
+    FILE *file = fopen(sPathName.c_str(), "rb");
        if (file != NULL)
        {
                unsigned int len = GetFileLen(file);
@@ -135,6 +209,7 @@ bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
        return true;
 }
 
+
 bool SeperateString(string s, string sSeperator, vector<string>& vPart)
 {
        vPart.clear();
@@ -209,9 +284,38 @@ unsigned int GetAvailPhysMemorySize()
 #endif
 }
 
+string GetApplicationPath()
+{
+       char fullPath[FILENAME_MAX];
+
+#ifdef _WIN32
+       GetModuleFileName(NULL, fullPath, FILENAME_MAX);
+#else
+       char szTmp[32];
+       // XXX linux/proc file system dependent
+       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
+       int nIndex = sApplicationPath.find_last_of('\\');
+#else
+       int nIndex = sApplicationPath.find_last_of('/');
+#endif
+
+       if ( nIndex != -1 )
+               sApplicationPath = sApplicationPath.substr(0, nIndex+1);
+
+       return sApplicationPath;
+}
+
 void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
 {
-       int i;
+       uint32 i;
        for (i = 0; i < sHash.size() / 2; i++)
        {
                string sSub = sHash.substr(i * 2, 2);