binutils "strings" like functionality?

Steve Holden steve at holdenweb.com
Thu Mar 3 12:34:27 EST 2005


Kent Johnson wrote:
> cjl wrote:
> 
>> Hey all:
>>
>> I am working on a little script that needs to pull the strings out of a
>> binary file, and then manipulate them with python.
>>
>> The command line utility "strings" (part of binutils) has exactly the
>> functionality I need, but I was thinking about trying to implement this
>> in pure python.
>>
>> I did some reading on opening and reading binary files, etc., and was
>> just wondering if people think this is possible, or worth my time (as a
>> learning exercise), or if something like this already exists.
> 
> 
> I think a bare-bones version is pretty simple:
> - read the file
> - use re.split() to split on non-printable characters (string.printable 
> could be handy here)
> - print anything in the resulting list that is at least 4 characters
> 
The binutils version may well use a zero terminator character to 
differentiate between random chunks of printable characters and those 
explicitly genreated as strings from C. Or it may not ...

> Since you mention this as a learning exercise I'll refrain from posting 
> code but it's only a handful of lines...of course implementing all of 
> 'strings' is a bit more work.
> 
regards
  Steve
-- 
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005                      http://www.pycon.org/
Steve Holden                           http://www.holdenweb.com/



More information about the Python-list mailing list