Coverage Report

Created: 2026-09-06 07:15

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/yara/libyara/hex_lexer.c
Line
Count
Source
1
#line 1 "libyara/hex_lexer.c"
2
3
#line 3 "libyara/hex_lexer.c"
4
5
#define  YY_INT_ALIGNED short int
6
7
/* A lexical scanner generated by flex */
8
9
#define FLEX_SCANNER
10
#define YY_FLEX_MAJOR_VERSION 2
11
#define YY_FLEX_MINOR_VERSION 6
12
#define YY_FLEX_SUBMINOR_VERSION 4
13
#if YY_FLEX_SUBMINOR_VERSION > 0
14
#define FLEX_BETA
15
#endif
16
17
#ifdef yy_create_buffer
18
#define hex_yy_create_buffer_ALREADY_DEFINED
19
#else
20
0
#define yy_create_buffer hex_yy_create_buffer
21
#endif
22
23
#ifdef yy_delete_buffer
24
#define hex_yy_delete_buffer_ALREADY_DEFINED
25
#else
26
0
#define yy_delete_buffer hex_yy_delete_buffer
27
#endif
28
29
#ifdef yy_scan_buffer
30
#define hex_yy_scan_buffer_ALREADY_DEFINED
31
#else
32
0
#define yy_scan_buffer hex_yy_scan_buffer
33
#endif
34
35
#ifdef yy_scan_string
36
#define hex_yy_scan_string_ALREADY_DEFINED
37
#else
38
0
#define yy_scan_string hex_yy_scan_string
39
#endif
40
41
#ifdef yy_scan_bytes
42
#define hex_yy_scan_bytes_ALREADY_DEFINED
43
#else
44
0
#define yy_scan_bytes hex_yy_scan_bytes
45
#endif
46
47
#ifdef yy_init_buffer
48
#define hex_yy_init_buffer_ALREADY_DEFINED
49
#else
50
0
#define yy_init_buffer hex_yy_init_buffer
51
#endif
52
53
#ifdef yy_flush_buffer
54
#define hex_yy_flush_buffer_ALREADY_DEFINED
55
#else
56
0
#define yy_flush_buffer hex_yy_flush_buffer
57
#endif
58
59
#ifdef yy_load_buffer_state
60
#define hex_yy_load_buffer_state_ALREADY_DEFINED
61
#else
62
0
#define yy_load_buffer_state hex_yy_load_buffer_state
63
#endif
64
65
#ifdef yy_switch_to_buffer
66
#define hex_yy_switch_to_buffer_ALREADY_DEFINED
67
#else
68
0
#define yy_switch_to_buffer hex_yy_switch_to_buffer
69
#endif
70
71
#ifdef yypush_buffer_state
72
#define hex_yypush_buffer_state_ALREADY_DEFINED
73
#else
74
#define yypush_buffer_state hex_yypush_buffer_state
75
#endif
76
77
#ifdef yypop_buffer_state
78
#define hex_yypop_buffer_state_ALREADY_DEFINED
79
#else
80
0
#define yypop_buffer_state hex_yypop_buffer_state
81
#endif
82
83
#ifdef yyensure_buffer_stack
84
#define hex_yyensure_buffer_stack_ALREADY_DEFINED
85
#else
86
0
#define yyensure_buffer_stack hex_yyensure_buffer_stack
87
#endif
88
89
#ifdef yylex
90
#define hex_yylex_ALREADY_DEFINED
91
#else
92
#define yylex hex_yylex
93
#endif
94
95
#ifdef yyrestart
96
#define hex_yyrestart_ALREADY_DEFINED
97
#else
98
0
#define yyrestart hex_yyrestart
99
#endif
100
101
#ifdef yylex_init
102
#define hex_yylex_init_ALREADY_DEFINED
103
#else
104
0
#define yylex_init hex_yylex_init
105
#endif
106
107
#ifdef yylex_init_extra
108
#define hex_yylex_init_extra_ALREADY_DEFINED
109
#else
110
#define yylex_init_extra hex_yylex_init_extra
111
#endif
112
113
#ifdef yylex_destroy
114
#define hex_yylex_destroy_ALREADY_DEFINED
115
#else
116
0
#define yylex_destroy hex_yylex_destroy
117
#endif
118
119
#ifdef yyget_debug
120
#define hex_yyget_debug_ALREADY_DEFINED
121
#else
122
#define yyget_debug hex_yyget_debug
123
#endif
124
125
#ifdef yyset_debug
126
#define hex_yyset_debug_ALREADY_DEFINED
127
#else
128
#define yyset_debug hex_yyset_debug
129
#endif
130
131
#ifdef yyget_extra
132
#define hex_yyget_extra_ALREADY_DEFINED
133
#else
134
#define yyget_extra hex_yyget_extra
135
#endif
136
137
#ifdef yyset_extra
138
#define hex_yyset_extra_ALREADY_DEFINED
139
#else
140
0
#define yyset_extra hex_yyset_extra
141
#endif
142
143
#ifdef yyget_in
144
#define hex_yyget_in_ALREADY_DEFINED
145
#else
146
#define yyget_in hex_yyget_in
147
#endif
148
149
#ifdef yyset_in
150
#define hex_yyset_in_ALREADY_DEFINED
151
#else
152
#define yyset_in hex_yyset_in
153
#endif
154
155
#ifdef yyget_out
156
#define hex_yyget_out_ALREADY_DEFINED
157
#else
158
#define yyget_out hex_yyget_out
159
#endif
160
161
#ifdef yyset_out
162
#define hex_yyset_out_ALREADY_DEFINED
163
#else
164
#define yyset_out hex_yyset_out
165
#endif
166
167
#ifdef yyget_leng
168
#define hex_yyget_leng_ALREADY_DEFINED
169
#else
170
#define yyget_leng hex_yyget_leng
171
#endif
172
173
#ifdef yyget_text
174
#define hex_yyget_text_ALREADY_DEFINED
175
#else
176
#define yyget_text hex_yyget_text
177
#endif
178
179
#ifdef yyget_lineno
180
#define hex_yyget_lineno_ALREADY_DEFINED
181
#else
182
#define yyget_lineno hex_yyget_lineno
183
#endif
184
185
#ifdef yyset_lineno
186
#define hex_yyset_lineno_ALREADY_DEFINED
187
#else
188
#define yyset_lineno hex_yyset_lineno
189
#endif
190
191
#ifdef yyget_column
192
#define hex_yyget_column_ALREADY_DEFINED
193
#else
194
#define yyget_column hex_yyget_column
195
#endif
196
197
#ifdef yyset_column
198
#define hex_yyset_column_ALREADY_DEFINED
199
#else
200
#define yyset_column hex_yyset_column
201
#endif
202
203
#ifdef yywrap
204
#define hex_yywrap_ALREADY_DEFINED
205
#else
206
0
#define yywrap hex_yywrap
207
#endif
208
209
#ifdef yyget_lval
210
#define hex_yyget_lval_ALREADY_DEFINED
211
#else
212
#define yyget_lval hex_yyget_lval
213
#endif
214
215
#ifdef yyset_lval
216
#define hex_yyset_lval_ALREADY_DEFINED
217
#else
218
#define yyset_lval hex_yyset_lval
219
#endif
220
221
#ifdef yyalloc
222
#define hex_yyalloc_ALREADY_DEFINED
223
#else
224
0
#define yyalloc hex_yyalloc
225
#endif
226
227
#ifdef yyrealloc
228
#define hex_yyrealloc_ALREADY_DEFINED
229
#else
230
0
#define yyrealloc hex_yyrealloc
231
#endif
232
233
#ifdef yyfree
234
#define hex_yyfree_ALREADY_DEFINED
235
#else
236
0
#define yyfree hex_yyfree
237
#endif
238
239
/* First, we deal with  platform-specific or compiler-specific issues. */
240
241
/* begin standard C headers. */
242
#include <stdio.h>
243
#include <string.h>
244
#include <errno.h>
245
#include <stdlib.h>
246
247
/* end standard C headers. */
248
249
/* flex integer type definitions */
250
251
#ifndef FLEXINT_H
252
#define FLEXINT_H
253
254
/* C99 systems have <inttypes.h>. Non-C99 systems may or may not. */
255
256
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
257
258
/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h,
259
 * if you want the limit (max/min) macros for int types. 
260
 */
261
#ifndef __STDC_LIMIT_MACROS
262
#define __STDC_LIMIT_MACROS 1
263
#endif
264
265
#include <inttypes.h>
266
typedef int8_t flex_int8_t;
267
typedef uint8_t flex_uint8_t;
268
typedef int16_t flex_int16_t;
269
typedef uint16_t flex_uint16_t;
270
typedef int32_t flex_int32_t;
271
typedef uint32_t flex_uint32_t;
272
#else
273
typedef signed char flex_int8_t;
274
typedef short int flex_int16_t;
275
typedef int flex_int32_t;
276
typedef unsigned char flex_uint8_t; 
277
typedef unsigned short int flex_uint16_t;
278
typedef unsigned int flex_uint32_t;
279
280
/* Limits of integral types. */
281
#ifndef INT8_MIN
282
#define INT8_MIN               (-128)
283
#endif
284
#ifndef INT16_MIN
285
#define INT16_MIN              (-32767-1)
286
#endif
287
#ifndef INT32_MIN
288
#define INT32_MIN              (-2147483647-1)
289
#endif
290
#ifndef INT8_MAX
291
#define INT8_MAX               (127)
292
#endif
293
#ifndef INT16_MAX
294
#define INT16_MAX              (32767)
295
#endif
296
#ifndef INT32_MAX
297
#define INT32_MAX              (2147483647)
298
#endif
299
#ifndef UINT8_MAX
300
#define UINT8_MAX              (255U)
301
#endif
302
#ifndef UINT16_MAX
303
#define UINT16_MAX             (65535U)
304
#endif
305
#ifndef UINT32_MAX
306
#define UINT32_MAX             (4294967295U)
307
#endif
308
309
#ifndef SIZE_MAX
310
#define SIZE_MAX               (~(size_t)0)
311
#endif
312
313
#endif /* ! C99 */
314
315
#endif /* ! FLEXINT_H */
316
317
/* begin standard C++ headers. */
318
319
/* TODO: this is always defined, so inline it */
320
#define yyconst const
321
322
#if defined(__GNUC__) && __GNUC__ >= 3
323
#define yynoreturn __attribute__((__noreturn__))
324
#else
325
#define yynoreturn
326
#endif
327
328
/* Returned upon end-of-file. */
329
0
#define YY_NULL 0
330
331
/* Promotes a possibly negative, possibly signed char to an
332
 *   integer in range [0..255] for use as an array index.
333
 */
334
0
#define YY_SC_TO_UI(c) ((YY_CHAR) (c))
335
336
/* An opaque pointer. */
337
#ifndef YY_TYPEDEF_YY_SCANNER_T
338
#define YY_TYPEDEF_YY_SCANNER_T
339
typedef void* yyscan_t;
340
#endif
341
342
/* For convenience, these vars (plus the bison vars far below)
343
   are macros in the reentrant scanner. */
344
0
#define yyin yyg->yyin_r
345
0
#define yyout yyg->yyout_r
346
0
#define yyextra yyg->yyextra_r
347
0
#define yyleng yyg->yyleng_r
348
0
#define yytext yyg->yytext_r
349
0
#define yylineno (YY_CURRENT_BUFFER_LVALUE->yy_bs_lineno)
350
0
#define yycolumn (YY_CURRENT_BUFFER_LVALUE->yy_bs_column)
351
0
#define yy_flex_debug yyg->yy_flex_debug_r
352
353
/* Enter a start condition.  This macro really ought to take a parameter,
354
 * but we do it the disgusting crufty way forced on us by the ()-less
355
 * definition of BEGIN.
356
 */
357
0
#define BEGIN yyg->yy_start = 1 + 2 *
358
/* Translate the current start state into a value that can be later handed
359
 * to BEGIN to return to the state.  The YYSTATE alias is for lex
360
 * compatibility.
361
 */
362
#define YY_START ((yyg->yy_start - 1) / 2)
363
#define YYSTATE YY_START
364
/* Action number for EOF rule of a given start state. */
365
0
#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1)
366
/* Special action meaning "start processing a new file". */
367
0
#define YY_NEW_FILE yyrestart( yyin , yyscanner )
368
0
#define YY_END_OF_BUFFER_CHAR 0
369
370
/* Size of default input buffer. */
371
#ifndef YY_BUF_SIZE
372
#ifdef __ia64__
373
/* On IA-64, the buffer size is 16k, not 8k.
374
 * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case.
375
 * Ditto for the __ia64__ case accordingly.
376
 */
377
#define YY_BUF_SIZE 32768
378
#else
379
0
#define YY_BUF_SIZE 16384
380
#endif /* __ia64__ */
381
#endif
382
383
/* The state buf must be large enough to hold one state per character in the main buffer.
384
 */
385
#define YY_STATE_BUF_SIZE   ((YY_BUF_SIZE + 2) * sizeof(yy_state_type))
386
387
#ifndef YY_TYPEDEF_YY_BUFFER_STATE
388
#define YY_TYPEDEF_YY_BUFFER_STATE
389
typedef struct yy_buffer_state *YY_BUFFER_STATE;
390
#endif
391
392
#ifndef YY_TYPEDEF_YY_SIZE_T
393
#define YY_TYPEDEF_YY_SIZE_T
394
typedef size_t yy_size_t;
395
#endif
396
397
0
#define EOB_ACT_CONTINUE_SCAN 0
398
0
#define EOB_ACT_END_OF_FILE 1
399
0
#define EOB_ACT_LAST_MATCH 2
400
    
401
    /* Note: We specifically omit the test for yy_rule_can_match_eol because it requires
402
     *       access to the local variable yy_act. Since yyless() is a macro, it would break
403
     *       existing scanners that call yyless() from OUTSIDE yylex.
404
     *       One obvious solution it to make yy_act a global. I tried that, and saw
405
     *       a 5% performance hit in a non-yylineno scanner, because yy_act is
406
     *       normally declared as a register variable-- so it is not worth it.
407
     */
408
    #define  YY_LESS_LINENO(n) \
409
            do { \
410
                int yyl;\
411
                for ( yyl = n; yyl < yyleng; ++yyl )\
412
                    if ( yytext[yyl] == '\n' )\
413
                        --yylineno;\
414
            }while(0)
415
    #define YY_LINENO_REWIND_TO(dst) \
416
            do {\
417
                const char *p;\
418
                for ( p = yy_cp-1; p >= (dst); --p)\
419
                    if ( *p == '\n' )\
420
                        --yylineno;\
421
            }while(0)
422
    
423
/* Return all but the first "n" matched characters back to the input stream. */
424
#define yyless(n) \
425
  do \
426
    { \
427
    /* Undo effects of setting up yytext. */ \
428
        int yyless_macro_arg = (n); \
429
        YY_LESS_LINENO(yyless_macro_arg);\
430
    *yy_cp = yyg->yy_hold_char; \
431
    YY_RESTORE_YY_MORE_OFFSET \
432
    yyg->yy_c_buf_p = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \
433
    YY_DO_BEFORE_ACTION; /* set up yytext again */ \
434
    } \
435
  while ( 0 )
436
#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
437
438
#ifndef YY_STRUCT_YY_BUFFER_STATE
439
#define YY_STRUCT_YY_BUFFER_STATE
440
struct yy_buffer_state
441
  {
442
  FILE *yy_input_file;
443
444
  char *yy_ch_buf;    /* input buffer */
445
  char *yy_buf_pos;   /* current position in input buffer */
446
447
  /* Size of input buffer in bytes, not including room for EOB
448
   * characters.
449
   */
450
  int yy_buf_size;
451
452
  /* Number of characters read into yy_ch_buf, not including EOB
453
   * characters.
454
   */
455
  int yy_n_chars;
456
457
  /* Whether we "own" the buffer - i.e., we know we created it,
458
   * and can realloc() it to grow it, and should free() it to
459
   * delete it.
460
   */
461
  int yy_is_our_buffer;
462
463
  /* Whether this is an "interactive" input source; if so, and
464
   * if we're using stdio for input, then we want to use getc()
465
   * instead of fread(), to make sure we stop fetching input after
466
   * each newline.
467
   */
468
  int yy_is_interactive;
469
470
  /* Whether we're considered to be at the beginning of a line.
471
   * If so, '^' rules will be active on the next match, otherwise
472
   * not.
473
   */
474
  int yy_at_bol;
475
476
    int yy_bs_lineno; /**< The line count. */
477
    int yy_bs_column; /**< The column count. */
478
479
  /* Whether to try to fill the input buffer when we reach the
480
   * end of it.
481
   */
482
  int yy_fill_buffer;
483
484
  int yy_buffer_status;
485
486
0
#define YY_BUFFER_NEW 0
487
0
#define YY_BUFFER_NORMAL 1
488
  /* When an EOF's been seen but there's still some text to process
489
   * then we mark the buffer as YY_EOF_PENDING, to indicate that we
490
   * shouldn't try reading from the input source any more.  We might
491
   * still have a bunch of tokens to match, though, because of
492
   * possible backing-up.
493
   *
494
   * When we actually see the EOF, we change the status to "new"
495
   * (via yyrestart()), so that the user can continue scanning by
496
   * just pointing yyin at a new input file.
497
   */
498
0
#define YY_BUFFER_EOF_PENDING 2
499
500
  };
501
#endif /* !YY_STRUCT_YY_BUFFER_STATE */
502
503
/* We provide macros for accessing buffer states in case in the
504
 * future we want to put the buffer states in a more general
505
 * "scanner state".
506
 *
507
 * Returns the top of the stack, or NULL.
508
 */
509
0
#define YY_CURRENT_BUFFER ( yyg->yy_buffer_stack \
510
0
                          ? yyg->yy_buffer_stack[yyg->yy_buffer_stack_top] \
511
0
                          : NULL)
512
/* Same as previous macro, but useful when we know that the buffer stack is not
513
 * NULL or when we need an lvalue. For internal use only.
514
 */
515
0
#define YY_CURRENT_BUFFER_LVALUE yyg->yy_buffer_stack[yyg->yy_buffer_stack_top]
516
517
void yyrestart ( FILE *input_file , yyscan_t yyscanner );
518
void yy_switch_to_buffer ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
519
YY_BUFFER_STATE yy_create_buffer ( FILE *file, int size , yyscan_t yyscanner );
520
void yy_delete_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
521
void yy_flush_buffer ( YY_BUFFER_STATE b , yyscan_t yyscanner );
522
void yypush_buffer_state ( YY_BUFFER_STATE new_buffer , yyscan_t yyscanner );
523
void yypop_buffer_state ( yyscan_t yyscanner );
524
525
static void yyensure_buffer_stack ( yyscan_t yyscanner );
526
static void yy_load_buffer_state ( yyscan_t yyscanner );
527
static void yy_init_buffer ( YY_BUFFER_STATE b, FILE *file , yyscan_t yyscanner );
528
#define YY_FLUSH_BUFFER yy_flush_buffer( YY_CURRENT_BUFFER , yyscanner)
529
530
YY_BUFFER_STATE yy_scan_buffer ( char *base, yy_size_t size , yyscan_t yyscanner );
531
YY_BUFFER_STATE yy_scan_string ( const char *yy_str , yyscan_t yyscanner );
532
YY_BUFFER_STATE yy_scan_bytes ( const char *bytes, int len , yyscan_t yyscanner );
533
534
void *yyalloc ( yy_size_t , yyscan_t yyscanner );
535
void *yyrealloc ( void *, yy_size_t , yyscan_t yyscanner );
536
void yyfree ( void * , yyscan_t yyscanner );
537
538
#define yy_new_buffer yy_create_buffer
539
#define yy_set_interactive(is_interactive) \
540
  { \
541
  if ( ! YY_CURRENT_BUFFER ){ \
542
        yyensure_buffer_stack (yyscanner); \
543
    YY_CURRENT_BUFFER_LVALUE =    \
544
            yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \
545
  } \
546
  YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \
547
  }
548
#define yy_set_bol(at_bol) \
549
  { \
550
  if ( ! YY_CURRENT_BUFFER ){\
551
        yyensure_buffer_stack (yyscanner); \
552
    YY_CURRENT_BUFFER_LVALUE =    \
553
            yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner); \
554
  } \
555
  YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \
556
  }
557
#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol)
558
559
/* Begin user sect3 */
560
561
0
#define hex_yywrap(yyscanner) (/*CONSTCOND*/1)
562
#define YY_SKIP_YYWRAP
563
typedef flex_uint8_t YY_CHAR;
564
565
typedef int yy_state_type;
566
567
0
#define yytext_ptr yytext_r
568
569
static yy_state_type yy_get_previous_state ( yyscan_t yyscanner );
570
static yy_state_type yy_try_NUL_trans ( yy_state_type current_state  , yyscan_t yyscanner);
571
static int yy_get_next_buffer ( yyscan_t yyscanner );
572
static void yynoreturn yy_fatal_error ( const char* msg , yyscan_t yyscanner );
573
574
/* Done after the current pattern has been matched and before the
575
 * corresponding action - sets up yytext.
576
 */
577
#define YY_DO_BEFORE_ACTION \
578
0
  yyg->yytext_ptr = yy_bp; \
579
0
  yyleng = (int) (yy_cp - yy_bp); \
580
0
  yyg->yy_hold_char = *yy_cp; \
581
0
  *yy_cp = '\0'; \
582
0
  yyg->yy_c_buf_p = yy_cp;
583
#define YY_NUM_RULES 23
584
0
#define YY_END_OF_BUFFER 24
585
/* This struct is not used in this scanner,
586
   but its presence is necessary. */
587
struct yy_trans_info
588
  {
589
  flex_int32_t yy_verify;
590
  flex_int32_t yy_nxt;
591
  };
592
static const flex_int16_t yy_accept[40] =
593
    {   0,
594
        0,    0,    0,    0,    0,    0,   24,   22,   20,   20,
595
       21,   22,    8,   22,   10,    9,   13,   13,   19,   18,
596
       18,   15,   16,   17,   11,   14,    1,    2,    4,    5,
597
        0,    0,   12,   16,   14,    3,    6,    7,    0
598
    } ;
599
600
static const YY_CHAR yy_ec[256] =
601
    {   0,
602
        1,    1,    1,    1,    1,    1,    1,    1,    2,    3,
603
        1,    1,    2,    1,    1,    1,    1,    1,    1,    1,
604
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
605
        1,    2,    1,    1,    1,    1,    1,    1,    1,    4,
606
        4,    5,    1,    1,    6,    1,    7,    8,    8,    8,
607
        8,    8,    8,    8,    8,    8,    8,    1,    1,    1,
608
        1,    1,    9,    1,   10,   10,   10,   10,   10,   10,
609
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
610
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
611
       11,    1,   12,    1,    1,    1,   10,   10,   10,   10,
612
613
       10,   10,    1,    1,    1,    1,    1,    1,    1,    1,
614
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
615
        1,    1,    4,    4,    4,   13,    1,    1,    1,    1,
616
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
617
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
618
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
619
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
620
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
621
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
622
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
623
624
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
625
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
626
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
627
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
628
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
629
        1,    1,    1,    1,    1
630
    } ;
631
632
static const YY_CHAR yy_meta[14] =
633
    {   0,
634
        1,    1,    2,    1,    1,    1,    1,    3,    4,    3,
635
        1,    1,    1
636
    } ;
637
638
static const flex_int16_t yy_base[48] =
639
    {   0,
640
        0,    0,   28,   27,   12,   23,   30,   59,   59,   59,
641
       59,   31,   19,   18,   59,   14,   59,   15,   59,   59,
642
       59,   59,   13,   59,   59,    0,   59,   59,   59,   59,
643
       10,    0,   59,    9,    0,   59,   59,   59,   59,   38,
644
       42,   44,   46,   48,   52,   54,   13
645
    } ;
646
647
static const flex_int16_t yy_def[48] =
648
    {   0,
649
       39,    1,   40,   40,   41,   41,   39,   39,   39,   39,
650
       39,   39,   42,   43,   39,   44,   39,   39,   39,   39,
651
       39,   39,   39,   39,   39,   45,   39,   39,   39,   39,
652
       46,   47,   39,   39,   45,   39,   39,   39,    0,   39,
653
       39,   39,   39,   39,   39,   39,   39
654
    } ;
655
656
static const flex_int16_t yy_nxt[73] =
657
    {   0,
658
        8,    9,   10,   11,    8,    8,   12,   13,   14,   13,
659
       15,    8,   16,   20,   21,   38,   34,   22,   37,   23,
660
       34,   33,   32,   24,   20,   21,   30,   28,   22,   39,
661
       23,   18,   18,   39,   24,   25,   39,   26,   17,   17,
662
       17,   17,   19,   19,   19,   19,   27,   27,   29,   29,
663
       31,   31,   35,   39,   35,   35,   36,   36,    7,   39,
664
       39,   39,   39,   39,   39,   39,   39,   39,   39,   39,
665
       39,   39
666
    } ;
667
668
static const flex_int16_t yy_chk[73] =
669
    {   0,
670
        1,    1,    1,    1,    1,    1,    1,    1,    1,    1,
671
        1,    1,    1,    5,    5,   47,   34,    5,   31,    5,
672
       23,   18,   16,    5,    6,    6,   14,   13,    6,    7,
673
        6,    4,    3,    0,    6,   12,    0,   12,   40,   40,
674
       40,   40,   41,   41,   41,   41,   42,   42,   43,   43,
675
       44,   44,   45,    0,   45,   45,   46,   46,   39,   39,
676
       39,   39,   39,   39,   39,   39,   39,   39,   39,   39,
677
       39,   39
678
    } ;
679
680
/* Table of booleans, true if rule could match eol. */
681
static const flex_int32_t yy_rule_can_match_eol[24] =
682
    {   0,
683
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 
684
    1, 0, 0, 0,     };
685
686
/* The intent behind this definition is that it'll catch
687
 * any uses of REJECT which flex missed.
688
 */
689
#define REJECT reject_used_but_not_detected
690
#define yymore() yymore_used_but_not_detected
691
0
#define YY_MORE_ADJ 0
692
#define YY_RESTORE_YY_MORE_OFFSET
693
#line 1 "libyara/hex_lexer.l"
694
/*
695
Copyright (c) 2013. The YARA Authors. All Rights Reserved.
696
697
Redistribution and use in source and binary forms, with or without modification,
698
are permitted provided that the following conditions are met:
699
700
1. Redistributions of source code must retain the above copyright notice, this
701
list of conditions and the following disclaimer.
702
703
2. Redistributions in binary form must reproduce the above copyright notice,
704
this list of conditions and the following disclaimer in the documentation and/or
705
other materials provided with the distribution.
706
707
3. Neither the name of the copyright holder nor the names of its contributors
708
may be used to endorse or promote products derived from this software without
709
specific prior written permission.
710
711
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
712
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
713
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
714
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
715
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
716
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
717
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
718
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
719
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
720
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
721
*/
722
/* Lexical analyzer for hex strings */
723
#line 33 "libyara/hex_lexer.l"
724
725
/* Disable warnings for unused functions in this file.
726
727
As we redefine YY_FATAL_ERROR macro to use our own function hex_yyfatal, the
728
yy_fatal_error function generated by Flex is not actually used, causing a
729
compiler warning. Flex doesn't offer any options to remove the yy_fatal_error
730
function. When they include something like %option noyy_fatal_error as they do
731
with noyywrap then we can remove this pragma.
732
*/
733
734
#ifdef __GNUC__
735
#pragma GCC diagnostic ignored "-Wunused-function"
736
#endif
737
738
#include <limits.h>
739
#include <setjmp.h>
740
741
#include <yara/globals.h>
742
#include <yara/limits.h>
743
#include <yara/error.h>
744
#include <yara/mem.h>
745
#include <yara/re.h>
746
#include <yara/threading.h>
747
#include <yara/strutils.h>
748
#include <yara/hex_lexer.h>
749
750
#include "hex_grammar.h"
751
752
#ifdef _WIN32
753
#define snprintf _snprintf
754
#define strtoll  _strtoi64
755
#endif
756
757
#define ERROR_IF(x, error) \
758
    if (x) \
759
    { \
760
      RE_AST* re_ast = yyget_extra(yyscanner); \
761
      re_ast->error_code = error; \
762
      YYABORT; \
763
    } \
764
765
#line 765 "libyara/hex_lexer.c"
766
#define YY_NO_UNISTD_H 1
767
#define YY_NO_INPUT 1
768
769
#line 769 "libyara/hex_lexer.c"
770
771
0
#define INITIAL 0
772
0
#define comment 1
773
0
#define range 2
774
775
#ifndef YY_NO_UNISTD_H
776
/* Special case for "unistd.h", since it is non-ANSI. We include it way
777
 * down here because we want the user's section 1 to have been scanned first.
778
 * The user has a chance to override it with an option.
779
 */
780
#include <unistd.h>
781
#endif
782
783
#ifndef YY_EXTRA_TYPE
784
#define YY_EXTRA_TYPE void *
785
#endif
786
787
/* Holds the entire state of the reentrant scanner. */
788
struct yyguts_t
789
    {
790
791
    /* User-defined. Not touched by flex. */
792
    YY_EXTRA_TYPE yyextra_r;
793
794
    /* The rest are the same as the globals declared in the non-reentrant scanner. */
795
    FILE *yyin_r, *yyout_r;
796
    size_t yy_buffer_stack_top; /**< index of top of stack. */
797
    size_t yy_buffer_stack_max; /**< capacity of stack. */
798
    YY_BUFFER_STATE * yy_buffer_stack; /**< Stack as an array. */
799
    char yy_hold_char;
800
    int yy_n_chars;
801
    int yyleng_r;
802
    char *yy_c_buf_p;
803
    int yy_init;
804
    int yy_start;
805
    int yy_did_buffer_switch_on_eof;
806
    int yy_start_stack_ptr;
807
    int yy_start_stack_depth;
808
    int *yy_start_stack;
809
    yy_state_type yy_last_accepting_state;
810
    char* yy_last_accepting_cpos;
811
812
    int yylineno_r;
813
    int yy_flex_debug_r;
814
815
    char *yytext_r;
816
    int yy_more_flag;
817
    int yy_more_len;
818
819
    YYSTYPE * yylval_r;
820
821
    }; /* end struct yyguts_t */
822
823
static int yy_init_globals ( yyscan_t yyscanner );
824
825
    /* This must go here because YYSTYPE and YYLTYPE are included
826
     * from bison output in section 1.*/
827
0
    #    define yylval yyg->yylval_r
828
    
829
int yylex_init (yyscan_t* scanner);
830
831
int yylex_init_extra ( YY_EXTRA_TYPE user_defined, yyscan_t* scanner);
832
833
/* Accessor methods to globals.
834
   These are made visible to non-reentrant scanners for convenience. */
835
836
int yylex_destroy ( yyscan_t yyscanner );
837
838
int yyget_debug ( yyscan_t yyscanner );
839
840
void yyset_debug ( int debug_flag , yyscan_t yyscanner );
841
842
YY_EXTRA_TYPE yyget_extra ( yyscan_t yyscanner );
843
844
void yyset_extra ( YY_EXTRA_TYPE user_defined , yyscan_t yyscanner );
845
846
FILE *yyget_in ( yyscan_t yyscanner );
847
848
void yyset_in  ( FILE * _in_str , yyscan_t yyscanner );
849
850
FILE *yyget_out ( yyscan_t yyscanner );
851
852
void yyset_out  ( FILE * _out_str , yyscan_t yyscanner );
853
854
      int yyget_leng ( yyscan_t yyscanner );
855
856
char *yyget_text ( yyscan_t yyscanner );
857
858
int yyget_lineno ( yyscan_t yyscanner );
859
860
void yyset_lineno ( int _line_number , yyscan_t yyscanner );
861
862
int yyget_column  ( yyscan_t yyscanner );
863
864
void yyset_column ( int _column_no , yyscan_t yyscanner );
865
866
YYSTYPE * yyget_lval ( yyscan_t yyscanner );
867
868
void yyset_lval ( YYSTYPE * yylval_param , yyscan_t yyscanner );
869
870
/* Macros after this point can all be overridden by user definitions in
871
 * section 1.
872
 */
873
874
#ifndef YY_SKIP_YYWRAP
875
#ifdef __cplusplus
876
extern "C" int yywrap ( yyscan_t yyscanner );
877
#else
878
extern int yywrap ( yyscan_t yyscanner );
879
#endif
880
#endif
881
882
#ifndef YY_NO_UNPUT
883
    
884
#endif
885
886
#ifndef yytext_ptr
887
static void yy_flex_strncpy ( char *, const char *, int , yyscan_t yyscanner);
888
#endif
889
890
#ifdef YY_NEED_STRLEN
891
static int yy_flex_strlen ( const char * , yyscan_t yyscanner);
892
#endif
893
894
#ifndef YY_NO_INPUT
895
#ifdef __cplusplus
896
static int yyinput ( yyscan_t yyscanner );
897
#else
898
static int input ( yyscan_t yyscanner );
899
#endif
900
901
#endif
902
903
/* Amount of stuff to slurp up with each read. */
904
#ifndef YY_READ_BUF_SIZE
905
#ifdef __ia64__
906
/* On IA-64, the buffer size is 16k, not 8k */
907
#define YY_READ_BUF_SIZE 16384
908
#else
909
0
#define YY_READ_BUF_SIZE 8192
910
#endif /* __ia64__ */
911
#endif
912
913
/* Copy whatever the last rule matched to the standard output. */
914
#ifndef ECHO
915
/* This used to be an fputs(), but since the string might contain NUL's,
916
 * we now use fwrite().
917
 */
918
#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0)
919
#endif
920
921
/* Gets input and stuffs it into "buf".  number of characters read, or YY_NULL,
922
 * is returned in "result".
923
 */
924
#ifndef YY_INPUT
925
#define YY_INPUT(buf,result,max_size) \
926
0
  if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \
927
0
    { \
928
0
    int c = '*'; \
929
0
    int n; \
930
0
    for ( n = 0; n < max_size && \
931
0
           (c = getc( yyin )) != EOF && c != '\n'; ++n ) \
932
0
      buf[n] = (char) c; \
933
0
    if ( c == '\n' ) \
934
0
      buf[n++] = (char) c; \
935
0
    if ( c == EOF && ferror( yyin ) ) \
936
0
      YY_FATAL_ERROR( "input in flex scanner failed" ); \
937
0
    result = n; \
938
0
    } \
939
0
  else \
940
0
    { \
941
0
    errno=0; \
942
0
    while ( (result = (int) fread(buf, 1, (yy_size_t) max_size, yyin)) == 0 && ferror(yyin)) \
943
0
      { \
944
0
      if( errno != EINTR) \
945
0
        { \
946
0
        YY_FATAL_ERROR( "input in flex scanner failed" ); \
947
0
        break; \
948
0
        } \
949
0
      errno=0; \
950
0
      clearerr(yyin); \
951
0
      } \
952
0
    }\
953
\
954
955
#endif
956
957
/* No semi-colon after return; correct usage is to write "yyterminate();" -
958
 * we don't want an extra ';' after the "return" because that will cause
959
 * some compilers to complain about unreachable statements.
960
 */
961
#ifndef yyterminate
962
0
#define yyterminate() return YY_NULL
963
#endif
964
965
/* Number of entries by which start-condition stack grows. */
966
#ifndef YY_START_STACK_INCR
967
#define YY_START_STACK_INCR 25
968
#endif
969
970
/* Report a fatal error. */
971
#ifndef YY_FATAL_ERROR
972
#define YY_FATAL_ERROR(msg) yy_fatal_error( msg , yyscanner)
973
#endif
974
975
/* end tables serialization structures and prototypes */
976
977
/* Default declaration of generated scanner - a define so the user can
978
 * easily add parameters.
979
 */
980
#ifndef YY_DECL
981
#define YY_DECL_IS_OURS 1
982
983
extern int yylex \
984
               (YYSTYPE * yylval_param , yyscan_t yyscanner);
985
986
#define YY_DECL int yylex \
987
               (YYSTYPE * yylval_param , yyscan_t yyscanner)
988
#endif /* !YY_DECL */
989
990
/* Code executed at the beginning of each rule, after yytext and yyleng
991
 * have been set up.
992
 */
993
#ifndef YY_USER_ACTION
994
#define YY_USER_ACTION
995
#endif
996
997
/* Code executed at the end of each rule. */
998
#ifndef YY_BREAK
999
0
#define YY_BREAK /*LINTED*/break;
1000
#endif
1001
1002
#define YY_RULE_SETUP \
1003
  YY_USER_ACTION
1004
1005
/** The main scanner function which does all the work.
1006
 */
1007
YY_DECL
1008
0
{
1009
0
  yy_state_type yy_current_state;
1010
0
  char *yy_cp, *yy_bp;
1011
0
  int yy_act;
1012
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1013
1014
0
    yylval = yylval_param;
1015
1016
0
  if ( !yyg->yy_init )
1017
0
    {
1018
0
    yyg->yy_init = 1;
1019
1020
#ifdef YY_USER_INIT
1021
    YY_USER_INIT;
1022
#endif
1023
1024
0
    if ( ! yyg->yy_start )
1025
0
      yyg->yy_start = 1; /* first start state */
1026
1027
0
    if ( ! yyin )
1028
0
      yyin = stdin;
1029
1030
0
    if ( ! yyout )
1031
0
      yyout = stdout;
1032
1033
0
    if ( ! YY_CURRENT_BUFFER ) {
1034
0
      yyensure_buffer_stack (yyscanner);
1035
0
      YY_CURRENT_BUFFER_LVALUE =
1036
0
        yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
1037
0
    }
1038
1039
0
    yy_load_buffer_state( yyscanner );
1040
0
    }
1041
1042
0
  {
1043
0
#line 97 "libyara/hex_lexer.l"
1044
1045
1046
1047
0
#line 1047 "libyara/hex_lexer.c"
1048
1049
0
  while ( /*CONSTCOND*/1 )    /* loops until end-of-file is reached */
1050
0
    {
1051
0
    yy_cp = yyg->yy_c_buf_p;
1052
1053
    /* Support of yytext. */
1054
0
    *yy_cp = yyg->yy_hold_char;
1055
1056
    /* yy_bp points to the position in yy_ch_buf of the start of
1057
     * the current run.
1058
     */
1059
0
    yy_bp = yy_cp;
1060
1061
0
    yy_current_state = yyg->yy_start;
1062
0
yy_match:
1063
0
    do
1064
0
      {
1065
0
      YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
1066
0
      if ( yy_accept[yy_current_state] )
1067
0
        {
1068
0
        yyg->yy_last_accepting_state = yy_current_state;
1069
0
        yyg->yy_last_accepting_cpos = yy_cp;
1070
0
        }
1071
0
      while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1072
0
        {
1073
0
        yy_current_state = (int) yy_def[yy_current_state];
1074
0
        if ( yy_current_state >= 40 )
1075
0
          yy_c = yy_meta[yy_c];
1076
0
        }
1077
0
      yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1078
0
      ++yy_cp;
1079
0
      }
1080
0
    while ( yy_current_state != 39 );
1081
0
    yy_cp = yyg->yy_last_accepting_cpos;
1082
0
    yy_current_state = yyg->yy_last_accepting_state;
1083
1084
0
yy_find_action:
1085
0
    yy_act = yy_accept[yy_current_state];
1086
1087
0
    YY_DO_BEFORE_ACTION;
1088
1089
0
    if ( yy_act != YY_END_OF_BUFFER && yy_rule_can_match_eol[yy_act] )
1090
0
      {
1091
0
      int yyl;
1092
0
      for ( yyl = 0; yyl < yyleng; ++yyl )
1093
0
        if ( yytext[yyl] == '\n' )
1094
          
1095
0
    do{ yylineno++;
1096
0
        yycolumn=0;
1097
0
    }while(0)
1098
0
;
1099
0
      }
1100
1101
0
do_action:  /* This label is used only to access EOF actions. */
1102
1103
0
    switch ( yy_act )
1104
0
  { /* beginning of action switch */
1105
0
      case 0: /* must back up */
1106
      /* undo the effects of YY_DO_BEFORE_ACTION */
1107
0
      *yy_cp = yyg->yy_hold_char;
1108
0
      yy_cp = yyg->yy_last_accepting_cpos;
1109
0
      yy_current_state = yyg->yy_last_accepting_state;
1110
0
      goto yy_find_action;
1111
1112
0
case 1:
1113
0
YY_RULE_SETUP
1114
0
#line 100 "libyara/hex_lexer.l"
1115
0
{
1116
1117
0
  yylval->integer = xtoi(yytext);
1118
0
  return _BYTE_;
1119
0
}
1120
0
  YY_BREAK
1121
0
case 2:
1122
0
YY_RULE_SETUP
1123
0
#line 106 "libyara/hex_lexer.l"
1124
0
{
1125
1126
0
  yytext[1] = '0'; // replace ? by 0
1127
0
  yylval->integer = xtoi(yytext) | 0xF000 ;
1128
0
  return _MASKED_BYTE_;
1129
0
}
1130
0
  YY_BREAK
1131
0
case 3:
1132
0
YY_RULE_SETUP
1133
0
#line 113 "libyara/hex_lexer.l"
1134
0
{
1135
1136
0
  yylval->integer = xtoi(&(yytext[1]));
1137
0
  return _NOT_BYTE_;
1138
0
}
1139
0
  YY_BREAK
1140
0
case 4:
1141
0
YY_RULE_SETUP
1142
0
#line 119 "libyara/hex_lexer.l"
1143
0
{
1144
1145
0
  yytext[0] = '0'; // replace ? by 0
1146
0
  yylval->integer = xtoi(yytext) | 0x0F00 ;
1147
0
  return _MASKED_BYTE_;
1148
0
}
1149
0
  YY_BREAK
1150
0
case 5:
1151
0
YY_RULE_SETUP
1152
0
#line 126 "libyara/hex_lexer.l"
1153
0
{
1154
1155
0
  yylval->integer = 0x0000;
1156
0
  return _MASKED_BYTE_;
1157
0
}
1158
0
  YY_BREAK
1159
0
case 6:
1160
0
YY_RULE_SETUP
1161
0
#line 132 "libyara/hex_lexer.l"
1162
0
{
1163
1164
0
  yytext[2] = '0'; // replace ? by 0
1165
0
  yylval->integer = xtoi(&(yytext[1])) | 0xF000 ;
1166
0
  return _MASKED_NOT_BYTE_;
1167
0
}
1168
0
  YY_BREAK
1169
0
case 7:
1170
0
YY_RULE_SETUP
1171
0
#line 139 "libyara/hex_lexer.l"
1172
0
{
1173
1174
0
  yytext[1] = '0'; // replace ? by 0
1175
0
  yylval->integer = xtoi(&(yytext[1])) | 0x0F00 ;
1176
0
  return _MASKED_NOT_BYTE_;
1177
0
}
1178
0
  YY_BREAK
1179
0
case 8:
1180
0
YY_RULE_SETUP
1181
0
#line 146 "libyara/hex_lexer.l"
1182
0
{
1183
1184
0
  yyerror(yyscanner, lex_env, "uneven number of digits in hex string");
1185
0
  yyterminate();
1186
0
}
1187
0
  YY_BREAK
1188
0
case 9:
1189
0
YY_RULE_SETUP
1190
0
#line 152 "libyara/hex_lexer.l"
1191
0
{
1192
1193
0
  yyerror(yyscanner, lex_env, "invalid not operator (~) in hex string");
1194
0
  yyterminate();
1195
0
}
1196
0
  YY_BREAK
1197
0
case 10:
1198
0
YY_RULE_SETUP
1199
0
#line 159 "libyara/hex_lexer.l"
1200
0
{
1201
1202
0
  BEGIN(range);
1203
0
  return yytext[0];
1204
0
}
1205
0
  YY_BREAK
1206
0
case 11:
1207
0
YY_RULE_SETUP
1208
0
#line 165 "libyara/hex_lexer.l"
1209
0
{
1210
1211
0
  BEGIN(comment);
1212
0
}
1213
0
  YY_BREAK
1214
0
case 12:
1215
0
YY_RULE_SETUP
1216
0
#line 170 "libyara/hex_lexer.l"
1217
0
{
1218
1219
0
  BEGIN(INITIAL);
1220
0
}
1221
0
  YY_BREAK
1222
0
case 13:
1223
/* rule 13 can match eol */
1224
0
YY_RULE_SETUP
1225
0
#line 175 "libyara/hex_lexer.l"
1226
// skip comments
1227
0
  YY_BREAK
1228
0
case 14:
1229
0
YY_RULE_SETUP
1230
0
#line 177 "libyara/hex_lexer.l"
1231
// skip single-line comments
1232
0
  YY_BREAK
1233
0
case 15:
1234
0
YY_RULE_SETUP
1235
0
#line 179 "libyara/hex_lexer.l"
1236
0
{
1237
1238
0
  return yytext[0];
1239
0
}
1240
0
  YY_BREAK
1241
0
case 16:
1242
0
YY_RULE_SETUP
1243
0
#line 184 "libyara/hex_lexer.l"
1244
0
{
1245
1246
  // strtoll is used instead of atoi because atoi has undefined behaviour for
1247
  // numbers that don't fit in an int. Numbers too large for a long long are
1248
  // clamped to LLONG_MAX by strtoll, which is still caught by the check below.
1249
1250
0
  yylval->integer = strtoll(yytext, NULL, 10);
1251
1252
  // Jump lengths end up stored in the int fields of a RE_NODE, anything above
1253
  // INT_MAX can't be represented.
1254
1255
0
  if (yylval->integer > INT_MAX)
1256
0
  {
1257
0
    yyerror(yyscanner, lex_env, "jump length too large");
1258
0
    yyterminate();
1259
0
  }
1260
1261
0
  return _NUMBER_;
1262
0
}
1263
0
  YY_BREAK
1264
0
case 17:
1265
0
YY_RULE_SETUP
1266
0
#line 204 "libyara/hex_lexer.l"
1267
0
{
1268
1269
0
  BEGIN(INITIAL);
1270
0
  return yytext[0];
1271
0
}
1272
0
  YY_BREAK
1273
0
case 18:
1274
/* rule 18 can match eol */
1275
0
YY_RULE_SETUP
1276
0
#line 210 "libyara/hex_lexer.l"
1277
// skip whitespaces
1278
0
  YY_BREAK
1279
0
case 19:
1280
0
YY_RULE_SETUP
1281
0
#line 212 "libyara/hex_lexer.l"
1282
0
{
1283
1284
0
  yyerror(yyscanner, lex_env, "invalid character in hex string jump");
1285
0
  yyterminate();
1286
0
}
1287
0
  YY_BREAK
1288
0
case 20:
1289
/* rule 20 can match eol */
1290
0
YY_RULE_SETUP
1291
0
#line 218 "libyara/hex_lexer.l"
1292
// skip whitespaces
1293
0
  YY_BREAK
1294
0
case 21:
1295
0
YY_RULE_SETUP
1296
0
#line 220 "libyara/hex_lexer.l"
1297
0
{        // pass valid characters to the parser
1298
1299
0
  return yytext[0];
1300
0
}
1301
0
  YY_BREAK
1302
0
case 22:
1303
0
YY_RULE_SETUP
1304
0
#line 225 "libyara/hex_lexer.l"
1305
0
{               // reject all other characters
1306
1307
0
  yyerror(yyscanner, lex_env, "invalid character in hex string");
1308
0
  yyterminate();
1309
0
}
1310
0
  YY_BREAK
1311
0
case 23:
1312
0
YY_RULE_SETUP
1313
0
#line 231 "libyara/hex_lexer.l"
1314
0
ECHO;
1315
0
  YY_BREAK
1316
0
#line 1316 "libyara/hex_lexer.c"
1317
0
case YY_STATE_EOF(INITIAL):
1318
0
case YY_STATE_EOF(comment):
1319
0
case YY_STATE_EOF(range):
1320
0
  yyterminate();
1321
1322
0
  case YY_END_OF_BUFFER:
1323
0
    {
1324
    /* Amount of text matched not including the EOB char. */
1325
0
    int yy_amount_of_matched_text = (int) (yy_cp - yyg->yytext_ptr) - 1;
1326
1327
    /* Undo the effects of YY_DO_BEFORE_ACTION. */
1328
0
    *yy_cp = yyg->yy_hold_char;
1329
0
    YY_RESTORE_YY_MORE_OFFSET
1330
1331
0
    if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW )
1332
0
      {
1333
      /* We're scanning a new file or input source.  It's
1334
       * possible that this happened because the user
1335
       * just pointed yyin at a new source and called
1336
       * yylex().  If so, then we have to assure
1337
       * consistency between YY_CURRENT_BUFFER and our
1338
       * globals.  Here is the right place to do so, because
1339
       * this is the first action (other than possibly a
1340
       * back-up) that will match for the new input source.
1341
       */
1342
0
      yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1343
0
      YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin;
1344
0
      YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL;
1345
0
      }
1346
1347
    /* Note that here we test for yy_c_buf_p "<=" to the position
1348
     * of the first EOB in the buffer, since yy_c_buf_p will
1349
     * already have been incremented past the NUL character
1350
     * (since all states make transitions on EOB to the
1351
     * end-of-buffer state).  Contrast this with the test
1352
     * in input().
1353
     */
1354
0
    if ( yyg->yy_c_buf_p <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
1355
0
      { /* This was really a NUL. */
1356
0
      yy_state_type yy_next_state;
1357
1358
0
      yyg->yy_c_buf_p = yyg->yytext_ptr + yy_amount_of_matched_text;
1359
1360
0
      yy_current_state = yy_get_previous_state( yyscanner );
1361
1362
      /* Okay, we're now positioned to make the NUL
1363
       * transition.  We couldn't have
1364
       * yy_get_previous_state() go ahead and do it
1365
       * for us because it doesn't know how to deal
1366
       * with the possibility of jamming (and we don't
1367
       * want to build jamming into it because then it
1368
       * will run more slowly).
1369
       */
1370
1371
0
      yy_next_state = yy_try_NUL_trans( yy_current_state , yyscanner);
1372
1373
0
      yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1374
1375
0
      if ( yy_next_state )
1376
0
        {
1377
        /* Consume the NUL. */
1378
0
        yy_cp = ++yyg->yy_c_buf_p;
1379
0
        yy_current_state = yy_next_state;
1380
0
        goto yy_match;
1381
0
        }
1382
1383
0
      else
1384
0
        {
1385
0
        yy_cp = yyg->yy_last_accepting_cpos;
1386
0
        yy_current_state = yyg->yy_last_accepting_state;
1387
0
        goto yy_find_action;
1388
0
        }
1389
0
      }
1390
1391
0
    else switch ( yy_get_next_buffer( yyscanner ) )
1392
0
      {
1393
0
      case EOB_ACT_END_OF_FILE:
1394
0
        {
1395
0
        yyg->yy_did_buffer_switch_on_eof = 0;
1396
1397
0
        if ( yywrap( yyscanner ) )
1398
0
          {
1399
          /* Note: because we've taken care in
1400
           * yy_get_next_buffer() to have set up
1401
           * yytext, we can now set up
1402
           * yy_c_buf_p so that if some total
1403
           * hoser (like flex itself) wants to
1404
           * call the scanner after we return the
1405
           * YY_NULL, it'll still work - another
1406
           * YY_NULL will get returned.
1407
           */
1408
0
          yyg->yy_c_buf_p = yyg->yytext_ptr + YY_MORE_ADJ;
1409
1410
0
          yy_act = YY_STATE_EOF(YY_START);
1411
0
          goto do_action;
1412
0
          }
1413
1414
0
        else
1415
0
          {
1416
0
          if ( ! yyg->yy_did_buffer_switch_on_eof )
1417
0
            YY_NEW_FILE;
1418
0
          }
1419
0
        break;
1420
0
        }
1421
1422
0
      case EOB_ACT_CONTINUE_SCAN:
1423
0
        yyg->yy_c_buf_p =
1424
0
          yyg->yytext_ptr + yy_amount_of_matched_text;
1425
1426
0
        yy_current_state = yy_get_previous_state( yyscanner );
1427
1428
0
        yy_cp = yyg->yy_c_buf_p;
1429
0
        yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1430
0
        goto yy_match;
1431
1432
0
      case EOB_ACT_LAST_MATCH:
1433
0
        yyg->yy_c_buf_p =
1434
0
        &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars];
1435
1436
0
        yy_current_state = yy_get_previous_state( yyscanner );
1437
1438
0
        yy_cp = yyg->yy_c_buf_p;
1439
0
        yy_bp = yyg->yytext_ptr + YY_MORE_ADJ;
1440
0
        goto yy_find_action;
1441
0
      }
1442
0
    break;
1443
0
    }
1444
1445
0
  default:
1446
0
    YY_FATAL_ERROR(
1447
0
      "fatal flex scanner internal error--no action found" );
1448
0
  } /* end of action switch */
1449
0
    } /* end of scanning one token */
1450
0
  } /* end of user's declarations */
1451
0
} /* end of yylex */
1452
1453
/* yy_get_next_buffer - try to read in a new buffer
1454
 *
1455
 * Returns a code representing an action:
1456
 *  EOB_ACT_LAST_MATCH -
1457
 *  EOB_ACT_CONTINUE_SCAN - continue scanning from current position
1458
 *  EOB_ACT_END_OF_FILE - end of file
1459
 */
1460
static int yy_get_next_buffer (yyscan_t yyscanner)
1461
0
{
1462
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1463
0
  char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf;
1464
0
  char *source = yyg->yytext_ptr;
1465
0
  int number_to_move, i;
1466
0
  int ret_val;
1467
1468
0
  if ( yyg->yy_c_buf_p > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] )
1469
0
    YY_FATAL_ERROR(
1470
0
    "fatal flex scanner internal error--end of buffer missed" );
1471
1472
0
  if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 )
1473
0
    { /* Don't try to fill the buffer, so this is an EOF. */
1474
0
    if ( yyg->yy_c_buf_p - yyg->yytext_ptr - YY_MORE_ADJ == 1 )
1475
0
      {
1476
      /* We matched a single character, the EOB, so
1477
       * treat this as a final EOF.
1478
       */
1479
0
      return EOB_ACT_END_OF_FILE;
1480
0
      }
1481
1482
0
    else
1483
0
      {
1484
      /* We matched some text prior to the EOB, first
1485
       * process it.
1486
       */
1487
0
      return EOB_ACT_LAST_MATCH;
1488
0
      }
1489
0
    }
1490
1491
  /* Try to read more data. */
1492
1493
  /* First move last chars to start of buffer. */
1494
0
  number_to_move = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr - 1);
1495
1496
0
  for ( i = 0; i < number_to_move; ++i )
1497
0
    *(dest++) = *(source++);
1498
1499
0
  if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING )
1500
    /* don't do the read, it's not guaranteed to return an EOF,
1501
     * just force an EOF
1502
     */
1503
0
    YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars = 0;
1504
1505
0
  else
1506
0
    {
1507
0
      int num_to_read =
1508
0
      YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
1509
1510
0
    while ( num_to_read <= 0 )
1511
0
      { /* Not enough room in the buffer - grow it. */
1512
1513
      /* just a shorter name for the current buffer */
1514
0
      YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
1515
1516
0
      int yy_c_buf_p_offset =
1517
0
        (int) (yyg->yy_c_buf_p - b->yy_ch_buf);
1518
1519
0
      if ( b->yy_is_our_buffer )
1520
0
        {
1521
0
        int new_size = b->yy_buf_size * 2;
1522
1523
0
        if ( new_size <= 0 )
1524
0
          b->yy_buf_size += b->yy_buf_size / 8;
1525
0
        else
1526
0
          b->yy_buf_size *= 2;
1527
1528
0
        b->yy_ch_buf = (char *)
1529
          /* Include room in for 2 EOB chars. */
1530
0
          yyrealloc( (void *) b->yy_ch_buf,
1531
0
               (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
1532
0
        }
1533
0
      else
1534
        /* Can't grow it, we don't own it. */
1535
0
        b->yy_ch_buf = NULL;
1536
1537
0
      if ( ! b->yy_ch_buf )
1538
0
        YY_FATAL_ERROR(
1539
0
        "fatal error - scanner input buffer overflow" );
1540
1541
0
      yyg->yy_c_buf_p = &b->yy_ch_buf[yy_c_buf_p_offset];
1542
1543
0
      num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size -
1544
0
            number_to_move - 1;
1545
1546
0
      }
1547
1548
0
    if ( num_to_read > YY_READ_BUF_SIZE )
1549
0
      num_to_read = YY_READ_BUF_SIZE;
1550
1551
    /* Read in more data. */
1552
0
    YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
1553
0
      yyg->yy_n_chars, num_to_read );
1554
1555
0
    YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1556
0
    }
1557
1558
0
  if ( yyg->yy_n_chars == 0 )
1559
0
    {
1560
0
    if ( number_to_move == YY_MORE_ADJ )
1561
0
      {
1562
0
      ret_val = EOB_ACT_END_OF_FILE;
1563
0
      yyrestart( yyin  , yyscanner);
1564
0
      }
1565
1566
0
    else
1567
0
      {
1568
0
      ret_val = EOB_ACT_LAST_MATCH;
1569
0
      YY_CURRENT_BUFFER_LVALUE->yy_buffer_status =
1570
0
        YY_BUFFER_EOF_PENDING;
1571
0
      }
1572
0
    }
1573
1574
0
  else
1575
0
    ret_val = EOB_ACT_CONTINUE_SCAN;
1576
1577
0
  if ((yyg->yy_n_chars + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) {
1578
    /* Extend the array by 50%, plus the number we really need. */
1579
0
    int new_size = yyg->yy_n_chars + number_to_move + (yyg->yy_n_chars >> 1);
1580
0
    YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc(
1581
0
      (void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf, (yy_size_t) new_size , yyscanner );
1582
0
    if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf )
1583
0
      YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" );
1584
    /* "- 2" to take care of EOB's */
1585
0
    YY_CURRENT_BUFFER_LVALUE->yy_buf_size = (int) (new_size - 2);
1586
0
  }
1587
1588
0
  yyg->yy_n_chars += number_to_move;
1589
0
  YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] = YY_END_OF_BUFFER_CHAR;
1590
0
  YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars + 1] = YY_END_OF_BUFFER_CHAR;
1591
1592
0
  yyg->yytext_ptr = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0];
1593
1594
0
  return ret_val;
1595
0
}
1596
1597
/* yy_get_previous_state - get the state just before the EOB char was reached */
1598
1599
    static yy_state_type yy_get_previous_state (yyscan_t yyscanner)
1600
0
{
1601
0
  yy_state_type yy_current_state;
1602
0
  char *yy_cp;
1603
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1604
1605
0
  yy_current_state = yyg->yy_start;
1606
1607
0
  for ( yy_cp = yyg->yytext_ptr + YY_MORE_ADJ; yy_cp < yyg->yy_c_buf_p; ++yy_cp )
1608
0
    {
1609
0
    YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1);
1610
0
    if ( yy_accept[yy_current_state] )
1611
0
      {
1612
0
      yyg->yy_last_accepting_state = yy_current_state;
1613
0
      yyg->yy_last_accepting_cpos = yy_cp;
1614
0
      }
1615
0
    while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1616
0
      {
1617
0
      yy_current_state = (int) yy_def[yy_current_state];
1618
0
      if ( yy_current_state >= 40 )
1619
0
        yy_c = yy_meta[yy_c];
1620
0
      }
1621
0
    yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1622
0
    }
1623
1624
0
  return yy_current_state;
1625
0
}
1626
1627
/* yy_try_NUL_trans - try to make a transition on the NUL character
1628
 *
1629
 * synopsis
1630
 *  next_state = yy_try_NUL_trans( current_state );
1631
 */
1632
    static yy_state_type yy_try_NUL_trans  (yy_state_type yy_current_state , yyscan_t yyscanner)
1633
0
{
1634
0
  int yy_is_jam;
1635
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; /* This var may be unused depending upon options. */
1636
0
  char *yy_cp = yyg->yy_c_buf_p;
1637
1638
0
  YY_CHAR yy_c = 1;
1639
0
  if ( yy_accept[yy_current_state] )
1640
0
    {
1641
0
    yyg->yy_last_accepting_state = yy_current_state;
1642
0
    yyg->yy_last_accepting_cpos = yy_cp;
1643
0
    }
1644
0
  while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
1645
0
    {
1646
0
    yy_current_state = (int) yy_def[yy_current_state];
1647
0
    if ( yy_current_state >= 40 )
1648
0
      yy_c = yy_meta[yy_c];
1649
0
    }
1650
0
  yy_current_state = yy_nxt[yy_base[yy_current_state] + yy_c];
1651
0
  yy_is_jam = (yy_current_state == 39);
1652
1653
0
  (void)yyg;
1654
0
  return yy_is_jam ? 0 : yy_current_state;
1655
0
}
1656
1657
#ifndef YY_NO_UNPUT
1658
1659
#endif
1660
1661
#ifndef YY_NO_INPUT
1662
#ifdef __cplusplus
1663
    static int yyinput (yyscan_t yyscanner)
1664
#else
1665
    static int input  (yyscan_t yyscanner)
1666
#endif
1667
1668
{
1669
  int c;
1670
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1671
1672
  *yyg->yy_c_buf_p = yyg->yy_hold_char;
1673
1674
  if ( *yyg->yy_c_buf_p == YY_END_OF_BUFFER_CHAR )
1675
    {
1676
    /* yy_c_buf_p now points to the character we want to return.
1677
     * If this occurs *before* the EOB characters, then it's a
1678
     * valid NUL; if not, then we've hit the end of the buffer.
1679
     */
1680
    if ( yyg->yy_c_buf_p < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[yyg->yy_n_chars] )
1681
      /* This was really a NUL. */
1682
      *yyg->yy_c_buf_p = '\0';
1683
1684
    else
1685
      { /* need more input */
1686
      int offset = (int) (yyg->yy_c_buf_p - yyg->yytext_ptr);
1687
      ++yyg->yy_c_buf_p;
1688
1689
      switch ( yy_get_next_buffer( yyscanner ) )
1690
        {
1691
        case EOB_ACT_LAST_MATCH:
1692
          /* This happens because yy_g_n_b()
1693
           * sees that we've accumulated a
1694
           * token and flags that we need to
1695
           * try matching the token before
1696
           * proceeding.  But for input(),
1697
           * there's no matching to consider.
1698
           * So convert the EOB_ACT_LAST_MATCH
1699
           * to EOB_ACT_END_OF_FILE.
1700
           */
1701
1702
          /* Reset buffer status. */
1703
          yyrestart( yyin , yyscanner);
1704
1705
          /*FALLTHROUGH*/
1706
1707
        case EOB_ACT_END_OF_FILE:
1708
          {
1709
          if ( yywrap( yyscanner ) )
1710
            return 0;
1711
1712
          if ( ! yyg->yy_did_buffer_switch_on_eof )
1713
            YY_NEW_FILE;
1714
#ifdef __cplusplus
1715
          return yyinput(yyscanner);
1716
#else
1717
          return input(yyscanner);
1718
#endif
1719
          }
1720
1721
        case EOB_ACT_CONTINUE_SCAN:
1722
          yyg->yy_c_buf_p = yyg->yytext_ptr + offset;
1723
          break;
1724
        }
1725
      }
1726
    }
1727
1728
  c = *(unsigned char *) yyg->yy_c_buf_p; /* cast for 8-bit char's */
1729
  *yyg->yy_c_buf_p = '\0';  /* preserve yytext */
1730
  yyg->yy_hold_char = *++yyg->yy_c_buf_p;
1731
1732
  if ( c == '\n' )
1733
    
1734
    do{ yylineno++;
1735
        yycolumn=0;
1736
    }while(0)
1737
;
1738
1739
  return c;
1740
}
1741
#endif  /* ifndef YY_NO_INPUT */
1742
1743
/** Immediately switch to a different input stream.
1744
 * @param input_file A readable stream.
1745
 * @param yyscanner The scanner object.
1746
 * @note This function does not reset the start condition to @c INITIAL .
1747
 */
1748
    void yyrestart  (FILE * input_file , yyscan_t yyscanner)
1749
0
{
1750
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1751
1752
0
  if ( ! YY_CURRENT_BUFFER ){
1753
0
        yyensure_buffer_stack (yyscanner);
1754
0
    YY_CURRENT_BUFFER_LVALUE =
1755
0
            yy_create_buffer( yyin, YY_BUF_SIZE , yyscanner);
1756
0
  }
1757
1758
0
  yy_init_buffer( YY_CURRENT_BUFFER, input_file , yyscanner);
1759
0
  yy_load_buffer_state( yyscanner );
1760
0
}
1761
1762
/** Switch to a different input buffer.
1763
 * @param new_buffer The new input buffer.
1764
 * @param yyscanner The scanner object.
1765
 */
1766
    void yy_switch_to_buffer  (YY_BUFFER_STATE  new_buffer , yyscan_t yyscanner)
1767
0
{
1768
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1769
1770
  /* TODO. We should be able to replace this entire function body
1771
   * with
1772
   *    yypop_buffer_state();
1773
   *    yypush_buffer_state(new_buffer);
1774
     */
1775
0
  yyensure_buffer_stack (yyscanner);
1776
0
  if ( YY_CURRENT_BUFFER == new_buffer )
1777
0
    return;
1778
1779
0
  if ( YY_CURRENT_BUFFER )
1780
0
    {
1781
    /* Flush out information for old buffer. */
1782
0
    *yyg->yy_c_buf_p = yyg->yy_hold_char;
1783
0
    YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
1784
0
    YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1785
0
    }
1786
1787
0
  YY_CURRENT_BUFFER_LVALUE = new_buffer;
1788
0
  yy_load_buffer_state( yyscanner );
1789
1790
  /* We don't actually know whether we did this switch during
1791
   * EOF (yywrap()) processing, but the only time this flag
1792
   * is looked at is after yywrap() is called, so it's safe
1793
   * to go ahead and always set it.
1794
   */
1795
0
  yyg->yy_did_buffer_switch_on_eof = 1;
1796
0
}
1797
1798
static void yy_load_buffer_state  (yyscan_t yyscanner)
1799
0
{
1800
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1801
0
  yyg->yy_n_chars = YY_CURRENT_BUFFER_LVALUE->yy_n_chars;
1802
0
  yyg->yytext_ptr = yyg->yy_c_buf_p = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos;
1803
0
  yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file;
1804
0
  yyg->yy_hold_char = *yyg->yy_c_buf_p;
1805
0
}
1806
1807
/** Allocate and initialize an input buffer state.
1808
 * @param file A readable stream.
1809
 * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE.
1810
 * @param yyscanner The scanner object.
1811
 * @return the allocated buffer state.
1812
 */
1813
    YY_BUFFER_STATE yy_create_buffer  (FILE * file, int  size , yyscan_t yyscanner)
1814
0
{
1815
0
  YY_BUFFER_STATE b;
1816
    
1817
0
  b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
1818
0
  if ( ! b )
1819
0
    YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1820
1821
0
  b->yy_buf_size = size;
1822
1823
  /* yy_ch_buf has to be 2 characters longer than the size given because
1824
   * we need to put in 2 end-of-buffer characters.
1825
   */
1826
0
  b->yy_ch_buf = (char *) yyalloc( (yy_size_t) (b->yy_buf_size + 2) , yyscanner );
1827
0
  if ( ! b->yy_ch_buf )
1828
0
    YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" );
1829
1830
0
  b->yy_is_our_buffer = 1;
1831
1832
0
  yy_init_buffer( b, file , yyscanner);
1833
1834
0
  return b;
1835
0
}
1836
1837
/** Destroy the buffer.
1838
 * @param b a buffer created with yy_create_buffer()
1839
 * @param yyscanner The scanner object.
1840
 */
1841
    void yy_delete_buffer (YY_BUFFER_STATE  b , yyscan_t yyscanner)
1842
0
{
1843
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1844
1845
0
  if ( ! b )
1846
0
    return;
1847
1848
0
  if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */
1849
0
    YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0;
1850
1851
0
  if ( b->yy_is_our_buffer )
1852
0
    yyfree( (void *) b->yy_ch_buf , yyscanner );
1853
1854
0
  yyfree( (void *) b , yyscanner );
1855
0
}
1856
1857
/* Initializes or reinitializes a buffer.
1858
 * This function is sometimes called more than once on the same buffer,
1859
 * such as during a yyrestart() or at EOF.
1860
 */
1861
    static void yy_init_buffer  (YY_BUFFER_STATE  b, FILE * file , yyscan_t yyscanner)
1862
1863
0
{
1864
0
  int oerrno = errno;
1865
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1866
1867
0
  yy_flush_buffer( b , yyscanner);
1868
1869
0
  b->yy_input_file = file;
1870
0
  b->yy_fill_buffer = 1;
1871
1872
    /* If b is the current buffer, then yy_init_buffer was _probably_
1873
     * called from yyrestart() or through yy_get_next_buffer.
1874
     * In that case, we don't want to reset the lineno or column.
1875
     */
1876
0
    if (b != YY_CURRENT_BUFFER){
1877
0
        b->yy_bs_lineno = 1;
1878
0
        b->yy_bs_column = 0;
1879
0
    }
1880
1881
0
        b->yy_is_interactive = 0;
1882
    
1883
0
  errno = oerrno;
1884
0
}
1885
1886
/** Discard all buffered characters. On the next scan, YY_INPUT will be called.
1887
 * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER.
1888
 * @param yyscanner The scanner object.
1889
 */
1890
    void yy_flush_buffer (YY_BUFFER_STATE  b , yyscan_t yyscanner)
1891
0
{
1892
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1893
0
  if ( ! b )
1894
0
    return;
1895
1896
0
  b->yy_n_chars = 0;
1897
1898
  /* We always need two end-of-buffer characters.  The first causes
1899
   * a transition to the end-of-buffer state.  The second causes
1900
   * a jam in that state.
1901
   */
1902
0
  b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR;
1903
0
  b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR;
1904
1905
0
  b->yy_buf_pos = &b->yy_ch_buf[0];
1906
1907
0
  b->yy_at_bol = 1;
1908
0
  b->yy_buffer_status = YY_BUFFER_NEW;
1909
1910
0
  if ( b == YY_CURRENT_BUFFER )
1911
0
    yy_load_buffer_state( yyscanner );
1912
0
}
1913
1914
/** Pushes the new state onto the stack. The new state becomes
1915
 *  the current state. This function will allocate the stack
1916
 *  if necessary.
1917
 *  @param new_buffer The new state.
1918
 *  @param yyscanner The scanner object.
1919
 */
1920
void yypush_buffer_state (YY_BUFFER_STATE new_buffer , yyscan_t yyscanner)
1921
0
{
1922
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1923
0
  if (new_buffer == NULL)
1924
0
    return;
1925
1926
0
  yyensure_buffer_stack(yyscanner);
1927
1928
  /* This block is copied from yy_switch_to_buffer. */
1929
0
  if ( YY_CURRENT_BUFFER )
1930
0
    {
1931
    /* Flush out information for old buffer. */
1932
0
    *yyg->yy_c_buf_p = yyg->yy_hold_char;
1933
0
    YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = yyg->yy_c_buf_p;
1934
0
    YY_CURRENT_BUFFER_LVALUE->yy_n_chars = yyg->yy_n_chars;
1935
0
    }
1936
1937
  /* Only push if top exists. Otherwise, replace top. */
1938
0
  if (YY_CURRENT_BUFFER)
1939
0
    yyg->yy_buffer_stack_top++;
1940
0
  YY_CURRENT_BUFFER_LVALUE = new_buffer;
1941
1942
  /* copied from yy_switch_to_buffer. */
1943
0
  yy_load_buffer_state( yyscanner );
1944
0
  yyg->yy_did_buffer_switch_on_eof = 1;
1945
0
}
1946
1947
/** Removes and deletes the top of the stack, if present.
1948
 *  The next element becomes the new top.
1949
 *  @param yyscanner The scanner object.
1950
 */
1951
void yypop_buffer_state (yyscan_t yyscanner)
1952
0
{
1953
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1954
0
  if (!YY_CURRENT_BUFFER)
1955
0
    return;
1956
1957
0
  yy_delete_buffer(YY_CURRENT_BUFFER , yyscanner);
1958
0
  YY_CURRENT_BUFFER_LVALUE = NULL;
1959
0
  if (yyg->yy_buffer_stack_top > 0)
1960
0
    --yyg->yy_buffer_stack_top;
1961
1962
0
  if (YY_CURRENT_BUFFER) {
1963
0
    yy_load_buffer_state( yyscanner );
1964
0
    yyg->yy_did_buffer_switch_on_eof = 1;
1965
0
  }
1966
0
}
1967
1968
/* Allocates the stack if it does not exist.
1969
 *  Guarantees space for at least one push.
1970
 */
1971
static void yyensure_buffer_stack (yyscan_t yyscanner)
1972
0
{
1973
0
  yy_size_t num_to_alloc;
1974
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
1975
1976
0
  if (!yyg->yy_buffer_stack) {
1977
1978
    /* First allocation is just for 2 elements, since we don't know if this
1979
     * scanner will even need a stack. We use 2 instead of 1 to avoid an
1980
     * immediate realloc on the next call.
1981
         */
1982
0
      num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */
1983
0
    yyg->yy_buffer_stack = (struct yy_buffer_state**)yyalloc
1984
0
                (num_to_alloc * sizeof(struct yy_buffer_state*)
1985
0
                , yyscanner);
1986
0
    if ( ! yyg->yy_buffer_stack )
1987
0
      YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
1988
1989
0
    memset(yyg->yy_buffer_stack, 0, num_to_alloc * sizeof(struct yy_buffer_state*));
1990
1991
0
    yyg->yy_buffer_stack_max = num_to_alloc;
1992
0
    yyg->yy_buffer_stack_top = 0;
1993
0
    return;
1994
0
  }
1995
1996
0
  if (yyg->yy_buffer_stack_top >= (yyg->yy_buffer_stack_max) - 1){
1997
1998
    /* Increase the buffer to prepare for a possible push. */
1999
0
    yy_size_t grow_size = 8 /* arbitrary grow size */;
2000
2001
0
    num_to_alloc = yyg->yy_buffer_stack_max + grow_size;
2002
0
    yyg->yy_buffer_stack = (struct yy_buffer_state**)yyrealloc
2003
0
                (yyg->yy_buffer_stack,
2004
0
                num_to_alloc * sizeof(struct yy_buffer_state*)
2005
0
                , yyscanner);
2006
0
    if ( ! yyg->yy_buffer_stack )
2007
0
      YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" );
2008
2009
    /* zero only the new slots.*/
2010
0
    memset(yyg->yy_buffer_stack + yyg->yy_buffer_stack_max, 0, grow_size * sizeof(struct yy_buffer_state*));
2011
0
    yyg->yy_buffer_stack_max = num_to_alloc;
2012
0
  }
2013
0
}
2014
2015
/** Setup the input buffer state to scan directly from a user-specified character buffer.
2016
 * @param base the character buffer
2017
 * @param size the size in bytes of the character buffer
2018
 * @param yyscanner The scanner object.
2019
 * @return the newly allocated buffer state object.
2020
 */
2021
YY_BUFFER_STATE yy_scan_buffer  (char * base, yy_size_t  size , yyscan_t yyscanner)
2022
0
{
2023
0
  YY_BUFFER_STATE b;
2024
    
2025
0
  if ( size < 2 ||
2026
0
       base[size-2] != YY_END_OF_BUFFER_CHAR ||
2027
0
       base[size-1] != YY_END_OF_BUFFER_CHAR )
2028
    /* They forgot to leave room for the EOB's. */
2029
0
    return NULL;
2030
2031
0
  b = (YY_BUFFER_STATE) yyalloc( sizeof( struct yy_buffer_state ) , yyscanner );
2032
0
  if ( ! b )
2033
0
    YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" );
2034
2035
0
  b->yy_buf_size = (int) (size - 2);  /* "- 2" to take care of EOB's */
2036
0
  b->yy_buf_pos = b->yy_ch_buf = base;
2037
0
  b->yy_is_our_buffer = 0;
2038
0
  b->yy_input_file = NULL;
2039
0
  b->yy_n_chars = b->yy_buf_size;
2040
0
  b->yy_is_interactive = 0;
2041
0
  b->yy_at_bol = 1;
2042
0
  b->yy_fill_buffer = 0;
2043
0
  b->yy_buffer_status = YY_BUFFER_NEW;
2044
2045
0
  yy_switch_to_buffer( b , yyscanner );
2046
2047
0
  return b;
2048
0
}
2049
2050
/** Setup the input buffer state to scan a string. The next call to yylex() will
2051
 * scan from a @e copy of @a str.
2052
 * @param yystr a NUL-terminated string to scan
2053
 * @param yyscanner The scanner object.
2054
 * @return the newly allocated buffer state object.
2055
 * @note If you want to scan bytes that may contain NUL values, then use
2056
 *       yy_scan_bytes() instead.
2057
 */
2058
YY_BUFFER_STATE yy_scan_string (const char * yystr , yyscan_t yyscanner)
2059
0
{
2060
    
2061
0
  return yy_scan_bytes( yystr, (int) strlen(yystr) , yyscanner);
2062
0
}
2063
2064
/** Setup the input buffer state to scan the given bytes. The next call to yylex() will
2065
 * scan from a @e copy of @a bytes.
2066
 * @param yybytes the byte buffer to scan
2067
 * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes.
2068
 * @param yyscanner The scanner object.
2069
 * @return the newly allocated buffer state object.
2070
 */
2071
YY_BUFFER_STATE yy_scan_bytes  (const char * yybytes, int  _yybytes_len , yyscan_t yyscanner)
2072
0
{
2073
0
  YY_BUFFER_STATE b;
2074
0
  char *buf;
2075
0
  yy_size_t n;
2076
0
  int i;
2077
    
2078
  /* Get memory for full buffer, including space for trailing EOB's. */
2079
0
  n = (yy_size_t) (_yybytes_len + 2);
2080
0
  buf = (char *) yyalloc( n , yyscanner );
2081
0
  if ( ! buf )
2082
0
    YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" );
2083
2084
0
  for ( i = 0; i < _yybytes_len; ++i )
2085
0
    buf[i] = yybytes[i];
2086
2087
0
  buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR;
2088
2089
0
  b = yy_scan_buffer( buf, n , yyscanner);
2090
0
  if ( ! b )
2091
0
    YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" );
2092
2093
  /* It's okay to grow etc. this buffer, and we should throw it
2094
   * away when we're done.
2095
   */
2096
0
  b->yy_is_our_buffer = 1;
2097
2098
0
  return b;
2099
0
}
2100
2101
#ifndef YY_EXIT_FAILURE
2102
#define YY_EXIT_FAILURE 2
2103
#endif
2104
2105
static void yynoreturn yy_fatal_error (const char* msg , yyscan_t yyscanner)
2106
0
{
2107
0
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2108
0
  (void)yyg;
2109
0
  fprintf( stderr, "%s\n", msg );
2110
0
  exit( YY_EXIT_FAILURE );
2111
0
}
2112
2113
/* Redefine yyless() so it works in section 3 code. */
2114
2115
#undef yyless
2116
#define yyless(n) \
2117
  do \
2118
    { \
2119
    /* Undo effects of setting up yytext. */ \
2120
        int yyless_macro_arg = (n); \
2121
        YY_LESS_LINENO(yyless_macro_arg);\
2122
    yytext[yyleng] = yyg->yy_hold_char; \
2123
    yyg->yy_c_buf_p = yytext + yyless_macro_arg; \
2124
    yyg->yy_hold_char = *yyg->yy_c_buf_p; \
2125
    *yyg->yy_c_buf_p = '\0'; \
2126
    yyleng = yyless_macro_arg; \
2127
    } \
2128
  while ( 0 )
2129
2130
/* Accessor  methods (get/set functions) to struct members. */
2131
2132
/** Get the user-defined data for this scanner.
2133
 * @param yyscanner The scanner object.
2134
 */
2135
YY_EXTRA_TYPE yyget_extra  (yyscan_t yyscanner)
2136
0
{
2137
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2138
0
    return yyextra;
2139
0
}
2140
2141
/** Get the current line number.
2142
 * @param yyscanner The scanner object.
2143
 */
2144
int yyget_lineno  (yyscan_t yyscanner)
2145
0
{
2146
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2147
2148
0
        if (! YY_CURRENT_BUFFER)
2149
0
            return 0;
2150
    
2151
0
    return yylineno;
2152
0
}
2153
2154
/** Get the current column number.
2155
 * @param yyscanner The scanner object.
2156
 */
2157
int yyget_column  (yyscan_t yyscanner)
2158
0
{
2159
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2160
2161
0
        if (! YY_CURRENT_BUFFER)
2162
0
            return 0;
2163
    
2164
0
    return yycolumn;
2165
0
}
2166
2167
/** Get the input stream.
2168
 * @param yyscanner The scanner object.
2169
 */
2170
FILE *yyget_in  (yyscan_t yyscanner)
2171
0
{
2172
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2173
0
    return yyin;
2174
0
}
2175
2176
/** Get the output stream.
2177
 * @param yyscanner The scanner object.
2178
 */
2179
FILE *yyget_out  (yyscan_t yyscanner)
2180
0
{
2181
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2182
0
    return yyout;
2183
0
}
2184
2185
/** Get the length of the current token.
2186
 * @param yyscanner The scanner object.
2187
 */
2188
int yyget_leng  (yyscan_t yyscanner)
2189
0
{
2190
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2191
0
    return yyleng;
2192
0
}
2193
2194
/** Get the current token.
2195
 * @param yyscanner The scanner object.
2196
 */
2197
2198
char *yyget_text  (yyscan_t yyscanner)
2199
0
{
2200
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2201
0
    return yytext;
2202
0
}
2203
2204
/** Set the user-defined data. This data is never touched by the scanner.
2205
 * @param user_defined The data to be associated with this scanner.
2206
 * @param yyscanner The scanner object.
2207
 */
2208
void yyset_extra (YY_EXTRA_TYPE  user_defined , yyscan_t yyscanner)
2209
0
{
2210
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2211
0
    yyextra = user_defined ;
2212
0
}
2213
2214
/** Set the current line number.
2215
 * @param _line_number line number
2216
 * @param yyscanner The scanner object.
2217
 */
2218
void yyset_lineno (int  _line_number , yyscan_t yyscanner)
2219
0
{
2220
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2221
2222
        /* lineno is only valid if an input buffer exists. */
2223
0
        if (! YY_CURRENT_BUFFER )
2224
0
           YY_FATAL_ERROR( "yyset_lineno called with no buffer" );
2225
    
2226
0
    yylineno = _line_number;
2227
0
}
2228
2229
/** Set the current column.
2230
 * @param _column_no column number
2231
 * @param yyscanner The scanner object.
2232
 */
2233
void yyset_column (int  _column_no , yyscan_t yyscanner)
2234
0
{
2235
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2236
2237
        /* column is only valid if an input buffer exists. */
2238
0
        if (! YY_CURRENT_BUFFER )
2239
0
           YY_FATAL_ERROR( "yyset_column called with no buffer" );
2240
    
2241
0
    yycolumn = _column_no;
2242
0
}
2243
2244
/** Set the input stream. This does not discard the current
2245
 * input buffer.
2246
 * @param _in_str A readable stream.
2247
 * @param yyscanner The scanner object.
2248
 * @see yy_switch_to_buffer
2249
 */
2250
void yyset_in (FILE *  _in_str , yyscan_t yyscanner)
2251
0
{
2252
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2253
0
    yyin = _in_str ;
2254
0
}
2255
2256
void yyset_out (FILE *  _out_str , yyscan_t yyscanner)
2257
0
{
2258
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2259
0
    yyout = _out_str ;
2260
0
}
2261
2262
int yyget_debug  (yyscan_t yyscanner)
2263
0
{
2264
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2265
0
    return yy_flex_debug;
2266
0
}
2267
2268
void yyset_debug (int  _bdebug , yyscan_t yyscanner)
2269
0
{
2270
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2271
0
    yy_flex_debug = _bdebug ;
2272
0
}
2273
2274
/* Accessor methods for yylval and yylloc */
2275
2276
YYSTYPE * yyget_lval  (yyscan_t yyscanner)
2277
0
{
2278
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2279
0
    return yylval;
2280
0
}
2281
2282
void yyset_lval (YYSTYPE *  yylval_param , yyscan_t yyscanner)
2283
0
{
2284
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2285
0
    yylval = yylval_param;
2286
0
}
2287
2288
/* User-visible API */
2289
2290
/* yylex_init is special because it creates the scanner itself, so it is
2291
 * the ONLY reentrant function that doesn't take the scanner as the last argument.
2292
 * That's why we explicitly handle the declaration, instead of using our macros.
2293
 */
2294
int yylex_init(yyscan_t* ptr_yy_globals)
2295
0
{
2296
0
    if (ptr_yy_globals == NULL){
2297
0
        errno = EINVAL;
2298
0
        return 1;
2299
0
    }
2300
2301
0
    *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), NULL );
2302
2303
0
    if (*ptr_yy_globals == NULL){
2304
0
        errno = ENOMEM;
2305
0
        return 1;
2306
0
    }
2307
2308
    /* By setting to 0xAA, we expose bugs in yy_init_globals. Leave at 0x00 for releases. */
2309
0
    memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2310
2311
0
    return yy_init_globals ( *ptr_yy_globals );
2312
0
}
2313
2314
/* yylex_init_extra has the same functionality as yylex_init, but follows the
2315
 * convention of taking the scanner as the last argument. Note however, that
2316
 * this is a *pointer* to a scanner, as it will be allocated by this call (and
2317
 * is the reason, too, why this function also must handle its own declaration).
2318
 * The user defined value in the first argument will be available to yyalloc in
2319
 * the yyextra field.
2320
 */
2321
int yylex_init_extra( YY_EXTRA_TYPE yy_user_defined, yyscan_t* ptr_yy_globals )
2322
0
{
2323
0
    struct yyguts_t dummy_yyguts;
2324
2325
0
    yyset_extra (yy_user_defined, &dummy_yyguts);
2326
2327
0
    if (ptr_yy_globals == NULL){
2328
0
        errno = EINVAL;
2329
0
        return 1;
2330
0
    }
2331
2332
0
    *ptr_yy_globals = (yyscan_t) yyalloc ( sizeof( struct yyguts_t ), &dummy_yyguts );
2333
2334
0
    if (*ptr_yy_globals == NULL){
2335
0
        errno = ENOMEM;
2336
0
        return 1;
2337
0
    }
2338
2339
    /* By setting to 0xAA, we expose bugs in
2340
    yy_init_globals. Leave at 0x00 for releases. */
2341
0
    memset(*ptr_yy_globals,0x00,sizeof(struct yyguts_t));
2342
2343
0
    yyset_extra (yy_user_defined, *ptr_yy_globals);
2344
2345
0
    return yy_init_globals ( *ptr_yy_globals );
2346
0
}
2347
2348
static int yy_init_globals (yyscan_t yyscanner)
2349
0
{
2350
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2351
    /* Initialization is the same as for the non-reentrant scanner.
2352
     * This function is called from yylex_destroy(), so don't allocate here.
2353
     */
2354
2355
0
    yyg->yy_buffer_stack = NULL;
2356
0
    yyg->yy_buffer_stack_top = 0;
2357
0
    yyg->yy_buffer_stack_max = 0;
2358
0
    yyg->yy_c_buf_p = NULL;
2359
0
    yyg->yy_init = 0;
2360
0
    yyg->yy_start = 0;
2361
2362
0
    yyg->yy_start_stack_ptr = 0;
2363
0
    yyg->yy_start_stack_depth = 0;
2364
0
    yyg->yy_start_stack =  NULL;
2365
2366
/* Defined in main.c */
2367
#ifdef YY_STDINIT
2368
    yyin = stdin;
2369
    yyout = stdout;
2370
#else
2371
0
    yyin = NULL;
2372
0
    yyout = NULL;
2373
0
#endif
2374
2375
    /* For future reference: Set errno on error, since we are called by
2376
     * yylex_init()
2377
     */
2378
0
    return 0;
2379
0
}
2380
2381
/* yylex_destroy is for both reentrant and non-reentrant scanners. */
2382
int yylex_destroy  (yyscan_t yyscanner)
2383
0
{
2384
0
    struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2385
2386
    /* Pop the buffer stack, destroying each element. */
2387
0
  while(YY_CURRENT_BUFFER){
2388
0
    yy_delete_buffer( YY_CURRENT_BUFFER , yyscanner );
2389
0
    YY_CURRENT_BUFFER_LVALUE = NULL;
2390
0
    yypop_buffer_state(yyscanner);
2391
0
  }
2392
2393
  /* Destroy the stack itself. */
2394
0
  yyfree(yyg->yy_buffer_stack , yyscanner);
2395
0
  yyg->yy_buffer_stack = NULL;
2396
2397
    /* Destroy the start condition stack. */
2398
0
        yyfree( yyg->yy_start_stack , yyscanner );
2399
0
        yyg->yy_start_stack = NULL;
2400
2401
    /* Reset the globals. This is important in a non-reentrant scanner so the next time
2402
     * yylex() is called, initialization will occur. */
2403
0
    yy_init_globals( yyscanner);
2404
2405
    /* Destroy the main struct (reentrant only). */
2406
0
    yyfree ( yyscanner , yyscanner );
2407
0
    yyscanner = NULL;
2408
0
    return 0;
2409
0
}
2410
2411
/*
2412
 * Internal utility routines.
2413
 */
2414
2415
#ifndef yytext_ptr
2416
static void yy_flex_strncpy (char* s1, const char * s2, int n , yyscan_t yyscanner)
2417
{
2418
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2419
  (void)yyg;
2420
2421
  int i;
2422
  for ( i = 0; i < n; ++i )
2423
    s1[i] = s2[i];
2424
}
2425
#endif
2426
2427
#ifdef YY_NEED_STRLEN
2428
static int yy_flex_strlen (const char * s , yyscan_t yyscanner)
2429
{
2430
  int n;
2431
  for ( n = 0; s[n]; ++n )
2432
    ;
2433
2434
  return n;
2435
}
2436
#endif
2437
2438
void *yyalloc (yy_size_t  size , yyscan_t yyscanner)
2439
0
{
2440
0
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2441
0
  (void)yyg;
2442
0
  return malloc(size);
2443
0
}
2444
2445
void *yyrealloc  (void * ptr, yy_size_t  size , yyscan_t yyscanner)
2446
0
{
2447
0
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2448
0
  (void)yyg;
2449
2450
  /* The cast to (char *) in the following accommodates both
2451
   * implementations that use char* generic pointers, and those
2452
   * that use void* generic pointers.  It works with the latter
2453
   * because both ANSI C and C++ allow castless assignment from
2454
   * any pointer type to void*, and deal with argument conversions
2455
   * as though doing an assignment.
2456
   */
2457
0
  return realloc(ptr, size);
2458
0
}
2459
2460
void yyfree (void * ptr , yyscan_t yyscanner)
2461
0
{
2462
0
  struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
2463
0
  (void)yyg;
2464
0
  free( (char *) ptr ); /* see yyrealloc() for (char *) cast */
2465
0
}
2466
2467
#define YYTABLES_NAME "yytables"
2468
2469
#line 231 "libyara/hex_lexer.l"
2470
2471
2472
//
2473
// yyfatal (actually named hex_yyfatal because of the '%option prefix="hex_yy"'
2474
// directive) is called when a fatal error occurs in the parser. When this
2475
// happens we are deep inside the parsing logic generated by flex/bison and
2476
// the only way to exit gracefully from there is using setjmp/longjmp.
2477
//
2478
void yyfatal(
2479
    yyscan_t yyscanner,
2480
    const char *error_message)
2481
0
{
2482
0
  jmp_buf* recovery_trampoline = (jmp_buf*) yr_thread_storage_get_value(
2483
0
      &yr_yyfatal_trampoline_tls);
2484
2485
  // Never returns.
2486
0
  longjmp(*recovery_trampoline, 1);
2487
0
}
2488
2489
void yyerror(
2490
    yyscan_t yyscanner,
2491
    HEX_LEX_ENVIRONMENT* lex_env,
2492
    const char *error_message)
2493
0
{
2494
  // if lex_env->last_error was set to some error code before
2495
  // don't overwrite it, we are interested in the first error, not in
2496
  // subsequent errors like "syntax error, unexpected $end" caused by
2497
  // early parser termination.
2498
2499
0
  if (lex_env->last_error == ERROR_SUCCESS)
2500
0
  {
2501
0
    lex_env->last_error = ERROR_INVALID_HEX_STRING;
2502
2503
0
    strlcpy(
2504
0
        lex_env->last_error_message,
2505
0
        error_message,
2506
0
        sizeof(lex_env->last_error_message));
2507
0
  }
2508
0
}
2509
2510
2511
int yr_parse_hex_string(
2512
    const char* hex_string,
2513
    RE_AST** re_ast,
2514
    RE_ERROR* error)
2515
0
{
2516
0
  yyscan_t yyscanner;
2517
0
  jmp_buf recovery_trampoline;
2518
0
  HEX_LEX_ENVIRONMENT lex_env;
2519
2520
0
  lex_env.last_error = ERROR_SUCCESS;
2521
0
  lex_env.inside_or = 0;
2522
2523
0
  yr_thread_storage_set_value(
2524
0
     &yr_yyfatal_trampoline_tls,
2525
0
     &recovery_trampoline);
2526
2527
0
  if (setjmp(recovery_trampoline) != 0)
2528
0
    return ERROR_INTERNAL_FATAL_ERROR;
2529
2530
0
  FAIL_ON_ERROR(yr_re_ast_create(re_ast));
2531
2532
  // The RE_FLAGS_FAST_REGEXP flag indicates a regular expression can be
2533
  // matched by faster algorithm. These regular expressions come from hex
2534
  // strings that do not contain alternatives, like in:
2535
  //
2536
  // { ( 01 02 | 03 04) 05 06 }.
2537
  //
2538
  // This flag is unset later during parsing if alternatives are used.
2539
2540
0
  (*re_ast)->flags |= RE_FLAGS_FAST_REGEXP;
2541
2542
  // Set RE_FLAGS_DOT_ALL because in hex strings the "dot" (?? in this case)
2543
  // must match all characters including new-line.
2544
2545
0
  (*re_ast)->flags |= RE_FLAGS_DOT_ALL;
2546
2547
0
  if (yylex_init(&yyscanner) != 0)
2548
0
  {
2549
0
    yr_re_ast_destroy(*re_ast);
2550
0
    *re_ast = NULL;
2551
0
    return ERROR_INSUFFICIENT_MEMORY;
2552
0
  }
2553
2554
0
  yyset_extra(*re_ast, yyscanner);
2555
0
  yy_scan_string(hex_string, yyscanner);
2556
0
  yyparse(yyscanner, &lex_env);
2557
0
  yylex_destroy(yyscanner);
2558
2559
0
  if (lex_env.last_error != ERROR_SUCCESS)
2560
0
  {
2561
0
    strlcpy(error->message, lex_env.last_error_message, sizeof(error->message));
2562
0
    return lex_env.last_error;
2563
0
  }
2564
2565
0
  return ERROR_SUCCESS;
2566
0
}
2567