Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/byakugan/msfpattern.cpp
Views: 11766
#define DEBUG 012#include <stdlib.h>3#include <memory.h>45#if DEBUG6#include <stdio.h>7#endif89void msf_pattern_create(int length, char *patternStr) {10char upper = 'A';11char lower = 'a';12char num = '0';13char c;14unsigned int i = 0;1516while (i != length) {17switch (i%3) {18case 0:19c = upper;20break;21case 1:22c = lower;23break;24case 2:25c = num;26if (num++ == '9') {27num = '0';28if (lower++ == 'z') {29lower = 'a';30if (upper++ == 'Z') {31upper = 'A';32}33}34}35break;36}37patternStr[i] = c;38i++;39}40}4142int msf_pattern_offset(int length, unsigned int needle) {43char *patternStr;44unsigned int *haystack;4546if (length < 4)47return (-1);4849patternStr = (char *) malloc(length+1);50if (patternStr == NULL) {51return (-1);52}53memset(patternStr, 0x00, length+1);5455msf_pattern_create(length, patternStr);5657length -= 4;58while (length >= 0) {59haystack = (unsigned int *) &patternStr[length];60//printf("Haystack: 0x%08x\n", *haystack);61if (needle == *haystack)62break;63length--;64}6566free(patternStr);67return (length);68}6970#if DEBUG71int main() {72char pattern[256];73char findme[] = "0Aa1";7475memset(pattern, 0x00, 256);76msf_pattern_create(255, pattern);7778printf("Pattern: %s\n", pattern);79printf("%s @ %d\n", findme, msf_pattern_offset(255, findme));80return (0);81}82#endif838485