On Wednesday, May 22, 2002, at 12:59 , Paul Company wrote:
> I want to replace a string "/usr/local" with another
> string "/tmp/local" in a binary file.
cf man patch
what you want is 'patch' - it is not nice to try to
patch binary files on the fly....
> This is what I wrote:
>
> #!/usr/local/bin/perl
>
> $file = "./mybinaryfile.out";
> $s1 = `strings $file | grep -b /usr/local`; # returned
> 2027:/usr/local/conf/
man strings
that is returning 'string patterns' from a file
not the sequence of actual bytes in the file.
let's have a coffee break moment here...
vladimir: 56:] wc -c perl
1175680 perl
vladimir: 57:] strings perl | head
$$$$((((,,,,0123336689::::>?@AAAJJJJHIJKLMJ6
1289:=ABC><;JGF0
!"#$%&'(),-
Use of uninitialized value%s%s
Semicolon seems to be missing
Unquoted string "%s" may clash with future reserved word
Unsuccessful %s on filename containing newline
Can't use %s ref as %s ref
Can't use string ("%.32s") as %s ref while "strict refs" in use
Can't use an undefined value as %s reference
vladimir: 58:] vladimir: 59:] !strings | grep -b "Use of uninitialized"
strings perl | head | grep -b "Use of uninitialized"
79:Use of uninitialized value%s%s
vladimir: 64:] od -c perl | head -5
0000000 177 E L F 001 002 001 \0 \0 \0 \0 \0 \0 \0 \0 \0
0000020 \0 002 \0 002 \0 \0 \0 001 \0 002 ~ 220 \0 \0 \0 4
0000040 \0 021 354 \0 \0 \0 \0 \0 4 \0 \0 005 \0 (
0000060 \0 034 \0 032 \0 \0 \0 006 \0 \0 \0 4 \0 001 \0 4
0000100 \0 \0 \0 \0 \0 \0 \0 240 \0 \0 \0 240 \0 \0 \0 005
vladimir: 65:]
how much are you really willing to bet that the 'string'
is really there in the first 79 bytes....
now what exactly did you think you were getting with using
strings in the first place....
for fun, you might want to try to write the wrapper on od
or hexdump to find the string file.... or you might
want to say use
sysread/syswrite/sysseek
to walk through your binary file to look for a specific
string....
but clearly you really do not want to abuse standard unix
tools willy nilly....
ciao
drieux
---
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]