News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Create copy of my exe

Started by Magnum, August 02, 2013, 05:02:57 AM

Previous topic - Next topic

Magnum

How would I make a copy of my program with a different name when it runs ?

Thanks.
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Vortex

If the program does not permit you to make a copy then you can use the volume shadow service.

Magnum

I am talking about writing a program that would write out another copy with a different name.

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

jj2007

No problem under Windows XP SP3:

include \masm32\MasmBasic\MasmBasic.inc        ; download
        Init
        FileWrite "MyCopy.exe", FileRead$(CL$(0))
        .if Exist("MyCopy.exe")
                MsgBox 0, Cat$("Written "+GfDate$(-1)+", "+GfTime$(-1)+Str$(": %i bytes", GfSize(-1))), "Create a copy:", MB_OK
        .endif
        Exit
end start

The question is of course, is there a legitimate reason to do that ::)

Vortex

Hi Magnum,

Copying locked files is much more meaningful.

Here is a quick example trying your idea :

include ExeCopy.inc

.data

FileName            db 'ExeCopy.exe',0
DestFile            db 'test.exe',0

.data?

pMem                dd ?
pNumbOfBytesRead    dd ?
buffer              db MAX_PATH dup(?)
buffer2             db MAX_PATH dup(?)

.code

start:

    invoke  GetModuleFileName,0,ADDR buffer,32
    invoke  NameFromPath,ADDR buffer,ADDR buffer2
    invoke  lstrcmp,ADDR buffer2,ADDR DestFile
    jz      @f  ; Terminate the application if already copied

    invoke  ReadFileToMem,ADDR FileName,ADDR pMem,\
            ADDR pNumbOfBytesRead

    invoke  WriteFileToDisc,ADDR DestFile,pMem,pNumbOfBytesRead

    invoke  FreeMemory,pMem
@@:
    invoke  ExitProcess,0

END start

qWord

A smart virus simply use the function CopyFile()  ::)
MREAL macros - when you need floating point arithmetic while assembling!

KeepingRealBusy

qWord,

I was about to ask the same question, but would have suggested using a batch file to do the copy, or use a file editor such as PFE to COPY the file and SAVEAS.

Why invest the time to program such a common task?

Dave.

jj2007

Quote from: qWord on August 02, 2013, 05:49:29 AM
A smart virus simply use the function CopyFile()  ::)

There are indeed many ways to skin a cat. Two questions:
1. Is there a situation (by Windows version, by login status) where the OS would not allow a running exe to be loaded in memory, or copied to a different folder?
2. Why would our Christian friend want to do this...?
::)

Magnum

Thanks Vortex.

It is not being used for any hurtful purpose.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

KeepingRealBusy

JJ,

I started a test of VSTest.exe and took a breakpoint. I then started a DOS prompt and copied the VSTest.exe to a Temp.exe, no problem. Then while  VSTest.exe was still at the breakpoint, i executed Temp.exe. It too executed and started another copy of VS which took the breakpoint. Again, no problem. So you can copy an executing exe and the copy will work. Now if both exes are trying to access the same files, there will be problems unless both are opening the files for reading.

Now, this was all with Windows 7.

YMMV.

Dave.

jj2007

Quote from: KeepingRealBusy on August 02, 2013, 07:53:52 AMSo you can copy an executing exe and the copy will work... Windows 7.

Thanks, Dave. Still, I do not see a meaningful application of this possibility, unless you want to spread your exe all over the place... and as usual, the OP will not reveal his "unhurtful" intentions ::)

KeepingRealBusy

JJ,

This was in response to your prior post about the OS allowing a running exe to be loaded into memory. I was not advocating such a copy.

Dave.