Modifying binary file by editing Hex values ?


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users Modifying binary file by editing Hex values ?
# 1  
Old 11-03-2005
Modifying binary file by editing Hex values ?

Hi ,

i'm using special binary file (lotus notes) and modifying an hexadecimal address range with windows hex editor and it works fine !

The file is an AIX one and i'm forced to transfert (ftp) it before modifying it and re-transfert !

NOW i would do this directly under AIX !

I can display the file with "od -h -Ax" and i wonder how to modify the all range in red with a shell script ?

od -h file.nsf
...........................................
0000140 0000 0025 2ff1 cb40 0000 0000 3204 0000
0000150 da03 0000 ca02 0000 4601 0000 1201 0000
0000160 4201 0000 0000 0000 2e02 0000 0000 0000
0000170 0000 0000 0000 0000 0000 0000 0000 0000
0000180 0000 0000 0000 0000 3e01 0000 0000 0000
0000190 0000 0000 3a01 0000 1e01 0000 0000 0000
00001a0 1a01 0000 0000 0000 0000 0000 0601 0000
00001b0 0000 000

the purpose here , is to write "0" over all values of the range !

Something like : "cat file.nsf|.................|od -h -Ax"

thanks in advance

Christian
# 2  
Old 11-03-2005
emacs can edit binary data. See this page. And adb can edit binary data, but it is stretching the tool a little bit.
# 3  
Old 11-03-2005
Thanks for your answer !

The reason i posted is :

1 i can'y install tool on the AIX , i'm not the root admin

2 i need an easy way to change the file for unix novice , simple users , so a script is the solution !

the range value is always the same , maybe an AWK can scan this range and do the change but i'm not AWK expert !

regards
Christian
# 4  
Old 11-03-2005
My od barfs on "od -h". I am not sure AIX can run this script. But it might give you an idea on how to do it on AIX. I took a core file as my file to be edited. And I build a 60 byte patch file. I made it all "FF" since my core file had a bunch of zeros in that range. Then I dump the interesting section of the core file, install the patch, and then dump the core file file a second time. It works for me.
Code:
#! /usr/bin/ksh

print -n aaaaaaaaaa > temp
print -n aaaaaaaaaa >> temp
print -n aaaaaaaaaa >> temp
print -n aaaaaaaaaa >> temp
print -n aaaaaaaaaa >> temp
print -n aaaaaaaaaa >> temp
tr "a" "\177" < temp > patch
od -v -A x -t x2 patch

echo
od -v -A x -t x2 < core | sed '1,20d;30q'

dd if=patch bs=1 conv=notrunc of=core seek=364 count=60

echo
od -v -A x -t x2 < core | sed '1,20d;30q'
exit 0

# 5  
Old 11-04-2005
It works !!!!!!!!!

THANK YOU VERY VERY VERY VERY MUCH !!!!!!!!!!!!!


christian
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Text File with Binary Values processing

Hello all, I have a txt file containing millions of lines. Below is the example: {tx:be} head -50 file.txt Instr1: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx Instr1:... (6 Replies)
Discussion started by: Zam_1234
6 Replies

2. Shell Programming and Scripting

Convert Binary File To Hex In Linux

dHi, I have the attached file(actual file can be extracted post unzipping it) & i am trying to use the following code for coversion to hex format. Starting hex value is 84 which is start of the record & termination is done using 00 00 followed by 84(hex) which i can see in the dump clearly using... (14 Replies)
Discussion started by: siramitsharma
14 Replies

3. Shell Programming and Scripting

How to replace with "sed" some hex values by other hex values?

Assume I have a file \usr\home\\somedir\myfile123.txt and I want to replace all occurencies of the two (concatenated) hex values x'AD' x'A0' bytwo other (concatenated) hex values x'20' x'6E' How can I achieve this with the gnu sed tool? Additional question: Is there a way to let sed show... (1 Reply)
Discussion started by: pstein
1 Replies

4. Shell Programming and Scripting

Editing Binary File

Dear Experts, I have one binary file which contains multiple 31k (31744) records. Each record begins with "a6 82". So the pattern is: a6 82 (+31742 bytes) a6 82 (+31742 bytes) a6 82 (+31742 bytes) a6 82 (+31742 bytes) There are some corrupted files where record does... (6 Replies)
Discussion started by: dhiraj4mann
6 Replies

5. Shell Programming and Scripting

convert hex to binary and send to variable

Folks, can anyone help with a script to convert hex to binary digits, and break the 32 bit binary into packs of 4 and send them to 8 different variables.Any help is sincerely appreciated. Thanks venu Its in korn shell...... (24 Replies)
Discussion started by: venu
24 Replies

6. Programming

Editing binary files

I am working in C and need a solution for below problem: I have a binary file, which needs to be edited in such a way no data is loss. For example i have to insert 3 bytes of data at some position without changing the contents of the file. if file has data as:... (2 Replies)
Discussion started by: junaid.nehvi
2 Replies

7. Shell Programming and Scripting

Editing a content which has branched values in a file

i have a file named tt which has content: dd=/cc/vv/bb i want to edit it by a script which will give as follows: dd=/cc/vv/bb/tt i tried sed -i -e 's/dd="/cc/vv/bb"/dd="/cc/vv/bb/tt"/' tt can any one pls help me on this? (1 Reply)
Discussion started by: Aditya.Gurgaon
1 Replies

8. Shell Programming and Scripting

binary/hex output

i want to output something like 2f 00 00 00 but i can't seem to escape characters like i'm used to in some programming languages, so with this: echo "/\0\0\0" >> outputfile i actually get 2f 5c 30 5c 30 5c 30 0a ie the \0 isn't giving me the 00 i need, and in addition it has got an... (8 Replies)
Discussion started by: peterworth
8 Replies

9. UNIX for Dummies Questions & Answers

Hex editing

Hi, I am new to UNIX. I have a text file where each line ends on the hexadecimal character "0A". In the file there are some records that contain the Hex characters "0D0A" which I need to replace by Hex "20". Is there a simple way to do this? Regards, Swanie (3 Replies)
Discussion started by: Swanie
3 Replies

10. Shell Programming and Scripting

Binary and hex in unix

not much familiar with binary and hex calculation in script programming.... explaination: binary format control the parameter turned on or off in the program stored in hex mode, the question is: how to change 39e to 19e using the binary calculation(although i don't know the command for... (2 Replies)
Discussion started by: trynew
2 Replies
Login or Register to Ask a Question