News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Make a clone of myself

Started by Magnum, December 13, 2012, 07:52:01 AM

Previous topic - Next topic

Magnum

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
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

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

jj2007

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

Magnum

I don't you understood my post.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

jj2007

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" ;-)

dedndave


Magnum

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
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

i figured you were just sleepy, Andy