int reexec(regex_t* re, char* s, size_t n, size_t nmatch, regmatch_t* match, int flags) { int code; if((code = regnexec(re, s, n, nmatch, match, flags)) && code != REG_NOMATCH) reerror(re, code); return code; }
GLOBAL (Boolean _p_CMatchRegExFrom (RegExType *r, const char *aString, int StrLength, Boolean NotBeginningOfLine, Boolean NotEndOfLine, int From)) { int i = r->Length = StrLength - From + 1; r->From = From; return !regnexec (r->RegEx, (i >= 0) ? aString + From - 1 : aString, (i >= 0) ? i : 0, r->SubExpressions + 1, &r->RegMatch, (NotBeginningOfLine ? REG_NOTBOL : 0) | (NotEndOfLine ? REG_NOTEOL : 0)); }
int regexec_20120528(const regex_t* p, const char* s, size_t nmatch, regmatch_t* match, regflags_t flags) { if (flags & REG_STARTEND) { int r; int m = match->rm_so; regmatch_t* e; if (!(r = regnexec(p, s + m, match->rm_eo - m, nmatch, match, flags)) && m > 0) for (e = match + nmatch; match < e; match++) if (match->rm_so >= 0) { match->rm_so += m; match->rm_eo += m; } return r; } return regnexec(p, s, s ? strlen(s) : 0, nmatch, match, flags); }
// do a regular expression search using the Tre regular expression // library. The needle is a previously compiled regular expression // (via Tre regcomp()). The caller must free the memory associated // with the returned regmatch_t structure. regmatch_t *re_needleinhaystack(regex_t * needle, char *haystack, size_t haystack_len) { regmatch_t *match = (regmatch_t *) malloc(sizeof(regmatch_t)); // LMIII temp fix till working with g++ if(!regnexec(needle, haystack, (size_t) haystack_len, (size_t) 1, match, 0)) { // match return match; } else { // no match return NULL; } }
static unsigned char should_print_message(const char *buffer, size_t length) { if (length < 3) return 0; // don't want blank lines size_t space_offsets[3]; find_space_offsets(buffer, length, space_offsets); // Check whether process name matches the one passed to -p option and filter if needed if (requiredProcessName != NULL) { int nameLength = space_offsets[1] - space_offsets[0]; //This size includes the NULL terminator. char *processName = malloc(nameLength); processName[nameLength - 1] = '\0'; memcpy(processName, buffer + space_offsets[0] + 1, nameLength - 1); for (int i = strlen(processName); i != 0; i--) if (processName[i] == '[') processName[i] = '\0'; if (strcmp(processName, requiredProcessName) != 0){ free(processName); return 0; } free(processName); } // Check whether message matches regex filter if (requiredRegexPattern != NULL) { int status = regnexec(&requiredRegex, buffer, length, 0, NULL, 0); if (status != 0) { // Not a match return 0; } } // More filtering options can be added here and return 0 when they won't meed filter criteria return 1; }
//wiz //This captured function is what Tibia uses to decrypt the packet // and determine which action types it contains in order to parse it properly // The function returns the action type and Tibia then parses the stream. // If the stream has not yet been used up, it will continually run this function to // determine the type of and parse the next action. // We can interfere with this process, but this requires knowing packet structures // and error handling for incomplete packets which takes much more work than payoff. int myShouldParseRecv() { CMemReader& reader = CMemReader::getMemReader(); typedef int(*Proto_fun)(); Proto_fun fun = (Proto_fun)baseAdjust(reader.m_memAddressFunTibiaShouldParseRecv); //This function looks ahead, it returns the next packet type. It will return -1 if no next packet. int ret = fun(); //look for this address near above location, it will be off by 8 packStream* recvStream = (packStream*)baseAdjust(reader.m_memAddressArrayPtrRecvStream); //int packLen = ((unsigned char)recvStream->s[6]) + ((unsigned char)recvStream->s[7])*256; if (prevNextRet != -1) { int actionStart = prevRecvStreamPos - 1; //Tibia eats 1 byte to return "ret" every call it is not -1 int actionEnd; // index of last byte if (recvStream->pos <= prevRecvStreamPos || recvStream->pos > prevRecvStreamLen) // when stream restarts, use previous length instead of current pos actionEnd = prevRecvStreamLen - 1; else if (ret == -1) actionEnd = recvStream->pos - 1; // did not eat an extra byte else actionEnd = recvStream->pos - 2; // ate an extra byte int actionLen = actionEnd - actionStart + 1; //Parse packet and perform any needed actions Protocol::parsePacketIn(NetworkMessage((char*)(prevRecvStream + actionStart), actionLen)); /* int packtype = ((char*)prevRecvStream+actionStart)[0]&0xff; int wanted = 0xb4; if(packtype == wanted){ Protocol::parsePacketIn(NetworkMessage((char*)(prevRecvStream+actionStart),actionLen),ipcPipeBack); bufToHexString(((char*)prevRecvStream+actionStart),actionLen); sendTAMessage(bufToHexStringRet); }*/ {for (int i = 0; i < recvRegexCount; i++) { if (recvRegex[i].inUse == 1) { int match = regnexec(&(recvRegex[i].preg), ((char*)prevRecvStream + actionStart), actionLen, 0, NULL, 0); if (match == 0) { if (0) { bufToHexString(((char*)prevRecvStream + actionStart), actionLen); sendTAMessage(bufToHexStringRet); } parseRecvActionData(recvRegex[i].handle, (char*)prevRecvStream + actionStart, actionLen); } } } } } if (ret != -1 && (recvStream->pos <= prevRecvStreamPos || recvStream->pos > prevRecvStreamLen)) { prevRecvStreamLen = recvStream->length; memcpy(prevRecvStream, recvStream->s, prevRecvStreamLen); } prevRecvStreamPos = recvStream->pos; prevNextRet = ret; //char buf[1111]; //sprintf(bufToHexStringRet,"%x:%d, %d %x%x",ret, recvStream->pos, recvStream->length,((char)recvStream->s[recvStream->pos-2]),((char)recvStream->s[recvStream->pos-2-1])); //AfxMessageBox(buf); //bufToHexString(recvStream->s,30); //sendTAMessage(bufToHexStringRet); if (0 && reader.isLoggedIn()) // see what happens when packets are ignored { if (ret == 107) ret = -1; if (ret == -1) recvStream->pos += 10; } return ret; }
int strngrpmatch(const char* b, size_t z, const char* p, ssize_t* sub, int n, register int flags) { register regex_t* re; register ssize_t* end; register int i; register regflags_t reflags; /* * 0 and empty patterns are special */ if (!p || !b) { if (!p && !b) regcache(NiL, 0, NiL); return 0; } if (!*p) { if (sub && n > 0) { if (flags & STR_INT) { int* subi = (int*)sub; subi[0] = subi[1] = 0; } else sub[0] = sub[1] = 0; } return *b == 0; } /* * convert flags */ if (flags & REG_ADVANCE) reflags = flags & ~REG_ADVANCE; else { reflags = REG_SHELL|REG_AUGMENTED; if (!(flags & STR_MAXIMAL)) reflags |= REG_MINIMAL; if (flags & STR_GROUP) reflags |= REG_SHELL_GROUP; if (flags & STR_LEFT) reflags |= REG_LEFT; if (flags & STR_RIGHT) reflags |= REG_RIGHT; if (flags & STR_ICASE) reflags |= REG_ICASE; } if (!sub || n <= 0) reflags |= REG_NOSUB; if (!(re = regcache(p, reflags, NiL))) return 0; if (n > matchstate.nmatch) { if (!(matchstate.match = newof(matchstate.match, regmatch_t, n, 0))) return 0; matchstate.nmatch = n; } if (regnexec(re, b, z, n, matchstate.match, reflags & ~(REG_MINIMAL|REG_SHELL_GROUP|REG_LEFT|REG_RIGHT|REG_ICASE))) return 0; if (!sub || n <= 0) return 1; i = re->re_nsub; if (flags & STR_INT) { int* subi = (int*)sub; int* endi = subi + n * 2; for (n = 0; subi < endi && n <= i; n++) { *subi++ = matchstate.match[n].rm_so; *subi++ = matchstate.match[n].rm_eo; } } else { end = sub + n * 2; for (n = 0; sub < end && n <= i; n++) { *sub++ = matchstate.match[n].rm_so; *sub++ = matchstate.match[n].rm_eo; } } return i + 1; }