Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 25th November 2009, 13:28
rjamesd rjamesd is offline
Member
 
Join Date: Aug 2007
Posts: 35
Thanks: 3
Thanked 4 Times in 3 Posts
Question Want Perl equivalent of linux strings command to extract strings from binary file

Hi,
I'm looking for a Perl function that does the same thing as the Linux strings command.

The strings command will output a list of strings contained in any file, including a binary file that has strings embedded with in.

Regular expressions don't seem to work very well (or at all) with searching for strings in binary files.

I've searched here already but not found answers.

I want a Perl equivalent as I want to make my Perl code platform independent. If I call strings from Perl then I have made my code dependent on the strings command being available from the underlying operating system.
Reply With Quote
Sponsored Links
  #2  
Old 25th November 2009, 14:17
id10t id10t is offline
Senior Member
 
Join Date: Nov 2008
Posts: 242
Thanks: 2
Thanked 22 Times in 22 Posts
Default

So include a copy of strings!

Its already on *nix systems - including OS X - and there are win32 versions available precompiled.
__________________
I'm a very happy linode.com customer, I'm sure you will be too!
Reply With Quote
The Following User Says Thank You to id10t For This Useful Post:
rjamesd (25th November 2009)
  #3  
Old 25th November 2009, 18:16
rjamesd rjamesd is offline
Member
 
Join Date: Aug 2007
Posts: 35
Thanks: 3
Thanked 4 Times in 3 Posts
Lightbulb

Quote:
Originally Posted by id10t View Post
So include a copy of strings!

Its already on *nix systems - including OS X - and there are win32 versions available precompiled.
Thanks - yes Windows strings is at:

http://technet.microsoft.com/en-us/s.../bb897439.aspx

I downloaded unzipped and placed this in the same folder as the Perl script.

It works straight out of the box (on Windows XP at least) but be aware that first time it is run it will ask for a license agreement, thereafter you wont be asked.

Just for info, I can then regex match the string I am looking for from this - and extract it out using the following code

Code:
# get just printable character sequences from binary file called the string stored in $binaryFilename 
my $fileStrings = `strings $binaryFilename`; # note backward single quote to capture output of executing command enclosed

# $fileStrings is just the printable character sequences in the file (minimum 3 chars - see technet link above about how to change)

# do the regex
if ( $fileStrings =~ # a regex here # )
{
# if got here regex found match
# so
# get start and beginning of string using $` and $& Perl global system variables set to values from the last regex
my $embeddedStringStart = length($`);
my $embeddedStringLength = length($&);
my $embeddedString = substr( $fileStrings, $embeddedStringStart, $embeddedStringLength );

# go on to do something with the $embeddedString ...
}

Last edited by rjamesd; 25th November 2009 at 18:26.
Reply With Quote
  #4  
Old 30th November 2009, 14:46
id10t id10t is offline
Senior Member
 
Join Date: Nov 2008
Posts: 242
Thanks: 2
Thanked 22 Times in 22 Posts
 
Default

You don't need to DL from microsoft for strings... strings is part of binutils, and there is a GPL win32 version from http://www.mingw.org/wiki/MinGW
__________________
I'm a very happy linode.com customer, I'm sure you will be too!
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
High on Lenny - Lvm Mount Problem Serverman Technical 1 23rd June 2009 16:26
Spamsnake - Problem with spamassassin, FuzzyOcr and MySQL debuguser HOWTO-Related Questions 6 16th September 2008 18:37
HotSaNIC domino Tips/Tricks/Mods 23 6th November 2006 05:19
Problems installing NForce4 sound drivers Wraithfire Installation/Configuration 21 16th April 2006 17:30
Debian install error jf1976 Installation/Configuration 25 19th January 2006 22:31


All times are GMT +2. The time now is 16:50.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.