]> git.sesse.net Git - freerainbowtables/blobdiff - Client Applications/rcracki_mt/CrackEngine.cpp
Merge branch 'master' of git@gitorious.org:freerainbowtables-applications/freerainbow...
[freerainbowtables] / Client Applications / rcracki_mt / CrackEngine.cpp
index d36ebbc74556e4717eb8ca53cf73992d4e22ccd0..0343588f38015dcead7af0a10818659b97a01cc4 100644 (file)
@@ -3,7 +3,7 @@
  * RainbowCrack\r
  *\r
  * Copyright (C) Zhu Shuanglei <shuanglei@hotmail.com>\r
- * Copyright Martin Westergaard Jørgensen <martinwj2005@gmail.com>\r
+ * Copyright 2009, 2010 Martin Westergaard Jørgensen <martinwj2005@gmail.com>\r
  * Copyright 2009, 2010 Daniël Niggebrugge <niggebrugge@fox-it.com>\r
  * Copyright 2009, 2010 James Nobis <frt@quelrod.net>\r
  * Copyright 2010 uroskn\r
@@ -1044,11 +1044,16 @@ void CCrackEngine::SearchRainbowTable(string sPathName, CHashSet& hs)
                                }\r
 \r
                                static CMemoryPool mp(bytesForChainWalkSet, debug, maxMem);\r
-                               RainbowChainO* pChain = (RainbowChainO*)mp.Allocate(nFileLen, nAllocatedSize);\r
-                               #ifdef _WIN32\r
-                                       if (debug) printf("Allocated %I64u bytes, filelen %lu\n", nAllocatedSize, (unsigned long)nFileLen);\r
+                               RainbowChainO* pChain = NULL;\r
+                               if(doRti2Format) {\r
+                                       pChain = (RainbowChainO*)mp.Allocate(pReader->GetChainsLeft() * 16, nAllocatedSize);\r
+                               } else {\r
+                                       pChain = (RainbowChainO*)mp.Allocate(nFileLen, nAllocatedSize);\r
+                               }\r
+                               #if defined(_WIN32) && !defined(__GNUC__)\r
+                                       if (debug) printf("Allocated %I64 bytes, filelen %ld\n", nAllocatedSize, nFileLen);\r
                                #else\r
-                                       if (debug) printf("Allocated %llu bytes, filelen %lu\n", nAllocatedSize, (unsigned long)nFileLen);\r
+                                       if (debug) printf("Allocated %llu bytes, filelen %ld\n", nAllocatedSize, nFileLen);\r
                                #endif\r
 \r
                                if (pChain != NULL)\r
@@ -1064,13 +1069,15 @@ void CCrackEngine::SearchRainbowTable(string sPathName, CHashSet& hs)
 \r
                                                // Load table chunk\r
                                                if (debug) printf("reading...\n");\r
-                                               unsigned int nDataRead = 0, nDataToRead = 0;\r
+                                               unsigned int nDataRead = 0;\r
                                                gettimeofday( &tv, NULL );\r
                                                if ( doRti2Format )\r
                                                {\r
-                                                       nDataToRead = nAllocatedSize / 16;\r
-                                                       nDataRead = nDataToRead;\r
+                                                       nDataRead = nAllocatedSize / 16;\r
+                                                       if(pReader->GetChainsLeft() <= 0) // No more data\r
+                                                               break; \r
                                                        pReader->ReadChains(nDataRead, pChain);\r
+\r
                                                        nDataRead *= 8; // Convert from chains read to bytes\r
                                                }\r
                                                else\r
@@ -1086,6 +1093,10 @@ void CCrackEngine::SearchRainbowTable(string sPathName, CHashSet& hs)
 \r
                                                int nRainbowChainCountRead = nDataRead / 16;\r
 \r
+                                               if(doRti2Format) {\r
+                                                       nRainbowChainCountRead = nDataRead / 8;\r
+                                               }\r
+\r
                                                // Verify table chunk\r
                                                if (!fVerified)\r
                                                {\r
@@ -1137,12 +1148,15 @@ void CCrackEngine::SearchRainbowTable(string sPathName, CHashSet& hs)
                                                if (!hs.AnyHashLeftWithLen(CChainWalkContext::GetHashLen()))\r
                                                        break;\r
 \r
+/*\r
+       // XXX eliminated by PB - check correctness\r
                                                // finished the current table\r
                                                if( doRti2Format && nDataToRead > (nDataRead / 8) )\r
                                                {\r
                                                        delete pReader;\r
                                                        break;\r
                                                }\r
+*/\r
                                        }\r
                                }\r
                                else\r
@@ -1162,21 +1176,21 @@ void CCrackEngine::SearchRainbowTable(string sPathName, CHashSet& hs)
                                if(fIndex != NULL)\r
                                {\r
                                        // File length check\r
-                                       unsigned int nFileLenIndex = GetFileLen(fIndex);\r
+                                       long nFileLenIndex = GetFileLen(fIndex);\r
                                        //unsigned int nRows = nFileLenIndex / 11;\r
                                        //unsigned int nSize = nRows * sizeof(IndexChain);\r
                                        //printf("Debug: 8\n");\r
                                        if (nFileLenIndex % 11 != 0)\r
-                                               printf("index file length mismatch (%u bytes)\n", nFileLenIndex);\r
+                                               printf("index file length mismatch (%ld bytes)\n", nFileLenIndex);\r
                                        else\r
                                        {\r
                                                //printf("index nSize: %d\n", nSize);\r
                                                //pIndex = (IndexChain*)new unsigned char[nSize];\r
                                                IndexChain *pIndex = (IndexChain*)mpIndex.Allocate(nFileLenIndex, nAllocatedSizeIndex);\r
                                                #ifdef _WIN32\r
-                                                       if (debug) printf("Debug: Allocated %I64u bytes for index with filelen %u\n", nAllocatedSizeIndex, nFileLenIndex);\r
+                                                       if (debug) printf("Debug: Allocated %I64u bytes for index with filelen %ld\n", nAllocatedSizeIndex, nFileLenIndex);\r
                                                #else\r
-                                                       if (debug) printf("Debug: Allocated %llu bytes for index with filelen %u\n", nAllocatedSizeIndex, nFileLenIndex);\r
+                                                       if (debug) printf("Debug: Allocated %llu bytes for index with filelen %ld\n", nAllocatedSizeIndex, nFileLenIndex);\r
                                                #endif\r
                                \r
                                                static CMemoryPool mp(bytesForChainWalkSet + nAllocatedSizeIndex, debug, maxMem);\r
@@ -1187,7 +1201,7 @@ void CCrackEngine::SearchRainbowTable(string sPathName, CHashSet& hs)
                                                \r
                                                        fseek(fIndex, 0, SEEK_SET);\r
 \r
-                                                       while ( (unsigned long)ftell(fIndex) != nFileLenIndex ) // Index chunk read loop\r
+                                                       while ( ftell(fIndex) != nFileLenIndex )        // Index chunk read loop\r
                                                        {\r
                                                                // Load index chunk\r
 #ifdef _WIN32\r
@@ -1230,7 +1244,7 @@ void CCrackEngine::SearchRainbowTable(string sPathName, CHashSet& hs)
                                                                        //fseek(file, 0, SEEK_SET);\r
                                                                        //bool fVerified = false;\r
                                                                        uint32 nProcessedChains = 0;\r
-                                                                       while (ftell(file) != nFileLen \r
+                                                                       while ( ftell(file) != nFileLen \r
                                                                                && nProcessedChains < nCoveredRainbowTableChains )      // Chunk read loop\r
                                                                        {\r
                                                                                // Load table chunk\r