2 * freerainbowtables is a project for generating, distributing, and using
3 * perfect rainbow tables
5 * Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>
6 * Copyright Martin Westergaard Jørgensen <martinwj2005@gmail.com>
7 * Copyright 2009, 2010 Daniël Niggebrugge <niggebrugge@fox-it.com>
8 * Copyright 2009, 2010 James Nobis <frt@quelrod.net>
10 * This file is part of freerainbowtables.
12 * freerainbowtables is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation, either version 2 of the License, or
15 * (at your option) any later version.
17 * freerainbowtables is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with freerainbowtables. If not, see <http://www.gnu.org/licenses/>.
27 #pragma warning(disable : 4786)
32 #include "boinc_win.h"
47 #include "boinc_api.h"
53 #elif defined(__APPLE__) || \
54 ((defined(__unix__) || defined(unix)) && !defined(USG))
56 #include <sys/param.h>
59 #include <sys/sysctl.h>
60 #elif defined(__linux__)
61 #include <sys/sysinfo.h>
63 #error Unsupported Operating system
67 //////////////////////////////////////////////////////////////////////
69 unsigned int GetFileLen(FILE* file)
71 unsigned int pos = ftell(file);
72 fseek(file, 0, SEEK_END);
73 unsigned int len = ftell(file);
74 fseek(file, pos, SEEK_SET);
79 string TrimString(string s)
83 if (s[0] == ' ' || s[0] == '\t')
91 if (s[s.size() - 1] == ' ' || s[s.size() - 1] == '\t')
92 s = s.substr(0, s.size() - 1);
99 bool GetHybridCharsets(string sCharset, vector<tCharset>& vCharset)
101 // Example: hybrid(mixalpha-numeric-all-space#1-6,numeric#1-4)
102 if(sCharset.substr(0, 6) != "hybrid") // Not hybrid charset
105 UINT4 nEnd = (int) sCharset.rfind(')');
106 UINT4 nStart = (int) sCharset.rfind('(');
107 string sChar = sCharset.substr(nStart + 1, nEnd - nStart - 1);
108 vector<string> vParts;
109 SeperateString(sChar, ",", vParts);
110 for(UINT4 i = 0; i < vParts.size(); i++)
113 vector<string> vParts2;
114 SeperateString(vParts[i], "#", vParts2);
115 stCharset.sName = vParts2[0];
116 vector<string> vParts3;
117 SeperateString(vParts2[1], "-", vParts3);
118 stCharset.nPlainLenMin = atoi(vParts3[0].c_str());
119 stCharset.nPlainLenMax = atoi(vParts3[1].c_str());
120 vCharset.push_back(stCharset);
125 bool boinc_ReadLinesFromFile(string sPathName, vector<string>& vLine)
128 vLine.push_back("loweralpha-space = [abcdefghijklmnopqrstuvwxyz ]");
129 vLine.push_back("loweralpha = [abcdefghijklmnopqrstuvwxyz]");
131 char input_path[512];
132 boinc_resolve_filename(sPathName.c_str(), input_path, sizeof(input_path));
133 FILE *file = boinc_fopen(input_path, "rb");
136 "Couldn't find input file, resolved name %s.\n", input_path
143 unsigned int len = GetFileLen(file);
144 char* data = new char[len + 1];
145 fread(data, 1, len, file);
147 string content = data;
152 for (i = 0; i < content.size(); i++)
154 if (content[i] == '\r')
159 while ((n = content.find("\n", 0)) != -1)
161 string line = content.substr(0, n);
162 line = TrimString(line);
164 vLine.push_back(line);
165 content = content.substr(n + 1);
176 bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
179 FILE *file = fopen(sPathName.c_str(), "rb");
182 unsigned int len = GetFileLen(file);
183 char* data = new char[len + 1];
184 fread(data, 1, len, file);
186 string content = data;
191 for (i = 0; i < content.size(); i++)
193 if (content[i] == '\r')
198 while ((n = content.find("\n", 0)) != -1)
200 string line = content.substr(0, n);
201 line = TrimString(line);
203 vLine.push_back(line);
204 content = content.substr(n + 1);
216 bool SeperateString(string s, string sSeperator, vector<string>& vPart)
221 for (i = 0; i < sSeperator.size(); i++)
223 int n = s.find(sSeperator[i]);
226 vPart.push_back(s.substr(0, n));
237 string uint64tostr(uint64 n)
242 sprintf(str, "%I64u", n);
244 sprintf(str, "%llu", n);
250 string uint64tohexstr(uint64 n)
255 sprintf(str, "%016I64x", n);
257 sprintf(str, "%016llx", n);
263 string HexToStr(const unsigned char* pData, int nLen)
267 for (i = 0; i < nLen; i++)
270 sprintf(szByte, "%02x", pData[i]);
277 unsigned int GetAvailPhysMemorySize()
281 GlobalMemoryStatus(&ms);
282 return ms.dwAvailPhys;
285 sysinfo(&info); // This function is Linux-specific
290 string GetApplicationPath()
292 char fullPath[FILENAME_MAX];
295 GetModuleFileName(NULL, fullPath, FILENAME_MAX);
298 // XXX linux/proc file system dependent
299 sprintf(szTmp, "/proc/%d/exe", getpid());
300 int bytes = readlink(szTmp, fullPath, FILENAME_MAX);
303 fullPath[bytes] = '\0';
306 string sApplicationPath = fullPath;
308 int nIndex = sApplicationPath.find_last_of('\\');
310 int nIndex = sApplicationPath.find_last_of('/');
314 sApplicationPath = sApplicationPath.substr(0, nIndex+1);
316 return sApplicationPath;
319 void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
322 for (i = 0; i < sHash.size() / 2; i++)
324 string sSub = sHash.substr(i * 2, 2);
326 sscanf(sSub.c_str(), "%02x", &nValue);
327 pHash[i] = (unsigned char)nValue;
330 nHashLen = sHash.size() / 2;
335 printf("RainbowCrack (improved) 2.0 - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");
336 printf("by Martin Westergaard <martinwj2005@gmail.com>\n");
337 printf("http://www.freerainbowtables.com/\n");
338 printf("original code by Zhu Shuanglei <shuanglei@hotmail.com>\n");
339 printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");