+/*
+ * freerainbowtables is a project for generating, distributing, and using
+ * perfect rainbow tables
+ *
+ * Copyright 2010, 2011 Martin Westergaard Jørgensen <martinwj2005@gmail.com>
+ * Copyright 2010, 2011 James Nobis <frt@quelrod.net>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
#include "RTI2Reader.h"
#include <math.h>
+
RTI2Header *RTI2Reader::m_pHeader = NULL;
RTI2Reader::RTI2Reader(string Filename)
{
}
m_chainPosition = 0;
- unsigned int len = GetFileLen(pFileIndex);
+ long len = GetFileLen(pFileIndex);
fseek(pFileIndex, 0, SEEK_SET);
- m_pIndex = new unsigned char[len];
- if(fread(m_pIndex, 1, len, pFileIndex) != len)
+ m_pIndex = new (nothrow) unsigned char[len];
+ if(m_pIndex == NULL) {
+ printf("Error allocating %ld MB memory for index in RTI2Reader::RTI2Reader()", len / (1024 * 1024));
+ exit(-2);
+ }
+ if(fread(m_pIndex, 1, len, pFileIndex) != (unsigned long)len)
{
printf("Error while reading index file");
exit(1);
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;
}
}
-unsigned int RTI2Reader::GetChainsLeft()
+uint32 RTI2Reader::GetChainsLeft()
{
- int len = GetFileLen(m_pFile);
+ long len = GetFileLen(m_pFile);
return len / m_chainsizebytes - m_chainPosition;
}
-int RTI2Reader::ReadChains(unsigned int &numChains, RainbowChainCP *pData)
+int RTI2Reader::ReadChains(unsigned int &numChains, RainbowChain *pData)
{
if(strncmp(m_pHeader->header, "RTI2", 4) != 0)
{
while(true) // Fast forward to current position
{
+ /// XXX
// 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;
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)
{
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;
- pData[chainsProcessed].nCheckPoint = (chainrow >> m_pHeader->rti_startptlength + m_pHeader->rti_endptlength);
+#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++;
}