Jump to page: 1 2
Thread overview
big file...
May 01, 2005
Anuj Goyal
May 01, 2005
Matthew
May 01, 2005
Sammy
May 02, 2005
Walter
May 02, 2005
Matthew
May 02, 2005
Matthew
Re: big file... ( DMC can shrink it too )
May 02, 2005
Sammy
May 02, 2005
Walter
May 02, 2005
Jan Knepper
May 02, 2005
Sammy
May 03, 2005
Matthew
May 01, 2005
just curious as to why this file is so large...

D:\jam>cat a.c
#include <stdio.h>
#include <stdlib.h>
#include <windows.h>

int main()
{
int i = GetCurrentProcessId();
printf("i = %d\n",i);
return 0;
}


D:\jam>dmc -WA -6 -o+all a.c
link a,,,user32+kernel32/noi;


D:\jam>ls -al a.exe
-rwxrwxrwx   1 user     group       39964 Apr 30 23:02 a.exe

is there an easy way to "strip" an executable?


May 01, 2005
There's nothing to strip. Your call to printf() guarantees you linkage to the C runtime library, and that's around 40K IIRC.

You could try
    WriteFile(GetStdHandle(STD_HANDLE_OUTPUT), "Hello", 5, . . .

(may have the syntax wrong)

If you want low footprint integer to string conversions, use STLSoft's integer_to_string, as in:

    /* STLSoft Header Files */
    #include <stlsoft.h>
    #include <stlsoft_integer_to_string.h>

    /* Standard C Header Files */
    #include <windows.h>

    /* Standard C++ Header Files */

    /*
//////////////////////////////////////////////////////////////////////////
*/

    int main(int /* argc */, char ** /*argv*/)
    {
        DWORD    pid =   ::GetCurrentProcessId();
        char             sz[21];
        size_t           n;
        char const   *s  =   ::stlsoft::integer_to_string(sz, 21,
(__int32)pid, n);
        DWORD    dummy;

        ::WriteFile(::GetStdHandle(STD_OUTPUT_HANDLE), s, n, &dummy,
NULL);

        return 0;
    }

    /*
//////////////////////////////////////////////////////////////////////////
*/


That compiles and builds to 2048 bytes with VC++ 7.1.

(You need the __int32 because of a bug - soon to be fixed! - in the STLSoft libs.)


"Anuj Goyal" <Anuj_member@pathlink.com> wrote in message news:d51rkp$20sp$1@digitaldaemon.com...
> just curious as to why this file is so large...
>
> D:\jam>cat a.c
> #include <stdio.h>
> #include <stdlib.h>
> #include <windows.h>
>
> int main()
> {
> int i = GetCurrentProcessId();
> printf("i = %d\n",i);
> return 0;
> }
>
>
> D:\jam>dmc -WA -6 -o+all a.c
> link a,,,user32+kernel32/noi;
>
>
> D:\jam>ls -al a.exe
> -rwxrwxrwx   1 user     group       39964 Apr 30 23:02 a.exe
>
> is there an easy way to "strip" an executable?
>
> 


May 01, 2005
Matthew wrote:
> There's nothing to strip. Your call to printf() guarantees you linkage to the C runtime library, and that's around 40K IIRC.
> 
> That compiles and builds to 2048 bytes with VC++ 7.1.

Interesting.

What is the exact command line you have used ?

Are you using VC++ Professional Version (with optimisations) ?

I have the 2003 Standard Version which does not permit optimisations.
May 02, 2005
"Matthew" <admin@stlsoft.dot.dot.dot.dot.org> wrote in message news:d51vdf$23uo$2@digitaldaemon.com...
> That compiles and builds to 2048 bytes with VC++ 7.1.

Probably because you're linking to the VC runtime DLL.


May 02, 2005
Puh-lease! Give me some credit.

See attached DepencyViewer, and if you don't believe that, run the exe. ;-)



"Walter" <newshound@digitalmars.com> wrote in message news:d548u4$p3u$1@digitaldaemon.com...
>
> "Matthew" <admin@stlsoft.dot.dot.dot.dot.org> wrote in message news:d51vdf$23uo$2@digitaldaemon.com...
>> That compiles and builds to 2048 bytes with VC++ 7.1.
>
> Probably because you're linking to the VC runtime DLL.
>
> 




May 02, 2005
Oops sorry for the huge bmp. I should've made it smaller. :$

btw, I'm sure I could have got smaller than 2048, as I'm aware that there are various packing / packaging options for doing so. (not off the top of my head, of course.)

"Matthew" <admin@stlsoft.dot.dot.dot.dot.org> wrote in message news:d54a7t$qr0$1@digitaldaemon.com...
> Puh-lease! Give me some credit.
>
> See attached DepencyViewer, and if you don't believe that, run the exe. ;-)
>
>
>
> "Walter" <newshound@digitalmars.com> wrote in message news:d548u4$p3u$1@digitaldaemon.com...
>>
>> "Matthew" <admin@stlsoft.dot.dot.dot.dot.org> wrote in message news:d51vdf$23uo$2@digitaldaemon.com...
>>> That compiles and builds to 2048 bytes with VC++ 7.1.
>>
>> Probably because you're linking to the VC runtime DLL.
>>
>>
>
>
> 


May 02, 2005
Matthew wrote:
> 
> btw, I'm sure I could have got smaller than 2048, as I'm aware that there are various packing / packaging options for doing so. (not off the top of my head, of course.)
> 

Hi Matthew,

You choose to ignore my post :-)
Of course that's ok.

It did probably upset you.
Because the question in it was two fold:

1) i really wanted to know how you did it.
   But as you ignored my post, i decided to do
   some research by myself.

2) I think the merit for the small size exe
   must be credited the the fact that the linker
   do 50% of the job and the other 50% comes
   from the fact that the called functions are
   available in kernel32.dll. And i was asking you
   to illustrate that to me.

So in order to come clean with you, i do offer
my apology, now, without conditions.

If i dont come clean with you, i am, at least
clean with BOB.

>>>> That compiles and builds to 2048 bytes with VC++ 7.1.

I have done some test with VC++ 6.0, and the best i got
was 800 bytes with the following program:

#include <windows.h>
#ifdef __DMC__
int _acrtused_con;
#endif

int main( )
{
  static char buf[21];
  wsprintf(buf,"pid: %d",(int)GetCurrentProcessId());
  WriteFile( GetStdHandle(STD_OUTPUT_HANDLE),
    buf, lstrlen(buf), NULL, NULL );
  return 0;
}

but now, we must use two dll: user32 and kernel32.

The good news, the same result, can almost be be achieved
with DMC.

The following command:
  dmc -NL -o+all  10.c /L/entry:_main
do produce a 3200 bytes exe.

Strangely, this exe *can* compressed, by UPX,
to the smallest size i got: 2048 bytes, and
still being a valid executable.

Ok, case closed (well, i guess).

Cheers.

Sammy




	
May 02, 2005
"Sammy" <Sammy.Deroy@sympatico.ca> wrote in message news:d55fv9$1tp0$1@digitaldaemon.com...
> #include <windows.h>
> #ifdef __DMC__
> int _acrtused_con;
> #endif
>
> int main( )
> {
>    static char buf[21];
>    wsprintf(buf,"pid: %d",(int)GetCurrentProcessId());
>    WriteFile( GetStdHandle(STD_OUTPUT_HANDLE),
>      buf, lstrlen(buf), NULL, NULL );
>    return 0;
> }
>
> but now, we must use two dll: user32 and kernel32.
>
> The good news, the same result, can almost be be achieved with DMC.
>
> The following command:
>    dmc -NL -o+all  10.c /L/entry:_main
> do produce a 3200 bytes exe.

I never thought of doing that! Pretty cool, and my congratulations.


May 02, 2005
Sammy wrote:
> Matthew wrote:
> 
>>
>> btw, I'm sure I could have got smaller than 2048, as I'm aware that there are various packing / packaging options for doing so. (not off the top of my head, of course.)
>>
> 
> Hi Matthew,
> 
> You choose to ignore my post :-)
> Of course that's ok.
> 
> It did probably upset you.
> Because the question in it was two fold:
> 
> 1) i really wanted to know how you did it.
>    But as you ignored my post, i decided to do
>    some research by myself.
> 
> 2) I think the merit for the small size exe
>    must be credited the the fact that the linker
>    do 50% of the job and the other 50% comes
>    from the fact that the called functions are
>    available in kernel32.dll. And i was asking you
>    to illustrate that to me.
> 
> So in order to come clean with you, i do offer
> my apology, now, without conditions.
> 
> If i dont come clean with you, i am, at least
> clean with BOB.
> 
>  >>>> That compiles and builds to 2048 bytes with VC++ 7.1.
> 
> I have done some test with VC++ 6.0, and the best i got
> was 800 bytes with the following program:
> 
> #include <windows.h>
> #ifdef __DMC__
> int _acrtused_con;
> #endif
> 
> int main( )
> {
>   static char buf[21];
>   wsprintf(buf,"pid: %d",(int)GetCurrentProcessId());
>   WriteFile( GetStdHandle(STD_OUTPUT_HANDLE),
>     buf, lstrlen(buf), NULL, NULL );
>   return 0;
> }

Try:
   #include <stdlib.h>

   char   buf [ 24 ];
   ltoa ( GetCurrentProcessId (), buf, 10 );
   WriteFile ( GetStdHandle ( STD_OUTPUT_HANDLE ), buf, lstrlen ( buf ), 0, 0 );

> 
> but now, we must use two dll: user32 and kernel32.
> 
> The good news, the same result, can almost be be achieved
> with DMC.
> 
> The following command:
>   dmc -NL -o+all  10.c /L/entry:_main
> do produce a 3200 bytes exe.
> 
> Strangely, this exe *can* compressed, by UPX,
> to the smallest size i got: 2048 bytes, and
> still being a valid executable.
> 
> Ok, case closed (well, i guess).
> 
> Cheers.
> 
> Sammy
> 
> 
> 
> 
>     


-- 
ManiaC++
Jan Knepper

But as for me and my household, we shall use Mozilla...
www.mozilla.org
May 02, 2005
Jan Knepper wrote:
> 
> Try:
>    #include <stdlib.h>
> 
>    char   buf [ 24 ];
>    ltoa ( GetCurrentProcessId (), buf, 10 );
>    WriteFile ( GetStdHandle ( STD_OUTPUT_HANDLE ), buf, lstrlen ( buf ), 0, 0 );
> 

You suggest to use ltoa( ) instead of wsprintf( ).
That gives an ever smaller exe (2588 bytes, see below).

You still needs windows.h. Looks like stdlib.h did not
pull in the DMC runtime.

/* 11.c */
#include <windows.h>
#include <stdlib.h>
int _acrtused_con=0;
int main( )
{
   char buf[ 24 ];
   ltoa(GetCurrentProcessId( ),buf,10);
   _lwrite((int)GetStdHandle(-11L),buf,lstrlen(buf));
   return 0;
}

Compiled with:
  dmc -NL -o+all 11.c /L/entry:_main snn.lib
gives:

2005-05-02  18:43 PM             2,588 11.exe

This exe depends only on kernel32.dll and ntdll.dll.

Undocumented ntdll.dll contains a lot of functions ( like ltoa ).
if we could have an import library for it, DMC could be
use to build tiny executables.

There is a 'tinylibc' librairie on the net which is
used to produce tiny exe.

It could probably work with DMC.



« First   ‹ Prev
1 2