]> git.sesse.net Git - freerainbowtables/blobdiff - Client Applications/converti2/converti2.cpp
(C)
[freerainbowtables] / Client Applications / converti2 / converti2.cpp
index 3ad8c09a75fb0dbc6e3dfe4c873621f3fa2b8ba2..c447f0c79e75e96feebc0bb5f87498f0b4d3b707 100644 (file)
@@ -1,7 +1,8 @@
 #include <string>
 #include <vector>
 #ifdef _WIN32
-#include <io.h>
+       #include <io.h>
+       #include <conio.h>
 #else
        #include <sys/types.h>
        #include <sys/stat.h>
@@ -13,7 +14,6 @@
 #include <time.h>
 #include <math.h>
 #include <vector>
-#include <conio.h>
 #include <sstream>
 #include "Public.h"
 #include "MemoryPool.h"
@@ -100,7 +100,7 @@ int GetMaxBits(uint64 highvalue)
                return 30;
        if(highvalue < 0x80000000)
                return 31;
-#ifdef WIN32
+#if defined(_WIN32) && !defined(__GNUC__)
        if(highvalue < 0x0000000100000000I64)
                return 32;
        if(highvalue < 0x0000000200000000I64)
@@ -297,7 +297,7 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int
        }
        unsigned int distribution[64] = {0};
        unsigned int numProcessedChains = 0;
-       FILE* fileR;
+       FILE* fileR = NULL;
        BaseRTReader *reader = NULL;
        if(sPathName.substr(sPathName.length() - 2, sPathName.length()) == "rt")
                reader = (BaseRTReader*)new RTReader(sPathName);
@@ -317,9 +317,9 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int
 
                int size = reader->GetChainsLeft() * sizeof(RainbowChain);
                        static CMemoryPool mp;
-                       unsigned int nAllocatedSize;
+                       uint64 nAllocatedSize;
                        RainbowChain* pChain = (RainbowChain*)mp.Allocate(size, nAllocatedSize);                        
-                       unsigned int chainrowsize = ceil((float)(rti_startptlength + rti_endptlength + rti_cplength) / 8) * 8 ; // The size in bits (in whole bytes)
+                       uint32 chainrowsize = (uint32)ceil((float)(rti_startptlength + rti_endptlength + rti_cplength) / 8) * 8 ; // The size in bits (in whole bytes)
                        unsigned int chainrowsizebytes = chainrowsize / 8;
 
                        if (pChain != NULL)     {
@@ -327,17 +327,19 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int
                                unsigned int nChains = nAllocatedSize / sizeof(RainbowChain);
                                uint64 curPrefix = 0, prefixStart = 0;
                                vector<IndexRow> indexes;
-                               while(reader->GetChainsLeft() > 0) {
+                               unsigned int chainsLeft;
+                               while((chainsLeft = reader->GetChainsLeft()) > 0) {
                                        
 /*                                     if (ftell(file) == nFileLen)
                                                break;*/
-                                       int nReadThisRound;
+                                       printf("%u chains left to read\n", chainsLeft);
+                                       //int nReadThisRound;
                                        clock_t t1 = clock();
                                        printf("reading...\n");
 #ifdef _MEMORYDEBUG
                        printf("Grabbing %i chains from file\n", nChains);
 #endif
-                       reader->ReadChains(nChains, pChain);
+                                       reader->ReadChains(nChains, pChain);
 #ifdef _MEMORYDEBUG
                        printf("Recieved %i chains from file\n", nChains);
 #endif
@@ -346,7 +348,7 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int
                                        printf("reading time: %.2f s\n", fTime);                
                                        printf("converting %i chains...\n", nChains);
                                        t1 = clock();
-                                       for(int i = 0; i < nChains; i++)        {
+                                       for(unsigned int i = 0; i < nChains; i++)       {
                                                if(showDistribution == 1) {
                                                        distribution[GetMaxBits(pChain[i].nIndexS)-1]++;
                                                }
@@ -401,7 +403,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(UINT4 i = 0; i < indexes.size(); i++)
+                               for(uint32 i = 0; i < indexes.size(); i++)
                                {
                                        if(indexes[i].numchains > high.numchains)
                                                high.numchains = indexes[i].numchains;
@@ -415,7 +417,7 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int
 //                                     unsigned int m_rti_index_prefixlength = GetMaxBits(high.prefix);
                                unsigned int m_rti_index_numchainslength = GetMaxBits(high.numchains);
 //                                     unsigned int m_rti_index_indexlength = GetMaxBits(high.prefixstart);
-                               unsigned int m_indexrowsize = ceil((float)(/*m_rti_index_indexlength + */m_rti_index_numchainslength) / 8) * 8; // The size in bits (in whole bytes)    
+                               uint32 m_indexrowsize = (uint32)ceil((float)(/*m_rti_index_indexlength + */m_rti_index_numchainslength) / 8) * 8; // The size in bits (in whole bytes)  
                                unsigned int m_indexrowsizebytes = m_indexrowsize / 8;
                                FILE *pFileIndex = fopen(sResultFileName.append(".index").c_str(), "wb");
                                fwrite("RTI2", 1, 4, pFileIndex);
@@ -425,18 +427,18 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int
 //                                     fwrite(&m_rti_index_indexlength , 1, 1, pFileIndex);
 
                                fwrite(&m_rti_index_numchainslength, 1, 1, pFileIndex);
-                               for(UINT4 i = 0; i < rti_cppos.size(); i++)     {
+                               for(uint32 i = 0; i < rti_cppos.size(); i++)    {
                                        fwrite(&rti_cppos[i], 1, 4, pFileIndex); // The position of the checkpoints
                                }
 //                                     fwrite(&m_rti_index_prefixlength, 1, 1, pFileIndex);
                                int zero = 0;
                                fwrite(&indexes[0].prefix, 1, 8, pFileIndex); // Write the first prefix
                                unsigned int lastPrefix = 0;
-                               for(UINT4 i = 0; i < indexes.size(); i++)       {
+                               for(uint32 i = 0; i < indexes.size(); i++)      {
                                        if(i == 0) {
                                                lastPrefix = indexes[0].prefix;
                                        }
-                                       unsigned int indexrow = 0;
+                                       //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) {
@@ -445,7 +447,7 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int
 
                                                // then write the distance amount of 00's
                                                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);
+                                                       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*m_indexrowsizebytes));
                                                        #ifdef _WIN32
                                                        if ( _getch() != 'y' ) {
                                                        #else
@@ -455,7 +457,7 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int
                                                                exit(1);
                                                        }
                                                }
-                                               for(UINT4 j = 1; j < diffSize; j++)
+                                               for(uint32 j = 1; j < diffSize; j++)
                                                {                                                               
                                                        fwrite(&zero, 1, m_indexrowsizebytes, pFileIndex);
                                                }
@@ -577,7 +579,7 @@ int main(int argc, char* argv[])
                }               
        }
        vector<string> vPathName;
-#ifdef WIN32
+#ifdef _WIN32
        string sWildCharPathName = argv[1];
        GetTableList(sWildCharPathName, vPathName);
 #else
@@ -587,7 +589,7 @@ int main(int argc, char* argv[])
                printf("no rainbow table found\n");
                return 0;
        }
-       for (UINT4 i = 0; i < vPathName.size(); i++) {
+       for (uint32 i = 0; i < vPathName.size(); i++) {
                string sResultFile;
                int n = vPathName[i].find_last_of('\\');
                if (n != -1) {
@@ -615,4 +617,4 @@ int main(int argc, char* argv[])
                printf("\n");
        }
        return 0;
-}
\ No newline at end of file
+}