/* have we done one of these yet */ int DoneOne() { int i,j; int match; FunctionInfo *fi; for (i = 0; i < numberOfWrappedFunctions; i++) { fi = wrappedFunctions[i]; if ((!strcmp(fi->Name,currentFunction->Name)) &&(fi->NumberOfArguments == currentFunction->NumberOfArguments)) { match = 1; for (j = 0; j < fi->NumberOfArguments; j++) { if (!CheckMatch(currentFunction->ArgTypes[j], fi->ArgTypes[j], currentFunction->ArgClasses[j],fi->ArgClasses[j])) { match = 0; } } if (!CheckMatch(currentFunction->ReturnType, fi->ReturnType, currentFunction->ReturnClass, fi->ReturnClass)) { match = 0; } if (match) return 1; } } return 0; }
MojoNewWhereMatcher::MatchResult MojoNewWhereMatcher::CheckMatches( const MojObject& rhsArray, const MojObject& op, const MojObject& val, MatchMode mode) const { /* Matching a value against an array */ for (MojObject::ConstArrayIterator iter = rhsArray.arrayBegin(); iter != rhsArray.arrayEnd(); ++iter) { MatchResult result = CheckMatch(*iter, op, val); if (mode == AndMode) { if (result != Matched) { return NotMatched; } } else { if (result == Matched) { return Matched; } } } /* If we got here in And mode it means all the values matched. If we * got here in Or mode, it means none of them did. */ if (mode == AndMode) { return Matched; } else { return NotMatched; } }
MojoNewWhereMatcher::MatchResult MojoNewWhereMatcher::CheckProperty( const MojObject& key, const MojObject& response, const MojObject& op, const MojObject& val, MatchMode mode) const { if (key.type() == MojObject::TypeString) { MojString keyStr; MojErr err = key.stringValue(keyStr); if (err) { throw std::runtime_error("Failed to convert property lookup key " "to string"); } MojObject propVal; bool found = response.get(keyStr.data(), propVal); if (!found) { return NoProperty; } return CheckMatch(propVal, op, val); } else if (key.type() == MojObject::TypeArray) { return CheckProperty(key, key.arrayBegin(), response, op, val, mode); } else { throw std::runtime_error("Key specified was neither a string or " "array of strings"); } }
MojoNewWhereMatcher::MatchResult MojoNewWhereMatcher::CheckProperty( const MojObject& keyArray, MojObject::ConstArrayIterator keyIter, const MojObject& response, const MojObject& op, const MojObject& val, MatchMode mode) const { MojObject onion = response; for (; keyIter != keyArray.arrayEnd(); ++keyIter) { if (onion.type() == MojObject::TypeArray) { return CheckProperty(keyArray, keyIter, onion, onion.arrayBegin(), op, val, mode); } else if (onion.type() == MojObject::TypeObject) { MojString keyStr; MojErr err = (*keyIter).stringValue(keyStr); if (err) { throw std::runtime_error("Failed to convert property lookup " "key to string"); } MojObject next; if (!onion.get(keyStr.data(), next)) { return NoProperty; } onion = next; } else { return NoProperty; } } return CheckMatch(onion, op, val); }
int GenerateString(string pass, int start, int end, int index, int length, string cipher_text, string salt) { int match = 1; //base case // if counter reaches 0 if (index == length) { // signal end of the string pass[index] = '\0'; // if matches, print if (CheckMatch(pass, cipher_text, salt) == 0) { printf("Cracked! The password is: %s\n", pass); match = 0; } return match; } //recursive case else { // for (int asci = start; (asci <= end) && (end - asci + 1 >= length - index); asci++) for (int asci = start; asci < end && match == 1; asci++) { pass[index] = (char) asci; match = GenerateString(pass, start, end, index + 1, length, cipher_text, salt); } } return match; }
// reads dictionary and prints the password if it is in the dictionary // TODO: refactor int CheckDict(string cipher_text, string salt) { FILE *file; //hard coded, should change string words[100000]; char word[60]; int count = 0; int length = 0; string correct; int matched = 0; // read dictionary to check for words file = fopen("/usr/share/dict/words", "r"); // if file doesn't exist, throw error if (file == NULL) { printf("Error opening file!"); return 1; } // storing words in array while ( fgets(word, 60, file) != NULL ) { length = strlen(word); word[length - 1] = '\0'; words[count] = strdup(word); // printf("storing %s\n", words[count]); count++; } //stop reading the file fclose(file); int j = 0; // check each word in dictionary if it's the password while ((j < count) && (matched < 1)) { // if found a match, prints it and toggles flag if (CheckMatch(words[j], cipher_text, salt) == 0) { correct = words[j]; printf("Cracked! The password is: %s\n", correct); matched = 1; } j++; } // return values if (matched == 1) { return 0; } else { return 1; } }
void MakeMove() { int x; int y; // Reset heuristic if (gem_matched) { current_error_threshold = error_threshold; gem_matched = false; } for (y = 0; y < cell_count; y++) { for (x = 0; x < cell_count; x++) { // Try move left if (x - 1 >= 0) { CopyGrid(); if (CheckMatch(x, y, x - 1, y)) { MoveGem(x, y, x - 1, y); gem_matched = true; break; } } // Try move right if (x + 1 < cell_count) { CopyGrid(); if (CheckMatch(x,y,x+1,y)) { MoveGem(x, y, x + 1, y); gem_matched = true; break; } } // Try move up if (y - 1 >= 0) { CopyGrid(); if (CheckMatch(x, y, x, y - 1)) { MoveGem(x, y, x, y - 1); gem_matched = true; break; } } // Try move down if (y + 1 < cell_count) { CopyGrid(); if (CheckMatch(x, y, x, y + 1)) { MoveGem(x, y, x, y + 1); gem_matched = true; break; } } } if (gem_matched) break; } // If we didn't find a match, we'll need to make // our heuristic less picky. Increment threshold if (!gem_matched && current_error_threshold < 255) { // Before taking screenshot we'll want to reset the cursor // position to prevent hover animations of gems. This // could possibly help in the detection of matches SetCursorPos(game_origin.x, game_origin.y); current_error_threshold += 5; if (current_error_threshold >= 255) { printf("Need some help here.\n"); current_error_threshold = 255; } } }
/* This function handles (ctx->state_count < 32767) */ uint32_t FUNC_NAME(const SCACTileSearchCtx *ctx, MpmThreadCtx *mpm_thread_ctx, PrefilterRuleStore *pmq, const uint8_t *buf, uint32_t buflen) { uint32_t i = 0; int matches = 0; uint8_t mpm_bitarray[ctx->mpm_bitarray_size]; memset(mpm_bitarray, 0, ctx->mpm_bitarray_size); const uint8_t* restrict xlate = ctx->translate_table; STYPE *state_table = (STYPE*)ctx->state_table; STYPE state = 0; int c = xlate[buf[0]]; /* If buflen at least 4 bytes and buf 4-byte aligned. */ if (buflen >= (4 + EXTRA) && ((uintptr_t)buf & 0x3) == 0) { BUF_TYPE data = *(BUF_TYPE* restrict)(&buf[0]); uint64_t index = 0; /* Process 4*floor(buflen/4) bytes. */ i = 0; while ((i + EXTRA) < (buflen & ~0x3)) { BUF_TYPE data1 = *(BUF_TYPE* restrict)(&buf[i + 4]); index = SINDEX(index, state); state = SLOAD(state_table + index + c); c = xlate[BYTE1(data)]; if (unlikely(SCHECK(state))) { matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray); } i++; index = SINDEX(index, state); state = SLOAD(state_table + index + c); c = xlate[BYTE2(data)]; if (unlikely(SCHECK(state))) { matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray); } i++; index = SINDEX(index, state); state = SLOAD(state_table + index + c); c = xlate[BYTE3(data)]; if (unlikely(SCHECK(state))) { matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray); } data = data1; i++; index = SINDEX(index, state); state = SLOAD(state_table + index + c); c = xlate[BYTE0(data)]; if (unlikely(SCHECK(state))) { matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray); } i++; } } /* Process buflen % 4 bytes. */ for (; i < buflen; i++) { size_t index = 0 ; index = SINDEX(index, state); state = SLOAD(state_table + index + c); #ifndef __tile__ if (likely(i+1 < buflen)) #endif c = xlate[buf[i+1]]; if (unlikely(SCHECK(state))) { matches = CheckMatch(ctx, pmq, buf, buflen, state, i, matches, mpm_bitarray); } } /* for (i = 0; i < buflen; i++) */ return matches; }