X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=Common%2Frt%20api%2FPublic.cpp;h=66e8ce46638521020d0dc13b4f76bd3c3e171403;hb=df8d800454d70f0fb39ab0c227ca55f91b581da7;hp=60d7072d8f5c590efa26f55b69fd17114bbe58c2;hpb=bcfd4a8e2d07b3a0fce0bc8e471d8562b142b7e0;p=freerainbowtables diff --git a/Common/rt api/Public.cpp b/Common/rt api/Public.cpp index 60d7072..66e8ce4 100644 --- a/Common/rt api/Public.cpp +++ b/Common/rt api/Public.cpp @@ -1,7 +1,26 @@ /* - RainbowCrack - a general propose implementation of Philippe Oechslin's faster time-memory trade-off technique. - - Copyright (C) Zhu Shuanglei + * freerainbowtables is a project for generating, distributing, and using + * perfect rainbow tables + * + * Copyright (C) Zhu Shuanglei + * Copyright Martin Westergaard Jørgensen + * Copyright 2009, 2010 Daniël Niggebrugge + * Copyright 2009, 2010 James Nobis + * + * 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 . */ #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 @@ -21,15 +42,26 @@ #include #endif -#include "filesys.h" -#include "boinc_api.h" - +#ifdef BOINC + #include "filesys.h" + #include "boinc_api.h" +#endif #include "Public.h" #ifdef _WIN32 #include -#else - #include +#elif defined(__APPLE__) || \ + ((defined(__unix__) || defined(unix)) && !defined(USG)) + + #include + + #if defined(BSD) + #include + #elif defined(__linux__) + #include + #else + #error Unsupported Operating system + #endif #endif ////////////////////////////////////////////////////////////////////// @@ -69,12 +101,13 @@ bool GetHybridCharsets(string sCharset, vector& 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 vParts; SeperateString(sChar, ",", vParts); - for(int i = 0; i < vParts.size(); i++) + for(UINT4 i = 0; i < vParts.size(); i++) { tCharset stCharset; vector vParts2; @@ -88,18 +121,59 @@ bool GetHybridCharsets(string sCharset, vector& vCharset) } return true; } +#ifdef BOINC +bool boinc_ReadLinesFromFile(string sPathName, vector& 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& 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& vLine) return true; } + bool SeperateString(string s, string sSeperator, vector& 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);