2 Copyright (C) 2008 Steve Thomas <SMT837784@yahoo.com>
4 This file is part of RT Perfecter v0.0.
6 RT Perfecter v0.0 is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 RT Perfecter v0.0 is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with RT Perfecter v0.0. If not, see <http://www.gnu.org/licenses/>.
29 #define DIRECTORY_SEPERATOR '\\'
32 #define DIRECTORY_SEPERATOR '/'
38 unsigned int endpt32_1;
39 unsigned int endpt32_2;
40 unsigned short checkpoint;
49 void usage(char *runStr);
51 int main(int argc, char **argv)
54 uint64 maxIndex = 0xffffffffffffffff;
56 uint64 maxIndex = 0xffffffffffffffffll;
58 int argi = 1, i, argsUsed = 0;
59 unsigned int maxChainsPerFile = 67108864;
62 if (argc > 3 && argc < 6)
64 for (; argi < argc - 2; argi++)
66 if (strcmp(argv[argi], "-v") == 0 && (argsUsed & 1) == 0)
68 // Enable verbose mode
71 else if (strncmp(argv[argi], "-s=", 3) == 0 && (argsUsed & 2) == 0)
73 // Max file size in MiB
76 for (i = 3; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++)
78 maxChainsPerFile *= 10;
79 maxChainsPerFile += ((int) argv[argi][i]) - 0x30;
81 if (argv[argi][i] != '\0')
83 printf("Error: Invalid number.\n\n");
87 if (i > 8 || maxChainsPerFile > 65535) // i - 3 > 5
89 printf("Error: Number is to large.\n\n");
93 maxChainsPerFile <<= 16; // maxChainsPerFile *= 1024 * 1024 / 16
95 else if (strncmp(argv[argi], "-i=", 3) == 0 && (argsUsed & 4) == 0)
97 // Maximum index for chains
100 for (i = 3; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++)
103 maxIndex += ((int) argv[argi][i]) - 0x30;
105 if (argv[argi][i] != '\0')
107 printf("Error: Invalid number.\n\n");
111 if (i > 23) // i - 3 > 20
113 printf("Error: Number is to large.\n\n");
120 printf("Error: Unknown argument.\n\n");
128 if (argc == 1 || argc == 2 && (strcmp(argv[1], "--help") == 0 || strcmp(argv[1], "-h") == 0))
133 printf("Error: Wrong number of arguments.\n\n");
139 RTChainU chain, prevChain;
140 memset(&prevChain.c, 0x00, sizeof(prevChain.c));
141 uint64 uniqueChains = 0;
142 RTRead inRt(argv[argi], maxIndex, argsUsed & 1);
143 RTWrite outRt(argv[argi + 1], maxChainsPerFile);
146 // Set stdin to non-blocking
147 fcntl(0, F_SETFL, fcntl(0, F_GETFL, 0) | O_NDELAY);
151 for (int ret = inRt.readChain(&(chain.c)); ret == 0; ret = inRt.readChain(&(chain.c)))
172 // Check the least significate 32 bits first
173 if (chain.c2.endpt32_1 != prevChain.c2.endpt32_1 || chain.c2.endpt32_2 != prevChain.c2.endpt32_2)
175 outRt.writeChain(&(chain.c));
181 printf("Unique Chains: %I64u\nTotal time: %1.2f\n", uniqueChains, (clock() - t) / (double)CLOCKS_PER_SEC);
183 printf("Unique Chains: %llu\nTotal time: %1.2f\n", uniqueChains, (clock() - t) / (double)CLOCKS_PER_SEC);
188 void usage(char *runStr)
190 printf("\n **** RT Perfecter v0.0 ****\n\n");
191 printf("Converts sorted rt files in a directory to a perfect rainbow table. All rt files\n");
192 printf("in the directory must all be from the same rainbow table.\n\n");
193 printf("%s [Options] input-directory output-file-pattern\n\n", runStr);
194 printf("Options:\n");
195 printf(" -i=number\n");
196 printf(" Maximum index for chains.\n\n");
197 printf(" -s=number\n");
198 printf(" Maximum size for output files in MiB [default is 1024, max is 65535].\n\n");
200 printf(" Verbose mode, displays extra info.\n\n");
201 printf("output-file-pattern:\n");
202 printf(" This will be passed into sprintf() with the number of chains in the file and\n");
203 printf(" the current file number starting at 0. This could look like:\n");
204 printf(" 'some-folder%csome-name%%u-%%03u.rt'\n", DIRECTORY_SEPERATOR);
205 printf(" Where '%%u' would be the number of chains in the file and '%%03u' would be the\n");
206 printf(" file number formated like 000, 001, 002, and so on.\n\n");
207 printf("Run-time:\n");
208 printf(" Press [Enter] to display a status message.\n\n");
209 printf("Copyright (c) 2008 Steve Thomas <SMT837784@yahoo.com>\n");
210 printf(" This is free software: you can redistribute it and/or modify it under the\n");
211 printf(" terms of the GNU General Public License as published by the Free Software\n");
212 printf(" Foundation, either version 3 of the License, or (at your option) any later\n");
213 printf(" version. There is NO WARRANTY, to the extent permitted by law.\n");