3 conv=notrunc
source | link

I need to change one byte at a well-known position of a binary file to a specific value, and am looking for a way to achieve that using command line tools.

Constraints:

  • I need to change one single byte.
  • I know the position of the byte in the file.
  • I know what value I want in the byte. This may be anything, including non-printable characters in the 0x01–0x19 range.
  • The new value does not depend on the old value, hence no need to retrieve the old value.

To zero out the 9th byte in a file, I would do

dd if=/dev/zero of=/the/file bs=1 seek=8 count=1 conv=notrunc

If I want anything other than zero in that file, I would try piping something containing the exact bit value into dd. Something like:

spit-out-bytes | dd of=/the/file bs=1 seek=8 count=1 conv=notrunc

What would I use for spit-out-bytes?

I need to change one byte at a well-known position of a binary file to a specific value, and am looking for a way to achieve that using command line tools.

Constraints:

  • I need to change one single byte.
  • I know the position of the byte in the file.
  • I know what value I want in the byte. This may be anything, including non-printable characters in the 0x01–0x19 range.
  • The new value does not depend on the old value, hence no need to retrieve the old value.

To zero out the 9th byte in a file, I would do

dd if=/dev/zero of=/the/file bs=1 seek=8 count=1

If I want anything other than zero in that file, I would try piping something containing the exact bit value into dd. Something like:

spit-out-bytes | dd of=/the/file bs=1 seek=8 count=1

What would I use for spit-out-bytes?

I need to change one byte at a well-known position of a binary file to a specific value, and am looking for a way to achieve that using command line tools.

Constraints:

  • I need to change one single byte.
  • I know the position of the byte in the file.
  • I know what value I want in the byte. This may be anything, including non-printable characters in the 0x01–0x19 range.
  • The new value does not depend on the old value, hence no need to retrieve the old value.

To zero out the 9th byte in a file, I would do

dd if=/dev/zero of=/the/file bs=1 seek=8 count=1 conv=notrunc

If I want anything other than zero in that file, I would try piping something containing the exact bit value into dd. Something like:

spit-out-bytes | dd of=/the/file bs=1 seek=8 count=1 conv=notrunc

What would I use for spit-out-bytes?

2 seek, not skip
source | link

I need to change one byte at a well-known position of a binary file to a specific value, and am looking for a way to achieve that using command line tools.

Constraints:

  • I need to change one single byte.
  • I know the position of the byte in the file.
  • I know what value I want in the byte. This may be anything, including non-printable characters in the 0x01–0x19 range.
  • The new value does not depend on the old value, hence no need to retrieve the old value.

To zero out the 9th byte in a file, I would do

dd if=/dev/zero of=/the/file bs=1 skip=8seek=8 count=1

If I want anything other than zero in that file, I would try piping something containing the exact bit value into dd. Something like:

spit-out-bytes | dd of=/the/file bs=1 skip=8seek=8 count=1

What would I use for spit-out-bytes?

I need to change one byte at a well-known position of a binary file to a specific value, and am looking for a way to achieve that using command line tools.

Constraints:

  • I need to change one single byte.
  • I know the position of the byte in the file.
  • I know what value I want in the byte. This may be anything, including non-printable characters in the 0x01–0x19 range.
  • The new value does not depend on the old value, hence no need to retrieve the old value.

To zero out the 9th byte in a file, I would do

dd if=/dev/zero of=/the/file bs=1 skip=8 count=1

If I want anything other than zero in that file, I would try piping something containing the exact bit value into dd. Something like:

spit-out-bytes | dd of=/the/file bs=1 skip=8 count=1

What would I use for spit-out-bytes?

I need to change one byte at a well-known position of a binary file to a specific value, and am looking for a way to achieve that using command line tools.

Constraints:

  • I need to change one single byte.
  • I know the position of the byte in the file.
  • I know what value I want in the byte. This may be anything, including non-printable characters in the 0x01–0x19 range.
  • The new value does not depend on the old value, hence no need to retrieve the old value.

To zero out the 9th byte in a file, I would do

dd if=/dev/zero of=/the/file bs=1 seek=8 count=1

If I want anything other than zero in that file, I would try piping something containing the exact bit value into dd. Something like:

spit-out-bytes | dd of=/the/file bs=1 seek=8 count=1

What would I use for spit-out-bytes?

1
source | link

Bit banging with dd?

I need to change one byte at a well-known position of a binary file to a specific value, and am looking for a way to achieve that using command line tools.

Constraints:

  • I need to change one single byte.
  • I know the position of the byte in the file.
  • I know what value I want in the byte. This may be anything, including non-printable characters in the 0x01–0x19 range.
  • The new value does not depend on the old value, hence no need to retrieve the old value.

To zero out the 9th byte in a file, I would do

dd if=/dev/zero of=/the/file bs=1 skip=8 count=1

If I want anything other than zero in that file, I would try piping something containing the exact bit value into dd. Something like:

spit-out-bytes | dd of=/the/file bs=1 skip=8 count=1

What would I use for spit-out-bytes?