Friday, October 07, 2005

modifying scripts with binary inside

Subject: SUMMARY: modifying scripts with binary inside

Hi Managers,

Sorry for the long delay. I have just completed fixing my problem.

I want to thank you all for your responses.
At the end of this msg I have attached the 3-4 suggestions I had from ppl.
I have not tried editing the binary but I wanted you all to see the other

My goal was to edit the text portion of the script w/o corrupting the binary.

First of all this file did in fact have text and binary w/i one file (script).
The script removes the binary w/ the "tail" cmd and then unzips, "tar xf" and
installs the binary.
The binary contains patches and packages, so the script was huge 240MB +. That
posed another problem, the file being
too large for vi.

I attacked this problem using Brad's method. Thank you Brad.

Objective: Remove the binary, edit the text portion, and still be able to run
my script.

At first I wanted to reattach my edited text back to the binary but instead I
just made the edited script (which has no binary now) access the original
script and work with the binary from that file. This worked wonderfully.


##Take the binary out
$ mv scriptname scriptname.yuck
$ strings scriptname.yuck > scriptname
$ vi scriptname
##Above works but the binary was turned into crazy chars and stayed inside the
file, so still too large for vi so here are the cmds to deal w/ that
##quote from Brad
Use split(1). I'd recommend

split -b 1m pre-req.install.orig.nobin chunk

This will produce about 156 one-megabyte files, named chunk.aa, chunk.ab, etc.

Then use:

for FILE in chunk.*
file $FILE
done > /tmp/chunkstyle

Now scan /tmp/chunkstyle for the first file that file(1) reports to be
non-text. If, for example, that one is, edit chunk.jd to remove the
binary characters at the end (if any), then:

cat chunk.[a-i]* chunk.j[a-d] > script

Afterwards, script should contain your script.

A better way is to find out which chunk contains the last line of the script.
It's probably "exit 0", test this with:

grep "exit 0" pre-req.install.orig.nobin

If you only get one result, that's the string to use to find the end of the
file in the middle of some chunk:

grep "exit 0" chunk.*

Then edit that chunk to get rid of binary characters, and cat using wildcards
as above.

If you don't get the wildcards part, here's the scoop: chunk.[a-i]* matches
chunk.aa, chunk.ab, ..., chunk.iz. You could also use chunk.[a-i][a-z]. The
second expression (chunk.j[a-d]) matches chunk.ja, chunk.jb, chunk.jc, and
chunk.jd. This assumes that the end of the script and the beginning of the
binary data is in the file chunk.jd.

Be sure to read the man page for split(1), and of course, take great care not
to clobber your original, pre-split files.
## END quote from Brad
I just edited the chunk that contained the text script portion which was the
first one. All the other junks had crazy chars (very much readable) that
represented the binary. Like I said up top my edited script (no bin) was
modified to just access and create the tar file from the orig. text/binary
Suggestions from others:
(You can use plain old Bill Joy vi just fine. vim, on the other hand,
will corrupt the binary portion.)
(You probably need a hex editor. Try this one
<> )
(If you can replace text with the same number of characters you may get
away with using emacs. If you're not familair with emacs, play with it a
little on some othe files first. It's very powerful, but it has a bit of a
learning curve. Also, and this should go without saying, work on a copy of
the script, not the original, and test the modified version before putting
it up for general consumption.
(Perl...but vi should work, too. )

> Subject: modifying scripts with binary inside
> I am just curious as to what is used to modify text scripts that also have
binaries inside of them.
> I want to modify the text only portion. I was told you can't use vi.
> Thank you for your time.
> Al


Post a Comment

<< Home