Replace a binary file within another binary file The 2019 Stack Overflow Developer Survey Results Are InHow to find all binary executables recursively within a directory?how to find offset of one binary file inside another?dowload find binary , accidentally deleted /usr/bin/find binary fileFind & replace image URLs in one file from another fileReplace or append a line with string within a fileExtract data between two matched patterns in a binary fileHow to view a binary file?Editing binary streams containing 'x00' bytesHow are binary files “binary”?Replace a binary block within a large file

How can I fix this gap between bookcases I made?

Limit to 0 ambiguity

What are the motivations for publishing new editions of an existing textbook, beyond new discoveries in a field?

How to create dashed lines/arrows in Illustrator

What is the steepest angle that a canal can be traversable without locks?

Springs with some finite mass

JSON.serialize: is it possible to suppress null values of a map?

Why do UK politicians seemingly ignore opinion polls on Brexit?

Why did Howard Stark use all the Vibranium they had on a prototype shield?

Geography at the pixel level

What is the meaning of Triage in Cybersec world?

Which Sci-Fi work first showed weapon of galactic-scale mass destruction?

Idiomatic way to prevent slicing?

The difference between dialogue marks

A poker game description that does not feel gimmicky

How to reverse every other sublist of a list?

Realistic Alternatives to Dust: What Else Could Feed a Plankton Bloom?

Output the Arecibo Message

How to manage monthly salary

Does it makes sense to buy a new cycle to learn riding?

Is this food a bread or a loaf?

"To split hairs" vs "To be pedantic"

What is the motivation for a law requiring 2 parties to consent for recording a conversation

Understanding the implication of what "well-defined" means for the operation in quotient group



Replace a binary file within another binary file



The 2019 Stack Overflow Developer Survey Results Are InHow to find all binary executables recursively within a directory?how to find offset of one binary file inside another?dowload find binary , accidentally deleted /usr/bin/find binary fileFind & replace image URLs in one file from another fileReplace or append a line with string within a fileExtract data between two matched patterns in a binary fileHow to view a binary file?Editing binary streams containing 'x00' bytesHow are binary files “binary”?Replace a binary block within a large file



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








-2















Is it possible replace in place a binary file located inside another binary file?
For example, compressed firmware.bin file contains:



DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
392 0x188 uImage header, header size: 64 bytes, header CRC: 0x15075729, created: 1969-12-31 23:59:59, image size: 1572736 bytes, Data Address: 0x20008000, Entry Point: 0x20008000, data CRC: 0x1DCD72E0, OS: Linux, CPU: ARM, image type: OS Kernel Image, compression type: none, image name: "abcd_rom_bin"
13596 0x351C gzip compressed data, maximum compression, from Unix, last modified: 2017-08-02 06:04:47
1573192 0x180148 uImage header, header size: 64 bytes, header CRC: 0x6FFB9B98, created: 1969-12-31 23:59:59, image size: 8376320 bytes, Data Address: 0x0, Entry Point: 0x0, data CRC: 0xC95886CF, OS: Linux, CPU: ARM, image type: Filesystem Image, compression type: none, image name: "abcd_rom_bin"
1573256 0x180188 Squashfs filesystem, little endian, non-standard signature, version 3.1, size: 8372772 bytes, 1028 inodes, blocksize: 131072 bytes, created: 2017-08-02 06:39:51


One of these binaries contains also busybox binary, is there way to replace it without the full decompression?










share|improve this question
























  • Can you make your question clearer.

    – ctrl-alt-delor
    Apr 6 at 21:46











  • It will depend on the file format.

    – ctrl-alt-delor
    Apr 6 at 21:48

















-2















Is it possible replace in place a binary file located inside another binary file?
For example, compressed firmware.bin file contains:



DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
392 0x188 uImage header, header size: 64 bytes, header CRC: 0x15075729, created: 1969-12-31 23:59:59, image size: 1572736 bytes, Data Address: 0x20008000, Entry Point: 0x20008000, data CRC: 0x1DCD72E0, OS: Linux, CPU: ARM, image type: OS Kernel Image, compression type: none, image name: "abcd_rom_bin"
13596 0x351C gzip compressed data, maximum compression, from Unix, last modified: 2017-08-02 06:04:47
1573192 0x180148 uImage header, header size: 64 bytes, header CRC: 0x6FFB9B98, created: 1969-12-31 23:59:59, image size: 8376320 bytes, Data Address: 0x0, Entry Point: 0x0, data CRC: 0xC95886CF, OS: Linux, CPU: ARM, image type: Filesystem Image, compression type: none, image name: "abcd_rom_bin"
1573256 0x180188 Squashfs filesystem, little endian, non-standard signature, version 3.1, size: 8372772 bytes, 1028 inodes, blocksize: 131072 bytes, created: 2017-08-02 06:39:51


One of these binaries contains also busybox binary, is there way to replace it without the full decompression?










share|improve this question
























  • Can you make your question clearer.

    – ctrl-alt-delor
    Apr 6 at 21:46











  • It will depend on the file format.

    – ctrl-alt-delor
    Apr 6 at 21:48













-2












-2








-2








Is it possible replace in place a binary file located inside another binary file?
For example, compressed firmware.bin file contains:



DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
392 0x188 uImage header, header size: 64 bytes, header CRC: 0x15075729, created: 1969-12-31 23:59:59, image size: 1572736 bytes, Data Address: 0x20008000, Entry Point: 0x20008000, data CRC: 0x1DCD72E0, OS: Linux, CPU: ARM, image type: OS Kernel Image, compression type: none, image name: "abcd_rom_bin"
13596 0x351C gzip compressed data, maximum compression, from Unix, last modified: 2017-08-02 06:04:47
1573192 0x180148 uImage header, header size: 64 bytes, header CRC: 0x6FFB9B98, created: 1969-12-31 23:59:59, image size: 8376320 bytes, Data Address: 0x0, Entry Point: 0x0, data CRC: 0xC95886CF, OS: Linux, CPU: ARM, image type: Filesystem Image, compression type: none, image name: "abcd_rom_bin"
1573256 0x180188 Squashfs filesystem, little endian, non-standard signature, version 3.1, size: 8372772 bytes, 1028 inodes, blocksize: 131072 bytes, created: 2017-08-02 06:39:51


One of these binaries contains also busybox binary, is there way to replace it without the full decompression?










share|improve this question
















Is it possible replace in place a binary file located inside another binary file?
For example, compressed firmware.bin file contains:



DECIMAL HEXADECIMAL DESCRIPTION
--------------------------------------------------------------------------------
392 0x188 uImage header, header size: 64 bytes, header CRC: 0x15075729, created: 1969-12-31 23:59:59, image size: 1572736 bytes, Data Address: 0x20008000, Entry Point: 0x20008000, data CRC: 0x1DCD72E0, OS: Linux, CPU: ARM, image type: OS Kernel Image, compression type: none, image name: "abcd_rom_bin"
13596 0x351C gzip compressed data, maximum compression, from Unix, last modified: 2017-08-02 06:04:47
1573192 0x180148 uImage header, header size: 64 bytes, header CRC: 0x6FFB9B98, created: 1969-12-31 23:59:59, image size: 8376320 bytes, Data Address: 0x0, Entry Point: 0x0, data CRC: 0xC95886CF, OS: Linux, CPU: ARM, image type: Filesystem Image, compression type: none, image name: "abcd_rom_bin"
1573256 0x180188 Squashfs filesystem, little endian, non-standard signature, version 3.1, size: 8372772 bytes, 1028 inodes, blocksize: 131072 bytes, created: 2017-08-02 06:39:51


One of these binaries contains also busybox binary, is there way to replace it without the full decompression?







sed data-recovery gzip binary






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago







minto

















asked Apr 6 at 13:54









mintominto

169312




169312












  • Can you make your question clearer.

    – ctrl-alt-delor
    Apr 6 at 21:46











  • It will depend on the file format.

    – ctrl-alt-delor
    Apr 6 at 21:48

















  • Can you make your question clearer.

    – ctrl-alt-delor
    Apr 6 at 21:46











  • It will depend on the file format.

    – ctrl-alt-delor
    Apr 6 at 21:48
















Can you make your question clearer.

– ctrl-alt-delor
Apr 6 at 21:46





Can you make your question clearer.

– ctrl-alt-delor
Apr 6 at 21:46













It will depend on the file format.

– ctrl-alt-delor
Apr 6 at 21:48





It will depend on the file format.

– ctrl-alt-delor
Apr 6 at 21:48










1 Answer
1






active

oldest

votes


















3














If you want to write the contents of file.gz at offset 13596 within firmware.bin (overwriting what's already there), you'd do:




zsh:



zmodload zsh/system
sysseek -u1 13596 && cat; < file.gz 1<> firmware.bin



ksh93:



cat < file.gz 1<> firmware.bin >#((13596))



dd, any shell, but reading and writing one byte at a time



dd conv=notrunc bs=1 seek=13596 if=file.gz of=firmware.bin


GNU dd, any shell, more efficient



dd bs=64k conv=notrunc oflag=seek_bytes seek=13596 if=file.gz of=firmware.bin


Or to pad with zeros to the length of 1573192 - 13596 (POSIX sh syntax for the arithmetic expansion):



dd bs=64k conv=notrunc,sync bs="$((1573192 - 13596))" count=1 
oflag=seek_bytes seek=13596 if=file.gz of=firmware.bin


Now you'll need file.gz to be at most as large as the gzipped file that was already in there. And if those headers contain checksums of the different parts, then you'll also need to compute and update the checksums.






share|improve this answer

























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f510904%2freplace-a-binary-file-within-another-binary-file%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    3














    If you want to write the contents of file.gz at offset 13596 within firmware.bin (overwriting what's already there), you'd do:




    zsh:



    zmodload zsh/system
    sysseek -u1 13596 && cat; < file.gz 1<> firmware.bin



    ksh93:



    cat < file.gz 1<> firmware.bin >#((13596))



    dd, any shell, but reading and writing one byte at a time



    dd conv=notrunc bs=1 seek=13596 if=file.gz of=firmware.bin


    GNU dd, any shell, more efficient



    dd bs=64k conv=notrunc oflag=seek_bytes seek=13596 if=file.gz of=firmware.bin


    Or to pad with zeros to the length of 1573192 - 13596 (POSIX sh syntax for the arithmetic expansion):



    dd bs=64k conv=notrunc,sync bs="$((1573192 - 13596))" count=1 
    oflag=seek_bytes seek=13596 if=file.gz of=firmware.bin


    Now you'll need file.gz to be at most as large as the gzipped file that was already in there. And if those headers contain checksums of the different parts, then you'll also need to compute and update the checksums.






    share|improve this answer





























      3














      If you want to write the contents of file.gz at offset 13596 within firmware.bin (overwriting what's already there), you'd do:




      zsh:



      zmodload zsh/system
      sysseek -u1 13596 && cat; < file.gz 1<> firmware.bin



      ksh93:



      cat < file.gz 1<> firmware.bin >#((13596))



      dd, any shell, but reading and writing one byte at a time



      dd conv=notrunc bs=1 seek=13596 if=file.gz of=firmware.bin


      GNU dd, any shell, more efficient



      dd bs=64k conv=notrunc oflag=seek_bytes seek=13596 if=file.gz of=firmware.bin


      Or to pad with zeros to the length of 1573192 - 13596 (POSIX sh syntax for the arithmetic expansion):



      dd bs=64k conv=notrunc,sync bs="$((1573192 - 13596))" count=1 
      oflag=seek_bytes seek=13596 if=file.gz of=firmware.bin


      Now you'll need file.gz to be at most as large as the gzipped file that was already in there. And if those headers contain checksums of the different parts, then you'll also need to compute and update the checksums.






      share|improve this answer



























        3












        3








        3







        If you want to write the contents of file.gz at offset 13596 within firmware.bin (overwriting what's already there), you'd do:




        zsh:



        zmodload zsh/system
        sysseek -u1 13596 && cat; < file.gz 1<> firmware.bin



        ksh93:



        cat < file.gz 1<> firmware.bin >#((13596))



        dd, any shell, but reading and writing one byte at a time



        dd conv=notrunc bs=1 seek=13596 if=file.gz of=firmware.bin


        GNU dd, any shell, more efficient



        dd bs=64k conv=notrunc oflag=seek_bytes seek=13596 if=file.gz of=firmware.bin


        Or to pad with zeros to the length of 1573192 - 13596 (POSIX sh syntax for the arithmetic expansion):



        dd bs=64k conv=notrunc,sync bs="$((1573192 - 13596))" count=1 
        oflag=seek_bytes seek=13596 if=file.gz of=firmware.bin


        Now you'll need file.gz to be at most as large as the gzipped file that was already in there. And if those headers contain checksums of the different parts, then you'll also need to compute and update the checksums.






        share|improve this answer















        If you want to write the contents of file.gz at offset 13596 within firmware.bin (overwriting what's already there), you'd do:




        zsh:



        zmodload zsh/system
        sysseek -u1 13596 && cat; < file.gz 1<> firmware.bin



        ksh93:



        cat < file.gz 1<> firmware.bin >#((13596))



        dd, any shell, but reading and writing one byte at a time



        dd conv=notrunc bs=1 seek=13596 if=file.gz of=firmware.bin


        GNU dd, any shell, more efficient



        dd bs=64k conv=notrunc oflag=seek_bytes seek=13596 if=file.gz of=firmware.bin


        Or to pad with zeros to the length of 1573192 - 13596 (POSIX sh syntax for the arithmetic expansion):



        dd bs=64k conv=notrunc,sync bs="$((1573192 - 13596))" count=1 
        oflag=seek_bytes seek=13596 if=file.gz of=firmware.bin


        Now you'll need file.gz to be at most as large as the gzipped file that was already in there. And if those headers contain checksums of the different parts, then you'll also need to compute and update the checksums.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Apr 6 at 14:20

























        answered Apr 6 at 14:08









        Stéphane ChazelasStéphane Chazelas

        313k57593950




        313k57593950



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f510904%2freplace-a-binary-file-within-another-binary-file%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

            Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

            Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.