
freddo
User
Mar 2, 2002, 11:53 AM
Post #1 of 9
(605 views)
|
|
Needing infos on parsing...
|
Can't Post
|
|
Hello everybody, I'm trying to make a little (well, now it grows big) hexeditor with perl, i'd like to add a function to edit some offsets of a file and i want this to be done by parsing a text file. This is not interactive, it parse a file, or the command line, and can do two things: 1) Output a text file from a binary file 2) From the text file, it can patch an existing binary file/create a new file. Although it is really easy to parse one line of the definition file, i'd like to use complex structures in them. I've read Jeffrey Goff's Parse::RecDescent Tutorial and few other ressources. I was wondering if someone already used that, and if he/she can give me a (example|link|whatever_to_start_with) on how it works, it looks a little weird for me... Actually, a definition file for a gif may look like this: so, the parsing is:offset packstring hash_key # a comment can be here Quite easy to parse, a hash is populated with the values with something like: [perl]open F, "<test.gif"; binmode F; $_= "8 S height"; # while(<gif_file_description_here>) # { @currentLine = split /\s+/; ### some code to remove trailling/leading spaces, comments etc etc seek(F, $currentLine[0], 0); $hash{$currentLine[2]} = unpack($currentLine[1], <F>); # } # end of while print $hash{width} ."x". $hash{height} ."\n";[/perl] It is generaly loaded with:[perl]use frhexedit; load($filename, \%file);[/perl] This code is too easy, for example, gif files can hold several images and i'd like to be able to express this with rules... I dont ask for someone to do my work, i just ask for a good starting point on parsing... Btw, i just found this nothing to do with the stuff here, but it's funny... Thanks in advance, Freddo ;---
|