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 char input_path[512];
129 boinc_resolve_filename(sPathName.c_str(), input_path, sizeof(input_path));
130 FILE *file = boinc_fopen(input_path, "rb");
133 "Couldn't find input file, resolved name %s.\n", input_path
140 unsigned int len = GetFileLen(file);
141 char* data = new char[len + 1];
142 fread(data, 1, len, file);
144 string content = data;
149 for (i = 0; i < content.size(); i++)
151 if (content[i] == '\r')
156 while ((n = content.find("\n", 0)) != -1)
158 string line = content.substr(0, n);
159 line = TrimString(line);
161 vLine.push_back(line);
162 content = content.substr(n + 1);
173 bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
176 FILE *file = fopen(sPathName.c_str(), "rb");
179 unsigned int len = GetFileLen(file);
180 char* data = new char[len + 1];
181 fread(data, 1, len, file);
183 string content = data;
188 for (i = 0; i < content.size(); i++)
190 if (content[i] == '\r')
195 while ((n = content.find("\n", 0)) != -1)
197 string line = content.substr(0, n);
198 line = TrimString(line);
200 vLine.push_back(line);
201 content = content.substr(n + 1);
213 bool SeperateString(string s, string sSeperator, vector<string>& vPart)
218 for (i = 0; i < sSeperator.size(); i++)
220 int n = s.find(sSeperator[i]);
223 vPart.push_back(s.substr(0, n));
234 string uint64tostr(uint64 n)
239 sprintf(str, "%I64u", n);
241 sprintf(str, "%llu", n);
247 string uint64tohexstr(uint64 n)
252 sprintf(str, "%016I64x", n);
254 sprintf(str, "%016llx", n);
260 string HexToStr(const unsigned char* pData, int nLen)
264 for (i = 0; i < nLen; i++)
267 sprintf(szByte, "%02x", pData[i]);
274 unsigned int GetAvailPhysMemorySize()
278 GlobalMemoryStatus(&ms);
279 return ms.dwAvailPhys;
282 sysinfo(&info); // This function is Linux-specific
287 string GetApplicationPath()
289 char fullPath[FILENAME_MAX];
292 GetModuleFileName(NULL, fullPath, FILENAME_MAX);
295 // XXX linux/proc file system dependent
296 sprintf(szTmp, "/proc/%d/exe", getpid());
297 int bytes = readlink(szTmp, fullPath, FILENAME_MAX);
300 fullPath[bytes] = '\0';
303 string sApplicationPath = fullPath;
305 int nIndex = sApplicationPath.find_last_of('\\');
307 int nIndex = sApplicationPath.find_last_of('/');
311 sApplicationPath = sApplicationPath.substr(0, nIndex+1);
313 return sApplicationPath;
316 void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
319 for (i = 0; i < sHash.size() / 2; i++)
321 string sSub = sHash.substr(i * 2, 2);
323 sscanf(sSub.c_str(), "%02x", &nValue);
324 pHash[i] = (unsigned char)nValue;
327 nHashLen = sHash.size() / 2;
332 printf("RainbowCrack (improved) 2.0 - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");
333 printf("by Martin Westergaard <martinwj2005@gmail.com>\n");
334 printf("http://www.freerainbowtables.com/\n");
335 printf("original code by Zhu Shuanglei <shuanglei@hotmail.com>\n");
336 printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");