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 3879852
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:46:30+00:00 2026-05-19T22:46:30+00:00

Lets say a have program.exe , i will create a python script that will

  • 0

Lets say a have program.exe , i will create a python script that will

  • read program.exe in binary mode and save it in variable data
  • open mypytonprog.py in binary append mode
  • append data to mypythonprog.py (?)

before this, mypythonprog.py would be prepared as:

program_data='''

after it, mypythonprog.py would continue as:

'''
programs continues....

(i want somehow to put that program code into a program_data variable)

This, does not work,of course, but can it be done in some way ?
What i want basicly is: mypythonfile.py to be able to create an exe file with binary data stored inside it.

I suppouse i have to encode that data to a shellcode to by able to put it inside mypythonfile.py,
right ?

  • 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-05-19T22:46:31+00:00Added an answer on May 19, 2026 at 10:46 pm
    import base64
    
    exe = 'c:/users/me/program.exe'
    script = 'c:/users/me/newpython.py'
    chunksize = 6144
    linelength = 80
    
    with open(exe,'rb') as inf, open(script,'w') as outf:
        outf.write('program_data = """')
    
        while True:
            progdata = inf.read(chunksize)
            if len(progdata):
                progdata = progdata.encode("base64")
                outf.writelines(progdata[i:i+linelength] for i in range(0, len(progdata), linelength))
            else:
                break
    
        outf.write('""".decode("base64")')
    

    Edit:

    The idea is to process the input file in convenient chunks rather than reading a potentially-huge file into memory.

    After base64-encoding the chunk, I then split it into 80-char lines (this is basically just to keep it manageable in the text editor) and write it to output.

    I wrap the data in program_data = “”” .. “””.decode(“base64”) such that when Python loads the file, the data will be automatically decrypted – program_data will contain the binary data you desire.

    8096 was a brain fart – I meant to use 8192 bytes (8KB). Then I realized there was a second problem; encoding a chunk other than a multiple of 3 chars long results in ‘=’-padded output, which prematurely truncates decoding. I have changed the chunk size to 6KB = 512 bytes (default NTFS block size) * 3 chars * 4 (arbitrary multiple); this seems to work as expected.

    Hope that helps!

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

Sidebar

Related Questions

Lets say I have a chat program that every time someone sends a message,
Hello Lets say I have a console application, that looks like this class Program
Lets say I have a server program that can accept connections from 10 (or
Lets say I have hierarchy like this (This is just a test program. Please
I have a command line program developed in c. Lets say, i have a
Lets say i have at least two lua script files. test1.lua test2.lua both define
Lets say I have a C++ program and I want to call functions from
Lets say I have files: Libs: one.cpp, one.h two.cpp, two.h three.cpp, three.h Program: program.cpp
Lets say we have a program which contains such classes: public interface AbstractItem {
lets say I have something like this: class Program { static void Main(string[] args)

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.