Jim wrote:
> Hello,
> 
> I am reverse engineering a binary file that has an embedded PNG image
> in it. I opened the file in a hex editor and found the png header
> information, but how to use Ruby to extract the PNG to it's own file?

Do you know the absolute starting position of the embedded PNG?

You can get the data as a string like this:

   start_pos = 5 # or whatever
   end_pos = -1 # assume end of file
   png_data = File.open('file_with_png', "rb") { |f|
     f.read[start_pos..end_pos]
   }

Note that "rb" means open for read ("r") and treat as binary data ("b") 
(avoids munging "\r\n" on windows).

If the end_pos has to be determined by reading a field, then this will 
take a little tinkering. I assume PNG has a length field somewhere? So 
you'll have to extract that (using String#unpack, perhaps) and chop off 
that many bytes from the start of the png_data string.

-- 
       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407