Hello Friends,

It's my first post to python-list, so first let me introduce myself...
* my name is Jan Kaliszewski,
* country -- Poland,
* occupation -- composer (studied in F. Chopin Academy of Music @Warsaw)
                and programmer (currently in Record System company,
                                working on Anakonda -- ERP system for
                                big companies [developed in Python + WX
                                + Postgres]).

Now, to the matter...

27-07-2009 Grant Edwards <inva...@invalid.chopin.edu.pl> wrote:

On 2009-07-27, r2 <rlichligh...@gmail.com> wrote:

I have a memory dump from a machine I am trying to analyze. I can view
the file in a hex editor to see text strings in the binary code. I
don't see a way to save these ascii representations of the binary,

$ strings memdump.binary >memdump.strings

$ hexdump -C memdump.binary >memdump.hex+as

Do You (r2) want to do get ASCII substrings (i.e. extract only those
pieces of file that consist of ASCII codes -- i.e. 7-bit values -- i.e in
range 0...127), or rather "possibly readable ascii representation" of
the whole file, with printable ascii characters preserved 'as is' and
not-printable/non-ascii characters being replaced with their codes
(e.g. with '\x...' notation).

If the latter, you probably want something like this:

import codecs
with open('memdump.binary', 'rb') as source:
    with open('memdump.txt', 'w') as target:
        for quasiline in codecs.iterencode(source, 'string_escape'):
            target.write(quasiline)

--
Jan Kaliszewski (zuo) <z...@chopin.edu.pl>
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to