-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

And the git-diff which might be easier to follow... :


diff --git a/src/binparse.c b/src/binparse.c
index bea4507..73bf959 100644
- --- a/src/binparse.c
+++ b/src/binparse.c
@@ -118,9 +118,10 @@ void print_tok_list(tokenlist* toklist)

        printf ("TOKLIST %s:\n",toklist->name);
        for (i=0; i<toklist->numtok; i++)
- -             printf ("TOK : %c , range : %d \n",
+               printf ("TOK : %c , range : %d mask : %x\n",
                        toklist->tl[i].mintok,
- -                     toklist->tl[i].range);
+                       toklist->tl[i].range,
+                       toklist->tl[i].mask);
        NEWLINE;
        printf ("\n");
 }
@@ -301,6 +302,43 @@ tokenizer* binparse_new_from_file(char *
        return tll ;
 }

+int binparse_get_mask_list ( char* mask , char* maskout )
+{
+       int i,j,k ;
+       char num [3];
+
+       num[2] = 0;
+
+       i = 0;  j = 0;  k = 0;
+       while ( mask[i] != 0 )
+       {
+               if ( mask[i] != ' ' ) {
+                       num[j] = mask[i];
+                       j++;
+               }
+               i++;
+               if ( j == 2 )
+               {
+                       sscanf ( num, "%x", &maskout[k] );
+                       k++;
+                       j = 0;
+               }
+
+       }
+
+       return k;
+}
+void binparse_apply_mask (char * maskout, int masklen , token* tlist ,
int ntok)
+{      
+       int i;
+       for  ( i = 0; i < ntok ; i ++ )
+       {
+               tlist[i].mask = maskout[i%masklen];
+
+       }
+
+
+}
 static tokenlist *binparse_token_mask(char *name, char *token, char *mask)
 {
        tokenlist *tls;
@@ -308,6 +346,8 @@ static tokenlist *binparse_token_mask(ch
        void *tlist = 0;
        int ntok = 0;
        int len;
+       int masklen;
+       char maskout[300];

        tls = malloc(sizeof( tokenlist )) ;
        // TODO mask not yet done
@@ -320,7 +360,16 @@ static tokenlist *binparse_token_mask(ch
        tls->lastpos = 0;
        tls->estat = 0;
        strcpy ( tls->name , name ); // XXX bof here!
+       
+       if ( mask == NULL )
+       {
+               mask = "ff" ;
+       }
+
+       masklen = binparse_get_mask_list ( mask , maskout );
+       binparse_apply_mask ( maskout, masklen , tlist , ntok ) ;

+       //print_tok_list ( tls ) ;
        return tls;
 }

@@ -341,17 +390,32 @@ int binparse_add(tokenizer *t, char *str

 void update_tlist(tokenizer* t, unsigned char inchar, off_t where )
 {
- -     int cmin;
- -     int cmax;
+       unsigned char cmin;
+       unsigned char cmax;
+       unsigned char cmask;
        int i;

        for (i=0; i<t->nlists; i++ ) {
                cmin = (t->tls[i]->tl[t->tls[i]->estat]).mintok;
- -             cmax = cmin + (t->tls[i]->tl[t->tls[i]->estat]).range;
- -     
- -             if ( (inchar >= cmin) && ( inchar <= cmax ) )
- -                     t->tls[i]->actp[t->tls[i]->estat++] = inchar;
- -             else    t->tls[i]->estat = 0;
+
+               if (  (t->tls[i]->tl[t->tls[i]->estat]).range > 0 )
+               {
+                       // RANGE
+                       cmax = cmin + (t->tls[i]->tl[t->tls[i]->estat]).range;
+               
+                       if ( (inchar >= cmin) && ( inchar <= cmax ) )
+                               t->tls[i]->actp[t->tls[i]->estat++] = inchar;
+                       else    t->tls[i]->estat = 0;
+               }
+               else
+               {
+                       // 1 char
+                       cmask = (t->tls[i]->tl[t->tls[i]->estat]).mask;
+                       if (  (inchar&cmask) == (cmin&cmask)   )
+                               t->tls[i]->actp[t->tls[i]->estat++] = inchar;
+                       else    t->tls[i]->estat = 0;
+
+               }

                if ( t->tls[i]->estat == (t->tls[i]->numtok) ) {
                        t->tls[i]->actp[t->tls[i]->estat+1] = 0 ;
diff --git a/src/binparse.h b/src/binparse.h
index ae8cfb4..2a666c0 100644
- --- a/src/binparse.h
+++ b/src/binparse.h
@@ -6,6 +6,7 @@
 typedef struct _token {
        unsigned char mintok;   //Token, or base
        unsigned char range;    //0 nomes el mintok, ( maxtoken - mintoken )
+       unsigned char mask;
 } token;

 typedef struct _tokenlist {
@@ -25,6 +26,7 @@ typedef struct _tokenizer {

 tokenizer* binparse_new();
 tokenizer* binparse_new_from_file(char *file);
+int binparse_get_mask_list ( char* mask , char* maskout );
 int binparse_add_search(tokenizer *t, int id);
 int binparser_free(tokenizer* ptokenizer);
 void update_tlist( tokenizer*  ptok, unsigned char inchar, off_t where);
@@ -36,5 +38,6 @@ tokenlist* get_tok_list(  char* line, in
 tokenizer* build_tokenizer( char * file ) ;
 void tokenize(int fd, tokenizer* ptok);
 int binparse_add(tokenizer *t, char *string, char *mask);
+void binparse_apply_mask (char * maskout, int masklen , token* tlist ,
int ntok) ;

 #endif


esteve espuna wrote:
> Hi,
> 
> Here is the new binparser which includes the mask. Needs more testing as
> I have just tried that it works... I have finally separated the range
> feature from the mask one, if range is defined then mask is not applied,
> as it is hard to tell the expected behaviour...
> 
> 
- -------------- next part --------------
A non-text attachment was scrubbed...
Name: binparse.c
Type: text/x-csrc
Size: 9097 bytes
Desc: not available
Url :
https://lists.nopcode.org/mailman/private/radare/attachments/20070408/9ca9df1f/attachment.c

- -------------- next part --------------
A non-text attachment was scrubbed...
Name: binparse.h
Type: text/x-chdr
Size: 1278 bytes
Desc: not available
Url :
https://lists.nopcode.org/mailman/private/radare/attachments/20070408/9ca9df1f/attachment.h

_______________________________________________
radare mailing list
[email protected]
https://lists.nopcode.org/mailman/listinfo/radare

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD8DBQFGGSkgHCkwMET/DRYRAguhAJ95E+g/t9fTaSqsqC1EDfrvz+STsACfcjK6
0ppDtyONTeTrGyL5Hk9KE6E=
=GO9U
-----END PGP SIGNATURE-----
_______________________________________________
radare mailing list
[email protected]
https://lists.nopcode.org/mailman/listinfo/radare

Reply via email to