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;
91 printf("%s:\n", sFileName.c_str());
92 FILE *fResult = fopen(sResultFileName.c_str(), "wb");
95 printf("Could not open %s for write access", sResultFileName.c_str());
98 static CMemoryPool mp;
99 unsigned int nAllocatedSize;
100 BaseRTReader *reader = NULL;
102 reader = (BaseRTReader*)new RTI2Reader(sFileName);
103 else if(sType == "RTI")
104 reader = (BaseRTReader*)new RTIReader(sFileName);
107 printf("Invalid table type '%s'", sType.c_str());
110 RainbowChainCP* pChain = (RainbowChainCP*)mp.Allocate(reader->GetChainsLeft() * sizeof(RainbowChainCP), nAllocatedSize);
113 nAllocatedSize = nAllocatedSize / sizeof(RainbowChainCP) * sizeof(RainbowChainCP); // Round to boundary
114 unsigned int nChains = nAllocatedSize / sizeof(RainbowChainCP);
115 while(reader->GetChainsLeft() > 0)
117 reader->ReadChains(nChains, pChain);
118 for(int i = 0; i < nChains; i++)
120 fwrite(&pChain[i], 1, 16, fResult);
128 int main(int argc, char* argv[])
137 string sWildCharPathName = argv[1];
138 vector<string> vPathName;
139 GetTableList(sWildCharPathName, vPathName);
146 for(int i = 0; i < argc; i++)
148 printf("%i: %s\n", i, argv[i]);
151 vector<string> vPathName;
152 GetTableList(argc, argv, vPathName);
154 if (vPathName.size() == 0)
156 printf("no rainbow table found\n");
159 for (int i = 0; i < vPathName.size(); i++)
161 string sResultFile, sType;
163 if(vPathName[i].substr(vPathName[i].length() - 4, vPathName[i].length()) == "rti2")
165 sResultFile = vPathName[i].substr(0, vPathName[i].length() - 2); // Resulting file is .rt, not .rti2
168 else if(vPathName[i].substr(vPathName[i].length() - 3, vPathName[i].length()) == "rti")
170 sResultFile = vPathName[i].substr(0, vPathName[i].length() - 1); // Resulting file is .rt, not .rti
175 printf("File %s is not a RTI or a RTI2 file", vPathName[i].c_str());
178 ConvertRainbowTable(vPathName[i], sResultFile, sType);