Author Topic: Make a clone of myself  (Read 4384 times)

Magnum

  • Member
  • *****
  • Posts: 2354
Make a clone of myself
« 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
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: Make a clone of myself
« Reply #1 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

jj2007

  • Member
  • *****
  • Posts: 10648
  • Assembler is fun ;-)
    • MasmBasic
Re: Make a clone of myself
« Reply #2 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
  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

  • Member
  • *****
  • Posts: 2354
Re: Make a clone of myself
« Reply #3 on: December 13, 2012, 01:07:24 PM »
I don't you understood my post.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

jj2007

  • Member
  • *****
  • Posts: 10648
  • Assembler is fun ;-)
    • MasmBasic
Re: Make a clone of myself
« Reply #4 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" ;-)

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: Make a clone of myself
« Reply #5 on: December 13, 2012, 05:36:17 PM »
I don't you understood my post.

Andy

that one, i don't   :P

Magnum

  • Member
  • *****
  • Posts: 2354
Re: Make a clone of myself
« Reply #6 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
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

  • Member
  • *****
  • Posts: 8827
  • Still using Abacus 2.0
    • DednDave
Re: Make a clone of myself
« Reply #7 on: December 14, 2012, 01:20:36 AM »
i figured you were just sleepy, Andy