Operating System - HP-UX
1833695 Members
3698 Online
110062 Solutions
New Discussion

changing contents of a file that can only be viewed using strings???

 
MAD_2
Super Advisor

changing contents of a file that can only be viewed using strings???

I have a file that is not simple text but rather seems to be compiled.

I can view it using strings, however I need to change a line of the text.

Can I use strings to redirect the contents to a simple text file and then is there a way to redirect that changed file to the format of the original file that I can view with "strings"???

Thanks!
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
10 REPLIES 10
Massimo Bianchi
Honored Contributor

Re: changing contents of a file that can only be viewed using strings???

Hi,
you can try, but at your own risk, to change the string using sed


cat yourfile | sed s/textin/textout/ > yournewfile.

Take a backup of that file, before.

Otherwise, if is is not very big, get an exadecimal editor, like ultraedit32 on windows, change whatever you want and then take the file back up hpux.

remember to transfer the file using binary mode.

Massimo
A. Clay Stephenson
Acclaimed Contributor

Re: changing contents of a file that can only be viewed using strings???

You need an editor that will handle binary data. One of the best is hexedit, available from any of the HP-UX Porting Centre's. Be sure to downloand and swinstall the dependent packages as well.Hexedit is very powerful and easy to use.

http://hpux.connect.org.uk/hppd/hpux/Development/Tools/hexedit-0.9.7/
If it ain't broke, I can fix that.
Pete Randall
Outstanding Contributor

Re: changing contents of a file that can only be viewed using strings???

Adam,

I guess I'd try that on a test copy of the file before I touched the real one. Sounds risky to me.


Pete


Pete
James R. Ferguson
Acclaimed Contributor

Re: changing contents of a file that can only be viewed using strings???

Hi Adam:

No, you cannot rely on the output of 'strings'.

You would need to know the exact data layout; read the binary file with a C-program; modify the data so read; and write it again.

'strings' simply reports what is can by finding four or more ASCII printing characters. You will *not* necessarily see all data!

Regards!

...JRF...
A. Clay Stephenson
Acclaimed Contributor

Re: changing contents of a file that can only be viewed using strings???

One more thing. Since you mentioned that this "seems to be compiled" and is thus an executable, you will only be able to alter your string to something of no greater length than the current string. If you need to shorten the string, pad it with spaces or better still NUL's.
If it ain't broke, I can fix that.
MAD_2
Super Advisor

Re: changing contents of a file that can only be viewed using strings???

Sorry Massimo, that's not going to work. The file is not simple text. I can do this:

1. strings file1 > file2.txt
2. vi file2.txt (make my simple change in this text file)

I still need to know how to change the file from file2.txt to the original format.

I am attaching the original file to see what I am talking about (named shell.so), I need to change the path shown from /oradata to /oradata2.
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
MAD_2
Super Advisor

Re: changing contents of a file that can only be viewed using strings???

Oh, by the way, I never intended to work on the original file, I will leave that one alone until I know what I do works, whatever that may be. Thanks everyone for your responses, i guess there is no easy way to fix this one.
Contrary to popular belief, Unix is user friendly. It's just very particular about who it makes friends with
Darren Prior
Honored Contributor

Re: changing contents of a file that can only be viewed using strings???

Hi Adam,

Running strings is a one-way process. Once you've done a strings yourbinaryfile >file2.txt then you've lost ALL the data EXCEPT for the stuff that strings believes is readable text (ie words of 4 chars or more.)

So - anything you then do with file2.txt after you edit it will not be able to be put back into a working state due to the missing stuff.

regards,

Darren.
Calm down. It's only ones and zeros...
Massimo Bianchi
Honored Contributor

Re: changing contents of a file that can only be viewed using strings???

Hi,
if you tried it and didn't work, the follow Clay's hint and get an hexadecimal editor, either on windows or on hpux, whichever is simpler for you.

Since file is short, i will use uedit32, i always have it on my pc, this is why i suggested it to you :)

Massimo
Darren Prior
Honored Contributor

Re: changing contents of a file that can only be viewed using strings???

Re-reading one of your earlier comments; it might be easier for you to link /oradata2 to /oradata as it's unlikely that you'll be able to lengthen the string in the .so file.

regards,

Darren.
Calm down. It's only ones and zeros...