News:

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

Main Menu

The smallest executable

Started by frktons, January 17, 2013, 09:29:34 AM

Previous topic - Next topic

frktons

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


dedndave

        push    18004Fh       ;79 x 24
        push    0
        INVOKE  SetConsoleWindowInfo, wHnd, TRUE, esp
        pop     ecx
        pop     edx


:P

jj2007

Initialised local variables? You are cheating, Dave ;-)

frktons

Quote from: jj2007 on January 19, 2013, 01:50:18 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.   ;)

Quote from: dedndave on January 19, 2013, 01:50:56 AM
        push    18004Fh       ;79 x 24
        push    0
        INVOKE  SetConsoleWindowInfo, wHnd, TRUE, esp
        pop     ecx
        pop     edx


:P

Is this the equivalent of:



    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

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

Quote from: dedndave 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
        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

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

That impressive and something I have needed.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

frktons

Quote from: Magnum on January 19, 2013, 03:32:24 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--

 :biggrin:

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

masm1k.exe is 1024 bytes. exampl07 directory. Done years ago.

frktons

#56
Quote from: hutch-- 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.
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:
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

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

Quote from: npnw 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.

Hi npnw,

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

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

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