📄 pcre_try_flipped.c
字号:
/************************************************** Perl-Compatible Regular Expressions **************************************************//* PCRE is a library of functions to support regular expressions whose syntaxand semantics are as close as possible to those of the Perl 5 language. Written by Philip Hazel Copyright (c) 1997-2007 University of Cambridge-----------------------------------------------------------------------------Redistribution and use in source and binary forms, with or withoutmodification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * Neither the name of the University of Cambridge nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THEIMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSEARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BELIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, ORCONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OFSUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESSINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER INCONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THEPOSSIBILITY OF SUCH DAMAGE.-----------------------------------------------------------------------------*//* This module contains an internal function that tests a compiled pattern tosee if it was compiled with the opposite endianness. If so, it uses anauxiliary local function to flip the appropriate bytes. */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "pcre_internal.h"/************************************************** Flip bytes in an integer **************************************************//* This function is called when the magic number in a regex doesn't match, inorder to flip its bytes to see if we are dealing with a pattern that wascompiled on a host of different endianness. If so, this function is used toflip other byte values.Arguments: value the number to flip n the number of bytes to flip (assumed to be 2 or 4)Returns: the flipped value*/static unsigned long intbyteflip(unsigned long int value, int n){if (n == 2) return ((value & 0x00ff) << 8) | ((value & 0xff00) >> 8);return ((value & 0x000000ff) << 24) | ((value & 0x0000ff00) << 8) | ((value & 0x00ff0000) >> 8) | ((value & 0xff000000) >> 24);}/************************************************** Test for a byte-flipped compiled regex **************************************************//* This function is called from pcre_exec(), pcre_dfa_exec(), and also frompcre_fullinfo(). Its job is to test whether the regex is byte-flipped - thatis, it was compiled on a system of opposite endianness. The function is calledonly when the native MAGIC_NUMBER test fails. If the regex is indeed flipped,we flip all the relevant values into a different data block, and return it.Arguments: re points to the regex study points to study data, or NULL internal_re points to a new regex block internal_study points to a new study blockReturns: the new block if is is indeed a byte-flipped regex NULL if it is not*/real_pcre *_pcre_try_flipped(const real_pcre *re, real_pcre *internal_re, const pcre_study_data *study, pcre_study_data *internal_study){if (byteflip(re->magic_number, sizeof(re->magic_number)) != MAGIC_NUMBER) return NULL;*internal_re = *re; /* To copy other fields */internal_re->size = byteflip(re->size, sizeof(re->size));internal_re->options = byteflip(re->options, sizeof(re->options));internal_re->flags = (pcre_uint16)byteflip(re->flags, sizeof(re->flags));internal_re->top_bracket = (pcre_uint16)byteflip(re->top_bracket, sizeof(re->top_bracket));internal_re->top_backref = (pcre_uint16)byteflip(re->top_backref, sizeof(re->top_backref));internal_re->first_byte = (pcre_uint16)byteflip(re->first_byte, sizeof(re->first_byte));internal_re->req_byte = (pcre_uint16)byteflip(re->req_byte, sizeof(re->req_byte));internal_re->name_table_offset = (pcre_uint16)byteflip(re->name_table_offset, sizeof(re->name_table_offset));internal_re->name_entry_size = (pcre_uint16)byteflip(re->name_entry_size, sizeof(re->name_entry_size));internal_re->name_count = (pcre_uint16)byteflip(re->name_count, sizeof(re->name_count));if (study != NULL) { *internal_study = *study; /* To copy other fields */ internal_study->size = byteflip(study->size, sizeof(study->size)); internal_study->options = byteflip(study->options, sizeof(study->options)); }return internal_re;}/* End of pcre_tryflipped.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -