The MASM Forum

General => The Workshop => Topic started by: Shintaro on January 06, 2023, 07:33:18 AM

Title: Dave Plummers Smallest Windows App 801 bytes
Post by: Shintaro on January 06, 2023, 07:33:18 AM
Hi,
This might be interesting, Dave Plummer and friends got the Windows App down to 801 bytes.
YouTube video is HERE. (https://youtu.be/-Vw-ONPfaFk)

Code on GitHub is HERE. (https://github.com/PlummersSoftwareLLC/HelloAssembly)
Cheers.
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: jj2007 on January 06, 2023, 08:05:25 AM
Have you looked at Tiny.asm? It's not impressive.
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: zedd151 on January 06, 2023, 08:12:02 AM
I wonder what the AV scanners will think of it ...
The 'hacky' coding to obtain kernel32 looks kinda suspicious. There was once a Masm32 example 'no imports' or something like that, that does something similar to obtain kernel32. Very fishy coding.
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: NoCforMe on January 06, 2023, 08:48:25 AM
Quote from: jj2007 on January 06, 2023, 08:05:25 AM
Have you looked at Tiny.asm? It's not impressive.

That was my reaction. Give me half and hour and I could write a smaller one. (We're talking executable size, not code size, right?)
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: hutch-- on January 06, 2023, 08:50:26 AM
It really is a gimmick, the specification for a 32 bit PE file is 2 x 512 byte sections. You can use the old driver alignment to set smaller sections but there is no garrantee that it will run on all Windows versions. You can build them a lot smaller that 801 bytes but they are all useless, if you want an app that runs and is useful, use the spec section sizes.
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: Shintaro on January 06, 2023, 10:36:57 AM
Interesting.

The criteria is:

1- Top level frame window
2- Caption
3- Title bar
4- Working minimize
5- Working maximize
6- Working close
7- Working system menu
8- Must paint its client area fully
9- Render CENTRED text in the middle of window
10 - Resizable from all sides and repaint itself properly.

YT link to criteria HERE. (https://youtu.be/-Vw-ONPfaFk?t=144)

I am not familiar with "tiny.asm" so I will try to find it.


EDIT: Sorry he was using masm, so not some other assembler.
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: jj2007 on January 06, 2023, 10:38:27 AM
Quote from: Shintaro on January 06, 2023, 10:36:57 AMI am not familiar with "tiny.asm" so I will try to find it.

It's in the GitHub code archive. Attached an even tinier one.

See also http://masm32.com/board/index.php?topic=6595.0
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: Shintaro on January 06, 2023, 11:11:41 AM
My apologies, I should have made the criteria part of the first post.
Tiny.asm is interesting, but does not meet the criteria above.
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: zedd151 on January 06, 2023, 11:16:23 AM
Quote from: jj2007 on January 06, 2023, 10:38:27 AM
Attached an even tinier one.
133 bytes of code, impressive!  :thumbsup:
Quote from: Shintaro on January 06, 2023, 11:11:41 AM
Tiny.asm is interesting, but does not meet the criteria above.
almost ...  :tongue:
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: jj2007 on January 06, 2023, 11:17:21 AM
Quote from: zedd151 on January 06, 2023, 11:16:23 AM
Quote from: jj2007 on January 06, 2023, 10:38:27 AM
Attached an even tinier one.
133 bytes of code, impressive!  :thumbsup:

Wot? I can't get the exe below 1536 bytes :cool:
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: zedd151 on January 06, 2023, 11:17:58 AM
Code only. Not the other stuff (headers, sections, etc...) ... and not including the imports jump table.  :azn:  85h bytes = 133d bytes  :tongue:
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: zedd151 on January 06, 2023, 11:22:51 AM
Quote from: jj2007 on January 06, 2023, 11:17:21 AM
I can't get the exe below 1536 bytes :cool:
Merge sections? ...  :badgrin:
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: jj2007 on January 06, 2023, 11:24:33 AM
Quote from: zedd151 on January 06, 2023, 11:22:51 AMMerge sections? ...  :badgrin:

Done, of course :bgrin:
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: zedd151 on January 06, 2023, 11:35:42 AM
Quote from: jj2007 on January 06, 2023, 11:24:33 AM
Done, of course :bgrin:
I just assembled & linked it (no merge) ... that was 2,560 bytes. That's why I asked.
There is a masm32 example "masm1k" that weighs in at 1024 bytes ... you mean that you can't beat that?   :tongue:
Attachment removed it can be found in /Masm32/examples...you need to have Masm32 SDK installed of course.
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: jj2007 on January 06, 2023, 11:37:32 AM
masm1k is not a function Windows application afaik
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: zedd151 on January 06, 2023, 11:39:59 AM
Quote from: jj2007 on January 06, 2023, 11:37:32 AM
masm1k is not a function Windows application afaik
Okay, it doesn't meet the criteria from above ...
All it does is display a blank window nothing else. But wait, so does your example.   :tongue:  Seems they are very much alike in some respects.  :biggrin:
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: hutch-- on January 06, 2023, 12:00:14 PM
 :biggrin:

masm1k is a valid Windows 32 bit PE file. It is a bare window without any facilities or accessories but it properly conforms to the system specified ABI (application binary interface) and it will run on any 32 bit or higher Windows OS.
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: jj2007 on January 06, 2023, 12:31:46 PM
Attached another trimmed version. I can't get it under 1,536 bytes, despite some tricks, but there are 400 bytes of zeros at the end.

In contrast, masm1k arrives at 1,024 bytes :rolleyes:
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: zedd151 on January 06, 2023, 03:20:48 PM
Quote from: jj2007 on January 06, 2023, 12:31:46 PM
Attached another trimmed version. I can't get it under 1,536 bytes, despite some tricks, but there are 400 bytes of zeros at the end.
In contrast, masm1k arrives at 1,024 bytes :rolleyes:
Well, what can you do ... ? I originally posted something else here, but thought better of it - and hereby disavow all knowledge of that posts (the original) contents.  :tongue:
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: hutch-- on January 06, 2023, 05:01:47 PM
jj,

Try it with Pelles linker.
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: jj2007 on January 06, 2023, 08:28:49 PM
Quote from: hutch-- on January 06, 2023, 05:01:47 PM
Try it with Pelles linker.

Hutch,

That's what I did. It's a question of a few bytes, and apparently your ...

externdef _imp__GetMessageA@16:PTR pr4
GetMessage equ <_imp__GetMessageA@16>

... technique is shorter than my GetProcAddress approach, that's all.

In any case, chasing the Guiness record for the smallest exe is fun but irrelevant for practical purposes. I do try to minimize size where it makes sense, but a minimum window MasmBasic style...
  include \masm32\MasmBasic\Res\MbGui.asm
  GuiEnd

... weighs in at two lines of source and a 59392 byte executable, and the latter is a shame but it's fine for me because it's only 1% of a bloated Hello World QT executable.

Both size and speed matter, but the real problem of Windows is that big pile of crap that builds up over time because most "programmers" don't care at all about size. Actually, they don't even know why their proggies are so bloated. Even the simplest "Hello World, I can translate ounces to grams for you" proggie comes along with a 20MB download. It's ridiculous.
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: daydreamer on January 07, 2023, 04:07:03 AM
You should check old forum, hitchhiker made 2 1024 bytes dx demos, minimum dx setup + Pixelshader
@JJ not guiness  for smallest .exe is of interest but place for squeeze more Pixelshader instructions in demoscene
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: zedd151 on January 07, 2023, 04:13:37 AM

Quote from: jj2007 on January 06, 2023, 08:28:49 PM

externdef _imp__GetMessageA@16:PTR pr4
GetMessage equ <_imp__GetMessageA@16>



... technique is shorter than my GetProcAddress approach ...
Yes, and no import jump table.  :cool:
I always wondered how to do that in masm. I thought it would be a switch that would make that possible. I hadn't really looked at masm1k before.
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: jj2007 on January 07, 2023, 06:30:55 AM
I admire what Oleh Yuschuk (https://en.wikipedia.org/wiki/OllyDbg) has done - he really knows his stuff:
CPU Disasm
Address   Hex dump          Command                       Comments
00401050   .  8D45 B4       lea eax, [ebp-4C]
00401053   .  50            push eax                      ; /pWndclassex
00401054   .  FF15 28114000 call near [<&user32.RegisterC ; \USER32.RegisterClassExA
0040105A   .  68 00000080   push 80000000
0040105F   .  59            pop ecx
00401060   .  57            push edi                      ; /lParam
00401061   .  56            push esi                      ; |hInst
00401062   .  57            push edi                      ; |hMenu
00401063   .  57            push edi                      ; |hParent
00401064   .  57            push edi                      ; |Height
00401065   .  51            push ecx                      ; |Width
00401066   .  57            push edi                      ; |Y
00401067   .  51            push ecx                      ; |X
00401068   .  68 0000CF10   push 10CF0000                 ; |Style = WS_OVERLAPPEDWINDOW|WS_VISIBLE
0040106D   .  53            push ebx                      ; |WindowName
0040106E   .  53            push ebx                      ; |ClassName
0040106F   .  57            push edi                      ; |ExtStyle
00401070   .  FF15 2C114000 call near [<&user32.CreateWin ; \USER32.CreateWindowExA
00401076   .  6A 01         push 1                        ; /Show = SW_SHOWNORMAL
00401078   .  50            push eax                      ; |hWnd
00401079   .  FF15 30114000 call near [<&user32.ShowWindo ; \USER32.ShowWindow
...
CPU Disasm
Address   Hex dump          Command                       Comments
004010BE  |> \FF75 14       push dword ptr [ebp+14]
004010C1  |.  FF75 10       push dword ptr [ebp+10]
004010C4  |.  FF75 0C       push dword ptr [ebp+0C]
004010C7  |.  FF75 08       push dword ptr [ebp+8]
004010CA  |.  FF15 44114000 call near [<&user32.DefWindow
004010D0  |.  5D            pop ebp
004010D1  \.  C2 1000       retn 10
004010D4   .  FC100000      dd 000010FC                   ; Struct 'IMAGE_IMPORT_DESCRIPTOR'
004010D8   .  00000000      dd 00000000
004010DC   .  00000000      dd 00000000
004010E0   .  E2110000      dd 000011E2
004010E4   .  24110000      dd 00001124
004010E8   .  00000000      dd 00000000                   ; Struct 'IMAGE_IMPORT_DESCRIPTOR'
004010EC   .  00000000      dd 00000000
004010F0   .  00000000      dd 00000000
004010F4   .  00000000      dd 00000000
004010F8   .  00000000      dd 00000000
004010FC   .  4C110000      dd 0000114C                   ; Import lookup table for 'user32.dll'
00401100   .  5A110000      dd 0000115A


Note there are no symbols in this 1024 byte executable!
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: zedd151 on January 07, 2023, 06:40:49 AM
Quote from: jj2007 on January 07, 2023, 06:30:55 AM
Note there are no symbols in this 1024 byte executable!
Trimmed a few bytes.  :tongue:  Now 1005 bytes.  :cool:  But I think thats cheating.  :biggrin:
Attachment removed, it has served its purpose
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: hutch-- on January 07, 2023, 07:23:15 AM
 :biggrin:

If it ain't 1024 bytes or bigger, its not a 32 bit PE file but it is a waste o disk space.  :tongue:

If you use driver alignment, you can get the file smaller than 1024 bytes but its still useless.
Title: Re: Dave Plummers Smallest Windows App 801 bytes
Post by: zedd151 on January 07, 2023, 08:19:17 AM
Quote from: hutch-- on January 07, 2023, 07:23:15 AM
If it ain't 1024 bytes or bigger, its not a 32 bit PE file but it is a waste o disk space.  :tongue:
I did say that I cheated.  :tongue: