1 /* A Bison parser, made by GNU Bison 2.3.  */
2 
3 /* Skeleton implementation for Bison's Yacc-like parsers in C
4 
5    Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004, 2005, 2006
6    Free Software Foundation, Inc.
7 
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2, or (at your option)
11    any later version.
12 
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17 
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor,
21    Boston, MA 02110-1301, USA.  */
22 
23 /* As a special exception, you may create a larger work that contains
24    part or all of the Bison parser skeleton and distribute that work
25    under terms of your choice, so long as that work isn't itself a
26    parser generator using the skeleton or a modified version thereof
27    as a parser skeleton.  Alternatively, if you modify or redistribute
28    the parser skeleton itself, you may (at your option) remove this
29    special exception, which will cause the skeleton and the resulting
30    Bison output files to be licensed under the GNU General Public
31    License without this special exception.
32 
33    This special exception was added by the Free Software Foundation in
34    version 2.2 of Bison.  */
35 
36 /* C LALR(1) parser skeleton written by Richard Stallman, by
37    simplifying the original so-called "semantic" parser.  */
38 
39 /* All symbols defined below should begin with yy or YY, to avoid
40    infringing on user name space.  This should be done even for local
41    variables, as they might otherwise be expanded by user macros.
42    There are some unavoidable exceptions within include files to
43    define necessary library symbols; they are noted "INFRINGES ON
44    USER NAME SPACE" below.  */
45 
46 /* Identify Bison output.  */
47 #define YYBISON 1
48 
49 /* Bison version.  */
50 #define YYBISON_VERSION "2.3"
51 
52 /* Skeleton name.  */
53 #define YYSKELETON_NAME "yacc.c"
54 
55 /* Pure parsers.  */
56 #define YYPURE 0
57 
58 /* Using locations.  */
59 #define YYLSP_NEEDED 0
60 
61 
62 
63 /* Tokens.  */
64 #ifndef YYTOKENTYPE
65 # define YYTOKENTYPE
66    /* Put the tokens into the symbol table, so that GDB and other debuggers
67       know about them.  */
68    enum yytokentype {
69      SC_ID = 258,
70      SC_LPAR = 259,
71      SC_RPAR = 260,
72      SC_LBR = 261,
73      SC_RBR = 262,
74      SC_COMMA = 263,
75      SC_SEMI = 264,
76      SC_COLON = 265,
77      SC_NONE = 266,
78      SC_FLAGS = 267,
79      SC_PATTERN = 268,
80      SC_TYPE = 269,
81      SC_MAPPING = 270,
82      SC_STRING = 271,
83      SC_XOR = 272,
84      SC_LINKXOR = 273,
85      SC_KONSTANZXOR = 274,
86      SC_LEIMBACHXOR = 275,
87      SC_ALPHANUMERICXOR = 276,
88      SC_BIND_SHELL = 277,
89      SC_CONNECTBACK_SHELL = 278,
90      SC_CONNECTBACK_FILETRANSFER = 279,
91      SC_BIND_FILETRANSFER = 280,
92      SC_EXECUTE = 281,
93      SC_DOWNLOAD = 282,
94      SC_URL = 283,
95      SC_BASE64 = 284,
96      SC_KEY = 285,
97      SC_SUBKEY = 286,
98      SC_SIZE = 287,
99      SC_SIZEINVERT = 288,
100      SC_HOST = 289,
101      SC_PORT = 290,
102      SC_COMMAND = 291,
103      SC_URI = 292,
104      SC_DECODER = 293,
105      SC_PRELOAD = 294,
106      SC_POSTLOAD = 295,
107      SC_HOSTKEY = 296,
108      SC_PORTKEY = 297,
109      SC_PAYLOAD = 298
110    };
111 #endif
112 /* Tokens.  */
113 #define SC_ID 258
114 #define SC_LPAR 259
115 #define SC_RPAR 260
116 #define SC_LBR 261
117 #define SC_RBR 262
118 #define SC_COMMA 263
119 #define SC_SEMI 264
120 #define SC_COLON 265
121 #define SC_NONE 266
122 #define SC_FLAGS 267
123 #define SC_PATTERN 268
124 #define SC_TYPE 269
125 #define SC_MAPPING 270
126 #define SC_STRING 271
127 #define SC_XOR 272
128 #define SC_LINKXOR 273
129 #define SC_KONSTANZXOR 274
130 #define SC_LEIMBACHXOR 275
131 #define SC_ALPHANUMERICXOR 276
132 #define SC_BIND_SHELL 277
133 #define SC_CONNECTBACK_SHELL 278
134 #define SC_CONNECTBACK_FILETRANSFER 279
135 #define SC_BIND_FILETRANSFER 280
136 #define SC_EXECUTE 281
137 #define SC_DOWNLOAD 282
138 #define SC_URL 283
139 #define SC_BASE64 284
140 #define SC_KEY 285
141 #define SC_SUBKEY 286
142 #define SC_SIZE 287
143 #define SC_SIZEINVERT 288
144 #define SC_HOST 289
145 #define SC_PORT 290
146 #define SC_COMMAND 291
147 #define SC_URI 292
148 #define SC_DECODER 293
149 #define SC_PRELOAD 294
150 #define SC_POSTLOAD 295
151 #define SC_HOSTKEY 296
152 #define SC_PORTKEY 297
153 #define SC_PAYLOAD 298
154 
155 
156 
157 
158 /* Copy the first part of user declarations.  */
159 #line 2 "signature_parser.y"
160 
161 	#define _GNU_SOURCE
162 	#include <string.h>
163 	#include <stdio.h>
164 	#include <memory.h>
165 	#include <errno.h>
166 
167 	#include "config.h"
168 	#include "parser.h"
169 
170 
171 	inline void string_reset();
172 	inline char *string_get_buffer();
173 	inline int string_get_len();
174 
175 	extern char *yytext;
176 	extern int yyleng;
177 	extern FILE *yyin;
178 
179 	static struct sc_shellcode *shellcodes = NULL;
180 	extern int line_number;
181 
182 	static struct sc_shellcode *init_shellcode();
183 
184 	static char error_buffer[0xff];
185 
186 #ifndef HAVE_STRNDUP
187 	extern char *strndup(const char *, size_t len);
188 #endif
189 
190 
191 
192 /* Enabling traces.  */
193 #ifndef YYDEBUG
194 # define YYDEBUG 0
195 #endif
196 
197 /* Enabling verbose error messages.  */
198 #ifdef YYERROR_VERBOSE
199 # undef YYERROR_VERBOSE
200 # define YYERROR_VERBOSE 1
201 #else
202 # define YYERROR_VERBOSE 0
203 #endif
204 
205 /* Enabling the token table.  */
206 #ifndef YYTOKEN_TABLE
207 # define YYTOKEN_TABLE 0
208 #endif
209 
210 #if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
211 typedef int YYSTYPE;
212 # define yystype YYSTYPE /* obsolescent; will be withdrawn */
213 # define YYSTYPE_IS_DECLARED 1
214 # define YYSTYPE_IS_TRIVIAL 1
215 #endif
216 
217 
218 
219 /* Copy the second part of user declarations.  */
220 
221 
222 /* Line 216 of yacc.c.  */
223 #line 224 "signature_parser.c"
224 
225 #ifdef short
226 # undef short
227 #endif
228 
229 #ifdef YYTYPE_UINT8
230 typedef YYTYPE_UINT8 yytype_uint8;
231 #else
232 typedef unsigned char yytype_uint8;
233 #endif
234 
235 #ifdef YYTYPE_INT8
236 typedef YYTYPE_INT8 yytype_int8;
237 #elif (defined __STDC__ || defined __C99__FUNC__ \
238      || defined __cplusplus || defined _MSC_VER)
239 typedef signed char yytype_int8;
240 #else
241 typedef short int yytype_int8;
242 #endif
243 
244 #ifdef YYTYPE_UINT16
245 typedef YYTYPE_UINT16 yytype_uint16;
246 #else
247 typedef unsigned short int yytype_uint16;
248 #endif
249 
250 #ifdef YYTYPE_INT16
251 typedef YYTYPE_INT16 yytype_int16;
252 #else
253 typedef short int yytype_int16;
254 #endif
255 
256 #ifndef YYSIZE_T
257 # ifdef __SIZE_TYPE__
258 #  define YYSIZE_T __SIZE_TYPE__
259 # elif defined size_t
260 #  define YYSIZE_T size_t
261 # elif ! defined YYSIZE_T && (defined __STDC__ || defined __C99__FUNC__ \
262      || defined __cplusplus || defined _MSC_VER)
263 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
264 #  define YYSIZE_T size_t
265 # else
266 #  define YYSIZE_T unsigned int
267 # endif
268 #endif
269 
270 #define YYSIZE_MAXIMUM ((YYSIZE_T) -1)
271 
272 #ifndef YY_
273 # if YYENABLE_NLS
274 #  if ENABLE_NLS
275 #   include <libintl.h> /* INFRINGES ON USER NAME SPACE */
276 #   define YY_(msgid) dgettext ("bison-runtime", msgid)
277 #  endif
278 # endif
279 # ifndef YY_
280 #  define YY_(msgid) msgid
281 # endif
282 #endif
283 
284 /* Suppress unused-variable warnings by "using" E.  */
285 #if ! defined lint || defined __GNUC__
286 # define YYUSE(e) ((void) (e))
287 #else
288 # define YYUSE(e) /* empty */
289 #endif
290 
291 /* Identity function, used to suppress warnings about constant conditions.  */
292 #ifndef lint
293 # define YYID(n) (n)
294 #else
295 #if (defined __STDC__ || defined __C99__FUNC__ \
296      || defined __cplusplus || defined _MSC_VER)
297 static int
YYID(int i)298 YYID (int i)
299 #else
300 static int
301 YYID (i)
302     int i;
303 #endif
304 {
305   return i;
306 }
307 #endif
308 
309 #if ! defined yyoverflow || YYERROR_VERBOSE
310 
311 /* The parser invokes alloca or malloc; define the necessary symbols.  */
312 
313 # ifdef YYSTACK_USE_ALLOCA
314 #  if YYSTACK_USE_ALLOCA
315 #   ifdef __GNUC__
316 #    define YYSTACK_ALLOC __builtin_alloca
317 #   elif defined __BUILTIN_VA_ARG_INCR
318 #    include <alloca.h> /* INFRINGES ON USER NAME SPACE */
319 #   elif defined _AIX
320 #    define YYSTACK_ALLOC __alloca
321 #   elif defined _MSC_VER
322 #    include <malloc.h> /* INFRINGES ON USER NAME SPACE */
323 #    define alloca _alloca
324 #   else
325 #    define YYSTACK_ALLOC alloca
326 #    if ! defined _ALLOCA_H && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
327      || defined __cplusplus || defined _MSC_VER)
328 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
329 #     ifndef _STDLIB_H
330 #      define _STDLIB_H 1
331 #     endif
332 #    endif
333 #   endif
334 #  endif
335 # endif
336 
337 # ifdef YYSTACK_ALLOC
338    /* Pacify GCC's `empty if-body' warning.  */
339 #  define YYSTACK_FREE(Ptr) do { /* empty */; } while (YYID (0))
340 #  ifndef YYSTACK_ALLOC_MAXIMUM
341     /* The OS might guarantee only one guard page at the bottom of the stack,
342        and a page size can be as small as 4096 bytes.  So we cannot safely
343        invoke alloca (N) if N exceeds 4096.  Use a slightly smaller number
344        to allow for a few compiler-allocated temporary stack slots.  */
345 #   define YYSTACK_ALLOC_MAXIMUM 4032 /* reasonable circa 2006 */
346 #  endif
347 # else
348 #  define YYSTACK_ALLOC YYMALLOC
349 #  define YYSTACK_FREE YYFREE
350 #  ifndef YYSTACK_ALLOC_MAXIMUM
351 #   define YYSTACK_ALLOC_MAXIMUM YYSIZE_MAXIMUM
352 #  endif
353 #  if (defined __cplusplus && ! defined _STDLIB_H \
354        && ! ((defined YYMALLOC || defined malloc) \
355 	     && (defined YYFREE || defined free)))
356 #   include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
357 #   ifndef _STDLIB_H
358 #    define _STDLIB_H 1
359 #   endif
360 #  endif
361 #  ifndef YYMALLOC
362 #   define YYMALLOC malloc
363 #   if ! defined malloc && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
364      || defined __cplusplus || defined _MSC_VER)
365 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
366 #   endif
367 #  endif
368 #  ifndef YYFREE
369 #   define YYFREE free
370 #   if ! defined free && ! defined _STDLIB_H && (defined __STDC__ || defined __C99__FUNC__ \
371      || defined __cplusplus || defined _MSC_VER)
372 void free (void *); /* INFRINGES ON USER NAME SPACE */
373 #   endif
374 #  endif
375 # endif
376 #endif /* ! defined yyoverflow || YYERROR_VERBOSE */
377 
378 
379 #if (! defined yyoverflow \
380      && (! defined __cplusplus \
381 	 || (defined YYSTYPE_IS_TRIVIAL && YYSTYPE_IS_TRIVIAL)))
382 
383 /* A type that is properly aligned for any stack member.  */
384 union yyalloc
385 {
386   yytype_int16 yyss;
387   YYSTYPE yyvs;
388   };
389 
390 /* The size of the maximum gap between one aligned stack and the next.  */
391 # define YYSTACK_GAP_MAXIMUM (sizeof (union yyalloc) - 1)
392 
393 /* The size of an array large to enough to hold all stacks, each with
394    N elements.  */
395 # define YYSTACK_BYTES(N) \
396      ((N) * (sizeof (yytype_int16) + sizeof (YYSTYPE)) \
397       + YYSTACK_GAP_MAXIMUM)
398 
399 /* Copy COUNT objects from FROM to TO.  The source and destination do
400    not overlap.  */
401 # ifndef YYCOPY
402 #  if defined __GNUC__ && 1 < __GNUC__
403 #   define YYCOPY(To, From, Count) \
404       __builtin_memcpy (To, From, (Count) * sizeof (*(From)))
405 #  else
406 #   define YYCOPY(To, From, Count)		\
407       do					\
408 	{					\
409 	  YYSIZE_T yyi;				\
410 	  for (yyi = 0; yyi < (Count); yyi++)	\
411 	    (To)[yyi] = (From)[yyi];		\
412 	}					\
413       while (YYID (0))
414 #  endif
415 # endif
416 
417 /* Relocate STACK from its old location to the new one.  The
418    local variables YYSIZE and YYSTACKSIZE give the old and new number of
419    elements in the stack, and YYPTR gives the new location of the
420    stack.  Advance YYPTR to a properly aligned location for the next
421    stack.  */
422 # define YYSTACK_RELOCATE(Stack)					\
423     do									\
424       {									\
425 	YYSIZE_T yynewbytes;						\
426 	YYCOPY (&yyptr->Stack, Stack, yysize);				\
427 	Stack = &yyptr->Stack;						\
428 	yynewbytes = yystacksize * sizeof (*Stack) + YYSTACK_GAP_MAXIMUM; \
429 	yyptr += yynewbytes / sizeof (*yyptr);				\
430       }									\
431     while (YYID (0))
432 
433 #endif
434 
435 /* YYFINAL -- State number of the termination state.  */
436 #define YYFINAL  2
437 /* YYLAST -- Last index in YYTABLE.  */
438 #define YYLAST   46
439 
440 /* YYNTOKENS -- Number of terminals.  */
441 #define YYNTOKENS  44
442 /* YYNNTS -- Number of nonterminals.  */
443 #define YYNNTS  15
444 /* YYNRULES -- Number of rules.  */
445 #define YYNRULES  47
446 /* YYNRULES -- Number of states.  */
447 #define YYNSTATES  62
448 
449 /* YYTRANSLATE(YYLEX) -- Bison symbol number corresponding to YYLEX.  */
450 #define YYUNDEFTOK  2
451 #define YYMAXUTOK   298
452 
453 #define YYTRANSLATE(YYX)						\
454   ((unsigned int) (YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
455 
456 /* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX.  */
457 static const yytype_uint8 yytranslate[] =
458 {
459        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
460        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
461        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
462        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
463        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
464        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
465        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
466        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
467        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
468        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
469        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
470        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
471        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
472        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
473        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
474        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
475        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
476        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
477        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
478        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
479        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
480        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
481        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
482        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
483        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
484        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
485        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
486       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
487       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
488       35,    36,    37,    38,    39,    40,    41,    42,    43
489 };
490 
491 #if YYDEBUG
492 /* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
493    YYRHS.  */
494 static const yytype_uint8 yyprhs[] =
495 {
496        0,     0,     3,     4,     7,    13,    18,    20,    22,    24,
497       26,    28,    30,    32,    34,    36,    38,    40,    42,    44,
498       45,    48,    51,    53,    55,    57,    60,    65,    68,    69,
499       73,    75,    77,    79,    81,    83,    85,    87,    89,    91,
500       93,    95,    97,    99,   101,   103,   107,   108
501 };
502 
503 /* YYRHS -- A `-1'-separated list of the rules' RHS.  */
504 static const yytype_int8 yyrhs[] =
505 {
506       45,     0,    -1,    -1,    45,    46,    -1,    47,     6,    49,
507        7,     9,    -1,    48,    10,    10,     3,    -1,    17,    -1,
508       18,    -1,    19,    -1,    20,    -1,    22,    -1,    23,    -1,
509       24,    -1,    26,    -1,    27,    -1,    28,    -1,    25,    -1,
510       29,    -1,    21,    -1,    -1,    50,    49,    -1,    51,     9,
511       -1,    57,    -1,    52,    -1,    53,    -1,    12,    11,    -1,
512       15,     4,    54,     5,    -1,    55,    56,    -1,    -1,    55,
513       56,     8,    -1,    30,    -1,    31,    -1,    32,    -1,    33,
514       -1,    35,    -1,    34,    -1,    36,    -1,    37,    -1,    38,
515       -1,    39,    -1,    40,    -1,    11,    -1,    41,    -1,    42,
516       -1,    43,    -1,    13,    16,    58,    -1,    -1,    16,    58,
517       -1
518 };
519 
520 /* YYRLINE[YYN] -- source line where rule number YYN was defined.  */
521 static const yytype_uint16 yyrline[] =
522 {
523        0,    54,    54,    56,    60,    86,    95,   100,   105,   110,
524      115,   120,   125,   130,   135,   140,   145,   150,   155,   161,
525      163,   167,   171,   172,   173,   177,   184,   188,   194,   196,
526      204,   208,   212,   216,   220,   224,   228,   232,   236,   240,
527      244,   248,   252,   256,   260,   267,   275,   277
528 };
529 #endif
530 
531 #if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
532 /* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
533    First, the terminals, then, starting at YYNTOKENS, nonterminals.  */
534 static const char *const yytname[] =
535 {
536   "$end", "error", "$undefined", "SC_ID", "SC_LPAR", "SC_RPAR", "SC_LBR",
537   "SC_RBR", "SC_COMMA", "SC_SEMI", "SC_COLON", "SC_NONE", "SC_FLAGS",
538   "SC_PATTERN", "SC_TYPE", "SC_MAPPING", "SC_STRING", "SC_XOR",
539   "SC_LINKXOR", "SC_KONSTANZXOR", "SC_LEIMBACHXOR", "SC_ALPHANUMERICXOR",
540   "SC_BIND_SHELL", "SC_CONNECTBACK_SHELL", "SC_CONNECTBACK_FILETRANSFER",
541   "SC_BIND_FILETRANSFER", "SC_EXECUTE", "SC_DOWNLOAD", "SC_URL",
542   "SC_BASE64", "SC_KEY", "SC_SUBKEY", "SC_SIZE", "SC_SIZEINVERT",
543   "SC_HOST", "SC_PORT", "SC_COMMAND", "SC_URI", "SC_DECODER", "SC_PRELOAD",
544   "SC_POSTLOAD", "SC_HOSTKEY", "SC_PORTKEY", "SC_PAYLOAD", "$accept",
545   "body", "shellcode", "identifier", "namespace", "statements",
546   "statement", "inline_statement", "flags", "mapping", "map_values",
547   "map_value_comma_list", "map_value", "pattern", "strings", 0
548 };
549 #endif
550 
551 # ifdef YYPRINT
552 /* YYTOKNUM[YYLEX-NUM] -- Internal token number corresponding to
553    token YYLEX-NUM.  */
554 static const yytype_uint16 yytoknum[] =
555 {
556        0,   256,   257,   258,   259,   260,   261,   262,   263,   264,
557      265,   266,   267,   268,   269,   270,   271,   272,   273,   274,
558      275,   276,   277,   278,   279,   280,   281,   282,   283,   284,
559      285,   286,   287,   288,   289,   290,   291,   292,   293,   294,
560      295,   296,   297,   298
561 };
562 # endif
563 
564 /* YYR1[YYN] -- Symbol number of symbol that rule YYN derives.  */
565 static const yytype_uint8 yyr1[] =
566 {
567        0,    44,    45,    45,    46,    47,    48,    48,    48,    48,
568       48,    48,    48,    48,    48,    48,    48,    48,    48,    49,
569       49,    50,    51,    51,    51,    52,    53,    54,    55,    55,
570       56,    56,    56,    56,    56,    56,    56,    56,    56,    56,
571       56,    56,    56,    56,    56,    57,    58,    58
572 };
573 
574 /* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN.  */
575 static const yytype_uint8 yyr2[] =
576 {
577        0,     2,     0,     2,     5,     4,     1,     1,     1,     1,
578        1,     1,     1,     1,     1,     1,     1,     1,     1,     0,
579        2,     2,     1,     1,     1,     2,     4,     2,     0,     3,
580        1,     1,     1,     1,     1,     1,     1,     1,     1,     1,
581        1,     1,     1,     1,     1,     3,     0,     2
582 };
583 
584 /* YYDEFACT[STATE-NAME] -- Default rule to reduce with in state
585    STATE-NUM when YYTABLE doesn't specify something else to do.  Zero
586    means the default is an error.  */
587 static const yytype_uint8 yydefact[] =
588 {
589        2,     0,     1,     6,     7,     8,     9,    18,    10,    11,
590       12,    16,    13,    14,    15,    17,     3,     0,     0,    19,
591        0,     0,     0,     0,     0,    19,     0,    23,    24,    22,
592        0,    25,    46,    28,     0,    20,    21,     5,    46,    45,
593        0,     0,     4,    47,    26,    41,    30,    31,    32,    33,
594       35,    34,    36,    37,    38,    39,    40,    42,    43,    44,
595       27,    29
596 };
597 
598 /* YYDEFGOTO[NTERM-NUM].  */
599 static const yytype_int8 yydefgoto[] =
600 {
601       -1,     1,    16,    17,    18,    24,    25,    26,    27,    28,
602       40,    41,    60,    29,    39
603 };
604 
605 /* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
606    STATE-NUM.  */
607 #define YYPACT_NINF -21
608 static const yytype_int8 yypact[] =
609 {
610      -21,    16,   -21,   -21,   -21,   -21,   -21,   -21,   -21,   -21,
611      -21,   -21,   -21,   -21,   -21,   -21,   -21,    -5,    -6,   -10,
612       -4,    -3,    -9,     5,     3,   -10,     2,   -21,   -21,   -21,
613        9,   -21,    -2,   -21,     4,   -21,   -21,   -21,    -2,   -21,
614       10,   -11,   -21,   -21,   -21,   -21,   -21,   -21,   -21,   -21,
615      -21,   -21,   -21,   -21,   -21,   -21,   -21,   -21,   -21,   -21,
616       38,   -21
617 };
618 
619 /* YYPGOTO[NTERM-NUM].  */
620 static const yytype_int8 yypgoto[] =
621 {
622      -21,   -21,   -21,   -21,   -21,    -8,   -21,   -21,   -21,   -21,
623      -21,   -21,   -21,   -21,   -20
624 };
625 
626 /* YYTABLE[YYPACT[STATE-NUM]].  What to do in state STATE-NUM.  If
627    positive, shift that token.  If negative, reduce the rule which
628    number is the opposite.  If zero, do what YYDEFACT says.
629    If YYTABLE_NINF, syntax error.  */
630 #define YYTABLE_NINF -1
631 static const yytype_uint8 yytable[] =
632 {
633       45,    19,    21,    22,    20,    23,    30,    32,    31,    33,
634       34,    36,    37,    42,    38,    44,     2,    35,    43,    46,
635       47,    48,    49,    50,    51,    52,    53,    54,    55,    56,
636       57,    58,    59,     3,     4,     5,     6,     7,     8,     9,
637       10,    11,    12,    13,    14,    15,    61
638 };
639 
640 static const yytype_uint8 yycheck[] =
641 {
642       11,     6,    12,    13,    10,    15,    10,    16,    11,     4,
643        7,     9,     3,     9,    16,     5,     0,    25,    38,    30,
644       31,    32,    33,    34,    35,    36,    37,    38,    39,    40,
645       41,    42,    43,    17,    18,    19,    20,    21,    22,    23,
646       24,    25,    26,    27,    28,    29,     8
647 };
648 
649 /* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
650    symbol of state STATE-NUM.  */
651 static const yytype_uint8 yystos[] =
652 {
653        0,    45,     0,    17,    18,    19,    20,    21,    22,    23,
654       24,    25,    26,    27,    28,    29,    46,    47,    48,     6,
655       10,    12,    13,    15,    49,    50,    51,    52,    53,    57,
656       10,    11,    16,     4,     7,    49,     9,     3,    16,    58,
657       54,    55,     9,    58,     5,    11,    30,    31,    32,    33,
658       34,    35,    36,    37,    38,    39,    40,    41,    42,    43,
659       56,     8
660 };
661 
662 #define yyerrok		(yyerrstatus = 0)
663 #define yyclearin	(yychar = YYEMPTY)
664 #define YYEMPTY		(-2)
665 #define YYEOF		0
666 
667 #define YYACCEPT	goto yyacceptlab
668 #define YYABORT		goto yyabortlab
669 #define YYERROR		goto yyerrorlab
670 
671 
672 /* Like YYERROR except do call yyerror.  This remains here temporarily
673    to ease the transition to the new meaning of YYERROR, for GCC.
674    Once GCC version 2 has supplanted version 1, this can go.  */
675 
676 #define YYFAIL		goto yyerrlab
677 
678 #define YYRECOVERING()  (!!yyerrstatus)
679 
680 #define YYBACKUP(Token, Value)					\
681 do								\
682   if (yychar == YYEMPTY && yylen == 1)				\
683     {								\
684       yychar = (Token);						\
685       yylval = (Value);						\
686       yytoken = YYTRANSLATE (yychar);				\
687       YYPOPSTACK (1);						\
688       goto yybackup;						\
689     }								\
690   else								\
691     {								\
692       yyerror (YY_("syntax error: cannot back up")); \
693       YYERROR;							\
694     }								\
695 while (YYID (0))
696 
697 
698 #define YYTERROR	1
699 #define YYERRCODE	256
700 
701 
702 /* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N].
703    If N is 0, then set CURRENT to the empty location which ends
704    the previous symbol: RHS[0] (always defined).  */
705 
706 #define YYRHSLOC(Rhs, K) ((Rhs)[K])
707 #ifndef YYLLOC_DEFAULT
708 # define YYLLOC_DEFAULT(Current, Rhs, N)				\
709     do									\
710       if (YYID (N))                                                    \
711 	{								\
712 	  (Current).first_line   = YYRHSLOC (Rhs, 1).first_line;	\
713 	  (Current).first_column = YYRHSLOC (Rhs, 1).first_column;	\
714 	  (Current).last_line    = YYRHSLOC (Rhs, N).last_line;		\
715 	  (Current).last_column  = YYRHSLOC (Rhs, N).last_column;	\
716 	}								\
717       else								\
718 	{								\
719 	  (Current).first_line   = (Current).last_line   =		\
720 	    YYRHSLOC (Rhs, 0).last_line;				\
721 	  (Current).first_column = (Current).last_column =		\
722 	    YYRHSLOC (Rhs, 0).last_column;				\
723 	}								\
724     while (YYID (0))
725 #endif
726 
727 
728 /* YY_LOCATION_PRINT -- Print the location on the stream.
729    This macro was not mandated originally: define only if we know
730    we won't break user code: when these are the locations we know.  */
731 
732 #ifndef YY_LOCATION_PRINT
733 # if YYLTYPE_IS_TRIVIAL
734 #  define YY_LOCATION_PRINT(File, Loc)			\
735      fprintf (File, "%d.%d-%d.%d",			\
736 	      (Loc).first_line, (Loc).first_column,	\
737 	      (Loc).last_line,  (Loc).last_column)
738 # else
739 #  define YY_LOCATION_PRINT(File, Loc) ((void) 0)
740 # endif
741 #endif
742 
743 
744 /* YYLEX -- calling `yylex' with the right arguments.  */
745 
746 #ifdef YYLEX_PARAM
747 # define YYLEX yylex (YYLEX_PARAM)
748 #else
749 # define YYLEX yylex ()
750 #endif
751 
752 /* Enable debugging if requested.  */
753 #if YYDEBUG
754 
755 # ifndef YYFPRINTF
756 #  include <stdio.h> /* INFRINGES ON USER NAME SPACE */
757 #  define YYFPRINTF fprintf
758 # endif
759 
760 # define YYDPRINTF(Args)			\
761 do {						\
762   if (yydebug)					\
763     YYFPRINTF Args;				\
764 } while (YYID (0))
765 
766 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)			  \
767 do {									  \
768   if (yydebug)								  \
769     {									  \
770       YYFPRINTF (stderr, "%s ", Title);					  \
771       yy_symbol_print (stderr,						  \
772 		  Type, Value); \
773       YYFPRINTF (stderr, "\n");						  \
774     }									  \
775 } while (YYID (0))
776 
777 
778 /*--------------------------------.
779 | Print this symbol on YYOUTPUT.  |
780 `--------------------------------*/
781 
782 /*ARGSUSED*/
783 #if (defined __STDC__ || defined __C99__FUNC__ \
784      || defined __cplusplus || defined _MSC_VER)
785 static void
yy_symbol_value_print(FILE * yyoutput,int yytype,YYSTYPE const * const yyvaluep)786 yy_symbol_value_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
787 #else
788 static void
789 yy_symbol_value_print (yyoutput, yytype, yyvaluep)
790     FILE *yyoutput;
791     int yytype;
792     YYSTYPE const * const yyvaluep;
793 #endif
794 {
795   if (!yyvaluep)
796     return;
797 # ifdef YYPRINT
798   if (yytype < YYNTOKENS)
799     YYPRINT (yyoutput, yytoknum[yytype], *yyvaluep);
800 # else
801   YYUSE (yyoutput);
802 # endif
803   switch (yytype)
804     {
805       default:
806 	break;
807     }
808 }
809 
810 
811 /*--------------------------------.
812 | Print this symbol on YYOUTPUT.  |
813 `--------------------------------*/
814 
815 #if (defined __STDC__ || defined __C99__FUNC__ \
816      || defined __cplusplus || defined _MSC_VER)
817 static void
yy_symbol_print(FILE * yyoutput,int yytype,YYSTYPE const * const yyvaluep)818 yy_symbol_print (FILE *yyoutput, int yytype, YYSTYPE const * const yyvaluep)
819 #else
820 static void
821 yy_symbol_print (yyoutput, yytype, yyvaluep)
822     FILE *yyoutput;
823     int yytype;
824     YYSTYPE const * const yyvaluep;
825 #endif
826 {
827   if (yytype < YYNTOKENS)
828     YYFPRINTF (yyoutput, "token %s (", yytname[yytype]);
829   else
830     YYFPRINTF (yyoutput, "nterm %s (", yytname[yytype]);
831 
832   yy_symbol_value_print (yyoutput, yytype, yyvaluep);
833   YYFPRINTF (yyoutput, ")");
834 }
835 
836 /*------------------------------------------------------------------.
837 | yy_stack_print -- Print the state stack from its BOTTOM up to its |
838 | TOP (included).                                                   |
839 `------------------------------------------------------------------*/
840 
841 #if (defined __STDC__ || defined __C99__FUNC__ \
842      || defined __cplusplus || defined _MSC_VER)
843 static void
yy_stack_print(yytype_int16 * bottom,yytype_int16 * top)844 yy_stack_print (yytype_int16 *bottom, yytype_int16 *top)
845 #else
846 static void
847 yy_stack_print (bottom, top)
848     yytype_int16 *bottom;
849     yytype_int16 *top;
850 #endif
851 {
852   YYFPRINTF (stderr, "Stack now");
853   for (; bottom <= top; ++bottom)
854     YYFPRINTF (stderr, " %d", *bottom);
855   YYFPRINTF (stderr, "\n");
856 }
857 
858 # define YY_STACK_PRINT(Bottom, Top)				\
859 do {								\
860   if (yydebug)							\
861     yy_stack_print ((Bottom), (Top));				\
862 } while (YYID (0))
863 
864 
865 /*------------------------------------------------.
866 | Report that the YYRULE is going to be reduced.  |
867 `------------------------------------------------*/
868 
869 #if (defined __STDC__ || defined __C99__FUNC__ \
870      || defined __cplusplus || defined _MSC_VER)
871 static void
yy_reduce_print(YYSTYPE * yyvsp,int yyrule)872 yy_reduce_print (YYSTYPE *yyvsp, int yyrule)
873 #else
874 static void
875 yy_reduce_print (yyvsp, yyrule)
876     YYSTYPE *yyvsp;
877     int yyrule;
878 #endif
879 {
880   int yynrhs = yyr2[yyrule];
881   int yyi;
882   unsigned long int yylno = yyrline[yyrule];
883   YYFPRINTF (stderr, "Reducing stack by rule %d (line %lu):\n",
884 	     yyrule - 1, yylno);
885   /* The symbols being reduced.  */
886   for (yyi = 0; yyi < yynrhs; yyi++)
887     {
888       fprintf (stderr, "   $%d = ", yyi + 1);
889       yy_symbol_print (stderr, yyrhs[yyprhs[yyrule] + yyi],
890 		       &(yyvsp[(yyi + 1) - (yynrhs)])
891 		       		       );
892       fprintf (stderr, "\n");
893     }
894 }
895 
896 # define YY_REDUCE_PRINT(Rule)		\
897 do {					\
898   if (yydebug)				\
899     yy_reduce_print (yyvsp, Rule); \
900 } while (YYID (0))
901 
902 /* Nonzero means print parse trace.  It is left uninitialized so that
903    multiple parsers can coexist.  */
904 int yydebug;
905 #else /* !YYDEBUG */
906 # define YYDPRINTF(Args)
907 # define YY_SYMBOL_PRINT(Title, Type, Value, Location)
908 # define YY_STACK_PRINT(Bottom, Top)
909 # define YY_REDUCE_PRINT(Rule)
910 #endif /* !YYDEBUG */
911 
912 
913 /* YYINITDEPTH -- initial size of the parser's stacks.  */
914 #ifndef	YYINITDEPTH
915 # define YYINITDEPTH 200
916 #endif
917 
918 /* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
919    if the built-in stack extension method is used).
920 
921    Do not make this value too large; the results are undefined if
922    YYSTACK_ALLOC_MAXIMUM < YYSTACK_BYTES (YYMAXDEPTH)
923    evaluated with infinite-precision integer arithmetic.  */
924 
925 #ifndef YYMAXDEPTH
926 # define YYMAXDEPTH 10000
927 #endif
928 
929 
930 
931 #if YYERROR_VERBOSE
932 
933 # ifndef yystrlen
934 #  if defined __GLIBC__ && defined _STRING_H
935 #   define yystrlen strlen
936 #  else
937 /* Return the length of YYSTR.  */
938 #if (defined __STDC__ || defined __C99__FUNC__ \
939      || defined __cplusplus || defined _MSC_VER)
940 static YYSIZE_T
yystrlen(const char * yystr)941 yystrlen (const char *yystr)
942 #else
943 static YYSIZE_T
944 yystrlen (yystr)
945     const char *yystr;
946 #endif
947 {
948   YYSIZE_T yylen;
949   for (yylen = 0; yystr[yylen]; yylen++)
950     continue;
951   return yylen;
952 }
953 #  endif
954 # endif
955 
956 # ifndef yystpcpy
957 #  if defined __GLIBC__ && defined _STRING_H && defined _GNU_SOURCE
958 #   define yystpcpy stpcpy
959 #  else
960 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
961    YYDEST.  */
962 #if (defined __STDC__ || defined __C99__FUNC__ \
963      || defined __cplusplus || defined _MSC_VER)
964 static char *
yystpcpy(char * yydest,const char * yysrc)965 yystpcpy (char *yydest, const char *yysrc)
966 #else
967 static char *
968 yystpcpy (yydest, yysrc)
969     char *yydest;
970     const char *yysrc;
971 #endif
972 {
973   char *yyd = yydest;
974   const char *yys = yysrc;
975 
976   while ((*yyd++ = *yys++) != '\0')
977     continue;
978 
979   return yyd - 1;
980 }
981 #  endif
982 # endif
983 
984 # ifndef yytnamerr
985 /* Copy to YYRES the contents of YYSTR after stripping away unnecessary
986    quotes and backslashes, so that it's suitable for yyerror.  The
987    heuristic is that double-quoting is unnecessary unless the string
988    contains an apostrophe, a comma, or backslash (other than
989    backslash-backslash).  YYSTR is taken from yytname.  If YYRES is
990    null, do not copy; instead, return the length of what the result
991    would have been.  */
992 static YYSIZE_T
yytnamerr(char * yyres,const char * yystr)993 yytnamerr (char *yyres, const char *yystr)
994 {
995   if (*yystr == '"')
996     {
997       YYSIZE_T yyn = 0;
998       char const *yyp = yystr;
999 
1000       for (;;)
1001 	switch (*++yyp)
1002 	  {
1003 	  case '\'':
1004 	  case ',':
1005 	    goto do_not_strip_quotes;
1006 
1007 	  case '\\':
1008 	    if (*++yyp != '\\')
1009 	      goto do_not_strip_quotes;
1010 	    /* Fall through.  */
1011 	  default:
1012 	    if (yyres)
1013 	      yyres[yyn] = *yyp;
1014 	    yyn++;
1015 	    break;
1016 
1017 	  case '"':
1018 	    if (yyres)
1019 	      yyres[yyn] = '\0';
1020 	    return yyn;
1021 	  }
1022     do_not_strip_quotes: ;
1023     }
1024 
1025   if (! yyres)
1026     return yystrlen (yystr);
1027 
1028   return yystpcpy (yyres, yystr) - yyres;
1029 }
1030 # endif
1031 
1032 /* Copy into YYRESULT an error message about the unexpected token
1033    YYCHAR while in state YYSTATE.  Return the number of bytes copied,
1034    including the terminating null byte.  If YYRESULT is null, do not
1035    copy anything; just return the number of bytes that would be
1036    copied.  As a special case, return 0 if an ordinary "syntax error"
1037    message will do.  Return YYSIZE_MAXIMUM if overflow occurs during
1038    size calculation.  */
1039 static YYSIZE_T
yysyntax_error(char * yyresult,int yystate,int yychar)1040 yysyntax_error (char *yyresult, int yystate, int yychar)
1041 {
1042   int yyn = yypact[yystate];
1043 
1044   if (! (YYPACT_NINF < yyn && yyn <= YYLAST))
1045     return 0;
1046   else
1047     {
1048       int yytype = YYTRANSLATE (yychar);
1049       YYSIZE_T yysize0 = yytnamerr (0, yytname[yytype]);
1050       YYSIZE_T yysize = yysize0;
1051       YYSIZE_T yysize1;
1052       int yysize_overflow = 0;
1053       enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 };
1054       char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM];
1055       int yyx;
1056 
1057 # if 0
1058       /* This is so xgettext sees the translatable formats that are
1059 	 constructed on the fly.  */
1060       YY_("syntax error, unexpected %s");
1061       YY_("syntax error, unexpected %s, expecting %s");
1062       YY_("syntax error, unexpected %s, expecting %s or %s");
1063       YY_("syntax error, unexpected %s, expecting %s or %s or %s");
1064       YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s");
1065 # endif
1066       char *yyfmt;
1067       char const *yyf;
1068       static char const yyunexpected[] = "syntax error, unexpected %s";
1069       static char const yyexpecting[] = ", expecting %s";
1070       static char const yyor[] = " or %s";
1071       char yyformat[sizeof yyunexpected
1072 		    + sizeof yyexpecting - 1
1073 		    + ((YYERROR_VERBOSE_ARGS_MAXIMUM - 2)
1074 		       * (sizeof yyor - 1))];
1075       char const *yyprefix = yyexpecting;
1076 
1077       /* Start YYX at -YYN if negative to avoid negative indexes in
1078 	 YYCHECK.  */
1079       int yyxbegin = yyn < 0 ? -yyn : 0;
1080 
1081       /* Stay within bounds of both yycheck and yytname.  */
1082       int yychecklim = YYLAST - yyn + 1;
1083       int yyxend = yychecklim < YYNTOKENS ? yychecklim : YYNTOKENS;
1084       int yycount = 1;
1085 
1086       yyarg[0] = yytname[yytype];
1087       yyfmt = yystpcpy (yyformat, yyunexpected);
1088 
1089       for (yyx = yyxbegin; yyx < yyxend; ++yyx)
1090 	if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
1091 	  {
1092 	    if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM)
1093 	      {
1094 		yycount = 1;
1095 		yysize = yysize0;
1096 		yyformat[sizeof yyunexpected - 1] = '\0';
1097 		break;
1098 	      }
1099 	    yyarg[yycount++] = yytname[yyx];
1100 	    yysize1 = yysize + yytnamerr (0, yytname[yyx]);
1101 	    yysize_overflow |= (yysize1 < yysize);
1102 	    yysize = yysize1;
1103 	    yyfmt = yystpcpy (yyfmt, yyprefix);
1104 	    yyprefix = yyor;
1105 	  }
1106 
1107       yyf = YY_(yyformat);
1108       yysize1 = yysize + yystrlen (yyf);
1109       yysize_overflow |= (yysize1 < yysize);
1110       yysize = yysize1;
1111 
1112       if (yysize_overflow)
1113 	return YYSIZE_MAXIMUM;
1114 
1115       if (yyresult)
1116 	{
1117 	  /* Avoid sprintf, as that infringes on the user's name space.
1118 	     Don't have undefined behavior even if the translation
1119 	     produced a string with the wrong number of "%s"s.  */
1120 	  char *yyp = yyresult;
1121 	  int yyi = 0;
1122 	  while ((*yyp = *yyf) != '\0')
1123 	    {
1124 	      if (*yyp == '%' && yyf[1] == 's' && yyi < yycount)
1125 		{
1126 		  yyp += yytnamerr (yyp, yyarg[yyi++]);
1127 		  yyf += 2;
1128 		}
1129 	      else
1130 		{
1131 		  yyp++;
1132 		  yyf++;
1133 		}
1134 	    }
1135 	}
1136       return yysize;
1137     }
1138 }
1139 #endif /* YYERROR_VERBOSE */
1140 
1141 
1142 /*-----------------------------------------------.
1143 | Release the memory associated to this symbol.  |
1144 `-----------------------------------------------*/
1145 
1146 /*ARGSUSED*/
1147 #if (defined __STDC__ || defined __C99__FUNC__ \
1148      || defined __cplusplus || defined _MSC_VER)
1149 static void
yydestruct(const char * yymsg,int yytype,YYSTYPE * yyvaluep)1150 yydestruct (const char *yymsg, int yytype, YYSTYPE *yyvaluep)
1151 #else
1152 static void
1153 yydestruct (yymsg, yytype, yyvaluep)
1154     const char *yymsg;
1155     int yytype;
1156     YYSTYPE *yyvaluep;
1157 #endif
1158 {
1159   YYUSE (yyvaluep);
1160 
1161   if (!yymsg)
1162     yymsg = "Deleting";
1163   YY_SYMBOL_PRINT (yymsg, yytype, yyvaluep, yylocationp);
1164 
1165   switch (yytype)
1166     {
1167 
1168       default:
1169 	break;
1170     }
1171 }
1172 
1173 
1174 /* Prevent warnings from -Wmissing-prototypes.  */
1175 
1176 #ifdef YYPARSE_PARAM
1177 #if defined __STDC__ || defined __cplusplus
1178 int yyparse (void *YYPARSE_PARAM);
1179 #else
1180 int yyparse ();
1181 #endif
1182 #else /* ! YYPARSE_PARAM */
1183 #if defined __STDC__ || defined __cplusplus
1184 int yyparse (void);
1185 #else
1186 int yyparse ();
1187 #endif
1188 #endif /* ! YYPARSE_PARAM */
1189 
1190 
1191 
1192 /* The look-ahead symbol.  */
1193 int yychar;
1194 
1195 /* The semantic value of the look-ahead symbol.  */
1196 YYSTYPE yylval;
1197 
1198 /* Number of syntax errors so far.  */
1199 int yynerrs;
1200 
1201 
1202 
1203 /*----------.
1204 | yyparse.  |
1205 `----------*/
1206 
1207 #ifdef YYPARSE_PARAM
1208 #if (defined __STDC__ || defined __C99__FUNC__ \
1209      || defined __cplusplus || defined _MSC_VER)
1210 int
yyparse(void * YYPARSE_PARAM)1211 yyparse (void *YYPARSE_PARAM)
1212 #else
1213 int
1214 yyparse (YYPARSE_PARAM)
1215     void *YYPARSE_PARAM;
1216 #endif
1217 #else /* ! YYPARSE_PARAM */
1218 #if (defined __STDC__ || defined __C99__FUNC__ \
1219      || defined __cplusplus || defined _MSC_VER)
1220 int
1221 yyparse (void)
1222 #else
1223 int
1224 yyparse ()
1225 
1226 #endif
1227 #endif
1228 {
1229 
1230   int yystate;
1231   int yyn;
1232   int yyresult;
1233   /* Number of tokens to shift before error messages enabled.  */
1234   int yyerrstatus;
1235   /* Look-ahead token as an internal (translated) token number.  */
1236   int yytoken = 0;
1237 #if YYERROR_VERBOSE
1238   /* Buffer for error messages, and its allocated size.  */
1239   char yymsgbuf[128];
1240   char *yymsg = yymsgbuf;
1241   YYSIZE_T yymsg_alloc = sizeof yymsgbuf;
1242 #endif
1243 
1244   /* Three stacks and their tools:
1245      `yyss': related to states,
1246      `yyvs': related to semantic values,
1247      `yyls': related to locations.
1248 
1249      Refer to the stacks thru separate pointers, to allow yyoverflow
1250      to reallocate them elsewhere.  */
1251 
1252   /* The state stack.  */
1253   yytype_int16 yyssa[YYINITDEPTH];
1254   yytype_int16 *yyss = yyssa;
1255   yytype_int16 *yyssp;
1256 
1257   /* The semantic value stack.  */
1258   YYSTYPE yyvsa[YYINITDEPTH];
1259   YYSTYPE *yyvs = yyvsa;
1260   YYSTYPE *yyvsp;
1261 
1262 
1263 
1264 #define YYPOPSTACK(N)   (yyvsp -= (N), yyssp -= (N))
1265 
1266   YYSIZE_T yystacksize = YYINITDEPTH;
1267 
1268   /* The variables used to return semantic value and location from the
1269      action routines.  */
1270   YYSTYPE yyval;
1271 
1272 
1273   /* The number of symbols on the RHS of the reduced rule.
1274      Keep to zero when no symbol should be popped.  */
1275   int yylen = 0;
1276 
1277   YYDPRINTF ((stderr, "Starting parse\n"));
1278 
1279   yystate = 0;
1280   yyerrstatus = 0;
1281   yynerrs = 0;
1282   yychar = YYEMPTY;		/* Cause a token to be read.  */
1283 
1284   /* Initialize stack pointers.
1285      Waste one element of value and location stack
1286      so that they stay on the same level as the state stack.
1287      The wasted elements are never initialized.  */
1288 
1289   yyssp = yyss;
1290   yyvsp = yyvs;
1291 
1292   goto yysetstate;
1293 
1294 /*------------------------------------------------------------.
1295 | yynewstate -- Push a new state, which is found in yystate.  |
1296 `------------------------------------------------------------*/
1297  yynewstate:
1298   /* In all cases, when you get here, the value and location stacks
1299      have just been pushed.  So pushing a state here evens the stacks.  */
1300   yyssp++;
1301 
1302  yysetstate:
1303   *yyssp = yystate;
1304 
1305   if (yyss + yystacksize - 1 <= yyssp)
1306     {
1307       /* Get the current used size of the three stacks, in elements.  */
1308       YYSIZE_T yysize = yyssp - yyss + 1;
1309 
1310 #ifdef yyoverflow
1311       {
1312 	/* Give user a chance to reallocate the stack.  Use copies of
1313 	   these so that the &'s don't force the real ones into
1314 	   memory.  */
1315 	YYSTYPE *yyvs1 = yyvs;
1316 	yytype_int16 *yyss1 = yyss;
1317 
1318 
1319 	/* Each stack pointer address is followed by the size of the
1320 	   data in use in that stack, in bytes.  This used to be a
1321 	   conditional around just the two extra args, but that might
1322 	   be undefined if yyoverflow is a macro.  */
1323 	yyoverflow (YY_("memory exhausted"),
1324 		    &yyss1, yysize * sizeof (*yyssp),
1325 		    &yyvs1, yysize * sizeof (*yyvsp),
1326 
1327 		    &yystacksize);
1328 
1329 	yyss = yyss1;
1330 	yyvs = yyvs1;
1331       }
1332 #else /* no yyoverflow */
1333 # ifndef YYSTACK_RELOCATE
1334       goto yyexhaustedlab;
1335 # else
1336       /* Extend the stack our own way.  */
1337       if (YYMAXDEPTH <= yystacksize)
1338 	goto yyexhaustedlab;
1339       yystacksize *= 2;
1340       if (YYMAXDEPTH < yystacksize)
1341 	yystacksize = YYMAXDEPTH;
1342 
1343       {
1344 	yytype_int16 *yyss1 = yyss;
1345 	union yyalloc *yyptr =
1346 	  (union yyalloc *) YYSTACK_ALLOC (YYSTACK_BYTES (yystacksize));
1347 	if (! yyptr)
1348 	  goto yyexhaustedlab;
1349 	YYSTACK_RELOCATE (yyss);
1350 	YYSTACK_RELOCATE (yyvs);
1351 
1352 #  undef YYSTACK_RELOCATE
1353 	if (yyss1 != yyssa)
1354 	  YYSTACK_FREE (yyss1);
1355       }
1356 # endif
1357 #endif /* no yyoverflow */
1358 
1359       yyssp = yyss + yysize - 1;
1360       yyvsp = yyvs + yysize - 1;
1361 
1362 
1363       YYDPRINTF ((stderr, "Stack size increased to %lu\n",
1364 		  (unsigned long int) yystacksize));
1365 
1366       if (yyss + yystacksize - 1 <= yyssp)
1367 	YYABORT;
1368     }
1369 
1370   YYDPRINTF ((stderr, "Entering state %d\n", yystate));
1371 
1372   goto yybackup;
1373 
1374 /*-----------.
1375 | yybackup.  |
1376 `-----------*/
1377 yybackup:
1378 
1379   /* Do appropriate processing given the current state.  Read a
1380      look-ahead token if we need one and don't already have one.  */
1381 
1382   /* First try to decide what to do without reference to look-ahead token.  */
1383   yyn = yypact[yystate];
1384   if (yyn == YYPACT_NINF)
1385     goto yydefault;
1386 
1387   /* Not known => get a look-ahead token if don't already have one.  */
1388 
1389   /* YYCHAR is either YYEMPTY or YYEOF or a valid look-ahead symbol.  */
1390   if (yychar == YYEMPTY)
1391     {
1392       YYDPRINTF ((stderr, "Reading a token: "));
1393       yychar = YYLEX;
1394     }
1395 
1396   if (yychar <= YYEOF)
1397     {
1398       yychar = yytoken = YYEOF;
1399       YYDPRINTF ((stderr, "Now at end of input.\n"));
1400     }
1401   else
1402     {
1403       yytoken = YYTRANSLATE (yychar);
1404       YY_SYMBOL_PRINT ("Next token is", yytoken, &yylval, &yylloc);
1405     }
1406 
1407   /* If the proper action on seeing token YYTOKEN is to reduce or to
1408      detect an error, take that action.  */
1409   yyn += yytoken;
1410   if (yyn < 0 || YYLAST < yyn || yycheck[yyn] != yytoken)
1411     goto yydefault;
1412   yyn = yytable[yyn];
1413   if (yyn <= 0)
1414     {
1415       if (yyn == 0 || yyn == YYTABLE_NINF)
1416 	goto yyerrlab;
1417       yyn = -yyn;
1418       goto yyreduce;
1419     }
1420 
1421   if (yyn == YYFINAL)
1422     YYACCEPT;
1423 
1424   /* Count tokens shifted since error; after three, turn off error
1425      status.  */
1426   if (yyerrstatus)
1427     yyerrstatus--;
1428 
1429   /* Shift the look-ahead token.  */
1430   YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
1431 
1432   /* Discard the shifted token unless it is eof.  */
1433   if (yychar != YYEOF)
1434     yychar = YYEMPTY;
1435 
1436   yystate = yyn;
1437   *++yyvsp = yylval;
1438 
1439   goto yynewstate;
1440 
1441 
1442 /*-----------------------------------------------------------.
1443 | yydefault -- do the default action for the current state.  |
1444 `-----------------------------------------------------------*/
1445 yydefault:
1446   yyn = yydefact[yystate];
1447   if (yyn == 0)
1448     goto yyerrlab;
1449   goto yyreduce;
1450 
1451 
1452 /*-----------------------------.
1453 | yyreduce -- Do a reduction.  |
1454 `-----------------------------*/
1455 yyreduce:
1456   /* yyn is the number of a rule to reduce with.  */
1457   yylen = yyr2[yyn];
1458 
1459   /* If YYLEN is nonzero, implement the default value of the action:
1460      `$$ = $1'.
1461 
1462      Otherwise, the following line sets YYVAL to garbage.
1463      This behavior is undocumented and Bison
1464      users should not rely upon it.  Assigning to YYVAL
1465      unconditionally makes the parser a bit smaller, and it avoids a
1466      GCC warning that YYVAL may be used uninitialized.  */
1467   yyval = yyvsp[1-yylen];
1468 
1469 
1470   YY_REDUCE_PRINT (yyn);
1471   switch (yyn)
1472     {
1473         case 4:
1474 #line 61 "signature_parser.y"
1475     {
1476 /*
1477 		printf("shellcode:\n");
1478 
1479 		printf("\tname					%s\n", shellcodes->name);
1480 		printf("\tnamespace			 %s (%d) \n", sc_get_namespace_by_numeric(shellcodes->nspace), shellcodes->nspace);
1481 //		printf("\tpattern				%s\n", shellcodes->pattern);
1482 		printf("\tmap-size			  %d\n", shellcodes->map_items);
1483 		printf("\tmap					 ");
1484 
1485 
1486 		for( i = 0; i < shellcodes->map_items; i++ )
1487 		{
1488 			printf("%s (%d) ", sc_get_mapping_by_numeric(shellcodes->map[i]),shellcodes->map[i]);
1489 		}
1490 
1491 		printf("\n\n");
1492 */
1493 
1494 		/* prepare for the next one */
1495 		init_shellcode();
1496 	}
1497     break;
1498 
1499   case 5:
1500 #line 87 "signature_parser.y"
1501     {
1502 		shellcodes->nspace = (yyvsp[(1) - (4)]);
1503 		shellcodes->name = strndup(string_get_buffer(), string_get_len());
1504 		string_reset();
1505 	}
1506     break;
1507 
1508   case 6:
1509 #line 96 "signature_parser.y"
1510     {
1511 		(yyval) = sc_xor;
1512 	}
1513     break;
1514 
1515   case 7:
1516 #line 101 "signature_parser.y"
1517     {
1518 		(yyval) = sc_linkxor;
1519 	}
1520     break;
1521 
1522   case 8:
1523 #line 106 "signature_parser.y"
1524     {
1525 		(yyval) = sc_konstanzxor;
1526 	}
1527     break;
1528 
1529   case 9:
1530 #line 111 "signature_parser.y"
1531     {
1532 		(yyval) = sc_leimbachxor;
1533 	}
1534     break;
1535 
1536   case 10:
1537 #line 116 "signature_parser.y"
1538     {
1539 		(yyval) = sc_bindshell;
1540 	}
1541     break;
1542 
1543   case 11:
1544 #line 121 "signature_parser.y"
1545     {
1546 		(yyval) = sc_connectbackshell;
1547 	}
1548     break;
1549 
1550   case 12:
1551 #line 126 "signature_parser.y"
1552     {
1553 		(yyval) = sc_connectbackfiletransfer;
1554 	}
1555     break;
1556 
1557   case 13:
1558 #line 131 "signature_parser.y"
1559     {
1560 		(yyval) = sc_execute;
1561 	}
1562     break;
1563 
1564   case 14:
1565 #line 136 "signature_parser.y"
1566     {
1567 		(yyval) = sc_download;
1568 	}
1569     break;
1570 
1571   case 15:
1572 #line 141 "signature_parser.y"
1573     {
1574 		(yyval) = sc_url;
1575 	}
1576     break;
1577 
1578   case 16:
1579 #line 146 "signature_parser.y"
1580     {
1581 		(yyval) = sc_bindfiletransfer;
1582 	}
1583     break;
1584 
1585   case 17:
1586 #line 151 "signature_parser.y"
1587     {
1588 		(yyval) = sc_base64;
1589 	}
1590     break;
1591 
1592   case 18:
1593 #line 156 "signature_parser.y"
1594     {
1595 		(yyval) = sc_alphanumericxor;
1596 	}
1597     break;
1598 
1599   case 25:
1600 #line 178 "signature_parser.y"
1601     {
1602 		printf("flags none...\n");
1603 	}
1604     break;
1605 
1606   case 27:
1607 #line 189 "signature_parser.y"
1608     {
1609 		shellcodes->map[shellcodes->map_items++] = (yyvsp[(2) - (2)]);
1610 	}
1611     break;
1612 
1613   case 29:
1614 #line 197 "signature_parser.y"
1615     {
1616 		if( shellcodes->map_items < (MAP_MAX - 1) )
1617 			shellcodes->map[shellcodes->map_items++] = (yyvsp[(2) - (3)]);
1618 	}
1619     break;
1620 
1621   case 30:
1622 #line 205 "signature_parser.y"
1623     {
1624 		(yyval) = sc_key;
1625 	}
1626     break;
1627 
1628   case 31:
1629 #line 209 "signature_parser.y"
1630     {
1631 		(yyval) = sc_subkey;
1632 	}
1633     break;
1634 
1635   case 32:
1636 #line 213 "signature_parser.y"
1637     {
1638 		(yyval) = sc_size;
1639 	}
1640     break;
1641 
1642   case 33:
1643 #line 217 "signature_parser.y"
1644     {
1645 		(yyval) = sc_sizeinvert;
1646 	}
1647     break;
1648 
1649   case 34:
1650 #line 221 "signature_parser.y"
1651     {
1652 		(yyval) = sc_port;
1653 	}
1654     break;
1655 
1656   case 35:
1657 #line 225 "signature_parser.y"
1658     {
1659 		(yyval) = sc_host;
1660 	}
1661     break;
1662 
1663   case 36:
1664 #line 229 "signature_parser.y"
1665     {
1666 		(yyval) = sc_command;
1667 	}
1668     break;
1669 
1670   case 37:
1671 #line 233 "signature_parser.y"
1672     {
1673 		(yyval) = sc_uri;
1674 	}
1675     break;
1676 
1677   case 38:
1678 #line 237 "signature_parser.y"
1679     {
1680 		(yyval) = sc_decoder;
1681 	}
1682     break;
1683 
1684   case 39:
1685 #line 241 "signature_parser.y"
1686     {
1687 		(yyval) = sc_pre;
1688 	}
1689     break;
1690 
1691   case 40:
1692 #line 245 "signature_parser.y"
1693     {
1694 		(yyval) = sc_post;
1695 	}
1696     break;
1697 
1698   case 41:
1699 #line 249 "signature_parser.y"
1700     {
1701 		(yyval) = sc_none;
1702 	}
1703     break;
1704 
1705   case 42:
1706 #line 253 "signature_parser.y"
1707     {
1708 		(yyval) = sc_hostkey;
1709 	}
1710     break;
1711 
1712   case 43:
1713 #line 257 "signature_parser.y"
1714     {
1715 		(yyval) = sc_portkey;
1716 	}
1717     break;
1718 
1719   case 44:
1720 #line 261 "signature_parser.y"
1721     {
1722 		(yyval) = sc_payload;
1723 	}
1724     break;
1725 
1726   case 45:
1727 #line 268 "signature_parser.y"
1728     {
1729 		shellcodes->pattern = strndup(string_get_buffer(), string_get_len());
1730 		shellcodes->pattern_size = string_get_len();
1731 		string_reset();
1732 	}
1733     break;
1734 
1735 
1736 /* Line 1267 of yacc.c.  */
1737 #line 1738 "signature_parser.c"
1738       default: break;
1739     }
1740   YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyn], &yyval, &yyloc);
1741 
1742   YYPOPSTACK (yylen);
1743   yylen = 0;
1744   YY_STACK_PRINT (yyss, yyssp);
1745 
1746   *++yyvsp = yyval;
1747 
1748 
1749   /* Now `shift' the result of the reduction.  Determine what state
1750      that goes to, based on the state we popped back to and the rule
1751      number reduced by.  */
1752 
1753   yyn = yyr1[yyn];
1754 
1755   yystate = yypgoto[yyn - YYNTOKENS] + *yyssp;
1756   if (0 <= yystate && yystate <= YYLAST && yycheck[yystate] == *yyssp)
1757     yystate = yytable[yystate];
1758   else
1759     yystate = yydefgoto[yyn - YYNTOKENS];
1760 
1761   goto yynewstate;
1762 
1763 
1764 /*------------------------------------.
1765 | yyerrlab -- here on detecting error |
1766 `------------------------------------*/
1767 yyerrlab:
1768   /* If not already recovering from an error, report this error.  */
1769   if (!yyerrstatus)
1770     {
1771       ++yynerrs;
1772 #if ! YYERROR_VERBOSE
1773       yyerror (YY_("syntax error"));
1774 #else
1775       {
1776 	YYSIZE_T yysize = yysyntax_error (0, yystate, yychar);
1777 	if (yymsg_alloc < yysize && yymsg_alloc < YYSTACK_ALLOC_MAXIMUM)
1778 	  {
1779 	    YYSIZE_T yyalloc = 2 * yysize;
1780 	    if (! (yysize <= yyalloc && yyalloc <= YYSTACK_ALLOC_MAXIMUM))
1781 	      yyalloc = YYSTACK_ALLOC_MAXIMUM;
1782 	    if (yymsg != yymsgbuf)
1783 	      YYSTACK_FREE (yymsg);
1784 	    yymsg = (char *) YYSTACK_ALLOC (yyalloc);
1785 	    if (yymsg)
1786 	      yymsg_alloc = yyalloc;
1787 	    else
1788 	      {
1789 		yymsg = yymsgbuf;
1790 		yymsg_alloc = sizeof yymsgbuf;
1791 	      }
1792 	  }
1793 
1794 	if (0 < yysize && yysize <= yymsg_alloc)
1795 	  {
1796 	    (void) yysyntax_error (yymsg, yystate, yychar);
1797 	    yyerror (yymsg);
1798 	  }
1799 	else
1800 	  {
1801 	    yyerror (YY_("syntax error"));
1802 	    if (yysize != 0)
1803 	      goto yyexhaustedlab;
1804 	  }
1805       }
1806 #endif
1807     }
1808 
1809 
1810 
1811   if (yyerrstatus == 3)
1812     {
1813       /* If just tried and failed to reuse look-ahead token after an
1814 	 error, discard it.  */
1815 
1816       if (yychar <= YYEOF)
1817 	{
1818 	  /* Return failure if at end of input.  */
1819 	  if (yychar == YYEOF)
1820 	    YYABORT;
1821 	}
1822       else
1823 	{
1824 	  yydestruct ("Error: discarding",
1825 		      yytoken, &yylval);
1826 	  yychar = YYEMPTY;
1827 	}
1828     }
1829 
1830   /* Else will try to reuse look-ahead token after shifting the error
1831      token.  */
1832   goto yyerrlab1;
1833 
1834 
1835 /*---------------------------------------------------.
1836 | yyerrorlab -- error raised explicitly by YYERROR.  |
1837 `---------------------------------------------------*/
1838 yyerrorlab:
1839 
1840   /* Pacify compilers like GCC when the user code never invokes
1841      YYERROR and the label yyerrorlab therefore never appears in user
1842      code.  */
1843   if (/*CONSTCOND*/ 0)
1844      goto yyerrorlab;
1845 
1846   /* Do not reclaim the symbols of the rule which action triggered
1847      this YYERROR.  */
1848   YYPOPSTACK (yylen);
1849   yylen = 0;
1850   YY_STACK_PRINT (yyss, yyssp);
1851   yystate = *yyssp;
1852   goto yyerrlab1;
1853 
1854 
1855 /*-------------------------------------------------------------.
1856 | yyerrlab1 -- common code for both syntax error and YYERROR.  |
1857 `-------------------------------------------------------------*/
1858 yyerrlab1:
1859   yyerrstatus = 3;	/* Each real token shifted decrements this.  */
1860 
1861   for (;;)
1862     {
1863       yyn = yypact[yystate];
1864       if (yyn != YYPACT_NINF)
1865 	{
1866 	  yyn += YYTERROR;
1867 	  if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
1868 	    {
1869 	      yyn = yytable[yyn];
1870 	      if (0 < yyn)
1871 		break;
1872 	    }
1873 	}
1874 
1875       /* Pop the current state because it cannot handle the error token.  */
1876       if (yyssp == yyss)
1877 	YYABORT;
1878 
1879 
1880       yydestruct ("Error: popping",
1881 		  yystos[yystate], yyvsp);
1882       YYPOPSTACK (1);
1883       yystate = *yyssp;
1884       YY_STACK_PRINT (yyss, yyssp);
1885     }
1886 
1887   if (yyn == YYFINAL)
1888     YYACCEPT;
1889 
1890   *++yyvsp = yylval;
1891 
1892 
1893   /* Shift the error token.  */
1894   YY_SYMBOL_PRINT ("Shifting", yystos[yyn], yyvsp, yylsp);
1895 
1896   yystate = yyn;
1897   goto yynewstate;
1898 
1899 
1900 /*-------------------------------------.
1901 | yyacceptlab -- YYACCEPT comes here.  |
1902 `-------------------------------------*/
1903 yyacceptlab:
1904   yyresult = 0;
1905   goto yyreturn;
1906 
1907 /*-----------------------------------.
1908 | yyabortlab -- YYABORT comes here.  |
1909 `-----------------------------------*/
1910 yyabortlab:
1911   yyresult = 1;
1912   goto yyreturn;
1913 
1914 #ifndef yyoverflow
1915 /*-------------------------------------------------.
1916 | yyexhaustedlab -- memory exhaustion comes here.  |
1917 `-------------------------------------------------*/
1918 yyexhaustedlab:
1919   yyerror (YY_("memory exhausted"));
1920   yyresult = 2;
1921   /* Fall through.  */
1922 #endif
1923 
1924 yyreturn:
1925   if (yychar != YYEOF && yychar != YYEMPTY)
1926      yydestruct ("Cleanup: discarding lookahead",
1927 		 yytoken, &yylval);
1928   /* Do not reclaim the symbols of the rule which action triggered
1929      this YYABORT or YYACCEPT.  */
1930   YYPOPSTACK (yylen);
1931   YY_STACK_PRINT (yyss, yyssp);
1932   while (yyssp != yyss)
1933     {
1934       yydestruct ("Cleanup: popping",
1935 		  yystos[*yyssp], yyvsp);
1936       YYPOPSTACK (1);
1937     }
1938 #ifndef yyoverflow
1939   if (yyss != yyssa)
1940     YYSTACK_FREE (yyss);
1941 #endif
1942 #if YYERROR_VERBOSE
1943   if (yymsg != yymsgbuf)
1944     YYSTACK_FREE (yymsg);
1945 #endif
1946   /* Make sure YYID is used.  */
1947   return YYID (yyresult);
1948 }
1949 
1950 
1951 #line 280 "signature_parser.y"
1952 
1953 
1954 #ifndef HAVE_STRNDUP
1955 // from http://www.unixpapa.com/incnote/string.html
strndup(const char * str,size_t len)1956 char *strndup(const char *str, size_t len)
1957 {
1958 	char *dup= (char *)malloc( len+1 );
1959 	if ( dup )
1960 	{
1961 		strncpy(dup,str,len);
1962 		dup[len]= '\0';
1963 	}
1964 	return dup;
1965 }
1966 #endif /* HAVE_STRNDUP */
1967 
1968 
init_shellcode()1969 struct sc_shellcode *init_shellcode()
1970 {
1971 	struct sc_shellcode *s = (struct sc_shellcode *)malloc(sizeof(struct sc_shellcode));
1972 
1973 	memset(s, 0, sizeof(struct sc_shellcode));
1974 
1975 	s->next = shellcodes;
1976 	shellcodes = s;
1977 
1978 	return s;
1979 }
1980 
free_shellcode(struct sc_shellcode * s)1981 int free_shellcode(struct sc_shellcode *s)
1982 {
1983 	free(s->name);
1984 	free(s->author);
1985 	free(s->reference);
1986 	free(s->pattern);
1987 	return 0;
1988 }
1989 
sc_free_shellcodes(struct sc_shellcode * s)1990 int sc_free_shellcodes(struct sc_shellcode *s)
1991 {
1992 	struct sc_shellcode *next = s;
1993 	int i=0;
1994 	while ((next = s->next) != NULL)
1995 	{
1996 		free_shellcode(s);
1997 		s = next;
1998 		i++;
1999 	}
2000 	return i;
2001 }
2002 
sc_get_namespace_by_numeric(int num)2003 char *sc_get_namespace_by_numeric(int num)
2004 {
2005 
2006 	static char *namespacemapping[]=
2007 	{
2008 		"xor",
2009 		"linkxor",
2010 		"konstanzxor",
2011 		"leimbachxor",
2012 		"connectbackshell",
2013 		"connectbackfiletransfer",
2014 		"bindshell",
2015 		"execute",
2016 		"download",
2017 		"url",
2018 		"bindfiletransfer",
2019 		"base64",
2020       "alphanumericxor"
2021 	};
2022 
2023 	if ( num >= sizeof(namespacemapping)/sizeof(char *) )
2024 		return "unmapped";
2025 	else
2026 		return namespacemapping[num];
2027 }
2028 
sc_get_mapping_by_numeric(int num)2029 char *sc_get_mapping_by_numeric(int num)
2030 {
2031 	static char *mapmapping[]=
2032 	{
2033 		"key",
2034 		"subkey",
2035 		"size",
2036 		"sizeinvert",
2037 		"port",
2038 		"host",
2039 		"command",
2040 		"uri",
2041 		"decoder",
2042 		"pre",
2043 		"post",
2044 		"none",
2045 		"hostkey",
2046 		"portkey",
2047       "payload"
2048 	};
2049 	if ( num >= sizeof(mapmapping)/sizeof(char *) )
2050 		return "unmapped";
2051 	else
2052 		return mapmapping[num];
2053 }
2054 
2055 
2056 
yyerror(char * s)2057 int yyerror(char* s)
2058 {
2059 	snprintf(error_buffer, sizeof(error_buffer),
2060 			 "%s at '%s' on line %d", s, yytext, line_number);
2061 	return 0;
2062 }
2063 
2064 
yywrap()2065 int yywrap()
2066 {
2067 	return 1;
2068 }
2069 
sc_parse_file(const char * filename)2070 struct sc_shellcode *sc_parse_file(const char *filename)
2071 {
2072 	yyin = fopen(filename, "r");
2073 
2074 	if ( yyin == NULL )
2075 	{
2076 		snprintf(error_buffer, sizeof(error_buffer), "%s", strerror(errno));
2077 		return NULL;
2078 	}
2079 
2080 	init_shellcode();
2081 	if ( yyparse() != 0 )
2082 	{
2083 		fclose(yyin);
2084 		/* TODO free partially alloc'd shellcodes */
2085 		return NULL;
2086 	}
2087 	fclose(yyin);
2088 // taken from shellcode-generic/sch_generic_stuttgart.cpp
2089 	return shellcodes;
2090 }
2091 
sc_get_error()2092 char *sc_get_error()
2093 {
2094 	return error_buffer;
2095 }
2096 
2097