1833873 Members
2147 Online
110063 Solutions
New Discussion

Re: Edit Binary Files

 
Karthik S S
Honored Contributor

Edit Binary Files

Is there a tool to edit binary files like "/etc/lvmtab" / "/etc/cmcluster/cmclconfig"??. I am not asking about vgscan/cmquerycl which can recreate these files.

I just want play around with these files by modifying them.

Thanks,
Karthik S S
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
15 REPLIES 15
Pete Randall
Outstanding Contributor

Re: Edit Binary Files

Karthik,

Boy, am I glad you don't work on my systems!

;^)

Seriously, I'm unaware of such a tool (though there may well be one) and I would have to question the wisdom of doing such a thing anyway. I think you would be better off to follow the conventional methods.


Pete

Pete
G. Vrijhoeven
Honored Contributor

Re: Edit Binary Files

Hi,

why not alter the kernel while you are at it.. I would try it on other files.


Gideon

PS. A collegeu of mine did it with Perl, but i do not know how.

Hoefnix
Honored Contributor

Re: Edit Binary Files

Karthik,

Like all above, you don't want to mess arround with these files by just filling in some data.
Or do you like to simulate system crashes.

Regards,
Peter
Karthik S S
Honored Contributor

Re: Edit Binary Files

Hi Pete,

Don't worry .. I have no plans as of now to work for "Holstein Association, Inc" .. :-)) ..

I have got few test machines where I can afford to perform these kind of destructive things ...

Well, the reason why I need to edit the cmclconfig is to change the lock device path when the cluster is running (In a huge SAN env. the device files may change and it is not possible to update the cluster unless otherwise you stop the cluster and do a cmquery and cmapplyconf). I am not sure this way if it will work or not but no harm in giving it a try ..

Thanks,
Karthik S S
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
T G Manikandan
Honored Contributor

Re: Edit Binary Files

These are some of the commands I learnt from forum
same discussion in the past,

#vis -n /etc/lvmtab >/tmp/outfile
Make changes to outfile
#inv -n /tmp/outfile >/tmp/binaryoutfile


Mark Grant
Honored Contributor

Re: Edit Binary Files

I have done this before but only as a joke, I changed a lot of the strings in a word processing application to give a, well, more relaxed attitude.

You can use any hex editor, several of them exist even some versions of "vi" will do it.

I belive GXedit does too and this is available here

http://hpux.connect.org.uk/hppd/hpux/Editors/GXedit-1.23/

Careful now though Karthik :)
Never preceed any demonstration with anything more predictive than "watch this"
Karthik S S
Honored Contributor

Re: Edit Binary Files

Hi Manikandan,

That was a good command .. using that I recreated the lvmtab by changing the device file names for some VG. When tried any VG related commands it throws the following error,

The version of /etc/lvmtab file is not correct.
Remove /etc/lvmtab file and execute vgscan command to recreate the file.
vgdisplay: No volume group name could be read from "/etc/lvmtab".


-Karthik S S
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
Pete Randall
Outstanding Contributor

Re: Edit Binary Files

Karthik,

So, you want to change the lock device path on the fly, while the cluster is running? The repercussions from that are absolutely scary to even contemplate.

Make absolutely sure that you are doing this within your test environment. I think most of us have at least one incident in our past where we "thought" we were on the test machine . . .

Good luck,


Pete

Pete
Hoefnix
Honored Contributor

Re: Edit Binary Files

Ok, if you do this in a test-cluster and you are lucky to change the lockdisk on the fly I like to know how, so please post your test results please.
Still I think it's dangerous.

Goodluck,
Peter
Karthik S S
Honored Contributor

Re: Edit Binary Files

Yeah .. I am trying my luck and let you if I succeed ..

Thanks,
Karthik S S
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn
Laurent Menase
Honored Contributor

Re: Edit Binary Files

Hi Karthik,

For the fun only - I won't edit such a file
on a prod system-

# xd toto
0000000 0000 0000 0000 0000 0000 0000 0000 0000
0000010 0000 0001 0000 0000 0000 0000 0000 0000
0000020 0000 0000 0000 0000 0000 0000 0000 0000
*
0000100 0000 0010 0000 0000 0000 0000 0000 0000
0000110 0000 0000 0000 0000 0000 0000 0000 0000
0000120 0000 0002
0000124

# adb -w toto
PA-32 adb ($h help $q quit)
adb>10?W 10000
10: 1 = 10000
adb>140?W 2
140: = 2
# xd toto
0000000 0000 0000 0000 0000 0000 0000 0000 0000
0000010 0001 0000 0000 0000 0000 0000 0000 0000
0000020 0000 0000 0000 0000 0000 0000 0000 0000
*
0000100 0000 0010 0000 0000 0000 0000 0000 0000
0000110 0000 0000 0000 0000 0000 0000 0000 0000
0000120 0000 0002 0000 0000 0000 0000 0000 0000
0000130 0000 0000 0000 0000 0000 0000 0000 0000
0000140 0000 0002
0000144
adb>100,3?4Xa
100: 10 0 0 0
110: 0 0 0 0
120: 2 0 0 0

by default adb uses hexadecimal
A. Clay Stephenson
Acclaimed Contributor

Re: Edit Binary Files

My weapon of choice for this is hexedit. It's quite good and easy to use. What you do with it is completely up to you.

http://hpux.connect.org.uk/hppd/hpux/Development/Tools/hexedit-0.9.7/
If it ain't broke, I can fix that.
Hein van den Heuvel
Honored Contributor

Re: Edit Binary Files

Ditto on hexedit, allthough debuggers like adb are pretty handy also.

Now in perl it is relatively easy to construct any funky byte pattern through the 'pack' function. Here is an example to replace 'short' in lvmtab on line 0000400:

$ xd /etc/lvmtab | grep 0000400
0000400 0000 0000 0000 0000 0000 0000 b65a 8e24
$ cat zap
#!/bin/perl
while (<>){
$old = pack("S",0xb65a );
$new = pack("S",0x0123 );
s/$old/$new/;
print;
}
$ zap < /etc/lvmtab > x
$ xd x | grep 0000400
0000400 0000 0000 0000 0000 0000 0000 0123 8e24
$ ls -l x /etc/lvmtab
-rw------- 1 root sys 2094 Jul 22 2003 /etc/lvmtab
-rw-r--r-- 1 root sys 2094 Mar 5 21:53 x

hth,
Hein.
Michael Schulte zur Sur
Honored Contributor

Re: Edit Binary Files

Hi Karthik,

you can also ftp file to pc and use editor like ultraedit.

remember: only softies use sam for kernel rebuild. Real mean do use a hexeditor. ;-)

Michael
Karthik S S
Honored Contributor

Re: Edit Binary Files

Hi All,

I was able to edit the cmclconfig file and do some changes to the cluster lock PV but as expected the changes were not reflected to the running cluster. I have identified (with ITRC help) few work arounds for this problem and I have posted them at,

http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=493491

Pl. have a look and respond .. I am waiting for your inputs on this :-)

Thanks,
KarthiK S S
For a list of all the ways technology has failed to improve the quality of life, please press three. - Alice Kahn