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

  • Home
  • SEARCH
  • 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 8977013
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:16:38+00:00 2026-06-15T19:16:38+00:00

I am processing thousands of binaries wrapped in zip-like file containers, pulled from a

  • 0

I am processing thousands of binaries wrapped in zip-like file containers, pulled from a remote database. I need to analyze the contents of these binaries with tools like readelf, but I want to avoid incurring unnecessary IO to write the binaries to disk.

Is there a way to invoke subprocess.Popen so that I can pass the in-memory file to the command-line utility that the command would understand as being a file? I’ve tried assigning the file descriptor to stdin, but the utilities don’t read the file contents from stdin as expected.

with zipfile.ZipFile(file,'r') as z:
  with z.open(binary_path) as bin:
    subprocess.Popen(['readelf','-d'],stdin=bin)

I’ve also tried directly setting the necessary argument to a reference to the file descriptor, but that’s also proven fruitless:

with zipfile.ZipFile(file,'r') as z:
  with z.open(binary_path) as bin:
    subprocess.Popen(['readelf','-d',bin])

Is what I’m attempting possible, or should I just resort to writing to disk and analyzing from there?

Much thanks!

  • 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-15T19:16:39+00:00Added an answer on June 15, 2026 at 7:16 pm

    Zeroth, why do you need to popen readelf, instead of using libelf or something similar? A quick search for “elf” at PyPI shows lots of possibilities. Have you looked them over?

    First, on many platforms, all of the I/O will end up going through the cache, so it won’t really slow you down, even if it does end up eventually flushing everything to disk just to delete it (which it may never do). Careful use of mmap can often help avoiding flushing to disk, but you may not even need it.

    So really, I’d test it first and see if excessive I/O really is slowing you down. If not, stop worrying about it.

    If you want to be sure there’s no disk I/O (I’m assuming you’ve disabled all swap, because otherwise that idea is meaningless in the first place), the easiest solution is to create a temporary file that isn’t actually backed to disk.

    The easiest way to do that is to create a ramdisk, and just put the temporary files there.

    Alternatively, most platforms have a way to create a temporary file that either is never backed to disk, or is only backed to disk if absolutely necessary. Unfortunately, I don’t think any of the stdlib Python functions can do this, in which case you’ll have to write platform-specific code for it.

    If you do want to pass an arbitrary buffer to a tool as stdin, it’s easy. But you have to know how to tell the tool to read stdin—often that means something like passing -c as an option or - as a fake filename, or sometimes just not passing any filenames. Read the manpage to see which. For example:

    with zipfile.ZipFile(file,'r') as z:
        with z.open(binary_path) as bin:
            subprocess.Popen(['gzip','-dc'], stdin=bin)
    

    Unfortunately, some tools won’t work this way, often because they require a seekable file rather than just a stream. I believe readelf is one of them. So this option isn’t available.

    And passing an arbitrary fd to a tool requires the tool to have a way to take arbitrary fds instead of filenames, which most of them don’t.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am processing a flat file, with data in line by line format, like
I'm processing a list of thousands of domain names from a DNSBL through dig,
I'm processing data from a hard disk from one large file (processing is fast
After processing form from POST I should redirect, to prevent user from hitting back.
I'm doing image processing with ImageMagick commands and I would like to port them
I'm going to download (for future purposes of language processing) some thousands webpages. Now
I have some processing I want to do on thousands of files simultaneously. Grab
I am building a batch processing system. Batches of Units come in quantities from
I need to fill in a large (maybe not so much - several thousands
I'm evaluating Rx for a trading platform project that will need to process thousands

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.