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

Quote from: hutch-- on January 20, 2013, 11:16:36 PM
:biggrin:

You can do a "REBOOT.COM" in 2 bytes, "int 19h".  :P


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

frktons,
yup, that was what I was thinking!


Vortex,

I read a PE format code for NT 3.1 in another article, and I think he referenced it in his article that there were windows versions that wouldn't run that small of program.  However, most will run it fine.


Magnum

If Dave can cheat, well Ich ....


; com.asm Com file template
;
; Ahh....Back in time when things were simpler, No I-Phones, Gas Wars were common, and
folks said Please and Thank you.
;       
;
.model       tiny
.386
.code

org          100h

begin:

jmp          start

; data goes here

start:
   
int     20h ; proper exit

end begin

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

dedndave

this is me, cheating   :P
        .MODEL  Tiny
        .386
        OPTION  CaseMap:None

;####################################################################################

        .CODE

;************************************************************************************

        ORG     100h

_main   PROC    NEAR

        ret

_main   ENDP

;####################################################################################

        END     _main

frktons

Quote from: dedndave on January 22, 2013, 03:19:14 AM
        .MODEL  Tiny
        .386
        OPTION  CaseMap:None

;####################################################################################

        .CODE

;************************************************************************************

        ORG     100h

_main   PROC    NEAR

        ret

_main   ENDP

;####################################################################################

        END     _main


Dave won the prize with his "Do nothing" program  :greenclp: :eusa_dance: :greenclp:
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

.COM programs start out with a 0 word pushed onto the stack and CS = DS = ES = SS = PSP
at PSP:0000, you will find CD 20, which is INT 20h
so, a NEAR RET gets you a terminate   :P

MZ .EXE's start out a little differently
the code segment is not the same as the PSP segment, like .COM's
as i recall, DS and ES are pointing to the PSP, though
so, you can do this...
        xor     ax,ax
        push    ds
        push    ax
;
;
;
        retf

the 8086/8088 didn't support pushing constants, so you couldn't use PUSH 0
most of the general registers are set to 0, i think
you might get away with PUSH DX or something
AX may not be 0 if there is 1 or 2 valid parsed path(s) on the command line
        push    ds
        push    dx
;
;
;
        retf

i think that's the minimal MZ EXE - 3 bytes of code, 512 for the header
you're not supposed to use INT 20h from an EXE, unless you set cs to psp - something like that

MichaelW

If just opening and closing meets the requirements, then I think you can get the same apparent result by renaming an arbitrary 1-byte file to whatever.exe.
Well Microsoft, here's another nice mess you've gotten us into.

dedndave

that would be cheating   :lol:

dedndave

i wonder how big an exe would be if we used one of these...

http://www.linurs.org/mc14500.html

:biggrin:

FORTRANS

Hi,

   This also works.  And is small.  Doesn't do much though.
Has to be a *.COM program of course.


CODE    SEGMENT
        ASSUME  CS:CODE,DS:CODE,ES:NOTHING
        ORG     100H    ; COM file opening
START:

        RET     ; Ensure near return.

CODE    ENDS
        END     START


Cheers,

Steve N.

Vortex

Hi npnw,

The article was interesting because MS link will simply refuse to link the object files because of the improper alignment value 1. At least, this is what I observed with the linker supplied with the Masm32 package. Windows 2000 will not run executables not importing API functions.

Greenhorn

WTF are you guys smoking ... ?  :shock: :lol: :t
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

npnw

Vortex,

He made reference to the API in win 2000 in the article. The linker probably won't work because of the 16 byte limit, or derivative of 16 for byte alignment and memory transfers at that time. Otherwise it would take two or more memory reads to transfer with the processor. I'm not sure if they have made this 32 bit now, or 64 byte alignment to optimize memory access.

Otherwise the 1 byte would work for 8088 virtual mode. If they have decoupled the linker from hardware, you can do this. If they are optimized for the hardware, this is why it wouldn't work.

http://msdn.microsoft.com/en-us/library/s0ksfwcf(v=vs.80).aspx

Align
http://msdn.microsoft.com/en-us/library/dwa9fwef(v=vs.80).aspx

directive references
http://msdn.microsoft.com/en-US/library/8t163bt0(v=vs.80).aspx

These were from the visual studio 2005 there are links to other assembler versions.

Vortex

Quote from: npnw on January 22, 2013, 09:22:23 AM
He made reference to the API in win 2000 in the article.

Here is the problem. Windows 2000 will simply refuse to run a PE not importing an API function. ( tiny.exe - 97 bytes )

Tried the 97 bytes example on a virtual Windows 2000 running on qemu. Ollydbg reported : Bad or unknown format of 32-bit executable file 'C:\tiny.exe'

Antariy

http://www.masmforum.com/board/index.php?topic=10252.msg125601#msg125601 :biggrin: