Advertisement
fastman92

permutations

Jan 11th, 2016
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.             {              
  2.                 tPermutationRequest request = { 0 };
  3.  
  4.                 struct tUserData  {
  5.                     unsigned __int32 hashToFind;
  6.                     std::vector<std::string> matches;
  7.                 } userData;
  8.                
  9.  
  10.                 request.firstPermutationInt = 0;
  11.                 request.lastPermutationInt = PermutationCalculator.GetLastPermutationOrdinalNumForSpecifiedLength(6);
  12.  
  13.                
  14.                 request.func = [](const char* permutatedStr, void* pUserData) -> bool
  15.                 {
  16.                     tUserData* pData = (tUserData*)pUserData;
  17.                    
  18.                     if (GTASA_CRC32_fromString(permutatedStr) == pData->hashToFind) // MYHASH
  19.                     {
  20.                         pData->matches.push_back(permutatedStr);
  21.                         return true;
  22.                     }
  23.  
  24.                     return false;
  25.                 };
  26.  
  27.                 request.pUserData = &userData;
  28.                 request.bAsynchronous = true;
  29.                 request.hEventWhenComplete = CreateEventA(NULL, false, false, "PermutationFinder");
  30.                 request.amplitudeToLastFoundMatch = 10000;
  31.                            
  32.                 unsigned __int32 hashesToFindArray[] = {
  33.                     0x219976ed
  34.                     /*
  35.                     0x61398fc7,
  36.                     0x6b6c7562,
  37.                     0x650952f8,
  38.                     0xf39b8ca1,
  39.                     0xbd985ec9
  40.                     */
  41.                 };
  42.  
  43.                 for (int i = 0; i < _countof(hashesToFindArray); i++)
  44.                 {
  45.                     userData.hashToFind = hashesToFindArray[i];
  46.                     userData.matches.clear();
  47.                     PermutationCalculator.PermutateStringAndExecuteFunction(&request);
  48.  
  49.                     while (true)
  50.                     {
  51.                         if (request.permutationState != PERMUTATION_STATE_IN_PROGRESS)
  52.                             break;
  53.  
  54.                         unsigned __int64 totalNumberOfPermutationsToDo = 0;
  55.                         unsigned __int64 numberOfPermutationsProcessed = 0;
  56.  
  57.                         for (int i = 0; i < request.numberOfThreadsActive; i++)
  58.                         {
  59.                             tPermutationRequestThreadInfo* pThreadInfo = request.threadInfo + i;
  60.  
  61.                             totalNumberOfPermutationsToDo += (pThreadInfo->lastPermutationInt - pThreadInfo->firstPermutationInt);
  62.                             numberOfPermutationsProcessed += (pThreadInfo->curPermutationInt - pThreadInfo->firstPermutationInt);
  63.                         }
  64.  
  65.                         DWORD tickCount = GetTickCount() - request.startTimeInMiliseconds;
  66.                         unsigned __int64 speed = numberOfPermutationsProcessed * 1000 / (tickCount != 0 ? tickCount : 1);
  67.  
  68.                        
  69.                         printf("\rWork in progress: %s processed: %lld total: %lld Speed: %lld per second",
  70.                             request.threadInfo[0].curPermutation,
  71.                             numberOfPermutationsProcessed,
  72.                             totalNumberOfPermutationsToDo,
  73.                             speed
  74.                             );
  75.                            
  76.  
  77.                         WaitForSingleObject(request.hEventWhenComplete, 200);
  78.                     }
  79.  
  80.                    
  81.                     if (userData.matches.size())
  82.                     {
  83.                         for (auto it = userData.matches.begin(); it != userData.matches.end(); it++)
  84.                             printf("\n%s\n", it->c_str());
  85.                     }
  86.                     else
  87.                         printf("\nString was not found!\n");
  88.                    
  89.  
  90.                 }
  91.  
  92.                            
  93.                 // WaitForSingleObject(request.hEventWhenComplete, INFINITE);
  94.  
  95.                 CloseHandle(request.hEventWhenComplete);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement