How do I change file headers from the command line?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








up vote
1
down vote

favorite












I have seen and used the GUI hex-editor bless, to modify bitmaps to match a separate file type (form bmp to srf). My question is how to modify file headers programmatically with the command line. What programs would allow me to make changes to file headers from shell script?



I have looked in synaptic package manager, but I'm new to modifying files in hex. Do bitmaps count as binary files? Where this is a software recommendation request, an acceptable answer would allow me to write, overwrite, or change specific values to specific locations (such as the first 16 bytes of a file), in the command line.







share|improve this question


























    up vote
    1
    down vote

    favorite












    I have seen and used the GUI hex-editor bless, to modify bitmaps to match a separate file type (form bmp to srf). My question is how to modify file headers programmatically with the command line. What programs would allow me to make changes to file headers from shell script?



    I have looked in synaptic package manager, but I'm new to modifying files in hex. Do bitmaps count as binary files? Where this is a software recommendation request, an acceptable answer would allow me to write, overwrite, or change specific values to specific locations (such as the first 16 bytes of a file), in the command line.







    share|improve this question
























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have seen and used the GUI hex-editor bless, to modify bitmaps to match a separate file type (form bmp to srf). My question is how to modify file headers programmatically with the command line. What programs would allow me to make changes to file headers from shell script?



      I have looked in synaptic package manager, but I'm new to modifying files in hex. Do bitmaps count as binary files? Where this is a software recommendation request, an acceptable answer would allow me to write, overwrite, or change specific values to specific locations (such as the first 16 bytes of a file), in the command line.







      share|improve this question














      I have seen and used the GUI hex-editor bless, to modify bitmaps to match a separate file type (form bmp to srf). My question is how to modify file headers programmatically with the command line. What programs would allow me to make changes to file headers from shell script?



      I have looked in synaptic package manager, but I'm new to modifying files in hex. Do bitmaps count as binary files? Where this is a software recommendation request, an acceptable answer would allow me to write, overwrite, or change specific values to specific locations (such as the first 16 bytes of a file), in the command line.









      share|improve this question













      share|improve this question




      share|improve this question








      edited May 13 at 6:11









      dessert

      19.6k55594




      19.6k55594










      asked May 9 at 23:03









      j0h

      5,9581348105




      5,9581348105




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted












          xxd is a very powerful command-line hex editor which allows you to change binary files with a single command line. You can use it this way:



          xxd -r -p -o OFFSET <(echo NEW HEX SIGNATURE) FILE # or
          echo NEW HEX SIGNATURE | xxd -r -p -o OFFSET - FILE


          Let's “convert” 01.png file to rar format (hex signature 5261 7221 1A07 0000, offset 01):



          $ file 01.png 
          01.png: PNG image data, 1280 x 1024, 8-bit/color RGB, non-interlaced
          $ xxd 01.png | head -1
          00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 .PNG........IHDR
          $ xxd -r -p -o 0 <(echo 5261 7221 1A07 0000) 01.png
          $ file 01.png
          01.png: RAR archive data, vdb, os: MS-DOS
          $ xxd 01.png | head -1
          00000000: 5261 7221 1a07 0000 0000 000d 4948 4452 Rar!........IHDR


          See man xxd for other useful options and lots of helpful examples.



          1If the offset is 0 the option -o can be omitted, I include it here only to show its usage.



          If you like it better you can do the truncating with dd as well, but that seems unnecessarily complicated:



          dd conv=notrunc obs=1 if=<(xxd -r -p -o 0 <(echo 5261 7221 1A07 0000)) of=01.png


          Further reading (besides usual command-line help):



          • Please recommend a hex editor for shell – xxd answer

          • Change the header in a huge file without rewriting the whole file
            · SO

          • Wikipedia's List of file signatures





          share|improve this answer






















          • This worked, for me. I figured out the magic number from the files on my GPS, and changed the files I generated to match those identities.
            – j0h
            May 12 at 23:23










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "89"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );








           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1034267%2fhow-do-i-change-file-headers-from-the-command-line%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          3
          down vote



          accepted












          xxd is a very powerful command-line hex editor which allows you to change binary files with a single command line. You can use it this way:



          xxd -r -p -o OFFSET <(echo NEW HEX SIGNATURE) FILE # or
          echo NEW HEX SIGNATURE | xxd -r -p -o OFFSET - FILE


          Let's “convert” 01.png file to rar format (hex signature 5261 7221 1A07 0000, offset 01):



          $ file 01.png 
          01.png: PNG image data, 1280 x 1024, 8-bit/color RGB, non-interlaced
          $ xxd 01.png | head -1
          00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 .PNG........IHDR
          $ xxd -r -p -o 0 <(echo 5261 7221 1A07 0000) 01.png
          $ file 01.png
          01.png: RAR archive data, vdb, os: MS-DOS
          $ xxd 01.png | head -1
          00000000: 5261 7221 1a07 0000 0000 000d 4948 4452 Rar!........IHDR


          See man xxd for other useful options and lots of helpful examples.



          1If the offset is 0 the option -o can be omitted, I include it here only to show its usage.



          If you like it better you can do the truncating with dd as well, but that seems unnecessarily complicated:



          dd conv=notrunc obs=1 if=<(xxd -r -p -o 0 <(echo 5261 7221 1A07 0000)) of=01.png


          Further reading (besides usual command-line help):



          • Please recommend a hex editor for shell – xxd answer

          • Change the header in a huge file without rewriting the whole file
            · SO

          • Wikipedia's List of file signatures





          share|improve this answer






















          • This worked, for me. I figured out the magic number from the files on my GPS, and changed the files I generated to match those identities.
            – j0h
            May 12 at 23:23














          up vote
          3
          down vote



          accepted












          xxd is a very powerful command-line hex editor which allows you to change binary files with a single command line. You can use it this way:



          xxd -r -p -o OFFSET <(echo NEW HEX SIGNATURE) FILE # or
          echo NEW HEX SIGNATURE | xxd -r -p -o OFFSET - FILE


          Let's “convert” 01.png file to rar format (hex signature 5261 7221 1A07 0000, offset 01):



          $ file 01.png 
          01.png: PNG image data, 1280 x 1024, 8-bit/color RGB, non-interlaced
          $ xxd 01.png | head -1
          00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 .PNG........IHDR
          $ xxd -r -p -o 0 <(echo 5261 7221 1A07 0000) 01.png
          $ file 01.png
          01.png: RAR archive data, vdb, os: MS-DOS
          $ xxd 01.png | head -1
          00000000: 5261 7221 1a07 0000 0000 000d 4948 4452 Rar!........IHDR


          See man xxd for other useful options and lots of helpful examples.



          1If the offset is 0 the option -o can be omitted, I include it here only to show its usage.



          If you like it better you can do the truncating with dd as well, but that seems unnecessarily complicated:



          dd conv=notrunc obs=1 if=<(xxd -r -p -o 0 <(echo 5261 7221 1A07 0000)) of=01.png


          Further reading (besides usual command-line help):



          • Please recommend a hex editor for shell – xxd answer

          • Change the header in a huge file without rewriting the whole file
            · SO

          • Wikipedia's List of file signatures





          share|improve this answer






















          • This worked, for me. I figured out the magic number from the files on my GPS, and changed the files I generated to match those identities.
            – j0h
            May 12 at 23:23












          up vote
          3
          down vote



          accepted







          up vote
          3
          down vote



          accepted








          xxd is a very powerful command-line hex editor which allows you to change binary files with a single command line. You can use it this way:



          xxd -r -p -o OFFSET <(echo NEW HEX SIGNATURE) FILE # or
          echo NEW HEX SIGNATURE | xxd -r -p -o OFFSET - FILE


          Let's “convert” 01.png file to rar format (hex signature 5261 7221 1A07 0000, offset 01):



          $ file 01.png 
          01.png: PNG image data, 1280 x 1024, 8-bit/color RGB, non-interlaced
          $ xxd 01.png | head -1
          00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 .PNG........IHDR
          $ xxd -r -p -o 0 <(echo 5261 7221 1A07 0000) 01.png
          $ file 01.png
          01.png: RAR archive data, vdb, os: MS-DOS
          $ xxd 01.png | head -1
          00000000: 5261 7221 1a07 0000 0000 000d 4948 4452 Rar!........IHDR


          See man xxd for other useful options and lots of helpful examples.



          1If the offset is 0 the option -o can be omitted, I include it here only to show its usage.



          If you like it better you can do the truncating with dd as well, but that seems unnecessarily complicated:



          dd conv=notrunc obs=1 if=<(xxd -r -p -o 0 <(echo 5261 7221 1A07 0000)) of=01.png


          Further reading (besides usual command-line help):



          • Please recommend a hex editor for shell – xxd answer

          • Change the header in a huge file without rewriting the whole file
            · SO

          • Wikipedia's List of file signatures





          share|improve this answer
















          xxd is a very powerful command-line hex editor which allows you to change binary files with a single command line. You can use it this way:



          xxd -r -p -o OFFSET <(echo NEW HEX SIGNATURE) FILE # or
          echo NEW HEX SIGNATURE | xxd -r -p -o OFFSET - FILE


          Let's “convert” 01.png file to rar format (hex signature 5261 7221 1A07 0000, offset 01):



          $ file 01.png 
          01.png: PNG image data, 1280 x 1024, 8-bit/color RGB, non-interlaced
          $ xxd 01.png | head -1
          00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 .PNG........IHDR
          $ xxd -r -p -o 0 <(echo 5261 7221 1A07 0000) 01.png
          $ file 01.png
          01.png: RAR archive data, vdb, os: MS-DOS
          $ xxd 01.png | head -1
          00000000: 5261 7221 1a07 0000 0000 000d 4948 4452 Rar!........IHDR


          See man xxd for other useful options and lots of helpful examples.



          1If the offset is 0 the option -o can be omitted, I include it here only to show its usage.



          If you like it better you can do the truncating with dd as well, but that seems unnecessarily complicated:



          dd conv=notrunc obs=1 if=<(xxd -r -p -o 0 <(echo 5261 7221 1A07 0000)) of=01.png


          Further reading (besides usual command-line help):



          • Please recommend a hex editor for shell – xxd answer

          • Change the header in a huge file without rewriting the whole file
            · SO

          • Wikipedia's List of file signatures






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited May 10 at 7:52

























          answered May 10 at 7:45









          dessert

          19.6k55594




          19.6k55594











          • This worked, for me. I figured out the magic number from the files on my GPS, and changed the files I generated to match those identities.
            – j0h
            May 12 at 23:23
















          • This worked, for me. I figured out the magic number from the files on my GPS, and changed the files I generated to match those identities.
            – j0h
            May 12 at 23:23















          This worked, for me. I figured out the magic number from the files on my GPS, and changed the files I generated to match those identities.
          – j0h
          May 12 at 23:23




          This worked, for me. I figured out the magic number from the files on my GPS, and changed the files I generated to match those identities.
          – j0h
          May 12 at 23:23












           

          draft saved


          draft discarded


























           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1034267%2fhow-do-i-change-file-headers-from-the-command-line%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          pylint3 and pip3 broken

          Missing snmpget and snmpwalk

          How to enroll fingerprints to Ubuntu 17.10 with VFS491