Changeset 423
- Timestamp:
- 03/25/06 20:52:18 (3 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nepenthes/trunk/modules/shellcode-signatures/parser.y
r422 r423 5 5 #include <stdio.h> 6 6 #include <memory.h> 7 #include <errno.h> 7 8 8 9 #include "parser.h" … … 22 23 static char *get_mapping_by_numeric(int num); 23 24 25 static char error_buffer[0xff]; 24 26 %} 25 27 … … 284 286 int yyerror(char* s) 285 287 { 286 printf(" %s at '%s' on line %d\n", s, yytext, line_number ); 288 snprintf(error_buffer, sizeof(error_buffer), 289 "%s at '%s' on line %d", s, yytext, line_number); 287 290 return 0; 288 291 } … … 296 299 struct shellcode *sc_parse_file(const char *filename) 297 300 { 301 yyin = fopen(filename, "r"); 302 303 if( yyin == NULL ) 304 { 305 snprintf(error_buffer, sizeof(error_buffer), "%s", strerror(errno)); 306 return NULL; 307 } 308 298 309 init_shellcode(); 299 300 yyin = fopen(filename, "r");301 302 if( yyin == NULL )310 if( yyparse() != 0 ) 311 { 312 fclose(yyin); 313 /* TODO free partially alloc'd shellcodes */ 303 314 return NULL; 304 305 yyparse(); 315 } 306 316 fclose(yyin); 307 317 … … 311 321 char *sc_get_error() 312 322 { 313 return "no idea";314 } 323 return error_buffer; 324 } nepenthes/trunk/modules/shellcode-signatures/y.tab.c
r422 r423 133 133 #include <stdio.h> 134 134 #include <memory.h> 135 #include <errno.h> 135 136 136 137 #include "parser.h" … … 150 151 static char *get_mapping_by_numeric(int num); 151 152 153 static char error_buffer[0xff]; 152 154 153 155 … … 178 180 179 181 /* Line 214 of yacc.c. */ 180 #line 18 1"y.tab.c"182 #line 183 "y.tab.c" 181 183 182 184 #if ! defined (yyoverflow) || YYERROR_VERBOSE … … 366 368 static const unsigned char yyrline[] = 367 369 { 368 0, 4 4, 44, 46, 50, 75, 83, 88, 93, 98,369 10 3, 108, 113, 118, 123, 128, 133, 138, 144, 146,370 15 0, 154, 155, 156, 160, 167, 171, 174, 176, 180,371 18 4, 188, 192, 196, 200, 204, 211, 219, 221370 0, 46, 46, 48, 52, 77, 85, 90, 95, 100, 371 105, 110, 115, 120, 125, 130, 135, 140, 146, 148, 372 152, 156, 157, 158, 162, 169, 173, 176, 178, 182, 373 186, 190, 194, 198, 202, 206, 213, 221, 223 372 374 }; 373 375 #endif … … 1106 1108 { 1107 1109 case 4: 1108 #line 5 1"parser.y"1110 #line 53 "parser.y" 1109 1111 { 1110 1112 int i; … … 1131 1133 1132 1134 case 5: 1133 #line 7 6"parser.y"1135 #line 78 "parser.y" 1134 1136 { 1135 1137 shellcodes->name = strndup(string_get_buffer(), string_get_len()); … … 1139 1141 1140 1142 case 6: 1141 #line 8 4"parser.y"1143 #line 86 "parser.y" 1142 1144 { 1143 1145 shellcodes->nspace = sc_xor; … … 1146 1148 1147 1149 case 7: 1148 #line 89"parser.y"1150 #line 91 "parser.y" 1149 1151 { 1150 1152 shellcodes->nspace = sc_linkxor; … … 1153 1155 1154 1156 case 8: 1155 #line 9 4"parser.y"1157 #line 96 "parser.y" 1156 1158 { 1157 1159 shellcodes->nspace = sc_konstanzxor; … … 1160 1162 1161 1163 case 9: 1162 #line 99"parser.y"1164 #line 101 "parser.y" 1163 1165 { 1164 1166 shellcodes->nspace = sc_leimbachxor; … … 1167 1169 1168 1170 case 10: 1169 #line 10 4"parser.y"1171 #line 106 "parser.y" 1170 1172 { 1171 1173 shellcodes->nspace = sc_bindshell; … … 1174 1176 1175 1177 case 11: 1176 #line 1 09"parser.y"1178 #line 111 "parser.y" 1177 1179 { 1178 1180 shellcodes->nspace = sc_connectbackshell; … … 1181 1183 1182 1184 case 12: 1183 #line 11 4"parser.y"1185 #line 116 "parser.y" 1184 1186 { 1185 1187 shellcodes->nspace = sc_connectbackfiletransfer; … … 1188 1190 1189 1191 case 13: 1190 #line 1 19"parser.y"1192 #line 121 "parser.y" 1191 1193 { 1192 1194 shellcodes->nspace = sc_execute; … … 1195 1197 1196 1198 case 14: 1197 #line 12 4"parser.y"1199 #line 126 "parser.y" 1198 1200 { 1199 1201 shellcodes->nspace = sc_download; … … 1202 1204 1203 1205 case 15: 1204 #line 1 29"parser.y"1206 #line 131 "parser.y" 1205 1207 { 1206 1208 shellcodes->nspace = sc_url; … … 1209 1211 1210 1212 case 16: 1211 #line 13 4"parser.y"1213 #line 136 "parser.y" 1212 1214 { 1213 1215 shellcodes->nspace = sc_link; … … 1216 1218 1217 1219 case 17: 1218 #line 1 39"parser.y"1220 #line 141 "parser.y" 1219 1221 { 1220 1222 shellcodes->nspace = sc_blink; … … 1223 1225 1224 1226 case 24: 1225 #line 16 1"parser.y"1227 #line 163 "parser.y" 1226 1228 { 1227 1229 printf("flags none...\n"); … … 1230 1232 1231 1233 case 29: 1232 #line 18 1"parser.y"1234 #line 183 "parser.y" 1233 1235 { 1234 1236 shellcodes->map[shellcodes->map_items++] = key; … … 1237 1239 1238 1240 case 30: 1239 #line 18 5"parser.y"1241 #line 187 "parser.y" 1240 1242 { 1241 1243 shellcodes->map[shellcodes->map_items++] = size; … … 1244 1246 1245 1247 case 31: 1246 #line 1 89"parser.y"1248 #line 191 "parser.y" 1247 1249 { 1248 1250 shellcodes->map[shellcodes->map_items++] = sizeinvert; … … 1251 1253 1252 1254 case 32: 1253 #line 19 3"parser.y"1255 #line 195 "parser.y" 1254 1256 { 1255 1257 shellcodes->map[shellcodes->map_items++] = port; … … 1258 1260 1259 1261 case 33: 1260 #line 19 7"parser.y"1262 #line 199 "parser.y" 1261 1263 { 1262 1264 shellcodes->map[shellcodes->map_items++] = host; … … 1265 1267 1266 1268 case 34: 1267 #line 20 1"parser.y"1269 #line 203 "parser.y" 1268 1270 { 1269 1271 shellcodes->map[shellcodes->map_items++] = command; … … 1272 1274 1273 1275 case 35: 1274 #line 20 5"parser.y"1276 #line 207 "parser.y" 1275 1277 { 1276 1278 shellcodes->map[shellcodes->map_items++] = uri; … … 1279 1281 1280 1282 case 36: 1281 #line 21 2"parser.y"1283 #line 214 "parser.y" 1282 1284 { 1283 1285 shellcodes->pattern = strndup(string_get_buffer(), string_get_len()); … … 1291 1293 1292 1294 /* Line 1010 of yacc.c. */ 1293 #line 129 4"y.tab.c"1295 #line 1296 "y.tab.c" 1294 1296 1295 1297 yyvsp -= yylen; … … 1516 1518 1517 1519 1518 #line 22 4"parser.y"1520 #line 226 "parser.y" 1519 1521 1520 1522 … … 1579 1581 int yyerror(char* s) 1580 1582 { 1581 printf(" %s at '%s' on line %d\n", s, yytext, line_number ); 1583 snprintf(error_buffer, sizeof(error_buffer), 1584 "%s at '%s' on line %d", s, yytext, line_number); 1582 1585 return 0; 1583 1586 } … … 1591 1594 struct shellcode *sc_parse_file(const char *filename) 1592 1595 { 1593 init_shellcode();1594 1595 1596 yyin = fopen(filename, "r"); 1596 1597 1597 1598 if( yyin == NULL ) 1599 { 1600 snprintf(error_buffer, sizeof(error_buffer), "%s", strerror(errno)); 1598 1601 return NULL; 1599 1600 yyparse(); 1602 } 1603 1604 init_shellcode(); 1605 if( yyparse() != 0 ) 1606 { 1607 fclose(yyin); 1608 /* TODO free partially alloc'd shellcodes */ 1609 return NULL; 1610 } 1601 1611 fclose(yyin); 1602 1612 … … 1606 1616 char *sc_get_error() 1607 1617 { 1608 return "no idea";1609 } 1610 1618 return error_buffer; 1619 } 1620
