General > The Workshop

Small .exes in C

(1/5) > >>

aw27:
Some people say it is impossible to make smaller applications in C than in Assembly Language.
This is not totally true. Using as model the code from this message I made a C .exe of the same size as the MASM one, i.e 3072 bytes. The output is the same, the difference is that the encrypted string is not in the middle of the code. That could have been done as well with inline asm, but I prefered to keep it all in C this time.
The compiler used was VS 2017 using the Windows SDK 7.1 toolset.
The code and .exe are attached.

hutch--:
I am taking unfair advantage of you here Jose, not only am I using MASM but I used Pelle's linker.

MASM the magnificent and modest at 1536 bytes.  :P

I forgot to free the allocated memory. Main should look like this.

main proc

    LOCAL ptxt:DWORD

    call mangled
    mov ptxt, eax
    invoke StdOut, ptxt
    free ptxt

    ret

main endp


Builds at the same size.

nidud:
Asmc: 1536 byte

--- Code: ---;
; Build: asmc -pe -D__PE__ main.asm
;
include alloc.inc
include conio.inc
include stdio.inc
include stdlib.inc

.code

obs dd 0x0BB11E534, 0x0BB3F9751, 0x0DE51FE36, 0x0B034DE53, 0x0C346BB25, 0x0A6349B4A, \
       0x0D214E92F, 0x0B6668847, 0x09612E167, 0x0F17C880C, 0x09011A820, 0x0F165C944, \
       0x0D101AC20, 0x0B564CE4D, 0x0D044AB39, 0x0B127D84C, 0x0D745B76C, 0x0B8319709, \
       0x0DC5EF429, 0x0B83F9C09, 0x0DD49F97D, 0x08E66911E, 0x0FA13D93E, 0x0D676B457, \
       0x0A256D139, 0x0CD76A578

main proc
   
    numberOfElements = sizeof(obs) / sizeof(dword)

    mov esi,calloc(numberOfElements + 1, 4)
    mov edi,sizeof(obs)

    .for (edx=0: edx<numberOfElements : edx++)

        mov eax,obs[edx*4]
        xor eax,edi
        mov edi,obs[edx*4]
        mov ecx,numberOfElements - 1
        sub ecx,edx
        mov [esi+ecx*4],eax
    .endf

    printf(esi)
    _getch()
    exit(0)

main endp

    end main

--- End code ---

hutch--:
ust looking at the code, it appears that neither of you guys are decrypting the data, it looks like you have just stored the text data in numeric form.

aw27:

--- Quote from: hutch-- on September 09, 2017, 03:45:25 AM ---Just looking at the code, it appears that neither of you guys are decrypting the data, it looks like you have just stored the text data in numeric form.

--- End quote ---

 :biggrin:


--- Quote --- 1536 byte

--- End quote ---

If I use polink i get 1536 bytes as well.  :t
\masm32\bin\polink /SUBSYSTEM:console /NODEFAULTLIB main.obj \masm32\lib\msvcrt.lib

Sometimes, my antivirus bark when look at polink linked files.

Navigation

[0] Message Index

[#] Next page

Go to full version