Pelles C forum

Assembly language => Assembly discussions => Topic started by: Vortex on December 08, 2025, 06:48:34 PM

Title: File downloader
Post by: Vortex on December 08, 2025, 06:48:34 PM
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
Title: Re: File downloader
Post by: Vortex on December 15, 2025, 07:36:59 PM
Attached is the 64-bit version.
Title: Re: File downloader
Post by: TimoVJL on December 16, 2025, 09:28:06 AM
Windows 7 suffer sites with https:// with TLS  :(
Title: Re: File downloader
Post by: Vortex on December 16, 2025, 08:53:33 PM
Hi Timo,

Probably, I need to rewrite the application employing WinInet functions.
Title: Re: File downloader
Post by: TimoVJL on December 17, 2025, 01:25:54 PM
Windows 7 WinInet just don't support latest TLS version.
Title: Re: File downloader
Post by: Vortex on December 17, 2025, 01:31:19 PM
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
Title: Re: File downloader
Post by: John Z on December 17, 2025, 10:58:58 PM
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
Title: Re: File downloader
Post by: TimoVJL on December 18, 2025, 07:24:01 AM
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;
}
Title: Re: File downloader
Post by: John Z on December 18, 2025, 03:26:58 PM
Quote from: TimoVJL on December 18, 2025, 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
Title: Re: File downloader
Post by: Vortex on December 18, 2025, 08:33:45 PM
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
Title: Re: File downloader
Post by: TimoVJL on December 19, 2025, 09:59:02 AM
Quote from: John Z on December 18, 2025, 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
Title: Re: File downloader
Post by: John Z on December 19, 2025, 12:07:43 PM
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
Title: Re: File downloader
Post by: TimoVJL on December 19, 2025, 12:22:22 PM
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.
Title: Re: File downloader
Post by: John Z on December 19, 2025, 12:57:58 PM
Quote from: TimoVJL on December 19, 2025, 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
Title: Re: File downloader
Post by: John Z on December 19, 2025, 03:11:54 PM
Posting system photographs to clarify system as WIN7 Pro and show the update history.
Last security update 12/18/2025 . . .

John Z
Title: Re: File downloader
Post by: Vortex on December 19, 2025, 07:16:38 PM

My registry settings :

C:\>reg Query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols"

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

C:\>reg Query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Client"

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\SecurityProviders\SCHANNEL\Protocols\SSL 2.0\Client
    DisabledByDefault    REG_DWORD    0x1
Title: Re: File downloader
Post by: John Z on December 19, 2025, 07:47:48 PM
Very interesting - I get the same result.  Attached screen shot - client.jpg.
The only place I see TLS is under CRYPTO. Attached screen shot - crypto_TLS.jpg
Ran test again I get the ICO. Attached screen shot. also shows the DOS version - dos.jpg
you can see the dates and times - I just ran it. 

Is it a matter of HTTP vs HTTPS?  HTTPS does not work on Win7 or my Win11.

Very confusing, however, my WIN 7 PRO gets the ico every time - I don't know why -

John Z
Title: Re: File downloader
Post by: Vortex on December 19, 2025, 08:20:59 PM
Can you share the output of this command?

Powershell -Command (Get-Item C:\Windows\System32\schannel.dll).VersionInfo.FileVersion
On my system :

6.1.7601.24545 (win7sp1_ldr_escrow.200102-1707)
Title: Re: File downloader
Post by: TimoVJL on December 19, 2025, 08:54:19 PM
I just lost all interst of this case.
Title: Re: File downloader
Post by: John Z on December 19, 2025, 09:22:05 PM
Here is is without using screen shot -

Powershell -Command (Get-Item C:\Windows\System32\schannel.dll).VersionInfo.FileVersion   

6.1.7601.24545 (win7sp1_ldr_escrow.200102-1707)


Seems lost cause, suggest terminating further .. ?

John Z
Title: Re: File downloader
Post by: TimoVJL on December 20, 2025, 11:01:07 AM
Thanks John, now we know detailed registry keys, that was from last Windows 7 update.
That schannel.dll might be last updated version, that add support for TLS 1.2
Title: Re: File downloader
Post by: Vortex on December 20, 2025, 11:17:55 AM
Concerning Windows 7 :

No TLS 1.3 support — only up through TLS 1.2 with updates and registry settings.