Author Topic: The smallest executable  (Read 54131 times)

frktons

  • Member
  • ****
  • Posts: 512
Re: The smallest executable
« Reply #45 on: January 19, 2013, 12:59:34 AM »
Does the attached 2K version crashes as well? On my pc is works.
If it does, I'll follow Jochen's advice and create a LOCAL variable.

I don't think it will affect the 2.048 bytes result.

To get there I had to leave only the essential and get rid of some
redundancy here and there.

And, well I restored the .data section as well, the link parameters I'm
using already merge data section so there is no need to make
strange things with preinitialized data.
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

jj2007

  • Member
  • *****
  • Posts: 13871
  • Assembly is fun ;-)
    • MasmBasic
Re: The smallest executable
« Reply #46 on: January 19, 2013, 01:50:18 AM »
2k, no crash :t

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: The smallest executable
« Reply #47 on: January 19, 2013, 01:50:56 AM »
Code: [Select]
        push    18004Fh       ;79 x 24
        push    0
        INVOKE  SetConsoleWindowInfo, wHnd, TRUE, esp
        pop     ecx
        pop     edx

 :P

jj2007

  • Member
  • *****
  • Posts: 13871
  • Assembly is fun ;-)
    • MasmBasic
Re: The smallest executable
« Reply #48 on: January 19, 2013, 01:53:09 AM »
Initialised local variables? You are cheating, Dave ;-)

frktons

  • Member
  • ****
  • Posts: 512
Re: The smallest executable
« Reply #49 on: January 19, 2013, 02:05:51 AM »
2k, no crash :t

I think it is enough, getting rid of 512 bytes more would be a bit complex
and too long way.   ;)

Code: [Select]
        push    18004Fh       ;79 x 24
        push    0
        INVOKE  SetConsoleWindowInfo, wHnd, TRUE, esp
        pop     ecx
        pop     edx

 :P

Is this the equivalent of:

Code: [Select]

    windowSize  SMALL_RECT <N0,N0,N79,N24>

    INVOKE SetConsoleWindowInfo, wHnd, TRUE, ADDR windowSize

?
You have pushed 8 bytes on the stack,
The SMALL_RECT is 8 bytes long.

Nice little trick to get around things.

Is it smaller or just smarter than usual code?
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: The smallest executable
« Reply #50 on: January 19, 2013, 02:27:24 AM »
when you push a constant, the assembler assumes it's a dword in a use32 segment
so, you have created the structure, temporarily, on the stack
when you are done using it, pop, pop, it's gone

one thing that is convenient, in this case, is that a pointer to the structure is in ESP
because the structure pointer is the last parameter of the function, you can use it directly
if the function had other parms afterwards, you'd have to move the current stack pointer into a register
ReadFile and WriteFile are examples of this if you want to create a temporary nNumberOfBytes dword
Code: [Select]
        push    0
        mov     edx,esp
        INVOKE  ReadFile,hFile,lpFileBuf,uFileSize,edx,NULL
        pop     ecx
that's because parameters are pushed onto the stack in reverse order
so - when NULL is pushed, ESP changes

frktons

  • Member
  • ****
  • Posts: 512
Re: The smallest executable
« Reply #51 on: January 19, 2013, 02:50:38 AM »
when you push a constant, the assembler assumes it's a dword in a use32 segment
so, you have created the structure, temporarily, on the stack
when you are done using it, pop, pop, it's gone

one thing that is convenient, in this case, is that a pointer to the structure is in ESP
because the structure pointer is the last parameter of the function, you can use it directly
if the function had other parms afterwards, you'd have to move the current stack pointer into a register
ReadFile and WriteFile are examples of this if you want to create a temporary nNumberOfBytes dword
Code: [Select]
        push    0
        mov     edx,esp
        INVOKE  ReadFile,hFile,lpFileBuf,uFileSize,edx,NULL
        pop     ecx
that's because parameters are pushed onto the stack in reverse order
so - when NULL is pushed, ESP changes


Thanks Master Dave, and here it is a present for you,
the 1.5K version of the program  :P

Do you think I've to shrink it more or I can pass through and
move to something else?  :lol:
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: The smallest executable
« Reply #52 on: January 19, 2013, 02:59:36 AM »
1.5 kb is about as small as a PE EXE gets
Alex can make a smaller EXE, but he plays a lot of tricks to do it   :P

Magnum

  • Member
  • *****
  • Posts: 2396
Re: The smallest executable
« Reply #53 on: January 19, 2013, 03:32:24 AM »
That impressive and something I have needed.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

frktons

  • Member
  • ****
  • Posts: 512
Re: The smallest executable
« Reply #54 on: January 19, 2013, 03:36:06 AM »
That impressive and something I have needed.

Andy

I'm happy to be of some help. :t
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10572
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: The smallest executable
« Reply #55 on: January 19, 2013, 08:03:53 AM »
 :biggrin:

> 1.5 kb is about as small as a PE EXE gets

masm1k.exe is 1024 bytes. exampl07 directory. Done years ago.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

frktons

  • Member
  • ****
  • Posts: 512
Re: The smallest executable
« Reply #56 on: January 19, 2013, 10:14:41 AM »
:biggrin:

> 1.5 kb is about as small as a PE EXE gets

masm1k.exe is 1024 bytes. exampl07 directory. Done years ago.
If the program only opens an empy window maybe it is possible
to do it in 700-800 bytes more or less, but it will appear as 1,024
anyway. I challenged everybody 2 years ago to shrink a 12K exe+
screen, but there was no real competition. I built it, step by
step, and here it is now. Somebody thought it was more or less
an impossible task. And I tend to love impossible tasks by my own
nature.  :lol:
« Last Edit: January 19, 2013, 11:27:38 AM by frktons »
There are only two days a year when you can't do anything: one is called yesterday, the other is called tomorrow, so today is the right day to love, believe, do and, above all, live.

Dalai Lama

npnw

  • Member
  • **
  • Posts: 152
Re: The smallest executable
« Reply #57 on: January 20, 2013, 09:41:10 PM »
http://www.phreedom.org/research/tinype/

Used to be able to write com files in a few bytes way back in the day. I think 5 bytes for a reboot code.
If they haven't changed the spec, the link above is the tiniest I know about.



Vortex

  • Member
  • *****
  • Posts: 2768
Re: The smallest executable
« Reply #58 on: January 20, 2013, 09:53:08 PM »
http://www.phreedom.org/research/tinype/

Used to be able to write com files in a few bytes way back in the day. I think 5 bytes for a reboot code.
If they haven't changed the spec, the link above is the tiniest I know about.

Hi npnw,

I wonder how the author of that article managed to link the object module :

Code: [Select]
link /nologo /ENTRY:main /NODEFAULTLIB /SUBSYSTEM:WINDOWS /ALIGN:1 tiny.obj
The alignment value 1 is less than section alignment 16. Some version(s) of Windows will refuse to run very small portable executables.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 10572
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: The smallest executable
« Reply #59 on: January 20, 2013, 11:16:36 PM »
 :biggrin:

You can do a "REBOOT.COM" in 2 bytes, "int 19h".  :P

Erol is correct here, go below 512 byte alignment and it becomes unreliable, particularly on earlier versions of Win32. The linkers generate the warning for good reason, it does not comply with the PE specs for Win32.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy: