The MASM Forum

General => The Workshop => Topic started by: DaviFN on June 05, 2018, 12:23:26 AM

Title: Tiniet portable executable
Post by: DaviFN on June 05, 2018, 12:23:26 AM
Hi everyone!

I've been, for the past days, searching for the smallest executable for Windows. The reason is that I want to start a small macro for a game (basically just presses a key and maybe draw some pixels on screen), and I'd like it to be tiny, just for the sake of it. I'll not use NASM, however; I intend to use Ollydbg or another such tool to directly "code" in the executable itself (sort of like a challenge).

I searched the web for the smallest executable, and it appears to be 97 bytes large. I couldn't find it for download, but I don't think it would run in any version of Windows (I want it to run from XP up (XP,7,8,10)). I found one called "hh2 golden.exe" (~400 bytes), which apparently runs from XP up, but it prints "Hello World!" in the screen (I'd like one that did nothing).

Also, I couldn't assemble them (I don't know how to properly use MASM). I'd use "hh2 golden.exe", but then I had the idea to ask here if one of you guys have a better executable that I could use in this adventure.

tl;dr: I'm asking for the smallest executable capable of running from winXP up. Preferrably it does nothing, since I want to modify it and put some functionality to it (but I need it to be completely clear at the beginning)

Thanks!
Title: Re: Tiniet portable executable
Post by: aw27 on June 05, 2018, 01:28:11 AM
There is a thread somewhere about that (found it):
http://masm32.com/board/index.php?topic=6595.0
Title: Re: Tiniet portable executable
Post by: hutch-- on June 05, 2018, 02:06:27 AM
If its tiny 16 bit DOS COM files, you can make a reboot COM file at 2 bytes. Win Win32, depending on the OS version you can go under the 2 x 512 byte sections but it risks being unreliable and may not work on all Windows versions. Write your own custom MZ stub and also set the section size in the linker until it won't run then tweak it it back up a little. It is an exercise in futility as you can't get a 32 bit PE file to do anything useful at under 2 x 512 byte sections. There is a full working windows in the MASM32 example code that builds at 1k and that is about the bottom limit for anything that may be useful.
Title: Re: Tiniet portable executable
Post by: DaviFN on June 05, 2018, 03:39:38 AM
Would it be too much if I asked for someone to upload a small win32 executable (the smaller, the better) capable of running in Windows XP, 7, 8 & 10? (As I said, I just want a working .exe in order to start modifying it and make it do what I want it to do, e.g. repeatedly press a key)

Thank you anyway!
Title: Re: Tiniet portable executable
Post by: felipe on June 05, 2018, 04:25:00 AM
You want to modify the exe or the source?  :idea:
Title: Re: Tiniet portable executable
Post by: DaviFN on June 05, 2018, 04:44:04 AM
I want to modify the .exe directly. That is why I want sort of a "scratch", an empty executable that does nothing. I want it to work in Win XP, 7, 8 and 10 (mainly 32 bits, but working on 64 too would be nice). The smaller it is, the better (I don't want irrelevant bytes).

I'll then use Cheat Engine & OllyDBG in order to modify it. I'll keep modifying until I make it do what I want it to do (something simple, like pressing a key).
Title: Re: Tiniet portable executable
Post by: Vortex on June 05, 2018, 05:08:17 AM
Hi DaviFN,

Welcome to the Masm Forum.

How are you sure that your code will fit into the code section of the tiny executable?
Title: Re: Tiniet portable executable
Post by: zedd151 on June 05, 2018, 05:13:29 AM
Quote from: DaviFN on June 05, 2018, 04:44:04 AM

...I'll then use Cheat Engine & OllyDBG in order to modify it. I'll keep modifying until I make it do what I want it to do...

Why don't you just learn a little bit of Masm32, and program what you need the right way. Then you can optimize it to you hearts content. For size, speed, or whatever floats your boat.   8)

Coding directly with olly is rather tedious, prone to error, etc.

Oh, and welcome the the Masm32 forum.   :icon14:
Title: Re: Tiniet portable executable
Post by: DaviFN on June 05, 2018, 06:17:02 AM
It won't fit in the code section. So I'll force it to jump to the end of the executable and continue from there.
Title: Re: Tiniet portable executable
Post by: DaviFN on June 05, 2018, 06:20:13 AM
I guess I like seing the whole file, and being able to have full control over it. MASM would do it, too, but I could simply code it in C. As I said, I want sort of like a challenge.

Thank you for the welcome!
Title: Re: Tiniet portable executable
Post by: zedd151 on June 05, 2018, 06:23:05 AM
Quote from: DaviFN on June 05, 2018, 06:17:02 AM
It won't fit in the code section. So I'll force it to jump to the end of the executable and continue from there.

That will surely trigger anti-virus scanners.
You're not writing a virus or other malware are you? Because having a small code section and jumping outside of it will make the virus detection algos flag your 'program' as a virus, or other malware.

It's better to program what you need correctly as to not trigger AV software.

And if you continue outside of the executable, will probably trigger a page fault.
Title: Re: Tiniet portable executable
Post by: DaviFN on June 05, 2018, 06:26:05 AM
I didn't know that. I'm not writing malware, just a macro that will keep pressing a key when a variable is set, and that variable would be toggled by pressing a key. But there must be a way to expand the code section...
Title: Re: Tiniet portable executable
Post by: zedd151 on June 05, 2018, 06:50:12 AM
Quote from: DaviFN on June 05, 2018, 06:26:05 AM
I didn't know that. I'm not writing malware, just a macro that will keep pressing a key when a variable is set, and that variable would be toggled by pressing a key. But there must be a way to expand the code section...

you can, using a hex editor. keep in mind that x86 executables are aligned to 200h bytes. So if you increase the code section, it should be by 200h bytes. Then if you also have a .data or imports, or .rsrc  section, the section headers should be adjusted according to the new .text section size.

;)

That's about all I have to say about that.   8)
Title: Re: Tiniet portable executable
Post by: felipe on June 05, 2018, 07:50:18 AM
 :eusa_snooty: MMM don't know don't know, sounds a little suspicious to me...Sorry i will not help you with this odd project... :idea:

But welcome to the forum anyway  :P. Try to read well the forum rules... :idea:
Title: Re: Tiniet portable executable
Post by: DaviFN on June 05, 2018, 08:39:19 AM
I just got inspired from that .kkrieger game (96 KB) and wanted to dive in this adventure of creating a small, useful executable. The game itself states "macros are allowed", and this specific macro I'll create is the most used one; the so-called "auto potion"; just presses Q, W and E indefinitely.

I understand the suspiction, though. I could quickly code a C program to do that. Just wanted some challenge.
Title: Re: Tiniet portable executable
Post by: felipe on June 05, 2018, 08:47:08 AM
I don't know that game.If you want a challenge what about making a program (doesn't matter the size) that process tiny files that have "the smaller code possible" to tell the program what action to take  :idea:? Now, that's interesting... :biggrin:
Title: Re: Tiniet portable executable
Post by: Siekmanski on June 05, 2018, 08:59:34 AM
Welcome to the forum.  :t

Quote from: DaviFN on June 05, 2018, 08:39:19 AM
I just got inspired from that .kkrieger game (96 KB) and wanted to dive in this adventure of creating a small, useful executable. The game itself states "macros are allowed", and this specific macro I'll create is the most used one; the so-called "auto potion"; just presses Q, W and E indefinitely.

I understand the suspiction, though. I could quickly code a C program to do that. Just wanted some challenge.

Isn't that the Farbraush production where they tested the first kkrunchy packer?
Title: Re: Tiniet portable executable
Post by: Jean-Marie on June 05, 2018, 06:59:28 PM
I remember Peter Ferrie had made an article on the smallest possible executable, but I can't find it back.
I found this page which explains where to insert some code in the header section.
http://pferrie.000webhostapp.com/misc/tiny/pehdr.htm (http://pferrie.000webhostapp.com/misc/tiny/pehdr.htm)
This can be helpful.
Title: Re: Tiniet portable executable
Post by: zedd151 on June 05, 2018, 07:02:34 PM
Quote from: Jean-Marie on June 05, 2018, 06:59:28 PM
.... which explains where to insert some code in the header section.
This can be helpful.
Which will also set off alarm bells from AV software.
Title: Re: Tiniet portable executable
Post by: aw27 on June 05, 2018, 07:14:35 PM
This was all discussed in the AM thread.
It is also not possible to modify PE headers with MASM, you need to use a clone like UASM.
With UASM we can obtain a small .exe of around 200 bytes able to run on win xp, vista, 7 and 10.
We made experiments to make the .exe as small as 103 bytes but it failed to run on more recent OSs.

And we have also explored how small a 64-bit .exe we can obtain.

BTW, we can also make small .exes in C with about 1KB, I think with talked about that as well in the AM thread (or in another).