Re: Generic awk script to write 1/2/4/8/16 bytes at a particular offset on a binary file



myscr <data> <offset> <filename>

myscr 0050630a 000000B0 /dev/dummy
myscr 0050 000000B0 /dev/dummy
myscr 00 000000B0 /dev/dummy

on /dev/dummy
First time:
000000B0 00000000 00000000 00000000 00000000 |................|

../myscr 0050630aecede455 000000B0 /dev/dummy
000000B0 0050630a ecede455 00000000 00000000 |................|

../myscr 0050630a 000000B8 /dev/dummy
000000B0 0050630a ecede455 0050630a 00000000 |................|

& so on...I din't want to give this eg first post,bcoz i wanted to
give some tries.

thanks!



On Jun 5, 1:51 pm, Vassilis <F.H.Nova...@xxxxxxxxx> wrote:
/ vibgyorbits :



Hi,
i'm trying to write a script that can modify the data on a BINARY file
depending on
the # bytes and offset i give.

Below is the eg:

000000B0 00000000 00000000 00000000 00000000 |................|

Note that i need to convert all the input data into UPPER case.

so my ./test.sh <data> <offset> <location>
./test.sh 2a 00000030 file1
000000B0 2A00000000 00000000 00000000 00000000 |................|

./test.sh 2a4d 00000037 file1
000000B0 2A00000000 00000000 2A4D0000 00000000 |................|

-----------
set -A offset `echo $hexoffset | awk ' {
print "ibase=16\n"toupper($0)
} '| bc 2>/dev/null`

set -A a `echo $data | awk ' {
print "ibase=16\nobase=8\n"toupper($0)
} '| bc 2>/dev/null`

----------

But i'm not been able to write the data on to the offset specified.
Also, note that since this is binary data, has to be written in Octal.
And depending on the
size of the <data> i need to write 1/2/4/8/16 bytes.

Any help will be highly useful

thanks in advance!

Your post seems a bit confusing (to say the least):

In the title you ask an awk way to write at specific offsets.
You also say that you've got a binary file, which you pass it through
od (I guess) and want to convert od output to uppercase. By changing
the output to uppercase doesn't change anything.
Then your write two scripts that, by them selfs, don't make much
sense.

Post some input, tell us what's this binary like/for or set a link to
an example, and then try to specify the least of your requirements.


.



Relevant Pages

  • Re: fseek
    ... >> relationship between a given offset in a binary file and the same ... >> offset in a text file. ... > AB> results of fseek and ftell to position the text file. ... While commenting on that, I mentioned that a file can ...
    (comp.lang.c)
  • Re: fseek
    ... If the writers had wanted to say ... I suspect they would have. ... > relationship between a given offset in a binary file and the same ... > offset in a text file. ...
    (comp.lang.c)
  • Re: Generic awk script to write 1/2/4/8/16 bytes at a particular offset on a binary file
    ... i'm trying to write a script that can modify the data on a BINARY file ... But i'm not been able to write the data on to the offset specified. ... And depending on the ... You also say that you've got a binary file, ...
    (comp.lang.awk)
  • Generic awk script to write 1/2/4/8/16 bytes at a particular offset on a binary file
    ... i'm trying to write a script that can modify the data on a BINARY file ... But i'm not been able to write the data on to the offset specified. ... And depending on the ...
    (comp.lang.awk)
  • File Attachment problem
    ... It is my first time to post the article. ... Now I ' m testing the file attachment module using WSE 2.0 ... only binary file has problem) ...
    (microsoft.public.dotnet.framework.webservices.enhancements)