Author Topic: The smallest executable  (Read 53650 times)

frktons

  • Member
  • ****
  • Posts: 512
Re: The smallest executable
« Reply #60 on: January 21, 2013, 04:26:56 AM »
: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

  • Member
  • **
  • Posts: 152
Re: The smallest executable
« Reply #61 on: January 21, 2013, 09:58:41 AM »
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

  • Member
  • *****
  • Posts: 2396
Re: The smallest executable
« Reply #62 on: January 21, 2013, 04:06:26 PM »
If Dave can cheat, well Ich ....

Code: [Select]
; 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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: The smallest executable
« Reply #63 on: January 22, 2013, 03:19:14 AM »
this is me, cheating   :P
Code: [Select]
        .MODEL  Tiny
        .386
        OPTION  CaseMap:None

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

        .CODE

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

        ORG     100h

_main   PROC    NEAR

        ret

_main   ENDP

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

        END     _main

frktons

  • Member
  • ****
  • Posts: 512
Re: The smallest executable
« Reply #64 on: January 22, 2013, 03:21:04 AM »
Code: [Select]
        .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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: The smallest executable
« Reply #65 on: January 22, 2013, 03:38:20 AM »
.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...
Code: [Select]
        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
Code: [Select]
        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

  • Global Moderator
  • Member
  • *****
  • Posts: 1196
Re: The smallest executable
« Reply #66 on: January 22, 2013, 04:40:10 AM »
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

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: The smallest executable
« Reply #67 on: January 22, 2013, 04:41:45 AM »
that would be cheating   :lol:

dedndave

  • Member
  • *****
  • Posts: 8828
  • Still using Abacus 2.0
    • DednDave
Re: The smallest executable
« Reply #68 on: January 22, 2013, 04:47:16 AM »
i wonder how big an exe would be if we used one of these...

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

 :biggrin:

FORTRANS

  • Member
  • *****
  • Posts: 1227
Re: The smallest executable
« Reply #69 on: January 22, 2013, 05:24:43 AM »
Hi,

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

Code: [Select]
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

  • Member
  • *****
  • Posts: 2745
Re: The smallest executable
« Reply #70 on: January 22, 2013, 05:32:23 AM »
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

  • Member
  • ***
  • Posts: 452
Re: The smallest executable
« Reply #71 on: January 22, 2013, 07:18:16 AM »
WTF are you guys smoking ... ?  :shock: :lol: :t
Kole Feut un Nordenwind gift en krusen Büdel un en lütten Pint.

npnw

  • Member
  • **
  • Posts: 152
Re: The smallest executable
« Reply #72 on: January 22, 2013, 09:22:23 AM »
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

  • Member
  • *****
  • Posts: 2745
Re: The smallest executable
« Reply #73 on: January 23, 2013, 07:46:43 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'