Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #67743

Re: find and replace string in binary file

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'encoding': 0.05; 'binary': 0.07; 'subject:file': 0.07; 'string': 0.09; 'bytes.': 0.09; 'encode': 0.09; 'image,': 0.09; 'subject:string': 0.09; 'cc:addr :python-list': 0.11; 'choose,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'file,': 0.19; 'cc:addr:python.org': 0.22; 'replace': 0.24; 'file.': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'character': 0.29; 'message-id:@mail.gmail.com': 0.30; 'file': 0.32; 'another': 0.32; 'possible.': 0.35; 'convert': 0.35; 'received:google.com': 0.35; 'clear': 0.37; 'whatever': 0.38; 'either': 0.39; 'how': 0.40; 'read': 0.60; "you'll": 0.62; 'mar': 0.68; 'otten': 0.84; 'subject:find': 0.84; 'to:none': 0.92
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=Ft+3uCSmbYBR1f1YXmqbIRae7CB49kDdWw7hkkfF/Ck=; b=hizP8Q4+i9HRXSHQ/r27zhEh0rJbOXz3EPvwDHAQ5K0KrIRvP112DcUmRB+YSAGeFn flUI1/OqxERKYxrPSfnzYIsyq4PLrCV1oJjckND3MRxOglMuPnf0+gu4qbSfrhrIPPoK hG0MdMCb04p3WrQ1aa9aYbMgWdZbTH2Acb6QawCb8Xz8qJzeUXs0Hr4pr2vl7yX/WoGj Ui7cnAjPIqf1MYBnJxyH+ec4T8T87heZxlpWWGuFCoBiIrN1uFicMXSaCzHw5kI6Y2eH zjQJF6IduCz/L/fM4Rr2GEafP6QL8Ay68e9nrC8pfaPxDOIiII3Ms2fzYqZiDk19G2E6 FjYw==
MIME-Version 1.0
X-Received by 10.68.247.6 with SMTP id ya6mr2391725pbc.45.1393973043219; Tue, 04 Mar 2014 14:44:03 -0800 (PST)
In-Reply-To <lf4jrk$95v$1@ger.gmane.org>
References <01951a7d-2ab3-4203-a9c5-2f79017a980d@googlegroups.com> <lf4jrk$95v$1@ger.gmane.org>
Date Wed, 5 Mar 2014 09:44:03 +1100
Subject Re: find and replace string in binary file
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.7760.1393973045.18130.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1393973045 news.xs4all.nl 2890 [2001:888:2000:d::a6]:33457
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:67743

Show key headers only | View raw


On Wed, Mar 5, 2014 at 12:18 AM, Peter Otten <__peter__@web.de> wrote:
> loial wrote:
>
>> How do I read a binary file, find/identify a character string and replace
>> it with another character string and write out to another file?
>>
>> Its the finding of the string in a binary file that I am not clear on.
>
> That's not possible. You have to convert either binary to string or string
> to binary before you can replace. Whatever you choose, you have to know the
> encoding of the file.

If it's actually a binary file (as in, an executable, or an image, or
something), then the *file* won't have an encoding, so you'll need to
know the encoding of the particular string you want and encode your
string to bytes.

ChrisA

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

find and replace string in binary file loial <jldunn2000@gmail.com> - 2014-03-04 04:27 -0800
  Re: find and replace string in binary file MRAB <python@mrabarnett.plus.com> - 2014-03-04 13:08 +0000
  Re: find and replace string in binary file Peter Otten <__peter__@web.de> - 2014-03-04 14:18 +0100
  Re: find and replace string in binary file Chris Angelico <rosuav@gmail.com> - 2014-03-05 09:44 +1100
  Re: find and replace string in binary file emile <emile@fenx.com> - 2014-03-04 16:13 -0800
    Re: find and replace string in binary file loial <jldunn2000@gmail.com> - 2014-03-05 01:59 -0800
      Re: find and replace string in binary file Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-03-05 12:42 +0000
      Re: find and replace string in binary file Emile van Sebille <emile@fenx.com> - 2014-03-05 09:46 -0800
  Re:find and replace string in binary file Dave Angel <davea@davea.name> - 2014-03-05 07:06 -0500

csiph-web