Making a Very Minimal Windows Executable in C

preview_player
Показать описание
In this video I will demonstrate how you can instruct the Visual Studio linker to produce a very minimalist executable

You can get the reverse engineering software that I use in the video by running "winget install Rizin.Cutter"
Рекомендации по теме
Комментарии
Автор

- Forgot to mention that you can also pass the /O1 option to the compiler to optimize for size, but for such a small program this will have little effect
- It is possible to make an even smaller executable with methods not covered in this video

nirlichtman
Автор

A bit more precision about the end :
Every NT executable has a small DOS program at the beginning just to print "This program cannot be run in DOS mode." We can see this by opening the executable in an hex editor. The DOS program starts with the letters "MZ" (the beginning of the header for a DOS program), then a bit after that, the actual program starts with the letters "PE" followed by two NULL bytes (0x50 0x45 0x00 0x00 in hex). Windows versions running on the NT kernel will just skip over the DOS program and start directly on the NT program part, but DOS based operating systems (Every MS-DOS version + Windows 1 -> Windows ME) will start at the beginning of the file and just execute the DOS program, saying "This program cannot be run in DOS mode."

This was added back at the time when NT and DOS were both used to make sure NT programs weren't run on DOS operating systems.

pixfri
Автор

It is just so cool. It feels fresh in the realm of the frameworks and libraries.

People forgot how it felt having snappy programs. There is whole generation of developers does not care about any memory or size management.

orcofnbu
Автор

It's not tiny, it's appropriately sized and it gets the job done, that's all that matters.

danutmh
Автор

A while ago i noticed that my C programs always are around 16KB, even though the contents in them differ a lot, and that video explain it perfectly

MszS
Автор

Fun fact: The MS linker has a /stub option, which lets you supply a custom DOS program.

Sevenisko
Автор

On the DOS thing, I actually had to update BIOS firmware on a Linux machine once, and only a Windows style .exe was availiable on the manufacturer's website.
After reading around a bit, I found that I could rename and run that exec from a FreeDOS USB stick and successfully updated BIOS that way. It blew my mind a little bit, for that kind of hybrid executable to be possible.

UranG
Автор

Really pragmatic approach to the concepts I used to read in textbooks. You really did the practical even if it was a small demo, would love to see more videos like this one. You earned one subscriber. Thanks for making this.

red.doritos
Автор

The "This program cannot be run in DOS mode." gave me an idea. One could probably create a dual-mode program. That will run in DOS and Windows.

grappydingus
Автор

What a great tutorial! I’m a web developer, I’ve written in C only a little and never programmed for Windows, but this video is super clear and interesting.

cheesebusiness
Автор

The way you explain how stuff works is incredible, I really enjoyed watching the video and learning something new. You just earned a new subscriber!

chasa
Автор

Straight to the point.
No chit chat
No self glorification


EngrUsmanx
Автор

The part of the application that says, "This program cannot be run in DOS mode." is referred to as the program stub, a program within a program if you will, you can modify this executable or even include a DOS version of your application inside of it by changing some compiler options.

DeviousMalcontent
Автор

This is such an interesting concept. I always heard about the c runtime but this is the first time it was actually demonstrated to me. Great tutorial! I wish you continue on this small executable concept and demonstrate further means of making the executable even smaller. I saw some discussions in the comments about removing DOS headers, and executable compression etc. They are beyond my skill level. :-) From demoscene I also heard about 4K executables that can run OpenGL, I looked at those projects but couldn't understand what's going on. Thank you!

Автор

I feel bad watching your videos. I feel like such a leech... So much great knowledge in such a great format.

ashrasmun
Автор

Very cool. Short and to the point, while still explaining everything you're doing fairly thoroughly. Thank you for the video!

Smoth
Автор

Man, cutter is neat. Thanks for that recommendation. I'm trying to build a z80 based computer at the moment, and I've been having difficulty debugging my software.

wizard-pirate
Автор

I've not done C for a time and your explanation was excellent.

tonywtyt
Автор

The question I wanted to know a few weeks ago

ABCABC-swmh
Автор

love how You explain everything so easily and clearly :)

maciejk