From 87683f08c709b00cd26ff0903f91a66f934a14db Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Fri, 10 May 2013 16:34:09 +0200 Subject: trafgen: lexer: also allow short forms for hex and binary Also allow for ... - hex: 0xff, xff - binary: 0b11110000, b11110000 Signed-off-by: Daniel Borkmann --- trafgen_lexer.l | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/trafgen_lexer.l b/trafgen_lexer.l index 20b6efe..ca5bff9 100644 --- a/trafgen_lexer.l +++ b/trafgen_lexer.l @@ -71,8 +71,8 @@ static char *try_convert_shellcode(char *sstr) %option nodefault number_oct ([0][0-9]+) -number_hex ([0][x][a-fA-F0-9]+) -number_bin ([0][b][0-1]+) +number_hex ([0]?[x][a-fA-F0-9]+) +number_bin ([0]?[b][0-1]+) number_dec (([0])|([1-9][0-9]*)) number_ascii ([a-zA-Z]) @@ -128,7 +128,8 @@ number_ascii ([a-zA-Z]) "#"[^\n]* { return K_COMMENT; } -{number_hex} { yylval.number = strtoul(yytext, NULL, 16); +{number_hex} { yylval.number = strtoul(yytext + (yytext[0] == 'x' ? 1 : 0), + NULL, 16); return number; } {number_dec} { yylval.number = strtol(yytext, NULL, 10); @@ -137,7 +138,8 @@ number_ascii ([a-zA-Z]) {number_oct} { yylval.number = strtol(yytext + 1, NULL, 8); return number; } -{number_bin} { yylval.number = strtol(yytext + 2, NULL, 2); +{number_bin} { yylval.number = strtol(yytext + (yytext[0] == 'b' ? 1 : 2), + NULL, 2); return number; } {number_ascii} { yylval.number = (uint8_t) (*yytext); -- cgit v1.2.3-54-g00ecf