From 08366be03fa6160b831222667a0c7f6df831f0d8 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 25 Oct 2010 11:01:56 +0200 Subject: [PATCH] Fixed up converti2 to support RTI files as input --- Client Applications/converti2/converti2.cpp | 273 ++++++++---------- Client Applications/converti2/converti2.sln | 16 +- Client Applications/converti2/converti2.suo | Bin 46080 -> 46592 bytes .../converti2/converti2.vcxproj | 105 +++++++ .../converti2/converti2.vcxproj.filters | 54 ++++ .../converti2/converti2.vcxproj.user | 7 + Client Applications/rti2rto/rti2rto.cpp | 24 +- Client Applications/rti2rto/rti2rto.sln | 6 +- Client Applications/rti2rto/rti2rto.suo | Bin 13824 -> 17920 bytes Common/rt api/BaseRTReader.h | 5 +- Common/rt api/MemoryPool.cpp | 52 ++-- Common/rt api/RTI2Reader.cpp | 10 +- Common/rt api/RTI2Reader.h | 2 +- Common/rt api/RTIReader.cpp | 26 +- Common/rt api/RTIReader.h | 2 +- Common/rt api/RTReader.cpp | 2 +- Common/rt api/RTReader.h | 2 +- 17 files changed, 387 insertions(+), 199 deletions(-) create mode 100644 Client Applications/converti2/converti2.vcxproj create mode 100644 Client Applications/converti2/converti2.vcxproj.filters create mode 100644 Client Applications/converti2/converti2.vcxproj.user diff --git a/Client Applications/converti2/converti2.cpp b/Client Applications/converti2/converti2.cpp index db703e9..3ad8c09 100644 --- a/Client Applications/converti2/converti2.cpp +++ b/Client Applications/converti2/converti2.cpp @@ -1,8 +1,7 @@ #include #include #ifdef _WIN32 - #include - #include +#include #else #include #include @@ -14,9 +13,12 @@ #include #include #include - +#include +#include #include "Public.h" #include "MemoryPool.h" +#include "RTIReader.h" +#include "RTReader.h" using namespace std; @@ -246,13 +248,10 @@ void GetTableList(string sWildCharPathName, vector& vPathName) _finddata_t fd; long handle = _findfirst(sWildCharPathName.c_str(), &fd); - if (handle != -1) - { - do - { + if (handle != -1) { + do { string sName = fd.name; - if (sName != "." && sName != ".." && !(fd.attrib & _A_SUBDIR)) - { + if (sName != "." && sName != ".." && !(fd.attrib & _A_SUBDIR)) { string sPathName = sPath + sName; vPathName.push_back(sPathName); } @@ -290,108 +289,91 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int int nIndex = sPathName.find_last_of('/'); #endif string sFileName; - if (nIndex != -1) + if (nIndex != -1) { sFileName = sPathName.substr(nIndex + 1); - else + } + else { sFileName = sPathName; - // Info - printf("%s:\n", sFileName.c_str()); - FILE* file = fopen(sPathName.c_str(), "rb"); - FILE* fileR = fopen(sResultFileName.c_str(), "wb"); + } unsigned int distribution[64] = {0}; unsigned int numProcessedChains = 0; - - if (file != NULL && fileR != NULL) - { + FILE* fileR; + BaseRTReader *reader = NULL; + if(sPathName.substr(sPathName.length() - 2, sPathName.length()) == "rt") + reader = (BaseRTReader*)new RTReader(sPathName); + else if(sPathName.substr(sPathName.length() - 3, sPathName.length()) == "rti") + reader = (BaseRTReader*)new RTIReader(sPathName); + if(reader == NULL) { + printf("%s is not a supported file (Only RT and RTI is supported)\n", sPathName.c_str()); + return; + } + // Info + printf("%s:\n", sFileName.c_str()); + if(showDistribution == 0) { + fileR = fopen(sResultFileName.c_str(), "wb"); + } + if (fileR != NULL || showDistribution == 1) { // File length check - UINT4 nFileLen = GetFileLen(file); - UINT4 nTotalChainCount = 0; - if(hascp == 0) nTotalChainCount = nFileLen / 16; - else nTotalChainCount = nFileLen / 18; - if ((hascp == 0 && nFileLen % 16 != 0) || (hascp == 1 && nFileLen % 18 != 0)) - { - printf("file length mismatch\n"); - } - else - { + + int size = reader->GetChainsLeft() * sizeof(RainbowChain); static CMemoryPool mp; unsigned int nAllocatedSize; - RainbowChainCP* pChain = (RainbowChainCP*)mp.Allocate(nFileLen, nAllocatedSize); - + RainbowChain* pChain = (RainbowChain*)mp.Allocate(size, nAllocatedSize); unsigned int chainrowsize = ceil((float)(rti_startptlength + rti_endptlength + rti_cplength) / 8) * 8 ; // The size in bits (in whole bytes) unsigned int chainrowsizebytes = chainrowsize / 8; - - if (pChain != NULL) - { - nAllocatedSize = nAllocatedSize / sizeof(RainbowChainCP) * sizeof(RainbowChainCP); - fseek(file, 0, SEEK_SET); + if (pChain != NULL) { + nAllocatedSize = nAllocatedSize / sizeof(RainbowChain) * sizeof(RainbowChain); + unsigned int nChains = nAllocatedSize / sizeof(RainbowChain); uint64 curPrefix = 0, prefixStart = 0; vector indexes; - UINT4 nRainbowChainCountRead = 0; - while (true) // Chunk read loop - { + while(reader->GetChainsLeft() > 0) { + /* if (ftell(file) == nFileLen) break;*/ - UINT4 nReadThisRound; - memset(pChain, 0x00, nAllocatedSize); - printf("reading...\n"); + int nReadThisRound; clock_t t1 = clock(); - for(nReadThisRound = 0; nReadThisRound < nAllocatedSize / sizeof(RainbowChainCP) && nRainbowChainCountRead < nTotalChainCount; nReadThisRound++) - { - if(fread(&pChain[nReadThisRound], 16, 1, file) != 1) - { - printf("Error reading file\n"); exit(1); - } - if(hascp == 1) - { - if(fread(&pChain[nReadThisRound].nCheckPoint, 2, 1, file) != 1) - { - printf("Error reading file\n"); exit(2); - } - } - nRainbowChainCountRead++; - } + printf("reading...\n"); +#ifdef _MEMORYDEBUG + printf("Grabbing %i chains from file\n", nChains); +#endif + reader->ReadChains(nChains, pChain); +#ifdef _MEMORYDEBUG + printf("Recieved %i chains from file\n", nChains); +#endif clock_t t2 = clock(); float fTime = 1.0f * (t2 - t1) / CLOCKS_PER_SEC; - int nDataRead = nRainbowChainCountRead * 16; - if(hascp == 1) nDataRead += nRainbowChainCountRead * 2; // Add the index readings too - printf("%u bytes read, disk access time: %.2f s\n", nDataRead , fTime); + printf("reading time: %.2f s\n", fTime); + printf("converting %i chains...\n", nChains); t1 = clock(); - - for(UINT4 i = 0; i < nReadThisRound; i++) - { - if(showDistribution == 1) - { + for(int i = 0; i < nChains; i++) { + if(showDistribution == 1) { distribution[GetMaxBits(pChain[i].nIndexS)-1]++; } else { uint64 chainrow = pChain[i].nIndexS; // Insert the complete start point chainrow |= ((uint64)pChain[i].nIndexE & (0xffffffff >> (32 - rti_endptlength))) << rti_startptlength; // - if(hascp == 1 && rti_cplength > 0) - { +/* if(hascp == 1 && rti_cplength > 0) { chainrow |= (uint64)pChain[i].nCheckPoint << rti_startptlength + rti_endptlength; - } + }*/ fwrite(&chainrow, 1, chainrowsizebytes, fileR); uint64 prefix = pChain[i].nIndexE >> rti_endptlength; if(i == 0) curPrefix = prefix; - if(prefix != curPrefix && numProcessedChains - prefixStart > 0) - { - if(prefix < curPrefix) - { - printf("**** Error writeChain(): Prefix is smaller than previous prefix. %llu < %llu****\n", prefix, curPrefix); - exit(1); - } - //unsigned char index[11] = {0}; // [0 - 10] - unsigned int numchains = numProcessedChains - prefixStart; - IndexRow index; - index.prefix = curPrefix; + if(prefix != curPrefix && numProcessedChains - prefixStart > 0) { + if(prefix < curPrefix) { + printf("**** Error writeChain(): Prefix is smaller than previous prefix. %llu < %llu****\n", prefix, curPrefix); + exit(1); + } + //unsigned char index[11] = {0}; // [0 - 10] + unsigned int numchains = numProcessedChains - prefixStart; + IndexRow index; + index.prefix = curPrefix; // index.prefixstart = prefixStart; - index.numchains = numchains; - indexes.push_back(index); - prefixStart = numProcessedChains; - curPrefix = prefix; + index.numchains = numchains; + indexes.push_back(index); + prefixStart = numProcessedChains; + curPrefix = prefix; } } numProcessedChains++; @@ -399,14 +381,11 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int t2 = clock(); fTime = 1.0f * (t2 - t1) / CLOCKS_PER_SEC; printf("conversion time: %.2f s\n", fTime); - if(nRainbowChainCountRead == nTotalChainCount) - break; - if(showDistribution == 1) - { - for(int i = 0; i < 64; i++) - { + if(showDistribution == 1) { + for(int i = 0; i < 64; i++) { printf("%u - %u\n", (i+1), distribution[i]); } + delete reader; return; } @@ -444,23 +423,23 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int fwrite(&rti_endptlength, 1, 1, pFileIndex); fwrite(&rti_cplength, 1, 1, pFileIndex); // 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(UINT4 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++) - { - if(i == 0) + for(UINT4 i = 0; i < indexes.size(); i++) { + if(i == 0) { lastPrefix = indexes[0].prefix; + } + unsigned int indexrow = 0; // Checks how big a distance there is between the current and the next prefix. eg cur is 3 and next is 10 = 7. unsigned int diffSize = indexes[i].prefix - lastPrefix; - if(i > 0 && diffSize > 1) - { + if(i > 0 && diffSize > 1) { //indexrow |= indexes[i].prefixstart; //printf("Diffsize is %u\n", diffSize); @@ -486,17 +465,20 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, unsigned int } fclose(pFileIndex); } - else printf("memory allocation fail\n"); - - - // Already finished? - - } - fclose(file); + else { + printf("memory allocation fail\n"); + } + // Already finished? } - else + else { printf("can't open file\n"); - + } + if(reader != NULL) + delete reader; + if(fileR != NULL) { + fclose(fileR); + } + } int main(int argc, char* argv[]) @@ -507,76 +489,63 @@ int main(int argc, char* argv[]) int usecp = 0;// How many bits to use from the index int hascp = 0; vector cppositions; - if (argc == 1) - { + if (argc == 1) { Usage(); return 0; } - else if(argc > 2) - { + else if(argc > 2) { for (; argi < argc; argi++) { - if (strcmp(argv[argi], "-d") == 0 && (argsUsed & 0x8) == 0) - { + if(strcmp(argv[argi], "-d") == 0 && (argsUsed & 0x8) == 0) { // Enable verbose mode argsUsed |= 0x8; showDistribution = 1; } - else if (strncmp(argv[argi], "-sptl=", 6) == 0 && (argsUsed & 0x1) == 0) - { + else if (strncmp(argv[argi], "-sptl=", 6) == 0 && (argsUsed & 0x1) == 0) { // Maximum index for starting point argsUsed |= 0x1; sptl = 0; - for (i = 6; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++) - { + for (i = 6; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++) { sptl *= 10; sptl += ((int) argv[argi][i]) - 0x30; } - if (argv[argi][i] != '\0') - { + if (argv[argi][i] != '\0') { printf("Error: Invalid number.\n\n"); Usage(); return 1; } - if (i > 23) // i - 3 > 20 - { + if (i > 23) { // i - 3 > 20 printf("Error: Number is too large.\n\n"); Usage(); return 1; } } - else if (strncmp(argv[argi], "-eptl=", 6) == 0 && (argsUsed & 0x2) == 0) - { + else if (strncmp(argv[argi], "-eptl=", 6) == 0 && (argsUsed & 0x2) == 0) { // Maximum index for ending points argsUsed |= 0x2; eptl = 0; - for (i = 6; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++) - { + for (i = 6; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++) { eptl *= 10; eptl += ((int) argv[argi][i]) - 0x30; } - if (argv[argi][i] != '\0') - { + if (argv[argi][i] != '\0') { printf("Error: Invalid number.\n\n"); Usage(); return 1; } - if (i > 23) // i - 3 > 20 - { + if (i > 23) { // i - 3 > 20 printf("Error: Number is too large.\n\n"); Usage(); return 1; } } - else if(strncmp(argv[argi], "-usecp=", 7) == 0 && (argsUsed & 0x4) == 0) - { + else if(strncmp(argv[argi], "-usecp=", 7) == 0 && (argsUsed & 0x4) == 0) { argsUsed |= 0x4; hascp = 1; usecp = 0; unsigned int cppos = 0; - for(i = 7; argv[argi][i] != ' ' && argv[argi][i] != '\n' && argv[argi][i] != 0;) - { + for(i = 7; argv[argi][i] != ' ' && argv[argi][i] != '\n' && argv[argi][i] != 0;) { if(cppositions.size() > 0) i++; for (; argv[argi][i] >= '0' && argv[argi][i] <= '9'; i++) { @@ -590,19 +559,19 @@ int main(int argc, char* argv[]) cppos = 0; //} } - if (argv[argi][i] != '\0') - { + if (argv[argi][i] != '\0') { printf("Error: Invalid number.\n\n"); Usage(); return 1; } - if (usecp > 16) // i - 3 > 20 - { + if (usecp > 16) { // i - 3 > 20 printf("Error: Number is too large.\n\n"); Usage(); return 1; } - else printf("Using %i bits of the checkpoints\n", usecp); + else { + printf("Using %i bits of the checkpoints\n", usecp); + } } } @@ -614,26 +583,36 @@ int main(int argc, char* argv[]) #else GetTableList(argc, argv, vPathName); #endif - if (vPathName.size() == 0) - { + if (vPathName.size() == 0) { printf("no rainbow table found\n"); return 0; } - for (UINT4 i = 0; i < vPathName.size(); i++) - { + for (UINT4 i = 0; i < vPathName.size(); i++) { string sResultFile; int n = vPathName[i].find_last_of('\\'); - if (n != -1) - sResultFile = vPathName[i].substr(n+1, vPathName[i].length()) + "i2"; - else - sResultFile = vPathName[i] + "i2"; // Resulting file is .rt, not .rti - printf("Using %i of 64 bits. sptl: %i, eptl: %i, cp: %i. Chains will be %i bytes in size\n", (sptl + eptl + usecp), sptl, eptl, usecp, ((sptl + eptl + usecp) / 8)); - if(sptl + eptl + usecp > 64) - { + if (n != -1) { + if(vPathName[i].substr(vPathName[i].length() - 3, vPathName[i].length()) == "rti") { + sResultFile = vPathName[i].substr(n+1, vPathName[i].length()) + "2"; + } + else { + sResultFile = vPathName[i].substr(n+1, vPathName[i].length()) + "i2"; + } + } + else { + if(vPathName[i].substr(vPathName[i].length() - 3, vPathName[i].length()) == "rti") { + sResultFile = vPathName[i] + "2"; + } else { + sResultFile = vPathName[i] + "i2"; // Resulting file is .rt, not .rti + } + } + if(usecp == 0 && showDistribution == 0) { + printf("Using %i of 64 bits. sptl: %i, eptl: %i, cp: %i. Chains will be %i bytes in size\n", (sptl + eptl + usecp), sptl, eptl, usecp, ((sptl + eptl + usecp) / 8)); + } + if(sptl + eptl + usecp > 64) { exit(1); } ConvertRainbowTable(vPathName[i], sResultFile, sptl, eptl, showDistribution, hascp, usecp, cppositions); printf("\n"); } return 0; -} +} \ No newline at end of file diff --git a/Client Applications/converti2/converti2.sln b/Client Applications/converti2/converti2.sln index d4e3874..0f6bcac 100644 --- a/Client Applications/converti2/converti2.sln +++ b/Client Applications/converti2/converti2.sln @@ -1,9 +1,9 @@  -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "converti2", "converti2.vcproj", "{066FD6F1-5990-47AD-B095-7AE0029CF5AE}" +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "converti2", "converti2.vcxproj", "{066FD6F1-5990-47AD-B095-7AE0029CF5AE}" EndProject -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rcracki_mt", "..\rcracki_mt\rcracki_mt.vcproj", "{D484ABA1-C117-4AB1-B361-22E5EA62FA00}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rcracki_mt", "..\rcracki_mt\rcracki_mt.vcxproj", "{966DA4B4-E13C-449D-9A93-303C6FEA25C4}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -15,10 +15,10 @@ Global {066FD6F1-5990-47AD-B095-7AE0029CF5AE}.Debug|Win32.Build.0 = Debug|Win32 {066FD6F1-5990-47AD-B095-7AE0029CF5AE}.Release|Win32.ActiveCfg = Release|Win32 {066FD6F1-5990-47AD-B095-7AE0029CF5AE}.Release|Win32.Build.0 = Release|Win32 - {D484ABA1-C117-4AB1-B361-22E5EA62FA00}.Debug|Win32.ActiveCfg = Debug|Win32 - {D484ABA1-C117-4AB1-B361-22E5EA62FA00}.Debug|Win32.Build.0 = Debug|Win32 - {D484ABA1-C117-4AB1-B361-22E5EA62FA00}.Release|Win32.ActiveCfg = Release|Win32 - {D484ABA1-C117-4AB1-B361-22E5EA62FA00}.Release|Win32.Build.0 = Release|Win32 + {966DA4B4-E13C-449D-9A93-303C6FEA25C4}.Debug|Win32.ActiveCfg = Debug|Win32 + {966DA4B4-E13C-449D-9A93-303C6FEA25C4}.Debug|Win32.Build.0 = Debug|Win32 + {966DA4B4-E13C-449D-9A93-303C6FEA25C4}.Release|Win32.ActiveCfg = Release|Win32 + {966DA4B4-E13C-449D-9A93-303C6FEA25C4}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Client Applications/converti2/converti2.suo b/Client Applications/converti2/converti2.suo index d24f654f1b2fc9a7db14eb69e0ba308469741148..def8f40e392dc394850c54d22bd895ffc6e3406c 100644 GIT binary patch delta 290 zcmZp8!PM}EX+r`tYa{~$!@r4vvnR3S@C8Ut3KlIn&BzQCb12wc#nQ$sFh$aWIm+>y z%N~RON44AS`6mZ*7;JXn;9zFtnB3^7J-LM2fAV1#!_8l~{aM%;*?~IEK;oNA1R6?s z_c1as><8ilKn%3x|Dra{$qmvn?5+$I3`PtVlNDKHCp!q3u>p!^?Y| zr|LVdn2_-Q?c_iXgUt>c9L$XDlN%kiCzo*hvoZb$0uB&&^A~P^mdS@%3^$huG?Z)% l;bC0Vra3vB!)5Z3^>&jJIGi>gSzp6ExzEuE$VmWVJpfEgGWq}j diff --git a/Client Applications/converti2/converti2.vcxproj b/Client Applications/converti2/converti2.vcxproj new file mode 100644 index 0000000..97d3dad --- /dev/null +++ b/Client Applications/converti2/converti2.vcxproj @@ -0,0 +1,105 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {066FD6F1-5990-47AD-B095-7AE0029CF5AE} + convertrti2 + Win32Proj + + + + Application + NotSet + true + + + Application + NotSet + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + true + $(SolutionDir)$(Configuration)\ + $(Configuration)\ + false + + + + Disabled + ../../Common/rt api;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + true + EnableFastChecks + MultiThreadedDebugDLL + + + Level3 + EditAndContinue + + + true + Console + MachineX86 + + + + + MaxSpeed + true + ../../Common/rt api;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + MultiThreaded + true + + + Level3 + ProgramDatabase + + + true + Console + true + true + MachineX86 + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Client Applications/converti2/converti2.vcxproj.filters b/Client Applications/converti2/converti2.vcxproj.filters new file mode 100644 index 0000000..e0c08d7 --- /dev/null +++ b/Client Applications/converti2/converti2.vcxproj.filters @@ -0,0 +1,54 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/Client Applications/converti2/converti2.vcxproj.user b/Client Applications/converti2/converti2.vcxproj.user new file mode 100644 index 0000000..8e3e8c4 --- /dev/null +++ b/Client Applications/converti2/converti2.vcxproj.user @@ -0,0 +1,7 @@ + + + + C:\Users\mwj\Desktop\tables\*.rti -d + WindowsLocalDebugger + + \ No newline at end of file diff --git a/Client Applications/rti2rto/rti2rto.cpp b/Client Applications/rti2rto/rti2rto.cpp index e4ee4fc..086c333 100644 --- a/Client Applications/rti2rto/rti2rto.cpp +++ b/Client Applications/rti2rto/rti2rto.cpp @@ -87,6 +87,7 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, string sType) sFileName = sPathName.substr(nIndex + 1); else sFileName = sPathName; + // Info printf("%s:\n", sFileName.c_str()); FILE *fResult = fopen(sResultFileName.c_str(), "wb"); @@ -98,7 +99,6 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, string sType) static CMemoryPool mp; unsigned int nAllocatedSize; BaseRTReader *reader = NULL; - if(sType == "RTI2") reader = (BaseRTReader*)new RTI2Reader(sFileName); else if(sType == "RTI") @@ -108,15 +108,27 @@ void ConvertRainbowTable(string sPathName, string sResultFileName, string sType) printf("Invalid table type '%s'", sType.c_str()); return ; } - - RainbowChainCP* pChain = (RainbowChainCP*)mp.Allocate(reader->GetChainsLeft() * sizeof(RainbowChainCP), nAllocatedSize); + int size = reader->GetChainsLeft() * sizeof(RainbowChain); +#ifdef _MEMORYDEBUG + printf("Starting allocation of %i bytes\n", size); +#endif + RainbowChain* pChain = (RainbowChain*)mp.Allocate(size, nAllocatedSize); +#ifdef _MEMORYDEBUG + printf("Finished. Got %i bytes\n", nAllocatedSize); +#endif if (pChain != NULL) { - nAllocatedSize = nAllocatedSize / sizeof(RainbowChainCP) * sizeof(RainbowChainCP); // Round to boundary - unsigned int nChains = nAllocatedSize / sizeof(RainbowChainCP); + nAllocatedSize = nAllocatedSize / sizeof(RainbowChain) * sizeof(RainbowChain); // Round to boundary + unsigned int nChains = nAllocatedSize / sizeof(RainbowChain); while(reader->GetChainsLeft() > 0) { +#ifdef _MEMORYDEBUG + printf("Grabbing %i chains from file\n", nChains); +#endif reader->ReadChains(nChains, pChain); +#ifdef _MEMORYDEBUG + printf("Recieved %i chains from file\n", nChains); +#endif for(UINT4 i = 0; i < nChains; i++) { fwrite(&pChain[i], 1, 16, fResult); @@ -181,4 +193,4 @@ int main(int argc, char* argv[]) printf("\n"); } return 0; -} +} \ No newline at end of file diff --git a/Client Applications/rti2rto/rti2rto.sln b/Client Applications/rti2rto/rti2rto.sln index a8000e5..5d97682 100644 --- a/Client Applications/rti2rto/rti2rto.sln +++ b/Client Applications/rti2rto/rti2rto.sln @@ -1,7 +1,7 @@  -Microsoft Visual Studio Solution File, Format Version 10.00 -# Visual Studio 2008 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rti2rto", "rti2rto.vcproj", "{E0FBC06A-C902-4468-A614-CBF9F591AA7C}" +Microsoft Visual Studio Solution File, Format Version 11.00 +# Visual Studio 2010 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "rti2rto", "rti2rto.vcxproj", "{E0FBC06A-C902-4468-A614-CBF9F591AA7C}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/Client Applications/rti2rto/rti2rto.suo b/Client Applications/rti2rto/rti2rto.suo index 023dd88423dd5610734f0721985fa9b1175e088d..9b9159c5128665c2eaeed02ff3c010e92854a2e7 100644 GIT binary patch literal 17920 zcmeHOdvH|M89#wgM63ehi)y+ML=duWo{&(4eI$y85|R*5Q|)GRH*B)myWPD@NP+sO zRcp1y)`GV6L5tLJsvT{sf7G^=KBnqSap*sN%sBc-TmQ4;*pAgI{r%3pCwupOvw4Bz z$^7=5d+xdCJCE=C&Ue0Z^6H6&uOEJP$r~aoTrFmc4^Pb#pRnauAWg`yK!{mL5Feg8 zb;`^X0?CiV88iYPpskgdyd}UKU@pKpKMR-#oDG}<%m+RRoC}->EC#>=Vj-{yI3KtG zxEQz)xCpoexD@ylKpwdau?wgIJ`F4dm`{8hW@ZFBg^oW1^U^9}h!bKIv*J8l2(D2r z=bRP`3yk)I3yoJQX0y4R0Xtmx`2T=a02kbh)F8}Mtyy!XgyVZAZq-q~m_?Mrn z#LNZC(nJEkKLGee3+6{je-i0ojNu^S0Hlx_!hm$f@f?PBFsxXUvKquJ#iaC(;7t&z zsQjiEwMOwylbY2fy!bvYb3!O(;Ej$qq{SK|qE5y-o=q9$WUzht`l#|N@%|`KZu{B0 zK9K^y4amOikSz;=_t@*w!BvL-osDX#D;Tor`!EI?+AxHX(&e}sMcc6w^r@@B<}%1i zOZ;%mT>L@ErqA_aEX-|;dRi_tH9@5 zkRL)R9doQhvS^3&ATNo&2l0gq<6t1&k31bu&B84__^t>1-YdVPBqrrJQEKj+<`z(j zqv&B6ZArI7J)bV^FuS!?l_v`I~M{%Y^%{ zqy7~7Y}Rb=a|dW9F$QT%!D_TE@}U3c;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mZWoOK1~O6uoaUGfkUV(>AFlrpZ`p8=F{@nwBb}8B@hdv{fr2xQNy)ltQIV{j?RL z?nI>KBDhjFY_NL+}Yc;2)XKQG+e&w2OFedpenJ1KJg;|U=q z%zHxpSt^y-sq_|dN=}?k8+kP)oV-vCRz@S`CmI$!6gDDC1b9S!po@91%lUaU%#(JN z4{0gYhX@;;21ivV7qv0FJkUDykZyD|0hP{T=;j$a0=)#%0$B=)LSm3s$TEnP{7la} zx4_vt8|W!Z*fX=v*|OB>Ucam5?fJd2mp7AVmYSEw)1?o**&gMD{f_M>Y6>Rm*cCcg zMx-FElFv6Z&3OSUNh@e4ZKEOnQT|Pg^Vf*&#R;C6YvLeY`3b?GDoBJU&v zaZjlSaQ_3;NBiLo z&^{W2JyRHEuDg?9kN=j4wjz}yGKQUzqq?KKm00*h!78ZHtE)2)yRND zwj8Kje5=O1UVB+^y;{qY^N#Tj`zmF#!56#++If}7y;0~y-j~!#*5Z)|=wVo@!Xv&e zi?*Wg72gj;9C3uxR`-Z+&-Ze~H29srJ@Y5=*n;Jw^^~Dqvh_fgYi`;kqoh7);snp-D7V zubPnOVM*NqS;a>eWkig3H3nI4OlcCcM%spvo*DIPR^|-}VM&c)ozCQRqapM7Qn?Ey zRdBAsHAn86UI%F(KaF_U2wjk8@ZHD=2h5fHeRVzOjOM~*=(wWOd~B|im2x)RZ9SP{ x_z}NIT;(@vHLmwW<`#NeiZ)SgH6@D#x4@&^z;}`>Ic@L!Q|IF*Lg{~G^)KU?B%c5P diff --git a/Common/rt api/BaseRTReader.h b/Common/rt api/BaseRTReader.h index b94114f..67f251d 100644 --- a/Common/rt api/BaseRTReader.h +++ b/Common/rt api/BaseRTReader.h @@ -4,16 +4,17 @@ #include "Public.h" #include #ifdef WIN32 -#include + #include #endif using namespace std; class BaseRTReader { public: - virtual int ReadChains(unsigned int &numChains, RainbowChainCP *pData) = 0; + virtual int ReadChains(unsigned int &numChains, RainbowChain *pData) = 0; virtual unsigned int GetChainsLeft() = 0; + virtual ~BaseRTReader() { }; }; #endif diff --git a/Common/rt api/MemoryPool.cpp b/Common/rt api/MemoryPool.cpp index 1019b4f..4c8d5c9 100644 --- a/Common/rt api/MemoryPool.cpp +++ b/Common/rt api/MemoryPool.cpp @@ -25,8 +25,10 @@ CMemoryPool::CMemoryPool() CMemoryPool::~CMemoryPool() { - if (m_pMem != NULL) - { + if (m_pMem != NULL) { +#ifdef _MEMORYDEBUG + printf("Freeing %i bytes of memory\n", m_nMemSize); +#endif delete m_pMem; m_pMem = NULL; m_nMemSize = 0; @@ -35,21 +37,23 @@ CMemoryPool::~CMemoryPool() unsigned char* CMemoryPool::Allocate(unsigned int nFileLen, unsigned int& 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 delete m_pMem; m_pMem = NULL; m_nMemSize = 0; @@ -57,21 +61,29 @@ 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]; -m_pMem = new (nothrow) unsigned char[nTargetSize]; -while (m_pMem == NULL && nTargetSize >= 512 * 1024 * 1024 ) -{ - nTargetSize -= 16 * 1024 * 1024; - m_pMem = new (nothrow) unsigned char[nTargetSize]; -} - if (m_pMem != NULL) - { + // 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 ) { +#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]; + } + if (m_pMem != NULL) { +#ifdef _MEMORYDEBUG + printf("success!\n"); +#endif m_nMemSize = nTargetSize; nAllocatedSize = nTargetSize; return m_pMem; } - else - { + else { nAllocatedSize = 0; return NULL; } diff --git a/Common/rt api/RTI2Reader.cpp b/Common/rt api/RTI2Reader.cpp index 443fd1c..004159c 100644 --- a/Common/rt api/RTI2Reader.cpp +++ b/Common/rt api/RTI2Reader.cpp @@ -23,7 +23,11 @@ RTI2Reader::RTI2Reader(string Filename) unsigned int len = GetFileLen(pFileIndex); fseek(pFileIndex, 0, SEEK_SET); - m_pIndex = new unsigned char[len]; + 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)); + exit(-2); + } if(fread(m_pIndex, 1, len, pFileIndex) != len) { printf("Error while reading index file"); @@ -62,7 +66,7 @@ unsigned int RTI2Reader::GetChainsLeft() 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) { @@ -115,7 +119,7 @@ int RTI2Reader::ReadChains(unsigned int &numChains, RainbowChainCP *pData) 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); + //pData[chainsProcessed].nCheckPoint = (chainrow >> m_pHeader->rti_startptlength + m_pHeader->rti_endptlength); curRowPosition++; chainsProcessed++; } diff --git a/Common/rt api/RTI2Reader.h b/Common/rt api/RTI2Reader.h index fb17dd8..2005028 100644 --- a/Common/rt api/RTI2Reader.h +++ b/Common/rt api/RTI2Reader.h @@ -33,7 +33,7 @@ private: public: RTI2Reader(string Filename); ~RTI2Reader(void); - int ReadChains(unsigned int &numChains, RainbowChainCP *pData); + int ReadChains(unsigned int &numChains, RainbowChain *pData); unsigned int GetChainsLeft(); static RTI2Header *GetHeader() { return m_pHeader; } }; diff --git a/Common/rt api/RTIReader.cpp b/Common/rt api/RTIReader.cpp index b72dbe2..5fcb1ef 100644 --- a/Common/rt api/RTIReader.cpp +++ b/Common/rt api/RTIReader.cpp @@ -29,11 +29,25 @@ RTIReader::RTIReader(string Filename) printf("index file length mismatch (%u bytes)\n", nIndexFileLen); else { - m_pIndex = new IndexChain[nIndexFileLen / 11]; + if(m_pIndex != NULL) { + delete m_pIndex; + m_pIndex = NULL; + } +#ifdef _MEMORYDEBUG + printf("Allocating %u MB memory for RTIReader::m_pIndex", nIndexFileLen / 11 / (1024 * 1024)); +#endif + m_pIndex = new (nothrow) IndexChain[nIndexFileLen / 11]; + if(m_pIndex == NULL) { + printf("\nFailed allocating %i MB memory.\n", nIndexFileLen / 11 / (1024 * 1024)); + exit(-2); + } +#ifdef _MEMORYDEBUG + printf(" - success!\n"); +#endif memset(m_pIndex, 0x00, sizeof(IndexChain) * (nIndexFileLen / 11)); fseek(pFileIndex, 0, SEEK_SET); int nRead = 0; - int nRows; + UINT4 nRows; for(nRows = 0; (nRows * 11) < nIndexFileLen; nRows++) { if(fread(&m_pIndex[nRows].nPrefix, 5, 1, pFileIndex) != 1) break; @@ -60,7 +74,7 @@ RTIReader::RTIReader(string Filename) } if(m_pIndex[m_nIndexSize - 1].nFirstChain + m_pIndex[m_nIndexSize - 1].nChainCount > nTotalChainCount) // +1 is not needed here { - printf("Corrupted index detected: The index is covering more than the file\n"); + printf("Corrupted index detected: The index is covering more than the file (%i chains of %i chains)\n", m_pIndex[m_nIndexSize - 1].nFirstChain + m_pIndex[m_nIndexSize - 1].nChainCount, nTotalChainCount); exit(-1); } @@ -76,13 +90,13 @@ RTIReader::RTIReader(string Filename) } -int RTIReader::ReadChains(unsigned int &numChains, RainbowChainCP *pData) +int RTIReader::ReadChains(unsigned int &numChains, RainbowChain *pData) { // We HAVE to reset the data to 0x00's or we will get in trouble - memset(pData, 0x00, sizeof(RainbowChainCP) * numChains); + memset(pData, 0x00, sizeof(RainbowChain) * numChains); unsigned int readChains = 0; unsigned int chainsleft = GetChainsLeft(); - for(int i = 0; i < m_nIndexSize; i++) + for(UINT4 i = 0; i < m_nIndexSize; i++) { if(m_chainPosition + readChains > m_pIndex[i].nFirstChain + m_pIndex[i].nChainCount) // We found the matching index continue; diff --git a/Common/rt api/RTIReader.h b/Common/rt api/RTIReader.h index 6d53e80..775ff0a 100644 --- a/Common/rt api/RTIReader.h +++ b/Common/rt api/RTIReader.h @@ -20,7 +20,7 @@ public: RTIReader(string Filename); ~RTIReader(void); - int ReadChains(unsigned int &numChains, RainbowChainCP *pData); + int ReadChains(unsigned int &numChains, RainbowChain *pData); unsigned int GetChainsLeft(); }; diff --git a/Common/rt api/RTReader.cpp b/Common/rt api/RTReader.cpp index b0de54e..f64d603 100644 --- a/Common/rt api/RTReader.cpp +++ b/Common/rt api/RTReader.cpp @@ -9,7 +9,7 @@ RTReader::~RTReader(void) { } -int RTReader::ReadChains(unsigned int &numChains, RainbowChainCP *pData) +int RTReader::ReadChains(unsigned int &numChains, RainbowChain *pData) { unsigned int numRead = fread(pData, 1, 16 * numChains, m_pFile); numChains = numRead / 16; diff --git a/Common/rt api/RTReader.h b/Common/rt api/RTReader.h index 3d189c3..d78261b 100644 --- a/Common/rt api/RTReader.h +++ b/Common/rt api/RTReader.h @@ -18,7 +18,7 @@ private: public: RTReader(string Filename); ~RTReader(void); - int ReadChains(unsigned int &numChains, RainbowChainCP *pData); + int ReadChains(unsigned int &numChains, RainbowChain *pData); unsigned int GetChainsLeft(); }; -- 2.39.2