X-Git-Url: https://git.sesse.net/?p=freerainbowtables;a=blobdiff_plain;f=Common%2Frt%20api%2FRTI2Reader.cpp;fp=Common%2Frt%20api%2FRTI2Reader.cpp;h=ad7db3dd12e31621d0abea5faa4dda2227efa90e;hp=004159ceba7b65506461157d43844233f13cc008;hb=86bbf0fd5ba4e07d3279b4179fd8fc808198eaae;hpb=3d42602c1f746b5768f0e6c9d22884a9806eadc0 diff --git a/Common/rt api/RTI2Reader.cpp b/Common/rt api/RTI2Reader.cpp index 004159c..ad7db3d 100644 --- a/Common/rt api/RTI2Reader.cpp +++ b/Common/rt api/RTI2Reader.cpp @@ -1,6 +1,30 @@ +/* + * freerainbowtables is a project for generating, distributing, and using + * perfect rainbow tables + * + * Copyright 2010 Martin Westergaard Jørgensen + * Copyright 2010 James Nobis + * + * This file is part of freerainbowtables. + * + * freerainbowtables is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * freerainbowtables is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with freerainbowtables. If not, see . + */ + #include "RTI2Reader.h" #include + RTI2Header *RTI2Reader::m_pHeader = NULL; RTI2Reader::RTI2Reader(string Filename) { @@ -20,15 +44,15 @@ RTI2Reader::RTI2Reader(string Filename) } m_chainPosition = 0; - unsigned int len = GetFileLen(pFileIndex); + long len = GetFileLen(pFileIndex); fseek(pFileIndex, 0, SEEK_SET); m_pIndex = new (nothrow) unsigned char[len]; if(m_pIndex == NULL) { - printf("Error allocating %u MB memory for index in RTI2Reader::RTI2Reader()", len / (1024 * 1024)); + printf("Error allocating %ld MB memory for index in RTI2Reader::RTI2Reader()", len / (1024 * 1024)); exit(-2); } - if(fread(m_pIndex, 1, len, pFileIndex) != len) + if(fread(m_pIndex, 1, len, pFileIndex) != (unsigned long)len) { printf("Error while reading index file"); exit(1); @@ -38,15 +62,15 @@ RTI2Reader::RTI2Reader(string Filename) memcpy(m_pHeader, m_pIndex, sizeof(RTI2Header)); m_pHeader->m_cppos = (unsigned int*)(m_pIndex + 8); m_pHeader->prefixstart = *(uint64*)(m_pIndex + 8 + (m_pHeader->rti_cplength * 4)); - m_chainsizebytes = ceil((float)(m_pHeader->rti_startptlength + m_pHeader->rti_endptlength + m_pHeader->rti_cplength) / 8); // Get the size of each chain in bytes - m_indexrowsizebytes = ceil((float)m_pHeader->rti_index_numchainslength / 8); + m_chainsizebytes = (uint32)ceil((float)(m_pHeader->rti_startptlength + m_pHeader->rti_endptlength + m_pHeader->rti_cplength) / 8); // Get the size of each chain in bytes + m_indexrowsizebytes = (uint32)ceil((float)m_pHeader->rti_index_numchainslength / 8); // Check the filesize fseek(m_pFile, 0, SEEK_END); len = ftell(m_pFile); fseek(m_pFile, 0, SEEK_SET); if(len % m_chainsizebytes > 0) { - printf("Invalid filesize %u\n", len); + printf("Invalid filesize %lu\n", len); return; } @@ -62,7 +86,7 @@ RTI2Reader::~RTI2Reader(void) unsigned int RTI2Reader::GetChainsLeft() { - int len = GetFileLen(m_pFile); + long len = GetFileLen(m_pFile); return len / m_chainsizebytes - m_chainPosition; } @@ -82,7 +106,12 @@ int RTI2Reader::ReadChains(unsigned int &numChains, RainbowChain *pData) { // ALERT: Possible problem here if m_indexrowsizebytes > 1 as pNumChains is a unsigned char. unsigned int NumChainsInRow = (unsigned int)*(pNumChains + indexRow * m_indexrowsizebytes); - if(m_indexrowsizebytes > 1) { printf("Have to find a solution to this problem"); exit(2);} + if(m_indexrowsizebytes > 1) + { + //XXX Have to find a solution to this problem + printf( "FATAL: m_indexrowsizebytes > 1: %d\n", m_indexrowsizebytes ); + exit(2); + } if(i + NumChainsInRow > m_chainPosition) { curRowPosition = m_chainPosition - i; @@ -95,7 +124,7 @@ int RTI2Reader::ReadChains(unsigned int &numChains, RainbowChain *pData) uint64 chainrow = 0; // Buffer to store a single read chain unsigned int chainsProcessed = 0; // Number of chains processed - // ALERT: same problem with unsigned char here. + // XXX: same problem with unsigned char here. unsigned int NumChainsInRow = *(pNumChains + indexRow); while(chainsProcessed < numChains && fread(&chainrow, 1, m_chainsizebytes, m_pFile) == m_chainsizebytes) { @@ -112,13 +141,17 @@ int RTI2Reader::ReadChains(unsigned int &numChains, RainbowChain *pData) curRowPosition = 0; } // Load the starting point from the data - pData[chainsProcessed].nIndexS = chainrow << 64 - m_pHeader->rti_startptlength; - pData[chainsProcessed].nIndexS = pData[chainsProcessed].nIndexS >> 64 - m_pHeader->rti_startptlength; + pData[chainsProcessed].nIndexS = chainrow << ( 64 - m_pHeader->rti_startptlength ); + pData[chainsProcessed].nIndexS = pData[chainsProcessed].nIndexS >> ( 64 - m_pHeader->rti_startptlength ); // Load the ending point prefix - pData[chainsProcessed].nIndexE = m_pHeader->prefixstart + indexRow << m_pHeader->rti_endptlength; + pData[chainsProcessed].nIndexE = ( m_pHeader->prefixstart + indexRow ) << m_pHeader->rti_endptlength; // Append the ending point suffix - pData[chainsProcessed].nIndexE |= (chainrow & (0xFFFFFFFFFFFFFFFF >> m_pHeader->rti_cplength)) >> m_pHeader->rti_startptlength; +#if defined(_WIN32) && !defined(__GNUC__) + pData[chainsProcessed].nIndexE |= (chainrow & (0xFFFFFFFFFFFFFFFFI64 >> m_pHeader->rti_cplength)) >> m_pHeader->rti_startptlength; +#else + pData[chainsProcessed].nIndexE |= (chainrow & (0xFFFFFFFFFFFFFFFFllu >> m_pHeader->rti_cplength)) >> m_pHeader->rti_startptlength; +#endif //pData[chainsProcessed].nCheckPoint = (chainrow >> m_pHeader->rti_startptlength + m_pHeader->rti_endptlength); curRowPosition++; chainsProcessed++;