momo33:

You can certainly edit binary data in perl, and there are a number of ways to do it. I'll assume you know all about the vagaries of differences in binary data structures between CPU architectures, so I won't open that particular can of worms.

Anyway, it works for me. If you show the code, we may be able to tell you the problem. Here's how I tested it:

$ cat binary_snr.pl #!/usr/bin/perl use strict; use warnings; my $binstr = join("", map { chr($_) } 0 .. 20); my $search_1 = join("", map { chr($_) } 7 .. 11); my $repl_1 = join("", map { 'A' } 7 .. 11); if ($binstr =~ s/$search_1/$repl_1/) { print "Fixed first one\n"; } print join(" ", map { ord($_) < 32 ? sprintf "0x%02x", ord($_) : $_ } split /|/, $binstr), "\n"; $ perl binary_snr.pl Fixed first one 0x00 0x01 0x02 0x03 0x04 0x05 0x06 A A A A A 0x0c 0x0d 0x0e 0x0f 0x10 +0x11 0x12 0x13 0x14 $

...roboticus

When your only tool is a hammer, all problems look like your thumb.

Update: minor text update to "If you show" sentence.


In reply to Re: binary search/replace by roboticus
in thread binary search/replace by momo33

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.