The MASM Forum

Miscellaneous => The Orphanage => Topic started by: Magnum on December 13, 2012, 07:52:01 AM

Title: Make a clone of myself
Post by: Magnum on December 13, 2012, 07:52:01 AM
In regards to my fixer which would change some bytes in MY code.

I would like my code to make a copy of itself with a different name.

That would make the program smaller since I would not have to store an .exe in my code.

Then the my program c - o=u l 'd change the string in it since it would not be running.

What do you think about that idea ?

Andy
Title: Re: Make a clone of myself
Post by: dedndave on December 13, 2012, 08:18:38 AM
it may depend on the OS
we all know that you cannot write to an EXE while it is running
but, you may be able to read it
try it out - then get someone to test it on windows 7/8   :t

you may need to play with the sharing flags a little (start with FILE_SHARE_READ)
probably use OPEN_EXISTING   :P
Title: Re: Make a clone of myself
Post by: jj2007 on December 13, 2012, 12:29:58 PM
The OS has no objections (at least XP hasn't). Here is a testpiece. Apologies if it looks a bit basic :bgrin:

include \masm32\MasmBasic\MasmBasic.inc        ; download (http://masm32.com/board/index.php?topic=94.0)
  Init
  Let esi="Hello, this is string #"
  xor ecx, ecx
  .Repeat
        inc ecx
        Print esi, Str$("%i\n", ecx)
        Delay 100
  .Until ecx>=10
  Let edi=FileRead$("SendStringsToConsole.exe")        ; <<<<<<< that's myself!!
  xor ecx, ecx
  .Repeat
        push esi
        mov edx, ecx
        .Repeat
                movzx ebx, byte ptr [edi+edx]                ; we are looking for "Hello..."
                inc edx
                lodsb
        .Until al!=[edi+edx] || !al
        pop esi
        .Break .if !al
        inc ecx
  .Until ecx>=LastFileSize
  .if !al
        Inkey CrLf$, "[", esi, Str$("] is at position %i", ecx), Str$(" of %i bytes.\nRelaunch clone (y)?\n", LastFileSize)
        .if eax=="y"
                Open "O", #1, "SendStringsToConsoleClone.exe"
                mov byte ptr [edi+ecx+19], "o"                ; look out for "strong"
                PrintBuffer #1, edi, LastFileSize
                Close
                Launch "SendStringsToConsoleClone.exe"
        .endif
  .else
        Inkey "[", esi, "] not found"
  .endif
  Exit
end start
Title: Re: Make a clone of myself
Post by: Magnum on December 13, 2012, 01:07:24 PM
I don't you understood my post.

Andy
Title: Re: Make a clone of myself
Post by: jj2007 on December 13, 2012, 05:18:59 PM
I think Dave and me understood that you want to change a string in your exe and write a modified copy to disk. If that is wrong, explain "Then the my program c - o=u l 'd change the string in it" ;-)
Title: Re: Make a clone of myself
Post by: dedndave on December 13, 2012, 05:36:17 PM
Quote from: Magnum on December 13, 2012, 01:07:24 PM
I don't you understood my post.

Andy

that one, i don't   :P
Title: Re: Make a clone of myself
Post by: Magnum on December 13, 2012, 11:46:42 PM
SuperDave,

I am a perfectionist. 

I put your response through the "Sloppy Language Translator."

Input: "that one, i don't"    Output: I do not understand your post.  :icon14:

Andy
Title: Re: Make a clone of myself
Post by: dedndave on December 14, 2012, 01:20:36 AM
i figured you were just sleepy, Andy  (http://l.yimg.com/us.yimg.com/i/mesg/emoticons7/28.gif)