Memory buffer IO spaces are cheap, and they are often used as “scratch” areas.
Suppose for example we want to experiment with the ELF header of foo.o. We could open it in poke:
(poke) .file foo.o The current IOS is now `./foo.o'.
The header of an ELF file comprises the first 64 bytes in the file:
(poke) dump :size 64#B 76543210 0011 2233 4455 6677 8899 aabb ccdd eeff 0123456789ABCDEF 00000000: 7f45 4c46 0201 0100 0000 0000 0000 0000 .ELF............ 00000010: 0100 3e00 0100 0000 0000 0000 0000 0000 ..>............. 00000020: 0000 0000 0000 0000 0802 0000 0000 0000 ................ 00000030: 0000 0000 4000 0000 0000 4000 0b00 0a00 ..............
We know that as soon as we poke something on an IO space, the underlying file is immediately modified. So if we start playing with foo.o’s header, we may corrupt the file. We could of course make a copy of foo.o and work on the copy, but it is much better to create a memory IO space and copy the ELF header there:
(poke) .mem scratch The current IOS is now `*scratch*'. (poke) copy :from_ios 0 :from 0#B :size 64#B (poke) dump :size 64#B 76543210 0011 2233 4455 6677 8899 aabb ccdd eeff 0123456789ABCDEF 00000000: 7f45 4c46 0201 0100 0000 0000 0000 0000 .ELF............ 00000010: 0100 3e00 0100 0000 0000 0000 0000 0000 ..>............. 00000020: 0000 0000 0000 0000 0802 0000 0000 0000 ................ 00000030: 0000 0000 4000 0000 0000 4000 0b00 0a00 ..............
The command copy
above copies 64 bytes starting at byte 0
from the IO with id 0 (the file foo.o) to the current IO space
(the buffer *scratch*
).
Once we are done working with the copy of the ELF header, and satisfied, we can copy it back to the file and close the memory IO space:
(poke) copy :from 0#B :size 64#B :to_ios 0 (poke) .close The current IOS is now `./foo.o'.
Note how the command arguments :from_ios
and :to_ios
are
assumed to be the current IO space if they are not explicitly
specified in the command invocation. For detailed information on the
copy
command, see copy
.