13 #include "MemoryPool.h"
14 #include "RTI2Reader.h"
15 #include "RTIReader.h"
20 printf("rti2rto - Indexed to Original rainbow table converter\n");
21 printf("by Martin Westergaard <martinwj2005@gmail.com>\n");
22 printf("http://www.freerainbowtables.com\n\n");
24 printf("usage: rti2rto rainbow_table_pathname\n");
25 printf("rainbow_table_pathname: pathname of the rainbow table(s), wildchar(*, ?) supported\n");
27 printf("example: rti2rto *.rti\n");
28 printf(" rti2rto md5_*.rti\n");
31 void GetTableList(string sWildCharPathName, vector<string>& vPathName)
36 int n = sWildCharPathName.find_last_of('\\');
38 sPath = sWildCharPathName.substr(0, n + 1);
41 long handle = _findfirst(sWildCharPathName.c_str(), &fd);
46 string sName = fd.name;
47 if (sName != "." && sName != ".." && !(fd.attrib & _A_SUBDIR))
49 string sPathName = sPath + sName;
50 vPathName.push_back(sPathName);
52 } while (_findnext(handle, &fd) == 0);
58 void GetTableList(int argc, char* argv[], vector<string>& vPathName)
63 for (i = 1; i < argc; i++)
65 string sPathName = argv[i];
67 if (lstat(sPathName.c_str(), &buf) == 0)
69 if (S_ISREG(buf.st_mode))
70 vPathName.push_back(sPathName);
78 void ConvertRainbowTable(string sPathName, string sResultFileName, string sType)
81 int nIndex = sPathName.find_last_of('\\');
83 int nIndex = sPathName.find_last_of('/');
87 sFileName = sPathName.substr(nIndex + 1);
89 sFileName = sPathName;
92 printf("%s:\n", sFileName.c_str());
93 FILE *fResult = fopen(sResultFileName.c_str(), "wb");
96 printf("Could not open %s for write access", sResultFileName.c_str());
99 static CMemoryPool mp;
100 unsigned int nAllocatedSize;
101 BaseRTReader *reader = NULL;
103 reader = (BaseRTReader*)new RTI2Reader(sFileName);
104 else if(sType == "RTI")
105 reader = (BaseRTReader*)new RTIReader(sFileName);
108 printf("Invalid table type '%s'", sType.c_str());
111 int size = reader->GetChainsLeft() * sizeof(RainbowChain);
113 printf("Starting allocation of %i bytes\n", size);
115 RainbowChain* pChain = (RainbowChain*)mp.Allocate(size, nAllocatedSize);
117 printf("Finished. Got %i bytes\n", nAllocatedSize);
121 nAllocatedSize = nAllocatedSize / sizeof(RainbowChain) * sizeof(RainbowChain); // Round to boundary
122 unsigned int nChains = nAllocatedSize / sizeof(RainbowChain);
123 while(reader->GetChainsLeft() > 0)
126 printf("Grabbing %i chains from file\n", nChains);
128 reader->ReadChains(nChains, pChain);
130 printf("Recieved %i chains from file\n", nChains);
132 for(uint32 i = 0; i < nChains; i++)
134 fwrite(&pChain[i], 1, 16, fResult);
142 int main(int argc, char* argv[])
151 string sWildCharPathName = argv[1];
152 vector<string> vPathName;
153 GetTableList(sWildCharPathName, vPathName);
160 for(int i = 0; i < argc; i++)
162 printf("%i: %s\n", i, argv[i]);
165 vector<string> vPathName;
166 GetTableList(argc, argv, vPathName);
168 if (vPathName.size() == 0)
170 printf("no rainbow table found\n");
173 for (uint32 i = 0; i < vPathName.size(); i++)
175 string sResultFile, sType;
177 if(vPathName[i].substr(vPathName[i].length() - 4, vPathName[i].length()) == "rti2")
179 sResultFile = vPathName[i].substr(0, vPathName[i].length() - 2); // Resulting file is .rt, not .rti2
182 else if(vPathName[i].substr(vPathName[i].length() - 3, vPathName[i].length()) == "rti")
184 sResultFile = vPathName[i].substr(0, vPathName[i].length() - 1); // Resulting file is .rt, not .rti
189 printf("File %s is not a RTI or a RTI2 file", vPathName[i].c_str());
192 ConvertRainbowTable(vPathName[i], sResultFile, sType);