X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=Client%20Applications%2Frcracki_mt%2FChainWalkContext.cpp;h=4fdcf6e2d08811264d1d2ce58648fa4fb016b15d;hb=47c71901e7a97c226c8f1df749e3606d43656f32;hp=1158dc6c648fa9450e1fefa49efae6f3da96558f;hpb=ce75ca839a9cd1863ea13636ffebf7ee1dcc4267;p=freerainbowtables diff --git a/Client Applications/rcracki_mt/ChainWalkContext.cpp b/Client Applications/rcracki_mt/ChainWalkContext.cpp index 1158dc6..4fdcf6e 100644 --- a/Client Applications/rcracki_mt/ChainWalkContext.cpp +++ b/Client Applications/rcracki_mt/ChainWalkContext.cpp @@ -5,10 +5,10 @@ * Copyright (C) Zhu Shuanglei * Copyright Martin Westergaard Jørgensen * Copyright 2009, 2010 Daniël Niggebrugge - * Copyright 2009, 2010 James Nobis + * Copyright 2009, 2010, 2011 James Nobis * Copyright 2010 Yngve AAdlandsvik * - * This file is part of racrcki_mt. + * This file is part of rcracki_mt. * * rcracki_mt is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -25,7 +25,7 @@ */ #if defined(_WIN32) && !defined(__GNUC__) - #pragma warning(disable : 4786 4267 4018) + #pragma warning(disable : 4786) #endif #include "ChainWalkContext.h" @@ -76,25 +76,26 @@ bool CChainWalkContext::LoadCharset(string sName) return true; } if(sName.substr(0, 6) == "hybrid") // Hybrid charset consisting of 2 charsets - { m_nHybridCharset = 1; - } else - { m_nHybridCharset = 0; - } bool readCharset = false; vector vLine; - if (ReadLinesFromFile("charset.txt", vLine)) { - readCharset = true; - } - else if (ReadLinesFromFile(GetApplicationPath() + "charset.txt", vLine)) { - readCharset = true; - } - if (readCharset) + + #ifdef BOINC + if ( boinc_ReadLinesFromFile( "charset.txt", vLine ) ) + readCharset = true; + #else + if ( ReadLinesFromFile("charset.txt", vLine) ) + readCharset = true; + else if ( ReadLinesFromFile(GetApplicationPath() + "charset.txt", vLine) ) + readCharset = true; + #endif + + if ( readCharset ) { - UINT4 i; + uint32 i; for (i = 0; i < vLine.size(); i++) { // Filter comment @@ -111,7 +112,7 @@ bool CChainWalkContext::LoadCharset(string sName) // sCharsetName charset check bool fCharsetNameCheckPass = true; - UINT4 j; + uint32 j; for (j = 0; j < sCharsetName.size(); j++) { if ( !isalpha(sCharsetName[j]) @@ -182,6 +183,7 @@ bool CChainWalkContext::LoadCharset(string sName) } else printf("can't open charset configuration file\n"); + return false; } @@ -222,7 +224,7 @@ bool CChainWalkContext::SetPlainCharset(string sCharsetName, int nPlainLenMin, i m_nPlainLenMaxTotal = 0; m_nPlainLenMinTotal = 0; uint64 nTemp = 1; - UINT4 j, k = 1; + uint32 j, k = 1; for(j = 0; j < m_vCharset.size(); j++) { int i; @@ -268,11 +270,11 @@ bool CChainWalkContext::SetupWithPathName(string sPathName, int& nRainbowChainLe // something like lm_alpha#1-7_0_100x16_test.rt #ifdef _WIN32 - int nIndex = sPathName.find_last_of('\\'); + string::size_type nIndex = sPathName.find_last_of('\\'); #else - int nIndex = (int) sPathName.find_last_of('/'); + string::size_type nIndex = sPathName.find_last_of('/'); #endif - if (nIndex != -1) + if (nIndex != string::npos) sPathName = sPathName.substr(nIndex + 1); if (sPathName.size() < 3) @@ -324,7 +326,7 @@ bool CChainWalkContext::SetupWithPathName(string sPathName, int& nRainbowChainLe } else { - if (sCharsetDefinition.find('#') == (unsigned long)-1) // For backward compatibility, "#1-7" is implied + if ( sCharsetDefinition.find('#') == string::npos ) // For backward compatibility, "#1-7" is implied { sCharsetName = sCharsetDefinition; nPlainLenMin = 1; @@ -408,8 +410,12 @@ void CChainWalkContext::Dump() printf("hash routine: %s\n", m_sHashRoutineName.c_str()); printf("hash length: %d\n", m_nHashLen); + printf( "m_vCharset[0].m_nPlainCharSetLen: %d\n", m_vCharset[0].m_nPlainCharsetLen ); + printf( "m_vCharset[1].m_nPlainCharSetLen: %d\n", m_vCharset[1].m_nPlainCharsetLen ); + printf("plain charset: "); unsigned int i; + for (i = 0; i < m_vCharset[0].m_nPlainCharsetLen; i++) { if (isprint(m_vCharset[0].m_PlainCharset[i])) @@ -473,14 +479,14 @@ void CChainWalkContext::IndexToPlain() m_nPlainLen = m_nPlainLenMinTotal; uint64 nIndexOfX = m_nIndex - m_nPlainSpaceUpToX[m_nPlainLen - 1]; -// this is the generic code for non x86/x86-64 platforms -#if !defined(_M_X64) && !defined(_M_X86) && !defined(__i386__) && !defined(__x86_64__) +// this is the generic code for non x86/x86_64 platforms +#if !defined(_M_X64) && !defined(_M_IX86) && !defined(__i386__) && !defined(__x86_64__) - // Slow/generic version + // generic version (slow for non 64-bit platforms and gcc < 4.5.x) for (i = m_nPlainLen - 1; i >= 0; i--) { int nCharsetLen = 0; - for(UINT4 j = 0; j < m_vCharset.size(); j++) + for(uint32 j = 0; j < m_vCharset.size(); j++) { nCharsetLen += m_vCharset[j].m_nPlainLenMax; if(i < nCharsetLen) // We found the correct charset @@ -491,14 +497,14 @@ void CChainWalkContext::IndexToPlain() } } } -#else +#elif defined(_M_X64) || defined(_M_IX86) || defined(__i386__) || defined(__x86_64__) // Fast ia32 version for (i = m_nPlainLen - 1; i >= 0; i--) { // 0x100000000 = 2^32 -#if defined(_M_X64) || defined(_M_X86) +#ifdef _M_IX86 if (nIndexOfX < 0x100000000I64) break; #else @@ -507,7 +513,7 @@ void CChainWalkContext::IndexToPlain() #endif int nCharsetLen = 0; - for(UINT4 j = 0; j < m_vCharset.size(); j++) + for(uint32 j = 0; j < m_vCharset.size(); j++) { nCharsetLen += m_vCharset[j].m_nPlainLenMax; if(i < nCharsetLen) // We found the correct charset @@ -519,11 +525,11 @@ void CChainWalkContext::IndexToPlain() } } - unsigned int nIndexOfX32 = (unsigned int)nIndexOfX; + uint32 nIndexOfX32 = (uint32)nIndexOfX; for (; i >= 0; i--) { int nCharsetLen = 0; - for(UINT4 j = 0; j < m_vCharset.size(); j++) + for(uint32 j = 0; j < m_vCharset.size(); j++) { nCharsetLen += m_vCharset[j].m_nPlainLenMax; if(i < nCharsetLen) // We found the correct charset @@ -532,33 +538,30 @@ void CChainWalkContext::IndexToPlain() // m_Plain[i] = m_vCharset[j].m_PlainCharset[nIndexOfX32 % m_vCharset[j].m_nPlainCharsetLen]; // nIndexOfX32 /= m_vCharset[j].m_nPlainCharsetLen; - // moving nPlainCharsetLen into the asm body and avoiding the extra temp // variable results in a performance gain // unsigned int nPlainCharsetLen = m_vCharset[j].m_nPlainCharsetLen; unsigned int nTemp; #if defined(_WIN32) && !defined(__GNUC__) + // VC++ still needs this + unsigned int nPlainCharsetLen = m_vCharset[j].m_nPlainCharsetLen; __asm { mov eax, nIndexOfX32 xor edx, edx - div m_vCharset[j].m_nPlainCharsetLen + div nPlainCharsetLen mov nIndexOfX32, eax mov nTemp, edx } m_Plain[i] = m_vCharset[j].m_PlainCharset[nTemp]; #else - __asm__ __volatile__ ( "mov %2, %%eax;" - "xor %%edx, %%edx;" + __asm__ __volatile__ ("xor %%edx, %%edx;" "divl %3;" - "mov %%eax, %0;" - "mov %%edx, %1;" - : "=m"(nIndexOfX32), "=m"(nTemp) - : "m"(nIndexOfX32), "m"(m_vCharset[j].m_nPlainCharsetLen) - : "%eax", "%edx" - ); + : "=a"(nIndexOfX32), "=d"(nTemp) + : "a"(nIndexOfX32), "rm"(m_vCharset[j].m_nPlainCharsetLen) + : ); m_Plain[i] = m_vCharset[j].m_PlainCharset[nTemp]; #endif break;