Jump to content
Sign in to follow this  
bluerein

write to exe

Recommended Posts

bluerein

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

Share this post


Link to post
Share on other sites
bluerein

??

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

Share this post


Link to post
Share on other sites
SmOke_N

??

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.

Share this post


Link to post
Share on other sites
bluerein

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!!

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
bluerein

sorry you lost me there...

Why whats wrong ??

Thats the bit that works..Its the last line that doesnt work..

Share this post


Link to post
Share on other sites
bluerein

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

Share this post


Link to post
Share on other sites
Jos

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


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
bluerein

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

Share this post


Link to post
Share on other sites
Jos

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 . :(

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Bert

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

Share this post


Link to post
Share on other sites
bluerein

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

Share this post


Link to post
Share on other sites
Jos

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.


Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
bluerein

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

Share this post


Link to post
Share on other sites
Jos

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

Visit the SciTE4AutoIt3 Download page for the latest versions  - Beta files                                How to post scriptsource        Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites
Bert

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.

Share this post


Link to post
Share on other sites
Bert

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?

Share this post


Link to post
Share on other sites
bluerein

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

Share this post


Link to post
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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.