News:

Download Pelles C here: http://www.smorgasbordet.com/pellesc/

Main Menu

File downloader

Started by Vortex, December 08, 2025, 06:48:34 PM

Previous topic - Next topic

Vortex

Here is a very simple file downloader :

DownloadFile.exe http://address filename.ext
include     DownloadFile.inc

.data?

buffer      db 512 dup(?)

.code

start:

    call    main
    invoke  ExitProcess,eax

main PROC uses esi

    mov     esi,OFFSET buffer
    invoke  ParseCmdLine,esi
    cmp     eax,3
    jne     finish

    xor     ecx,ecx
    invoke  URLDownloadToFile,ecx,DWORD PTR [esi+4],\
            DWORD PTR [esi+8],BINDF_GETNEWESTVERSION,ecx
finish:

    ret

main ENDP

ParseCmdLine PROC uses esi edi ebx _buffer:DWORD

    push    0
    mov     esi,_buffer
    lea     edi,[esi+256]
    invoke  GetCommandLine
    lea     edx,[eax-1]
    mov     ax,32+256*34
    mov     ch,al
    mov     bx,9+256*9

scan:

    inc     edx
    mov     cl,BYTE PTR [edx]
    test    cl,cl
    jz      finish
    cmp     cl,al
    je      scan
    cmp     cl,bh
    je      scan
    inc     DWORD PTR [esp]
    mov     DWORD PTR [esi],edi
    add     esi,4

restart:

    mov     cl,BYTE PTR [edx]
    test    cl,cl
    jne     @f
    mov     BYTE PTR [edi],cl
    jmp     finish
@@:
    cmp     cl,ch
    je      end_of_line
    cmp     cl,bl
    je      end_of_line
    cmp     cl,ah
    jne     @f
    xor     ch,al
    xor     bl,bh
    jmp     next_char
@@:   
    mov     BYTE PTR [edi],cl
    inc     edi

next_char:

    inc     edx
    jmp     restart

end_of_line:

    mov     BYTE PTR [edi],0
    inc     edi
    jmp     scan
   
finish:

    pop     eax
    ret

ParseCmdLine ENDP

END start
Code it... That's all...

Vortex

Attached is the 64-bit version.
Code it... That's all...

TimoVJL

Windows 7 suffer sites with https:// with TLS  :(
May the source be with you

Vortex

Hi Timo,

Probably, I need to rewrite the application employing WinInet functions.
Code it... That's all...

TimoVJL

Windows 7 WinInet just don't support latest TLS version.
May the source be with you

Vortex

You would probably have to install some hotfixes on Windows 7 and do some registry tweakings. Better is WinHTTP.

ChatGPT suggests :

You must install these (even if Win7 is "fully patched"):

Update   Purpose
KB3140245   Adds TLS 1.1 / 1.2 support to WinINet
KB3055973   SChannel improvements
Code it... That's all...

John Z

Quote from: Vortex on December 15, 2025, 07:36:59 PMAttached is the 64-bit version.

I can test on Win 7 PRO, but I need to know a location and file to try to download ....

John Z

TimoVJL

#7
DownloadFile.exe http://www.pellesc.de/favicon.ico favicon.icoA https:// won't work in Windows 7, as missing TLS 1.3 support

A bit more code in C
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <wininet.h>
#pragma comment(lib, "wininet.lib")

#define BLOCK_SIZE 1024

int GetHTTPFile(TCHAR *szUrl, TCHAR *szFile)
{
    HINTERNET hInet;
    char aBuffer[BLOCK_SIZE];
    hInet = InternetOpen(TEXT(""), 0, 0, 0, 0);
    if (hInet) {
        HINTERNET hUrl= InternetOpenUrl(hInet, szUrl, 0, 0, 0, 0);
        if (hUrl) {
            HANDLE hFile = CreateFile(szFile,GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_FLAG_SEQUENTIAL_SCAN, NULL);
            DWORD dwRead, dwWritten;
            do {
                if (!InternetReadFile(hUrl, &aBuffer, BLOCK_SIZE, &dwRead)) break;
                WriteFile(hFile, aBuffer, dwRead, &dwWritten, NULL);
            } while(dwRead);
            CloseHandle(hFile);
            InternetCloseHandle(hUrl);
        }
        InternetCloseHandle(hInet);
    }
    return 0;
}

int main(int argc, char **argv)
{
    GetHTTPFile("http://www.pellesc.de/favicon.ico", "favicon.ico");
    return 0;
}
May the source be with you

John Z

#8
Quote from: TimoVJL on Yesterday at 07:24:01 AMDownloadFile.exe http://www.pellesc.de/favicon.ico favicon.icoA https:// won't work in Windows 7, as missing TLS 1.3 support

Thanks for the link Timo!

It works perfectly in Win 7 PRO.  Pro versions contain more intrinsic features than
other versions.  I still get security updates for Win 7 PRO too.  :)

John Z

Vortex

Hi Timo,

Thanks for your code.

DownloadFile.exe http://www.pellesc.de/favicon.ico favicon.ico
This did not work on my Windows 7 Home Premium Sp1 64-bit
Code it... That's all...

TimoVJL

Quote from: John Z on Yesterday at 03:26:58 PMIt works perfectly in Win 7 PRO.  Pro versions contain more intrinsic features than
other versions.  I still get security updates for Win 7 PRO too.  :)

John Z
What version is that a schannel.dll and is in register TLS 1.3 ?

I have dll 6.1.7601.24545 2020-01-03, that support TLS 1.2

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\TLS 1.2
May the source be with you

John Z

#11
Well ---

registry shows
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0

Attached images of two schannel.dll files on the system, looks like one 64 bit one 32 bit
One matches your version.

Searched registry did not locate TLS 1.2 anywhere

Is it possible to switch yours to SSL 2.0?

John Z

TimoVJL

So you might have an updated dll for TLS 1.2, but a your register settings are totally wrong.
Erol gave some info for fixing some register settings.
May the source be with you

John Z

#13
Quote from: TimoVJL on Today at 12:22:22 PMSo you might have an updated dll for TLS 1.2, but a your register settings are totally wrong.
Erol gave some info for fixing some register settings.


Agree to disagree - The system has never been changed - it is as delivered from DELL, I've never tweaked it, there is nothing that I know of that does not work.  So the settings are different but I can't agree that they are wrong...and hey it works for the example too  :)


John Z

John Z

#14
Posting system photographs to clarify system as WIN7 Pro and show the update history.
Last security update 12/18/2025 . . .

John Z