123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319 |
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
- #include "pcre_internal.h"
- static pcre_uint32
- swap_uint32(pcre_uint32 value)
- {
- return ((value & 0x000000ff) << 24) |
- ((value & 0x0000ff00) << 8) |
- ((value & 0x00ff0000) >> 8) |
- (value >> 24);
- }
- static pcre_uint16
- swap_uint16(pcre_uint16 value)
- {
- return (value >> 8) | (value << 8);
- }
- #if defined COMPILE_PCRE8
- PCRE_EXP_DECL int pcre_pattern_to_host_byte_order(pcre *argument_re,
- pcre_extra *extra_data, const unsigned char *tables)
- #elif defined COMPILE_PCRE16
- PCRE_EXP_DECL int pcre16_pattern_to_host_byte_order(pcre16 *argument_re,
- pcre16_extra *extra_data, const unsigned char *tables)
- #elif defined COMPILE_PCRE32
- PCRE_EXP_DECL int pcre32_pattern_to_host_byte_order(pcre32 *argument_re,
- pcre32_extra *extra_data, const unsigned char *tables)
- #endif
- {
- REAL_PCRE *re = (REAL_PCRE *)argument_re;
- pcre_study_data *study;
- #ifndef COMPILE_PCRE8
- pcre_uchar *ptr;
- int length;
- #if defined SUPPORT_UTF && defined COMPILE_PCRE16
- BOOL utf;
- BOOL utf16_char;
- #endif
- #endif
- if (re == NULL) return PCRE_ERROR_NULL;
- if (re->magic_number == MAGIC_NUMBER)
- {
- if ((re->flags & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE;
- re->tables = tables;
- return 0;
- }
- if (re->magic_number != REVERSED_MAGIC_NUMBER) return PCRE_ERROR_BADMAGIC;
- if ((swap_uint32(re->flags) & PCRE_MODE) == 0) return PCRE_ERROR_BADMODE;
- re->magic_number = MAGIC_NUMBER;
- re->size = swap_uint32(re->size);
- re->options = swap_uint32(re->options);
- re->flags = swap_uint32(re->flags);
- re->limit_match = swap_uint32(re->limit_match);
- re->limit_recursion = swap_uint32(re->limit_recursion);
- #if defined COMPILE_PCRE8 || defined COMPILE_PCRE16
- re->first_char = swap_uint16(re->first_char);
- re->req_char = swap_uint16(re->req_char);
- #elif defined COMPILE_PCRE32
- re->first_char = swap_uint32(re->first_char);
- re->req_char = swap_uint32(re->req_char);
- #endif
- re->max_lookbehind = swap_uint16(re->max_lookbehind);
- re->top_bracket = swap_uint16(re->top_bracket);
- re->top_backref = swap_uint16(re->top_backref);
- re->name_table_offset = swap_uint16(re->name_table_offset);
- re->name_entry_size = swap_uint16(re->name_entry_size);
- re->name_count = swap_uint16(re->name_count);
- re->ref_count = swap_uint16(re->ref_count);
- re->tables = tables;
- if (extra_data != NULL && (extra_data->flags & PCRE_EXTRA_STUDY_DATA) != 0)
- {
- study = (pcre_study_data *)extra_data->study_data;
- study->size = swap_uint32(study->size);
- study->flags = swap_uint32(study->flags);
- study->minlength = swap_uint32(study->minlength);
- }
- #ifndef COMPILE_PCRE8
- ptr = (pcre_uchar *)re + re->name_table_offset;
- length = re->name_count * re->name_entry_size;
- #if defined SUPPORT_UTF && defined COMPILE_PCRE16
- utf = (re->options & PCRE_UTF16) != 0;
- utf16_char = FALSE;
- #endif
- while(TRUE)
- {
-
- while (length-- > 0)
- {
- #if defined COMPILE_PCRE16
- *ptr = swap_uint16(*ptr);
- #elif defined COMPILE_PCRE32
- *ptr = swap_uint32(*ptr);
- #endif
- ptr++;
- }
- #if defined SUPPORT_UTF && defined COMPILE_PCRE16
- if (utf16_char)
- {
- if (HAS_EXTRALEN(ptr[-1]))
- {
-
- *ptr = swap_uint16(*ptr);
- ptr++;
- }
- }
- utf16_char = FALSE;
- #endif
-
- length = 0;
- #if defined COMPILE_PCRE16
- *ptr = swap_uint16(*ptr);
- #elif defined COMPILE_PCRE32
- *ptr = swap_uint32(*ptr);
- #endif
- switch (*ptr)
- {
- case OP_END:
- return 0;
- #if defined SUPPORT_UTF && defined COMPILE_PCRE16
- case OP_CHAR:
- case OP_CHARI:
- case OP_NOT:
- case OP_NOTI:
- case OP_STAR:
- case OP_MINSTAR:
- case OP_PLUS:
- case OP_MINPLUS:
- case OP_QUERY:
- case OP_MINQUERY:
- case OP_UPTO:
- case OP_MINUPTO:
- case OP_EXACT:
- case OP_POSSTAR:
- case OP_POSPLUS:
- case OP_POSQUERY:
- case OP_POSUPTO:
- case OP_STARI:
- case OP_MINSTARI:
- case OP_PLUSI:
- case OP_MINPLUSI:
- case OP_QUERYI:
- case OP_MINQUERYI:
- case OP_UPTOI:
- case OP_MINUPTOI:
- case OP_EXACTI:
- case OP_POSSTARI:
- case OP_POSPLUSI:
- case OP_POSQUERYI:
- case OP_POSUPTOI:
- case OP_NOTSTAR:
- case OP_NOTMINSTAR:
- case OP_NOTPLUS:
- case OP_NOTMINPLUS:
- case OP_NOTQUERY:
- case OP_NOTMINQUERY:
- case OP_NOTUPTO:
- case OP_NOTMINUPTO:
- case OP_NOTEXACT:
- case OP_NOTPOSSTAR:
- case OP_NOTPOSPLUS:
- case OP_NOTPOSQUERY:
- case OP_NOTPOSUPTO:
- case OP_NOTSTARI:
- case OP_NOTMINSTARI:
- case OP_NOTPLUSI:
- case OP_NOTMINPLUSI:
- case OP_NOTQUERYI:
- case OP_NOTMINQUERYI:
- case OP_NOTUPTOI:
- case OP_NOTMINUPTOI:
- case OP_NOTEXACTI:
- case OP_NOTPOSSTARI:
- case OP_NOTPOSPLUSI:
- case OP_NOTPOSQUERYI:
- case OP_NOTPOSUPTOI:
- if (utf) utf16_char = TRUE;
- #endif
-
- default:
- length = PRIV(OP_lengths)[*ptr] - 1;
- break;
- case OP_CLASS:
- case OP_NCLASS:
-
- ptr += 32/sizeof(pcre_uchar);
- length = 0;
- break;
- case OP_XCLASS:
-
- ptr++;
- #if defined COMPILE_PCRE16
- *ptr = swap_uint16(*ptr);
- #elif defined COMPILE_PCRE32
- *ptr = swap_uint32(*ptr);
- #endif
- #ifndef COMPILE_PCRE32
- if (LINK_SIZE > 1)
- {
-
- ptr++;
- *ptr = swap_uint16(*ptr);
- }
- #endif
- ptr++;
- length = (GET(ptr, -LINK_SIZE)) - (1 + LINK_SIZE + 1);
- #if defined COMPILE_PCRE16
- *ptr = swap_uint16(*ptr);
- #elif defined COMPILE_PCRE32
- *ptr = swap_uint32(*ptr);
- #endif
- if ((*ptr & XCL_MAP) != 0)
- {
-
- ptr += 32/sizeof(pcre_uchar);
- length -= 32/sizeof(pcre_uchar);
- }
- break;
- }
- ptr++;
- }
- #else
- return 0;
- #endif
- }
|