Hi Everyone

I'm pretty new to this stuff but I love it already.

I've a challenge for you all.

I'm trying to write a very very small exe that connects to a webserver and downloads a file. Once downloaded the exe executes this file and exits itself. The reason for this is I'm distributing an exe using a authenticode signed cab file but the exe is largeish (~100K). Microsoft in their wizdom don't really give the user much feedback when a cab file is downloading. Thus what I want to do is write a small bootstrap downloader that displays the download progress usign a progress bar.

I was inspired by Iczellion's programs HTTP Downloder and HTTP Zip Downloader (the source is at http://spiff.tripnet.se/~iczelion/files/http15.zip, and http://spiff.tripnet.se/~iczelion/files/zipdl.zip). Problem is these programs are still kind of big they do it with raw socket calls. Using InternetOpenUrl I managed to write a nice small version but it is not asychronous so I can't display the download progress.

Anyone got any ideas. Perhaps usign InternetOpenUrl in some kind of multi treaded way might work.

TIA
Posted on 2002-08-23 10:40:07 by timkempster
You should make a new thread for that InternetOpenUrl thing and use the main thread to display download progress. This way while downloading you get your UI still working and you could provide user a chance to cancel the download and such things.
Posted on 2002-08-23 11:22:08 by SamiP
Thanks SamiP

that was surprisingly easy! I thought the thread stuff would be very difficult but it wasn't.

Got it down to 11.6K does anyone have any tips for making it smaller? I'm sure my code must only be a few hundred bytes.
Posted on 2002-08-23 11:42:59 by timkempster
If you want it small, use FASM or any other assembler and put the code and data in the import section. Then remove the need of a relocation section by putting the image pointer in a register. Something like this:

call a
a:
pop ebx
sub ebx, SOMETHING

Then you can use 'ebx' to access data and call functions.


I would be gratefull if you could post the 11,6 kB version here so I don't have to make the app from scratch.
Posted on 2002-08-24 15:10:20 by gliptic
Well here is the latest attempt. I'm looking at various posting to make the program smaller using various link options etc but it's not too bad 7.5K it will compress down to about 3K in a cab file before signing which is acceptable.

Gliptic I'd be very happy if you could do as you suggest and put all the code in an import section to get rid of the relocation issues.

Enjoy!
Posted on 2002-08-25 12:28:25 by timkempster
You don't need delta-relative code just because you strip relocations; just use imagebase 0x400000 and everything will be fine.
Posted on 2002-08-25 13:23:18 by f0dder
Should be <3k uncompressed, imo. ;)

Hints:
Use OFFSET instead of ADDR with global data.
Only use stack for API calling.
Save no register values.
Inline everything possible.
Posted on 2002-08-25 15:23:12 by bitRAKE

You don't need delta-relative code just because you strip relocations; just use imagebase 0x400000 and everything will be fine.


So, what are those relocations for then? Isn't there any situations where the imagebase may be changed?
Posted on 2002-08-28 07:35:35 by gliptic

So, what are those relocations for then? Isn't
there any situations where the imagebase may
be changed?


if windows detect that need use another imagebase, and the file dont have relocations, the loading fail ;)

so, your delta dont will get a chance to run, even if imagebase change

ancev

ps: if you remove reloc info, but keep clear the RELOCS_STRIPPED flag, maintain a 'valid' pointer, but put a size 0, in the pe header, will the loading continue with a changed imagebase??? :grin:
Posted on 2002-08-28 08:48:01 by ancev
The image base is frequently changed with DLLs because they cannot all be loaded into the same address. Normally, there is only one executable (EXE) loaded in the process address space, so relocations aren't necessary.
Posted on 2002-08-28 12:50:51 by comrade