The OP's question implies the use of a hex editor. User Marc Wilson has pointed out in a comment that "… macOS does include at least one hex editor, that being xxd, and one binary-safe application that can be used as one, that being vim." Additionally, third party hex editors do also exist, as shown in the answer by Marc Wilson.
This answer demonstrates how to make the necessary changes without relying on any hex editors or third party tools. Since I do not currently have access to Sonoma, I will be using Ventura 13.3.1 (a).
Note: This answer assumes grep version 2.6.0-FreeBSD is being used, which is included with macOS Monterey through at least macOS Sonoma. In this case, the previous grep version 2.5.1-FreeBSD will not work properly, which is included with macOS Big Sur down to at least Mac OS X Snow Leopard.
The commands below copy the TrashIcon.icns file to my Desktop.
cd ~/Desktop cp /System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/TrashIcon.icns .
Next, use the commands below to determine where the first occurrence of the FD D9 2F A8 byte sequence is in the TrashIcon.icns file. In both bash and zsh, the byte sequence can be represented as the $'\xFD\xD9\x2F\xA8' string. Basically, each byte is preceded by \x and the result is preceded by $' and succeeded by '. (For an explanation of the use of the commands, see this answer.)
(export LC_ALL=C BS=$'\xFD\xD9\x2F\xA8'; cat TrashIcon.icns | tr -c "$BS" '\n' | grep -aoFbm1 "$BS" | sed 's/:.*//')
The output from the above commands is shown below. This output shows the byte sequence starts at offset 1225184.
1225184
The next command copies the TrashIcon.icns file starting at offset 1225184 to the tempfile file. (Note: 1225184=0x12b1e0)
dd bs=1 skip=1225184 if=TrashIcon.icns of=tempfile
The output from the above command is shown below.
939131+0 records in 939131+0 records out 939131 bytes transferred in 3.128151 secs (300219 bytes/sec)
The next command replaces the first 4 bytes the tempfile file with the 4 byte ASCII character string icns.
echo -n "icns" | dd bs=1 of=tempfile conv=notrunc
The command below shows the hexadecimal and ASCII values for the first 32 bytes of the tempfile file. Note: Non‑printable ASCII and non‑ASCII values are shown as the . character.
hexdump -Cv -n 32 tempfile
The output from the above command is shown below. The hexadecimal values are the same as shown in the answer by Marc Wilson.
00000000 69 63 6e 73 00 0e 54 7b 69 63 31 32 00 00 10 fe |icns..T{ic12....| 00000010 89 50 4e 47 0d 0a 1a 0a 00 00 00 0d 49 48 44 52 |.PNG........IHDR| 00000020
The command below can be used to show tempfile is an icon file.
file tempfile
The output from the above command is shown below.
tempfile: Mac OS X icon, 939131 bytes, "ic12" type
viwill let you do the operation you mention you’re not sure how to execute. If you already know the tool, you’ll just need to :help binary in the editor to get going with the instructions.