]> git.sesse.net Git - freerainbowtables/blobdiff - Client Applications/converti2/converti2.cpp
actually commit everything
[freerainbowtables] / Client Applications / converti2 / converti2.cpp
index dec2b6494f108f9e6625a32abb913df251cf94db..db703e92d243a16dd46cbd0fa6475758f49fc0c9 100644 (file)
@@ -1,18 +1,23 @@
 #include <string>
 #include <vector>
 #ifdef _WIN32
-#include <io.h>
+       #include <io.h>
+       #include <conio.h>
 #else
        #include <sys/types.h>
        #include <sys/stat.h>
        #include <unistd.h>
 #endif
 
+#include <stdlib.h>
+#include <string.h>
 #include <time.h>
 #include <math.h>
 #include <vector>
+
 #include "Public.h"
 #include "MemoryPool.h"
+
 using namespace std;
 
 void Usage()
@@ -299,8 +304,8 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int
        if (file != NULL && fileR != NULL)
        {
                // File length check
-               unsigned int nFileLen = GetFileLen(file);
-               unsigned int nTotalChainCount = 0;
+               UINT4 nFileLen = GetFileLen(file);
+               UINT4 nTotalChainCount = 0;
                if(hascp == 0) nTotalChainCount = nFileLen / 16;
                else nTotalChainCount = nFileLen / 18;
                if ((hascp == 0 && nFileLen % 16 != 0) || (hascp == 1 && nFileLen % 18 != 0))
@@ -323,12 +328,12 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int
                                fseek(file, 0, SEEK_SET);
                                uint64 curPrefix = 0, prefixStart = 0;
                                vector<IndexRow> indexes;
-                               int nRainbowChainCountRead = 0;
+                               UINT4 nRainbowChainCountRead = 0;
                                while (true)    // Chunk read loop
                                {
 /*                                     if (ftell(file) == nFileLen)
                                                break;*/
-                                       int nReadThisRound;
+                                       UINT4 nReadThisRound;
                                        memset(pChain, 0x00, nAllocatedSize);
                                        printf("reading...\n");
                                        clock_t t1 = clock();
@@ -354,7 +359,7 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int
                                        printf("%u bytes read, disk access time: %.2f s\n", nDataRead , fTime);
                                        t1 = clock();
 
-                                       for(int i = 0; i < nReadThisRound; i++)
+                                       for(UINT4 i = 0; i < nReadThisRound; i++)
                                        {
                                                if(showDistribution == 1)
                                                {
@@ -417,7 +422,7 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int
                                indexes.push_back(index);
 
                                IndexRow high = {0}; // Used to find the highest numbers. This tells us how much we can pack the index bits
-                               for(int i = 0; i < indexes.size(); i++)
+                               for(UINT4 i = 0; i < indexes.size(); i++)
                                {
                                        if(indexes[i].numchains > high.numchains)
                                                high.numchains = indexes[i].numchains;
@@ -440,7 +445,7 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int
                                fwrite(&rti_cplength, 1, 1, pFileIndex);
 //                                     fwrite(&m_rti_index_indexlength , 1, 1, pFileIndex);
                                fwrite(&m_rti_index_numchainslength, 1, 1, pFileIndex);
-                               for(int i = 0; i < rti_cppos.size(); i++)
+                               for(UINT4 i = 0; i < rti_cppos.size(); i++)
                                {
                                        fwrite(&rti_cppos[i], 1, 4, pFileIndex); // The position of the checkpoints
                                }
@@ -448,11 +453,10 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int
                                int zero = 0;
                                fwrite(&indexes[0].prefix, 1, 8, pFileIndex); // Write the first prefix
                                unsigned int lastPrefix = 0;
-                               for(int i = 0; i < indexes.size(); i++)
+                               for(UINT4 i = 0; i < indexes.size(); i++)
                                {
                                        if(i == 0)
                                                lastPrefix = indexes[0].prefix;
-                                       unsigned int indexrow = 0;
                                        // Checks how big a distance there is between the current and the next prefix. eg cur is 3 and next is 10 = 7.
                                        unsigned int diffSize = indexes[i].prefix - lastPrefix; 
                                        if(i > 0 && diffSize > 1)
@@ -461,7 +465,18 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int
                                                //printf("Diffsize is %u\n", diffSize);
 
                                                // then write the distance amount of 00's
-                                               for(int j = 1; j < diffSize; j++)
+                                               if(diffSize > 1000) {
+                                                       printf("WARNING! The distance to the next prefix is %i. Do you want to continue writing %i bytes of 0x00? Press y to continue", diffSize, diffSize);
+                                                       #ifdef _WIN32
+                                                       if ( _getch() != 'y' ) {
+                                                       #else
+                                                       if ( tty_getchar() != 'y' ) {
+                                                       #endif
+                                                               printf("Aborting...");
+                                                               exit(1);
+                                                       }
+                                               }
+                                               for(UINT4 j = 1; j < diffSize; j++)
                                                {                                                               
                                                        fwrite(&zero, 1, m_indexrowsizebytes, pFileIndex);
                                                }
@@ -604,7 +619,7 @@ int main(int argc, char* argv[])
                printf("no rainbow table found\n");
                return 0;
        }
-       for (int i = 0; i < vPathName.size(); i++)
+       for (UINT4 i = 0; i < vPathName.size(); i++)
        {
                string sResultFile;
                int n = vPathName[i].find_last_of('\\');
@@ -612,7 +627,7 @@ int main(int argc, char* argv[])
                        sResultFile = vPathName[i].substr(n+1, vPathName[i].length()) + "i2";
                else 
                        sResultFile = vPathName[i] + "i2"; // Resulting file is .rt, not .rti
-               printf("Using %i of 64 bits\n", (sptl + eptl + usecp));
+               printf("Using %i of 64 bits. sptl: %i, eptl: %i, cp: %i. Chains will be %i bytes in size\n", (sptl + eptl + usecp), sptl, eptl, usecp, ((sptl + eptl + usecp) / 8));
                if(sptl + eptl + usecp > 64)
                {
                        exit(1);
@@ -621,4 +636,4 @@ int main(int argc, char* argv[])
                printf("\n");
        }
        return 0;
-}
\ No newline at end of file
+}