Re: finding/replacing a long binary pattern in a .bin file

2005-01-19 Thread yaipa
John, Thanks for reminding me of the mmap module. The following worked as expected. # import mmap source_data = open("source_file.bin", 'rb').read() search_data = open("search_data.bin", 'rb').read() replace_data = open("replace_data.bin",

Re: finding/replacing a long binary pattern in a .bin file

2005-01-19 Thread yaipa
Bengt, Thanks for the input, sorry, your diff threw me the first time I looked at it, but then I went back and tried it later. Yes it works fine and I've tucked it away for later use. For this particular Use Case String.replace seems to get the job done in short order and the tool needs to be ma

Re: finding/replacing a long binary pattern in a .bin file

2005-01-19 Thread yaipa
Thanks Francois, It worked as expected. --- source_data = open("source_data.bin", 'rb').read() search_data = open("search_data.bin", 'rb').read() replace_data = open("replace_data.bin", 'rb').read() outFile = open("

Re: finding/replacing a long binary pattern in a .bin file

2005-01-14 Thread John Lenton
On Wed, Jan 12, 2005 at 10:36:54PM -0800, yaipa wrote: > What would be the common sense way of finding a binary pattern in a > .bin file, say some 200 bytes, and replacing it with an updated pattern > of the same length at the same offset? > > Also, the pattern can occur on any byte boundary in th

Re: finding/replacing a long binary pattern in a .bin file

2005-01-14 Thread Bengt Richter
On 14 Jan 2005 15:40:27 -0800, "yaipa" <[EMAIL PROTECTED]> wrote: >Bengt, and all, > >Thanks for all the good input. The problems seems to be that .find() >is good for text files on Windows, but is not much use when it is >binary data. The script is for a Assy Language build tool, so I know Did

Re: finding/replacing a long binary pattern in a .bin file

2005-01-14 Thread yaipa
Bengt, and all, Thanks for all the good input. The problems seems to be that .find() is good for text files on Windows, but is not much use when it is binary data. The script is for a Assy Language build tool, so I know the exact seek address of the binary data that I need to replace, so maybe

Re: finding/replacing a long binary pattern in a .bin file

2005-01-14 Thread Bengt Richter
On Thu, 13 Jan 2005 11:40:52 -0800, Jeff Shannon <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> BTW, I'm sure you could write a generator that would take a file name >> and oldbinstring and newbinstring as arguments, and read and yield nice >> os-file-system-friendly disk-sector-multiple ch

Re: finding/replacing a long binary pattern in a .bin file

2005-01-13 Thread Bengt Richter
On Thu, 13 Jan 2005 11:40:52 -0800, Jeff Shannon <[EMAIL PROTECTED]> wrote: >Bengt Richter wrote: > >> BTW, I'm sure you could write a generator that would take a file name >> and oldbinstring and newbinstring as arguments, and read and yield nice >> os-file-system-friendly disk-sector-multiple ch

Re: finding/replacing a long binary pattern in a .bin file

2005-01-13 Thread Jeff Shannon
Bengt Richter wrote: BTW, I'm sure you could write a generator that would take a file name and oldbinstring and newbinstring as arguments, and read and yield nice os-file-system-friendly disk-sector-multiple chunks, so you could write fout = open('mynewbinfile', 'wb') for buf in updated_fil

Re: finding/replacing a long binary pattern in a .bin file

2005-01-13 Thread François Pinard
[Stephen Thorne] > On 12 Jan 2005 22:36:54 -0800, yaipa <[EMAIL PROTECTED]> wrote: > > > What would be the common sense way of finding a binary pattern in > > a .bin file, say some 200 bytes, and replacing it with an updated > > pattern of the same length at the same offset? The file itself > > i

Re: finding/replacing a long binary pattern in a .bin file

2005-01-13 Thread Bengt Richter
On Thu, 13 Jan 2005 16:51:46 +1000, Stephen Thorne <[EMAIL PROTECTED]> wrote: >On 12 Jan 2005 22:36:54 -0800, yaipa <[EMAIL PROTECTED]> wrote: >> What would be the common sense way of finding a binary pattern in a >> .bin file, say some 200 bytes, and replacing it with an updated pattern >> of the

Re: finding/replacing a long binary pattern in a .bin file

2005-01-12 Thread Stephen Thorne
On 12 Jan 2005 22:36:54 -0800, yaipa <[EMAIL PROTECTED]> wrote: > What would be the common sense way of finding a binary pattern in a > .bin file, say some 200 bytes, and replacing it with an updated pattern > of the same length at the same offset? > > Also, the pattern can occur on any byte bound