Jump to content

write to exe


 Share

Recommended Posts

Is there anyway to alter a compiled exe ....on the fly??

eg

$szFile="my.exe"
        FileOpen($szFile, BitOR(16, 1))
        $letters=""
        For $i = 1 To 2
        $letters &= Chr(Random(48, 57, 1))
        Next
        FileDelete($szFile)
        FileWrite($szFile,$letters )

so basically this code is in the exe ,when its started it writes some numbers at the end of the file

Link to comment
Share on other sites

  • Moderators

??

yeah that works on a file called my.exe not if the file im executing is called my.exe

You can't write to an executable that is open.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

thought as much...

ok then ...I created a loader first then ...so I run the loader it alters the main exe then it launches the exe...

Why wont it work though??

$szFile="my.exe"
FileOpen($szFile, BitOR(16, 1))
 $letters=""
 For $i = 1 To 2
         $letters &= Chr(Random(48, 57, 1))
     Next
        FileDelete($szFile)
        FileWrite($szFile,$letters )
    FileClose($szFile)
    sleep(1000)
    run("my.exe")
        exit

it opens the exe writes to it then wont open it!!

Link to comment
Share on other sites

  • Moderators

You need to learn how to use FileOpen()/FileRead()/FileWrite() it seems...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Developers

Not sure what servers,id's and passwords have got to do with it...

I'll explain a bit better...

I have 2 exe's in a folder loader.exe and app.exe ...

when i run loader.exe it:

1,writes to app.exe

2, runs app.exe

3,exits

The question is still not answered: Why do you need to write to the exe and not use another way of passing the variables?

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Developers

The exe is just wrote to ,to change the crc32 thats all...

:mellow: I hope this is not the answer to my question because else I do not understand it . :(

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I don't think you understand what I'm getting at. You would be passing information to the exe that you need for it to use. If you want to write to the EXE, then you would need to inject the code in. The only time you need to write to the exe is if you want to permanently change the exe if it was to be ran later by itself. (without any interaction from you or your loader. (Note, this is what a virus does, so you may want to think about this approach) Is that what you need to happen?

If you are basically telling it what it needs to access something for example, then pass that to it via the switch. It is pretty basic and a simple way to solve your problem.

Edited by Volly
Link to comment
Share on other sites

Im really confused now!!

The exe will be permanetly change ... it adds "XX" to the end of the file each time the loader runs...

so I run the loader , it then writes "XX" to the end of app.exe , then lauches app.exe , then loader.exe closes

Link to comment
Share on other sites

  • Developers

Im really confused now!!

The exe will be permanetly change ... it adds "XX" to the end of the file each time the loader runs...

so I run the loader , it then writes "XX" to the end of app.exe , then lauches app.exe , then loader.exe closes

Maybe I missed it but could you try to explain what you want in stead of asking for a solution to the way you think it should work.

Explain to us what you exactly want to accomplish and maybe we can help you.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I'll repost my original code..

$szFile="my.exe"
FileOpen($szFile, BitOR(16, 1))
$letters=""
For $i = 1 To 2
         $letters &= Chr(Random(48, 57, 1))
     Next
        FileDelete($szFile)
        FileWrite($szFile,$letters )
    FileClose($szFile)
    sleep(1000)
    run("my.exe")
        exit

lets start at the beginning then..

The code above is what I'll refer to as loader.exe..

And another exe called app.exe which is the main prog(example a msgbox compiled as an exe)

Now when loader.exe is ran it writes 2 numbers to the end of app.exe , once loader.exe has done this loader.exe launches the modified app.exe then loader.exe closes and the app.exe should now be running

Hope this helps

Link to comment
Share on other sites

  • Developers

Try to answer the questions asked, not to repeat what you already said.

Why do you want to add something to the end of an EXE. What is the purpose?

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Another way to ask - What do those 2 numbers do for the my.exe? Could you use a ini file to host the numbers and my.exe reference that?

What we are trying to get at is there isn't a good reason to write to the exe when there are many easier ways to get information the exe needs.

Link to comment
Share on other sites

Now when loader.exe is ran it writes 2 numbers to the end of app.exe , once loader.exe has done this loader.exe launches the modified app.exe then loader.exe closes and the app.exe should now be running

What does those 2 numbers do to the exe? Are you trying to change the file size of the exe?

Link to comment
Share on other sites

the sole purpose of writing to the exe is to change the crc32...thats all

I found if you write to the end of a file it still runs...

I think this is where were getting lost .. alls I want to do is change the files crc32 then launch it... Im passing no info about ..its straight forward openfile() filewrite() run()

Edited by bluerein
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...