From 47c71901e7a97c226c8f1df749e3606d43656f32 Mon Sep 17 00:00:00 2001 From: James Nobis Date: Tue, 18 Jan 2011 22:00:17 -0600 Subject: [PATCH] (C) misc cleanup merging of shared source --- .../distrrtgen_cuda/rcuda.cu | 1 + Client Applications/converti2/converti2.cpp | 12 +++---- .../rcracki_mt/BaseRTReader.cpp | 2 +- Client Applications/rcracki_mt/BaseRTReader.h | 2 +- .../rcracki_mt/ChainWalkContext.cpp | 2 +- .../rcracki_mt/HashAlgorithm.cpp | 2 +- .../rcracki_mt/HashRoutine.cpp | 2 +- Client Applications/rcracki_mt/Public.cpp | 6 ++-- Client Applications/rcracki_mt/Public.h | 5 +-- Client Applications/rcracki_mt/RTI2Reader.cpp | 2 +- Client Applications/rti2rto/rti2rto.cpp | 4 +-- Common/rt api/BaseRTReader.cpp | 2 +- Common/rt api/BaseRTReader.h | 4 +-- Common/rt api/ChainWalkSet.cpp | 2 +- Common/rt api/HashAlgorithm.cpp | 2 +- Common/rt api/MemoryPool.cpp | 36 +++++++++++-------- Common/rt api/MemoryPool.h | 6 ++-- Common/rt api/Public.cpp | 4 +-- Common/rt api/RTI2Reader.cpp | 3 +- Common/rt api/RTI2Reader.h | 2 +- Common/rt api/RTIReader.cpp | 6 ++-- Common/rt api/RTIReader.h | 2 +- Common/rt api/RTReader.cpp | 4 +-- Common/rt api/RTReader.h | 2 +- 24 files changed, 60 insertions(+), 55 deletions(-) diff --git a/BOINC software/BOINC client apps/distrrtgen_cuda/rcuda.cu b/BOINC software/BOINC client apps/distrrtgen_cuda/rcuda.cu index b626041..412128e 100644 --- a/BOINC software/BOINC client apps/distrrtgen_cuda/rcuda.cu +++ b/BOINC software/BOINC client apps/distrrtgen_cuda/rcuda.cu @@ -160,6 +160,7 @@ extern "C" int CalcChainsOnCUDA(const rcuda::RCudaTask* task, uint64 *resultBuff cuErr = cudaSuccess; cudaSetDeviceFlags(cudaDeviceBlockingSync); + for(int idx = 0; idx < task->rainbowChainLen-1 && cuErr == cudaSuccess; idx+=KERN_CHAIN_SIZE) { switch(task->hash) { case rcuda::RHASH_MD5: diff --git a/Client Applications/converti2/converti2.cpp b/Client Applications/converti2/converti2.cpp index 13b492e..c447f0c 100644 --- a/Client Applications/converti2/converti2.cpp +++ b/Client Applications/converti2/converti2.cpp @@ -317,7 +317,7 @@ 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); 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; @@ -403,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; @@ -427,14 +427,14 @@ 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; } @@ -457,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); } @@ -589,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) { diff --git a/Client Applications/rcracki_mt/BaseRTReader.cpp b/Client Applications/rcracki_mt/BaseRTReader.cpp index e0f8fa8..7ee1223 100644 --- a/Client Applications/rcracki_mt/BaseRTReader.cpp +++ b/Client Applications/rcracki_mt/BaseRTReader.cpp @@ -2,7 +2,7 @@ * rcracki_mt is a multithreaded implementation and fork of the original * RainbowCrack * - * Copyright 2010 Martin Westergaard Jørgensen + * Copyright 2010, 2011 Martin Westergaard Jørgensen * Copyright 2010 Daniël Niggebrugge * Copyright 2010, 2011 James Nobis * diff --git a/Client Applications/rcracki_mt/BaseRTReader.h b/Client Applications/rcracki_mt/BaseRTReader.h index 01073a5..2086d86 100644 --- a/Client Applications/rcracki_mt/BaseRTReader.h +++ b/Client Applications/rcracki_mt/BaseRTReader.h @@ -2,7 +2,7 @@ * rcracki_mt is a multithreaded implementation and fork of the original * RainbowCrack * - * Copyright 2010 Martin Westergaard Jørgensen + * Copyright 2010, 2011 Martin Westergaard Jørgensen * Copyright 2010 Daniël Niggebrugge * Copyright 2010, 2011 James Nobis * diff --git a/Client Applications/rcracki_mt/ChainWalkContext.cpp b/Client Applications/rcracki_mt/ChainWalkContext.cpp index deb6f51..4fdcf6e 100644 --- a/Client Applications/rcracki_mt/ChainWalkContext.cpp +++ b/Client Applications/rcracki_mt/ChainWalkContext.cpp @@ -25,7 +25,7 @@ */ #if defined(_WIN32) && !defined(__GNUC__) - #pragma warning(disable : 4786 4267 4018) + #pragma warning(disable : 4786) #endif #include "ChainWalkContext.h" diff --git a/Client Applications/rcracki_mt/HashAlgorithm.cpp b/Client Applications/rcracki_mt/HashAlgorithm.cpp index bb5b94e..3c3c558 100644 --- a/Client Applications/rcracki_mt/HashAlgorithm.cpp +++ b/Client Applications/rcracki_mt/HashAlgorithm.cpp @@ -3,7 +3,7 @@ * RainbowCrack * * Copyright (C) Zhu Shuanglei - * Copyright 2009, 2010 Martin Westergaard Jørgensen + * Copyright 2009, 2010, 2011 Martin Westergaard Jørgensen * Copyright 2009, 2010 Daniël Niggebrugge * Copyright 2009, 2010, 2011 James Nobis * diff --git a/Client Applications/rcracki_mt/HashRoutine.cpp b/Client Applications/rcracki_mt/HashRoutine.cpp index 1d0ca53..71e9eef 100644 --- a/Client Applications/rcracki_mt/HashRoutine.cpp +++ b/Client Applications/rcracki_mt/HashRoutine.cpp @@ -24,7 +24,7 @@ */ #if defined(_WIN32) && !defined(__GNUC__) - #pragma warning(disable : 4786 4267 4018) + #pragma warning(disable : 4786) #endif #include "HashRoutine.h" diff --git a/Client Applications/rcracki_mt/Public.cpp b/Client Applications/rcracki_mt/Public.cpp index 959e691..6e02af6 100644 --- a/Client Applications/rcracki_mt/Public.cpp +++ b/Client Applications/rcracki_mt/Public.cpp @@ -23,7 +23,7 @@ */ #if defined(_WIN32) && !defined(__GNUC__) - #pragma warning(disable : 4786 4267 4018) + #pragma warning(disable : 4786) #endif #include "Public.h" @@ -44,8 +44,8 @@ struct timezone { - int tz_minuteswest; /* minutes W of Greenwich */ - int tz_dsttime; /* type of dst correction */ + int tz_minuteswest; /* minutes W of Greenwich */ + int tz_dsttime; /* type of dst correction */ }; int gettimeofday(struct timeval *tv, struct timezone *tz) diff --git a/Client Applications/rcracki_mt/Public.h b/Client Applications/rcracki_mt/Public.h index 0508842..08943d4 100644 --- a/Client Applications/rcracki_mt/Public.h +++ b/Client Applications/rcracki_mt/Public.h @@ -36,7 +36,6 @@ using namespace std; - struct RainbowChainO { uint64 nIndexS; @@ -114,9 +113,7 @@ void tty_flush(void); #if defined(_WIN32) && !defined(__GNUC__) int gettimeofday( struct timeval *tv, struct timezone *tz ); -#endif - -#if !defined(_WIN32) || defined(__GNUC__) +#else #include #endif diff --git a/Client Applications/rcracki_mt/RTI2Reader.cpp b/Client Applications/rcracki_mt/RTI2Reader.cpp index 9176fa6..5453898 100644 --- a/Client Applications/rcracki_mt/RTI2Reader.cpp +++ b/Client Applications/rcracki_mt/RTI2Reader.cpp @@ -71,7 +71,7 @@ RTI2Reader::RTI2Reader(string Filename) fseek(m_pFile, 0, SEEK_SET); if(len % m_chainsizebytes > 0) { - printf("Invalid filesize %ld\n", len); + printf("Invalid filesize %lu\n", len); return; } diff --git a/Client Applications/rti2rto/rti2rto.cpp b/Client Applications/rti2rto/rti2rto.cpp index ba7f163..760a7f5 100644 --- a/Client Applications/rti2rto/rti2rto.cpp +++ b/Client Applications/rti2rto/rti2rto.cpp @@ -97,7 +97,7 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, string sType) return; } static CMemoryPool mp; - unsigned int nAllocatedSize; + uint64 nAllocatedSize; BaseRTReader *reader = NULL; if(sType == "RTI2") reader = (BaseRTReader*)new RTI2Reader(sFileName); @@ -108,7 +108,7 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, string sType) printf("Invalid table type '%s'", sType.c_str()); return ; } - int size = reader->GetChainsLeft() * sizeof(RainbowChain); + uint64 size = reader->GetChainsLeft() * sizeof(RainbowChain); #ifdef _MEMORYDEBUG printf("Starting allocation of %i bytes\n", size); #endif diff --git a/Common/rt api/BaseRTReader.cpp b/Common/rt api/BaseRTReader.cpp index c48dd3c..d56eefe 100644 --- a/Common/rt api/BaseRTReader.cpp +++ b/Common/rt api/BaseRTReader.cpp @@ -2,7 +2,7 @@ * freerainbowtables is a project for generating, distributing, and using * perfect rainbow tables * - * Copyright 2010 Martin Westergaard Jørgensen + * Copyright 2010, 2011 Martin Westergaard Jørgensen * Copyright 2010 Daniël Niggebrugge * Copyright 2010, 2011 James Nobis * diff --git a/Common/rt api/BaseRTReader.h b/Common/rt api/BaseRTReader.h index 4b7accd..e06e94a 100644 --- a/Common/rt api/BaseRTReader.h +++ b/Common/rt api/BaseRTReader.h @@ -2,7 +2,7 @@ * freerainbowtables is a project for generating, distributing, and using * perfect rainbow tables * - * Copyright 2010 Martin Westergaard Jørgensen + * Copyright 2010, 2011 Martin Westergaard Jørgensen * Copyright 2010 Daniël Niggebrugge * Copyright 2010, 2011 James Nobis * @@ -37,7 +37,7 @@ using namespace std; class BaseRTReader { public: - virtual int ReadChains(uint32 &numChains, RainbowChainO *pData) = 0; + virtual int ReadChains(uint32 &numChains, RainbowChain *pData) = 0; virtual uint32 GetChainsLeft() = 0; virtual ~BaseRTReader() { }; diff --git a/Common/rt api/ChainWalkSet.cpp b/Common/rt api/ChainWalkSet.cpp index f426b82..ff7cb29 100644 --- a/Common/rt api/ChainWalkSet.cpp +++ b/Common/rt api/ChainWalkSet.cpp @@ -67,7 +67,7 @@ string CChainWalkSet::CheckOrRotatePreCalcFile() sprintf(sPreCalcFileName, "%s.%d", sPrecalcPathName.c_str(), preCalcPart); string sReturnPreCalcPath(sPreCalcFileName); - unsigned int fileLen = 0; + long fileLen = 0; FILE* file = fopen(sReturnPreCalcPath.c_str(), "ab"); if(file!=NULL) diff --git a/Common/rt api/HashAlgorithm.cpp b/Common/rt api/HashAlgorithm.cpp index 2761cfa..3fe3382 100644 --- a/Common/rt api/HashAlgorithm.cpp +++ b/Common/rt api/HashAlgorithm.cpp @@ -3,7 +3,7 @@ * perfect rainbow tables * * Copyright (C) Zhu Shuanglei - * Copyright Martin Westergaard Jørgensen + * Copyright 2009, 2010, 2011 Martin Westergaard Jørgensen * Copyright 2009, 2010 Daniël Niggebrugge * Copyright 2009, 2010, 2011 James Nobis * diff --git a/Common/rt api/MemoryPool.cpp b/Common/rt api/MemoryPool.cpp index 7e17b2a..bde4ed0 100644 --- a/Common/rt api/MemoryPool.cpp +++ b/Common/rt api/MemoryPool.cpp @@ -32,7 +32,7 @@ CMemoryPool::CMemoryPool() m_pMem = NULL; m_nMemSize = 0; - unsigned int nAvailPhys = GetAvailPhysMemorySize(); + unsigned long nAvailPhys = GetAvailPhysMemorySize(); if (nAvailPhys < 16 * 1024 * 1024) { nAvailPhys = 512 * 1024 * 1024; // There is atleast 256 mb available (Some Linux distros returns a really low GetAvailPhysMemorySize() @@ -45,7 +45,8 @@ CMemoryPool::CMemoryPool() CMemoryPool::~CMemoryPool() { - if (m_pMem != NULL) { + if (m_pMem != NULL) + { #ifdef _MEMORYDEBUG printf("Freeing %i bytes of memory\n", m_nMemSize); #endif @@ -55,22 +56,23 @@ CMemoryPool::~CMemoryPool() } } -unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& nAllocatedSize) +unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, uint64& nAllocatedSize) { - if (nFileLen <= m_nMemSize) { + if (nFileLen <= m_nMemSize) + { nAllocatedSize = nFileLen; return m_pMem; } unsigned int nTargetSize; - if (nFileLen < m_nMemMax) { + if (nFileLen < m_nMemMax) nTargetSize = nFileLen; - } - else { + else nTargetSize = m_nMemMax; - } + // Free existing memory - if (m_pMem != NULL) { + if (m_pMem != NULL) + { #ifdef _MEMORYDEBUG printf("Freeing %i bytes of memory\n", m_nMemSize); #endif @@ -81,21 +83,23 @@ unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& nAlloc // Allocate new memory //printf("allocating %u bytes memory\n", nTargetSize); - // m_pMem = new unsigned char[nTargetSize]; #ifdef _MEMORYDEBUG printf("Allocating %i bytes of memory - ", nTargetSize); #endif m_pMem = new (nothrow) unsigned char[nTargetSize]; - while (m_pMem == NULL && nTargetSize >= 512 * 1024 * 1024 ) { + while (m_pMem == NULL && nTargetSize >= 512 * 1024 * 1024 ) + { #ifdef _MEMORYDEBUG printf("failed!\n"); printf("Allocating %i bytes of memory (backup) - ", nTargetSize); #endif - nTargetSize -= 16 * 1024 * 1024; - m_pMem = new (nothrow) unsigned char[nTargetSize]; + nTargetSize -= 16 * 1024 * 1024; + m_pMem = new (nothrow) unsigned char[nTargetSize]; } - if (m_pMem != NULL) { + + if (m_pMem != NULL) + { #ifdef _MEMORYDEBUG printf("success!\n"); #endif @@ -103,7 +107,9 @@ unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& nAlloc nAllocatedSize = nTargetSize; return m_pMem; } - else { + else + { + m_nMemSize = 0; nAllocatedSize = 0; return NULL; } diff --git a/Common/rt api/MemoryPool.h b/Common/rt api/MemoryPool.h index 2ac33d4..c5668e5 100644 --- a/Common/rt api/MemoryPool.h +++ b/Common/rt api/MemoryPool.h @@ -38,12 +38,12 @@ public: private: bool debug; unsigned char* m_pMem; - unsigned int m_nMemSize; + uint64 m_nMemSize; - unsigned int m_nMemMax; + uint64 m_nMemMax; public: - unsigned char* Allocate(unsigned int nFileLen, unsigned int& nAllocatedSize); + unsigned char* Allocate(unsigned int nFileLen, uint64& nAllocatedSize); }; #endif diff --git a/Common/rt api/Public.cpp b/Common/rt api/Public.cpp index a3980ff..424e8f2 100644 --- a/Common/rt api/Public.cpp +++ b/Common/rt api/Public.cpp @@ -254,7 +254,7 @@ bool boinc_ReadLinesFromFile(string sPathName, vector& vLine) if (file != NULL) { - unsigned int len = GetFileLen(file); + long len = GetFileLen(file); char* data = new char[len + 1]; fread(data, 1, len, file); data[len] = '\0'; @@ -294,7 +294,7 @@ bool ReadLinesFromFile(string sPathName, vector& vLine) FILE* file = fopen(sPathName.c_str(), "rb"); if (file != NULL) { - unsigned int len = GetFileLen(file); + long len = GetFileLen(file); char* data = new char[len + 1]; fread(data, 1, len, file); data[len] = '\0'; diff --git a/Common/rt api/RTI2Reader.cpp b/Common/rt api/RTI2Reader.cpp index cd1e85d..57f671c 100644 --- a/Common/rt api/RTI2Reader.cpp +++ b/Common/rt api/RTI2Reader.cpp @@ -84,7 +84,7 @@ RTI2Reader::~RTI2Reader(void) } -unsigned int RTI2Reader::GetChainsLeft() +uint32 RTI2Reader::GetChainsLeft() { long len = GetFileLen(m_pFile); return len / m_chainsizebytes - m_chainPosition; @@ -104,6 +104,7 @@ int RTI2Reader::ReadChains(unsigned int &numChains, RainbowChain *pData) 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) diff --git a/Common/rt api/RTI2Reader.h b/Common/rt api/RTI2Reader.h index dadde2a..d56ee8d 100644 --- a/Common/rt api/RTI2Reader.h +++ b/Common/rt api/RTI2Reader.h @@ -60,7 +60,7 @@ public: RTI2Reader(string Filename); ~RTI2Reader(void); int ReadChains(uint32 &numChains, RainbowChain *pData); - unsigned int GetChainsLeft(); + uint32 GetChainsLeft(); static RTI2Header *GetHeader() { return m_pHeader; } }; diff --git a/Common/rt api/RTIReader.cpp b/Common/rt api/RTIReader.cpp index 329f8f7..2215f46 100644 --- a/Common/rt api/RTIReader.cpp +++ b/Common/rt api/RTIReader.cpp @@ -113,13 +113,13 @@ RTIReader::RTIReader(string Filename) } -int RTIReader::ReadChains(unsigned int &numChains, RainbowChain *pData) +int RTIReader::ReadChains(uint32 &numChains, RainbowChain *pData) { // We HAVE to reset the data to 0x00's or we will get in trouble memset(pData, 0x00, sizeof(RainbowChain) * numChains); unsigned int readChains = 0; unsigned int chainsleft = GetChainsLeft(); - for(UINT4 i = 0; i < m_nIndexSize; i++) + for(uint32 i = 0; i < m_nIndexSize; i++) { if(m_chainPosition + readChains > m_pIndex[i].nFirstChain + m_pIndex[i].nChainCount) // We found the matching index continue; @@ -143,7 +143,7 @@ int RTIReader::ReadChains(unsigned int &numChains, RainbowChain *pData) return 0; } -UINT4 RTIReader::GetChainsLeft() +uint32 RTIReader::GetChainsLeft() { return (GetFileLen(m_pFile) / 8) - m_chainPosition; } diff --git a/Common/rt api/RTIReader.h b/Common/rt api/RTIReader.h index becb000..954eeea 100644 --- a/Common/rt api/RTIReader.h +++ b/Common/rt api/RTIReader.h @@ -43,7 +43,7 @@ public: RTIReader(string Filename); ~RTIReader(void); - int ReadChains(unsigned int &numChains, RainbowChain *pData); + int ReadChains(uint32 &numChains, RainbowChain *pData); unsigned int GetChainsLeft(); }; diff --git a/Common/rt api/RTReader.cpp b/Common/rt api/RTReader.cpp index fc8166b..9c00558 100644 --- a/Common/rt api/RTReader.cpp +++ b/Common/rt api/RTReader.cpp @@ -32,14 +32,14 @@ RTReader::~RTReader(void) { } -int RTReader::ReadChains(unsigned int &numChains, RainbowChain *pData) +int RTReader::ReadChains(uint32 &numChains, RainbowChain *pData) { unsigned int numRead = fread(pData, 1, 16 * numChains, m_pFile); numChains = numRead / 16; m_chainPosition += numChains; return 0; } -UINT4 RTReader::GetChainsLeft() +uint32 RTReader::GetChainsLeft() { return (GetFileLen(m_pFile) / 16) - m_chainPosition; } diff --git a/Common/rt api/RTReader.h b/Common/rt api/RTReader.h index d2ba7bc..bcb5bc3 100644 --- a/Common/rt api/RTReader.h +++ b/Common/rt api/RTReader.h @@ -41,7 +41,7 @@ private: public: RTReader(string Filename); ~RTReader(void); - int ReadChains(unsigned int &numChains, RainbowChain *pData); + int ReadChains(uint32 &numChains, RainbowChain *pData); unsigned int GetChainsLeft(); }; -- 2.39.2