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("byte = []");
129 vLine.push_back("alpha = [ABCDEFGHIJKLMNOPQRSTUVWXYZ]");
130 vLine.push_back("alpha-space = [ABCDEFGHIJKLMNOPQRSTUVWXYZ ]");
131 vLine.push_back("alpha-numeric = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]");
132 vLine.push_back("alpha-numeric-space = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ]");
133 vLine.push_back("alpha-numeric-symbol14 = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D]");
134 vLine.push_back("alpha-numeric-symbol14-space= [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x20]");
135 vLine.push_back("all = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x7E\x60\x5B\x5D\x7B\x7D\x7C\x5C\x3A\x3B\x22\x27\x3C\x3E\x2C\x2E\x3F\x2F]");
136 vLine.push_back("all-space = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x7E\x60\x5B\x5D\x7B\x7D\x7C\x5C\x3A\x3B\x22\x27\x3C\x3E\x2C\x2E\x3F\x2F\x20]");
137 vLine.push_back("alpha-numeric-symbol32-space = [ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x7E\x60\x5B\x5D\x7B\x7D\x7C\x5C\x3A\x3B\x22\x27\x3C\x3E\x2C\x2E\x3F\x2F\x20]");
138 vLine.push_back("lm-frt-cp437 = [\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x7B\x7C\x7D\x7E\x80\x8E\x8F\x90\x92\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA5\xE0\xE1\xE2\xE3\xE4\xE6\xE7\xE8\xE9\xEA\xEB\xEE]");
139 vLine.push_back("lm-frt-cp850 = [\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x7B\x7C\x7D\x7E\x80\x8E\x8F\x90\x92\x99\x9A\x9C\x9D\x9F\xA5\xB5\xB6\xB7\xBD\xBE\xC7\xCF\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xDE\xE0\xE1\xE2\xE3\xE5\xE6\xE8\xE9\xEA\xEB\xED\xEF]");
140 vLine.push_back("lm-frt-cp437-850 = [\x20\x21\x22\x23\x24\x25\x26\x27\x28\x29\x2A\x2B\x2C\x2D\x2E\x2F\x30\x31\x32\x33\x34\x35\x36\x37\x38\x39\x3A\x3B\x3C\x3D\x3E\x3F\x40\x41\x42\x43\x44\x45\x46\x47\x48\x49\x4A\x4B\x4C\x4D\x4E\x4F\x50\x51\x52\x53\x54\x55\x56\x57\x58\x59\x5A\x5B\x5C\x5D\x5E\x5F\x60\x7B\x7C\x7D\x7E\x80\x8E\x8F\x90\x92\x99\x9A\x9B\x9C\x9D\x9E\x9F\xA5\xB5\xB6\xB7\xBD\xBE\xC7\xCF\xD1\xD2\xD3\xD4\xD5\xD6\xD7\xD8\xDE\xE0\xE1\xE2\xE3\xE4\xE5\xE6\xE7\xE8\xE9\xEA\xEB\xED\xEE\xEF]");
141 vLine.push_back("numeric = [0123456789]");
142 vLine.push_back("numeric-space = [0123456789 ]");
143 vLine.push_back("loweralpha = [abcdefghijklmnopqrstuvwxyz]");
144 vLine.push_back("loweralpha-space = [abcdefghijklmnopqrstuvwxyz ]");
145 vLine.push_back("loweralpha-numeric = [abcdefghijklmnopqrstuvwxyz0123456789]");
146 vLine.push_back("loweralpha-numeric-space = [abcdefghijklmnopqrstuvwxyz0123456789 ]");
147 vLine.push_back("loweralpha-numeric-symbol14 = [abcdefghijklmnopqrstuvwxyz0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D]");
148 vLine.push_back("loweralpha-numeric-all = [abcdefghijklmnopqrstuvwxyz0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x7E\x60\x5B\x5D\x7B\x7D\x7C\x5C\x3A\x3B\x22\x27\x3C\x3E\x2C\x2E\x3F\x2F]");
149 vLine.push_back("loweralpha-numeric-symbol32-space= [abcdefghijklmnopqrstuvwxyz0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x7E\x60\x5B\x5D\x7B\x7D\x7C\x5C\x3A\x3B\x22\x27\x3C\x3E\x2C\x2E\x3F\x2F\x20]");
150 vLine.push_back("mixalpha = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]");
151 vLine.push_back("mixalpha-space = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ ]");
152 vLine.push_back("mixalpha-numeric = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]");
153 vLine.push_back("mixalpha-numeric-space = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 ]");
154 vLine.push_back("mixalpha-numeric-symbol14 = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D]");
155 vLine.push_back("mixalpha-numeric-all = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x7E\x60\x5B\x5D\x7B\x7D\x7C\x5C\x3A\x3B\x22\x27\x3C\x3E\x2C\x2E\x3F\x2F]");
156 vLine.push_back("mixalpha-numeric-symbol32-space = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x7E\x60\x5B\x5D\x7B\x7D\x7C\x5C\x3A\x3B\x22\x27\x3C\x3E\x2C\x2E\x3F\x2F\x20]");
157 vLine.push_back("mixalpha-numeric-all-space = [abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\x21\x40\x23\x24\x25\x5E\x26\x2A\x28\x29\x2D\x5F\x2B\x3D\x7E\x60\x5B\x5D\x7B\x7D\x7C\x5C\x3A\x3B\x22\x27\x3C\x3E\x2C\x2E\x3F\x2F\x20]");
159 /* char input_path[512];
160 boinc_resolve_filename(sPathName.c_str(), input_path, sizeof(input_path));
161 FILE *file = boinc_fopen(input_path, "rb");
164 "Couldn't find input file, resolved name %s.\n", input_path
171 unsigned int len = GetFileLen(file);
172 char* data = new char[len + 1];
173 fread(data, 1, len, file);
175 string content = data;
180 for (i = 0; i < content.size(); i++)
182 if (content[i] == '\r')
187 while ((n = content.find("\n", 0)) != -1)
189 string line = content.substr(0, n);
190 line = TrimString(line);
192 vLine.push_back(line);
193 content = content.substr(n + 1);
204 bool ReadLinesFromFile(string sPathName, vector<string>& vLine)
207 FILE *file = fopen(sPathName.c_str(), "rb");
210 unsigned int len = GetFileLen(file);
211 char* data = new char[len + 1];
212 fread(data, 1, len, file);
214 string content = data;
219 for (i = 0; i < content.size(); i++)
221 if (content[i] == '\r')
226 while ((n = content.find("\n", 0)) != -1)
228 string line = content.substr(0, n);
229 line = TrimString(line);
231 vLine.push_back(line);
232 content = content.substr(n + 1);
244 bool SeperateString(string s, string sSeperator, vector<string>& vPart)
249 for (i = 0; i < sSeperator.size(); i++)
251 int n = s.find(sSeperator[i]);
254 vPart.push_back(s.substr(0, n));
265 string uint64tostr(uint64 n)
270 sprintf(str, "%I64u", n);
272 sprintf(str, "%llu", n);
278 string uint64tohexstr(uint64 n)
283 sprintf(str, "%016I64x", n);
285 sprintf(str, "%016llx", n);
291 string HexToStr(const unsigned char* pData, int nLen)
295 for (i = 0; i < nLen; i++)
298 sprintf(szByte, "%02x", pData[i]);
305 unsigned int GetAvailPhysMemorySize()
309 GlobalMemoryStatus(&ms);
310 return ms.dwAvailPhys;
313 sysinfo(&info); // This function is Linux-specific
318 string GetApplicationPath()
320 char fullPath[FILENAME_MAX];
323 GetModuleFileName(NULL, fullPath, FILENAME_MAX);
326 // XXX linux/proc file system dependent
327 sprintf(szTmp, "/proc/%d/exe", getpid());
328 int bytes = readlink(szTmp, fullPath, FILENAME_MAX);
331 fullPath[bytes] = '\0';
334 string sApplicationPath = fullPath;
336 int nIndex = sApplicationPath.find_last_of('\\');
338 int nIndex = sApplicationPath.find_last_of('/');
342 sApplicationPath = sApplicationPath.substr(0, nIndex+1);
344 return sApplicationPath;
347 void ParseHash(string sHash, unsigned char* pHash, int& nHashLen)
350 for (i = 0; i < sHash.size() / 2; i++)
352 string sSub = sHash.substr(i * 2, 2);
354 sscanf(sSub.c_str(), "%02x", &nValue);
355 pHash[i] = (unsigned char)nValue;
358 nHashLen = sHash.size() / 2;
363 printf("RainbowCrack (improved) 2.0 - Making a Faster Cryptanalytic Time-Memory Trade-Off\n");
364 printf("by Martin Westergaard <martinwj2005@gmail.com>\n");
365 printf("http://www.freerainbowtables.com/\n");
366 printf("original code by Zhu Shuanglei <shuanglei@hotmail.com>\n");
367 printf("http://www.antsight.com/zsl/rainbowcrack/\n\n");