Nathan_84 has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I'm trying to create a script which searches for string patterns in a image file of a disk. I haven't got a clue how to go about this as I'm a newbie :) Please please could somebody advise me. Thanks

Replies are listed 'Best First'.
Re: Perl Script for searching an Image
by Marshall (Canon) on May 13, 2010 at 06:05 UTC
    Your question doesn't have enough information to offer anything but general advice. First you need to figure out what kind of a image file of a disk that you have. That could mean a bunch of different things! Popular Disk Image Formats.

    The software that made the disk image (what ever that software was), will have a "restore" function that re-creates the original disk represented by the disk image. That means among other things that there will be a file system instead of a huge single "thing" consisting of just a bunch of bits in a possibly proprietary format. So first step is to re-create the original disk on a new disk or some file system partition, etc.

    Once you have something like that, you can think about writing code that searches this collection of files (a directory is just a special kind of file) for what you want. At this point, I have no idea of what you really want to do.

      Hi Marshall, Well the idea is to take a dd image of a 1GB USB drive in Ubuntu and then mount it. Once mounted, I would like the script to be able to search for particular strings of data. Hope that helps.

        Nathan_84:

        If you're going to mount it, you needn't worry about the fact that it's an image--once mounted it will just be a tree of files like any other. If you just want to directly scan the image file, you don't even need perl, try:

        grep -a your_image_file_name

        ...roboticus

        Ok. It appears that you can take this dd image and create a mount point with all the files, e.g. a file system structure at a Linux file system mount point.

        Look at http://perldoc.perl.org/File/Find.html and take a stab at it. It is tricky to get this "right", but try it with a good explanation of what you are trying do and you will get lot's of help.

Re: Perl Script for searching an Image
by BrowserUk (Patriarch) on May 13, 2010 at 06:22 UTC

    Are you taking about OCR?