X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=Client%20Applications%2Frcracki_mt%2FPublic.cpp;h=941331ba7443b0393e3c87d24e0ffdd5e60a5b49;hb=86bbf0fd5ba4e07d3279b4179fd8fc808198eaae;hp=0aba1a8943311706202a6cbef4afde7d8f340e0f;hpb=ce75ca839a9cd1863ea13636ffebf7ee1dcc4267;p=freerainbowtables diff --git a/Client Applications/rcracki_mt/Public.cpp b/Client Applications/rcracki_mt/Public.cpp index 0aba1a8..941331b 100644 --- a/Client Applications/rcracki_mt/Public.cpp +++ b/Client Applications/rcracki_mt/Public.cpp @@ -7,7 +7,7 @@ * Copyright 2009, 2010 Daniël Niggebrugge * Copyright 2009, 2010 James Nobis * - * This file is part of racrcki_mt. + * 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 @@ -22,7 +22,7 @@ * along with rcracki_mt. If not, see . */ -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__GNUC__) #pragma warning(disable : 4786 4267 4018) #endif @@ -30,6 +30,10 @@ #ifdef _WIN32 #include +#endif + +#if defined(_WIN32) && !defined(__GNUC__) + #include #include #if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) @@ -125,11 +129,13 @@ timeval sub_timeofday( timeval tv2, timeval tv ) return final; } -unsigned int GetFileLen(FILE* file) +long GetFileLen(FILE* file) { - long int pos = ftell(file); + // XXX on x86/x86_64 linux returns long + // 32-bit this is a problem if the file is > (2^31-1) bytes + long pos = ftell(file); fseek(file, 0, SEEK_END); - long int len = ftell(file); + long len = ftell(file); fseek(file, pos, SEEK_SET); return len; @@ -161,12 +167,12 @@ bool GetHybridCharsets(string sCharset, vector& vCharset) if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset return false; - UINT4 nEnd = (int) sCharset.rfind(')'); - UINT4 nStart = (int) sCharset.rfind('('); + string::size_type nEnd = sCharset.rfind(')'); + string::size_type nStart = (int) sCharset.rfind('('); string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1); vector vParts; SeperateString(sChar, ",", vParts); - for(UINT4 i = 0; i < vParts.size(); i++) + for(uint32 i = 0; i < vParts.size(); i++) { tCharset stCharset; vector vParts2; @@ -180,6 +186,55 @@ 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) + { + long 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; +} +#endif bool ReadLinesFromFile(string sPathName, vector& vLine) { vLine.clear(); @@ -187,7 +242,7 @@ bool ReadLinesFromFile(string sPathName, vector& vLine) FILE* file = fopen(sPathName.c_str(), "rb"); if (file != NULL) { - unsigned int len = GetFileLen(file); + long len = GetFileLen(file); char* data = new char[len + 1]; fread(data, 1, len, file); data[len] = '\0'; @@ -202,8 +257,8 @@ bool ReadLinesFromFile(string sPathName, vector& vLine) content[i] = '\n'; } - int n; - while ((n = content.find("\n", 0)) != -1) + string::size_type n; + while ((n = content.find("\n", 0)) != string::npos) { string line = content.substr(0, n); line = TrimString(line); @@ -241,8 +296,8 @@ bool SeperateString(string s, string sSeperator, vector& vPart) unsigned int i; for (i = 0; i < sSeperator.size(); i++) { - int n = s.find(sSeperator[i]); - if (n != -1) + string::size_type n; + if ( (n = s.find(sSeperator[i])) != string::npos) { vPart.push_back(s.substr(0, n)); s = s.substr(n + 1); @@ -299,7 +354,7 @@ string HexToStr(const unsigned char* pData, int nLen) return sRet; } -uint64 GetAvailPhysMemorySize() +unsigned long GetAvailPhysMemorySize() { #ifdef _WIN32 MEMORYSTATUS ms; @@ -331,29 +386,30 @@ string GetApplicationPath() 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) + + if( bytes >= 0 ) fullPath[bytes] = '\0'; #endif string sApplicationPath = fullPath; #ifdef _WIN32 - int nIndex = sApplicationPath.find_last_of('\\'); + string::size_type nIndex = sApplicationPath.find_last_of('\\'); #else - int nIndex = sApplicationPath.find_last_of('/'); + string::size_type nIndex = sApplicationPath.find_last_of('/'); #endif - if (nIndex != -1) + 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; + uint32 i; for (i = 0; i < sHash.size() / 2; i++) { string sSub = sHash.substr(i * 2, 2);