Minimum Sized C/C++ applications

Started by Twister, February 01, 2011, 01:24:17 AM

Previous topic - Next topic

Twister

Funny you should say that hutch. :lol

Source (.cpp):
#pragma comment(linker, "/ENTRY:main")

#undef UNICODE

#include <Windows.h>

void main()
{
MessageBox(NULL, "PowerBASIC shall bow down to VC++!", "VC++", MB_OK);
exit(0);
}


I guess you could say I cheated because I created my own entry point instead of VC++'s  t_main(int, char**)   ::)

hutch--

Here is a 1k version of MessageBox but its written in C without the ++.


/* ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ */

#include <windows.h>

void main()
  {
    MessageBox(0,"Yo Ho Ho Horton","Small C",MB_OK);
  }

/* ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤ */
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Twister

I'm coming back hard now hutch.

768 bytes in VC++. :8)

Update: Took out the exit() call to size it down to 688 bytes.

dedndave

nice name, Horton
Alex will probably make one at 512 bytes   :P

Twister

I think I have came up with a way to size it down past 512 bytes. :P

hutch--

 :bg

Yo ho ho, the minimum legal size for a PE file in 1024 bytes, 1st section has the MZ and PE headers and the section table, the second is .CODE. The tweaked versions don't run on all windows versions.  :P
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Twister

Dang! It's tough squeezing out a few extra bytes!

Final size comes out to be 640 bytes.

#pragma comment(linker, "/ENTRY:main")

#undef UNICODE

#define WIN32_EXTRA_LEAN

#include <Windows.h>

#pragma section(".text", read, execute, shared)

#pragma comment(linker, "/MERGE:.rdata=.text")

void __stdcall main()
{
MessageBox(NULL, "PowerBASIC shall bow down to VC++!", "VC++", MB_OK);
}

Antariy

Quote from: hutch-- on February 01, 2011, 01:56:54 AM
:bg

Yo ho ho, the minimum legal size for a PE file in 1024 bytes, 1st section has the MZ and PE headers and the section table, the second is .CODE. The tweaked versions don't run on all windows versions.  :P

Please have a look into MemInfoMicro thread (http://www.masm32.com/board/index.php?topic=15159.0)
It is 976 bytes. Without an icon it will be less than 800 bytes long.
It is not ordinary "Hello world!" stuff. See details in thread.
It works on *all* Windows versions.

Twister


Antariy

751 bytes C++ proggie. Without "dirty" tricks!!!

MSVC10 compiler. Should work on ALL Windows versions - msvcrt independed.

Antariy

Quote from: Antariy on February 01, 2011, 03:21:39 AM
751 bytes

Some final automatical postprocessing of EXE. Still it is not "dirty" trick.
735 bytes.

Antariy

Quote from: hutch-- on February 01, 2011, 06:58:43 AM
Alex,

All I need to do is look at the Microsoft PE specifications and the minimum size for a valid PE file is 2 x 512 byte sections, 1024 bytes. I have seen hand coded hex PE files under 200 bytes but they are not valid 32 bit PE files, they are just non-functional oddities that may not crash all Windows versions.

Reference Microsoft PECOFF.DOCX

Still, MemInfoMicro smaller that 1024 bytes. And it still work under *all* versions of Windows. Just have a look :bg

At least, executable provided are existed, they are not fantasy :bg

Minimum size of executables which may do something useful (i.e. - has import(s)) is less than 600 bytes (~548 bytes is limit by my tests) and this executable will be compatible with all Windows versions.

P.S. I'm fan of PB, too, you know this :bg

hutch--

:bg

Alex,

Manufacturers specifications are no fantasy, they are designed by the vendor to suit their OS loader. Some versions are more tolerant than others but the bottom line is 2 x 512 byte sections = 1024 bytes. i have seen "PE" files under 500 bytes but they are just curios, not valid applications.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

japheth

Quote from: Antariy on February 01, 2011, 07:50:48 AM
MemInfoMicro smaller that 1024 bytes ...

Another contest of "Who has the smallest ....?"  :bg

I can't compete, so I won't participate  :snooty:

It's also the wrong focus, because who cares nowadays about super-small sizes. All you are likely to get with such binaries are problems with various anti-virus software.

The true issues with PB are:
- no support for an object format. You're stuck in the little PB world.
- you have to buy 2 compilers to get the full functionality.

Quote
P.S. I'm fan of PB, too, you know this :bg

I like toys, that's why I'm also a fan.


Antariy

Quote from: hutch-- on February 01, 2011, 07:59:22 AM
:bg

Alex,

Manufacturers specifications are no fantasy, they are designed by the vendor to suit their OS loader. Some versions are more tolerant than others but the bottom line is 2 x 512 byte sections = 1024 bytes. i have seen "PE" files under 500 bytes but they are just curios, not valid applications.

But I told about real applications. I'm even not deciding things which only do "proper return to OS and exiting" as applications.

1024 bytes is big size to put many things to it, you know :bg

Actually, it is even too big - much more complex app than just "Hello World!" maybe placed into smaller size than bloated 1KB (I'm again about MemInfoMicro :bg :bg :bg)