Editing binary files


 
Thread Tools Search this Thread
Top Forums Programming Editing binary files
# 1  
Old 04-12-2010
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:
64795F8144054D595343435F813605494E44544D

and i need to add data 630000 like

64796300005F8144054D595343435F813605494E44544D

I have an Hex editor which enables me to see binary files in Hexadecimal mode.

I have tried fseek to reach that position and then write but it overwrites the current data bytes e.g,
6479630000054D595343435F813605494E44544D
data 5F8144 is lost.

but i want it to get inserted at that position as in earlier case.

Please share your comments.
Thanks in advance.
# 2  
Old 04-12-2010
There's no file operation for "insert bytes here", you'll have to do this the hard way: store everything after the modified bytes in memory or temp file so you can overwrite everything after the insertion with the data you want to be there.
# 3  
Old 04-19-2010
try `bvi' - the binary vi

try `bvi' - the binary vi ;

- it's available at sourceforge ;

good luck, and success !

alexandre botao
<< botao {dot} org >>
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Editing files

This is a smallpart of my input file.I want to change the ID values of entries having CMW as an entry. Cont_1.266 . CMW 2958 3269 . - 0 PARENT=t:UM06506T0;ID=UM06506P0;rank=6 Cont_1.266 . CMW 3394 3505 . - 0 ... (3 Replies)
Discussion started by: sasdf
3 Replies

2. Shell Programming and Scripting

Bash script deleting my files, and editing files in subdirectories question

#!/bin/bash # name=$1 type=$2 number=1 for file in ./** do if then filenumber=00$number elif then filenumber=0$number fi tempname="$name""$filenumber"."$type" if (4 Replies)
Discussion started by: TheGreatGizmo
4 Replies

3. Shell Programming and Scripting

editing files.

hello, i have a problem. suppose file.txt i want to add lines over those lines in a file if it starts and ends with how and "?" respectively. i want output like output file.txt thanks (4 Replies)
Discussion started by: yashwantkumar
4 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

Editing files to add some thing in all the files in a folder

Hi All, I have a folder that contains 100's of files and each file have a similar content like the following format: ((STBJa:200.0,((STBTz:200.0,(STSwe:200.0,(STDUw:200.0,(ST4Bu:200.0,STL2b:200.0):127.0):86.0):80.0):120.0, STAHr:200.0):134.0):200.0,STuNg:200.0);What I need is to do is add "#1"... (2 Replies)
Discussion started by: Lucky Ali
2 Replies

6. Shell Programming and Scripting

editing files

Is there any command which I can apply from the command line to find and replace a particular text say "00:00:00:00" with "00" from all the files( where ever this text exists) of the current directory? (17 Replies)
Discussion started by: cobroraj
17 Replies

7. Shell Programming and Scripting

Editing Binary Files in Unix

Hi, Is there a way to edit BINARY files in Unix. Or even are there any commands (shellscript/perl) through which I can replace all the occurences of a string inside a BINARY file with another string ?? (1 Reply)
Discussion started by: cool.aquarian
1 Replies

8. Shell Programming and Scripting

search for files excluding binary files

Hi All, I need a solution on my following find command find ./.. -name '*.file' -print BTW This gives me the output as belows ./rtlsim/test/ADCONV0/infile/ad0_dagctst.file ./rtlsim/test/ADCONV0/user_command.file ./rtlsim/test/ADCONV0/simv.daidir/scsim.db.dir/scsim.db.file... (2 Replies)
Discussion started by: user_prady
2 Replies

9. UNIX for Dummies Questions & Answers

Editing files

hi i would like to know whether i can delete a part of a file in C for eg. if my file contained 1234567890 and i want to delete 456 so that it becomes 1237890 is there a way i can do this. well, one way i can achieve this is by creating a new file, copy whatever i want, then... (2 Replies)
Discussion started by: sameersbn
2 Replies

10. UNIX for Advanced & Expert Users

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... (4 Replies)
Discussion started by: Nicol
4 Replies
Login or Register to Ask a Question