flat assembler
Message board for the users of flat assembler.

Index > Windows > Simple URL downloader

Author
Thread Post new topic Reply to topic
me239



Joined: 06 Jan 2011
Posts: 200
me239
Hello everyone! Recently I noticed that Windows lacks a http downloader for it's cmd. Here is a small download utitlity I made in FASM that parses the command line into two parts(URL, output). It also has some error catching capabilities. To make it native, just place it inside the system32 folder.
Code:
format PE console 4.0
include 'win32a.inc'
entry start
start:
        invoke  GetCommandLine
        mov     ebx, eax
        mov     edi, buff1
        mov     esi, ebx
        xor     ecx, ecx
next:
        lodsb
        cmp     al, ' '
        jz      pf1
        inc     ecx
        cmp     ecx, 11
        jae     error1
        jmp     next
pf1:
        inc     esi
        xor     ecx, ecx
@@:
        lodsb
        cmp     al, 20h
        jz      pf2
        stosb
        inc     ecx
        cmp     ecx, 11d
        jae     error2
        jmp     @b
pf2:
        mov     edi, buff2
@@:
        lodsb
        cmp     al, 0
        jz      pdone
        stosb
        jmp     @b
pdone:
        invoke  URLDownloadToFileA, 0, buff1, buff2, 0, 0
exit:
        invoke  ExitProcess, NULL
error1:
        invoke  printf, emsg1
        pop     ecx
        jmp     exit
error2:
        invoke  printf, emsg2
        pop     ecx
        jmp     exit
;section '.data' data readable writeable
emsg1   db      "ERROR: Invalid or no URL", 0
emsg2   db      "ERROR: Invalid or no output file name", 0
buff1   db      300 dup (0)
buff2   db      50 dup (0)
section '.idata' import data readable writeable
        library kernel32, "KERNEL32.DLL",\
                urlmon, "URLMON.DLL",\
                msvcrt, "MSVCRT.DLL"
        include 'api\kernel32.inc'
import  urlmon, URLDownloadToFileA, "URLDownloadToFileA"
import  msvcrt, printf, "printf"    
Post 13 Mar 2011, 05:35
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
Interesting work - one can use it to download updates from bat file.
But some error check of the network transfer is needed in order to guarantee the file was downloaded properly.
Post 13 Mar 2011, 06:24
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
typedef



Joined: 25 Jul 2010
Posts: 2913
Location: 0x77760000
typedef
or you could use FormatMessage with GetLastError() so that in case of other errors, the system tells you what's wrong. But otherwise it's good. I love it.
Post 13 Mar 2011, 15:28
View user's profile Send private message Reply with quote
me239



Joined: 06 Jan 2011
Posts: 200
me239
JohnFound wrote:
Interesting work - one can use it to download updates from bat file.
But some error check of the network transfer is needed in order to guarantee the file was downloaded properly.
I could also just check to see if the new file exists. I know that method might not work the best in cases where files are being overwritten, but it's a start.
Post 13 Mar 2011, 19:09
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.