Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8665211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:25:38+00:00 2026-06-12T17:25:38+00:00

I want to extract a binary section fron a .a ELF archive file in

  • 0

I want to extract a binary section fron a .a ELF archive file in Linux.

When I run objdump -h on an archive file, it lists the object files it contains, and the section headers for each section. However, the File Offset column appears to be relative to the object file position in the archive, as otherwise they would all the sections would be overlapping.

I expected I could use dd to extract binary information from the archive file. (see How do you extract only the contents of an ELF section). How do I do this with an archive?

I should also mention the section I’m extracting is added with this command :

echo "hi" > commentFile
objcopy libmylib.a --add-section .mysection=commentFile libmylib.a
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T17:25:39+00:00Added an answer on June 12, 2026 at 5:25 pm

    the File Offset column appears to be relative to the object file position in the archive

    The file offset you get from objdump is relative to the beginning of the individual object file. You can think of an archive library as a bookshelf, and the ouput of objdump -h as the index within each individual book. You wouldn’t expected the index to change depending on which other books are on the shelf, or when you take the book from the shelf. Similarly, the object file itself (and the output of objdump -h) does not change when you put into the library, or extract it out again (you get bit-identical copy).

    I expected I could use dd to extract binary information from the archive file

    You could use dd, but you’d have to first find the position of each individual object file in the archive. That’s not too difficult: the format of UNIX archive files is documented. But the format can change depending on which UNIX variant you use, and it’s not really necessary for the task you want to perform.

    How do I do this with an archive?

    If you know that .mysection has identical contents in all object files in libmylib.a (as would be the case for the objcopy --add-section command you gave), then extract one object, from the archive, then extract the section:

    firstobj=$(ar t libmylib.a | grep '\.o$' | head -1)
    ar x libmylib.a $firstobj
    # use objdump -h and dd to extract section context.
    # or use "readelf -p .mysection $firstobj
    rm -f $firstobj
    

    If the contents of .mysection may be different in different object files, extract them to a temporary directory:

    mkdir tmp.$$ && cd tmp.$$ && ar x ../libmylib.a
    for obj in $(find . -type f); do
      # extract .mysection from $obj
    done
    cd .. && rm -rf tmp.$$
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically what I want to do is to read a binary file, and extract
I want to extract the file name 13572_BranchInformationReport_2012-06-28.zip from the following text - 1:30,/icons/def13572_BranchInformationReport_2012-06-28.zip,13572_BranchInformationReport_2012-06-28.zip,0,184296,Jun
I want to extract the desired information from a file and append it into
I want to extract the white area of my binary image. Everywhere I check
On a Linux desktop (RHEL4) I want to extract a range of bytes (typically
I want to scrape string data from some binary text files that contain embedded
i want to read\write a binary file which has the following structure: The file
I have binary and want to extract part of it, starting from know byte
I have .mfd files and I want to import my information in .mfd file
How can I extract information from a binary file that I don't have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.