1 // This file is part of BOINC.
2 // http://boinc.berkeley.edu
3 // Copyright (C) 2008 University of California
5 // BOINC is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License
7 // as published by the Free Software Foundation,
8 // either version 3 of the License, or (at your option) any later version.
10 // BOINC is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 // See the GNU Lesser General Public License for more details.
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with BOINC. If not, see <http://www.gnu.org/licenses/>.
18 // Modified by Martin Westergaard for the chain check usage
20 #include "boinc_win.h"
38 #include "boinc_api.h"
41 #include "ChainWalkContext.h"
42 #include "chain_checker.h"
44 typedef unsigned int uint32;
49 int main(int argc, char **argv) {
51 char output_path[512], chkpt_path[512];
52 string sHashRoutineName, sCharsetName, sHash;
53 uint32 nPlainLenMin, nPlainLenMax, nRainbowTableIndex;
54 FILE* state, *infile, *outfile;
55 retval = boinc_init();
57 fprintf(stderr, "boinc_init returned %d\n", retval);
63 std::cerr << "Not enough parameters";
67 // Initialize the args
68 sHashRoutineName = argv[1];
69 sCharsetName = argv[2];
70 nPlainLenMin = atoi(argv[3]);
71 nPlainLenMax = atoi(argv[4]);
72 nRainbowTableIndex = atoi(argv[5]);
76 // Setup the ChainWalkContext
77 if (!CChainWalkContext::SetHashRoutine(sHashRoutineName))
79 std::cerr << "hash routine " << sHashRoutineName << " not supported" << std::endl;
83 if (!CChainWalkContext::SetPlainCharset(sCharsetName, nPlainLenMin, nPlainLenMax))
85 std::cerr << "charset " << sCharsetName << " not supported" << std::endl;
89 if (!CChainWalkContext::SetRainbowTableIndex(nRainbowTableIndex))
91 std::cerr << "invalid rainbow table index " << nRainbowTableIndex << std::endl;
96 // Open the file containing the chains we have to check.
97 boinc_resolve_filename("chains", output_path, sizeof(output_path));
98 infile = boinc_fopen(output_path, "rb");
101 std::cerr << "failed to open " << output_path << std::endl;
105 // Open the resulting file. This will *maybe* contain the password (if found)
106 boinc_resolve_filename("result", output_path, sizeof(output_path));
107 outfile = boinc_fopen(output_path, "wb");
110 std::cerr << "failed to create " << output_path << std::endl;
114 // Read the chains from the input file
115 int len = GetFileLen(infile);
116 int numchains = len / 12; // Each chain is 12 bytes. 8 bytes startpoint and 4 bytes for the guessed position
117 fseek(infile, 0, SEEK_SET);
118 ChainCheckChain *pChain = new ChainCheckChain[numchains];
119 int totalread = 0, read;
120 for(int i = 0; i < numchains; i++)
122 int read = fread(&pChain[i].nIndexS, sizeof(pChain[i].nIndexS), 1, infile);
125 std::cerr << "Error reading chaincheck file" << std::endl;
128 read = fread(&pChain[i].nGuessedPos, sizeof(pChain[i].nGuessedPos), 1, infile);
131 std::cerr << "Error reading chaincheck file" << std::endl;
139 // Start checking the chains for false alarms
140 CChainWalkContext cwc;
142 for(int i = 0; i < numchains; i++)
144 cwc.SetIndex(pChain[i].nIndexS);
146 for (nPos = 0; nPos < pChain[i].nGuessedPos; nPos++)
150 cwc.HashToIndex(nPos);
154 std::string sHashme = cwc.GetHash();
155 // Check if this is a matching chain
156 if(sHashme.compare(sHash) == 0)
158 fwrite(cwc.GetPlain().c_str(), 1, cwc.GetPlain().length(), outfile);
159 std::cout << "Password is " << cwc.GetPlain() << std::endl;
161 break; // Password is found. Lets break out.
163 // This chain didn't contain the password, so we update the progress
164 boinc_fraction_done((double)i / (double)numchains);
168 fwrite("0x00", 4, 1, outfile);
169 // Last step: Clean up
171 boinc_fraction_done(1);
176 int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR Args, int WinMode) {
181 command_line = GetCommandLine();
182 argc = parse_command_line( command_line, argv );
183 return main(argc, argv);
187 const char *BOINC_RCSID_33ac47a071 = "$Id: chain_checker.cpp 2008-11-28 Martin Westergaard $";