News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Download a file from the internet

Started by Matthias Merkel, December 17, 2017, 11:00:20 PM

Previous topic - Next topic

Matthias Merkel

I've been trying to figure this out for a few hours now but wasn't able to find a way to download a file from the internet. Does anyone know how that would be possible to do?

jj2007

Like this?

include \masm32\MasmBasic\MasmBasic.inc         ; download
  Init
  FileWrite "test.html", FileRead$("http://masm32.com/board/index.php?board=1.0")
  ShEx "test.html"   ; show it in your browser
EndOfCode



Matthias Merkel


aw27

 :biggrin:

You can also do it in pure VB.Net and have lots of fun too:


        Using client As System.Net.WebClient = New System.Net.WebClient()
            client.DownloadFile("http://masm32.com/board/index.php?board=1.0", "test.html")
        End Using


Matthias Merkel

Quote from: aw27 on December 18, 2017, 01:12:10 AM
:biggrin:

You can also do it in pure VB.Net and have lots of fun too:


        Using client As System.Net.WebClient = New System.Net.WebClient()
            client.DownloadFile("http://masm32.com/board/index.php?board=1.0", "test.html")
        End Using


The question was about ASM though.

aw27

The important thing is that you are happy with what you have learnt about ASM.

felipe

 :P

Welcome to the forum Matthias Merkel.   :icon14:

Matthias Merkel


Vortex

Hi Matthias Merkel,

Here is a quick example :

.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\urlmon.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\urlmon.lib

.data

szURL       db 'http://vortex.masmcode.com/files/Wcrt0_7.zip',0
FileName    db 'TinyCRT.zip',0

.code

start:

    invoke  URLDownloadToFile,0,ADDR szURL,\
            ADDR FileName,0,0

    invoke  ExitProcess,0

END start


The trick is to use the API function URLDownloadToFile.

hutch--

I wonder if anyone knows how to construct the callback for the last argument to get download progress. The API works fine in 64 bit but it has a COM interface for the callback that I have no data on at all. Other than that, is there any viable alternatives for win64 (win7 up) that can both do the download AND have progress information ?

This in 64 bit works fine.

invoke URLDownloadToFile,0,url,targ,0,0       ; pCB

Matthias Merkel

Quote from: Vortex on December 18, 2017, 06:55:05 AM
Hi Matthias Merkel,

Here is a quick example :

.386
.model flat,stdcall
option casemap:none

include     \masm32\include\windows.inc
include     \masm32\include\kernel32.inc
include     \masm32\include\urlmon.inc

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\urlmon.lib

.data

szURL       db 'http://vortex.masmcode.com/files/Wcrt0_7.zip',0
FileName    db 'TinyCRT.zip',0

.code

start:

    invoke  URLDownloadToFile,0,ADDR szURL,\
            ADDR FileName,0,0

    invoke  ExitProcess,0

END start


The trick is to use the API function URLDownloadToFile.

The huge issue with that way is that it's detected by a lot of antivirus vendors as malware: https://www.virustotal.com/#/file/4785d45664ef436c1f2cbd11e9dd46a358aee36f323fd213101c289b5632b523/detection

aw27

Quote from: hutch-- on December 18, 2017, 12:16:20 PM
Other than that, is there any viable alternatives for win64 (win7 up) that can both do the download AND have progress information ?
I prefer InternetOpenUrl, HttpQueryInfo, InternetReadFile. HttpQueryInfo gives you the number of bytes to read.

aw27

Quote
The huge issue with that way is that it's detected by a lot of antivirus vendors as malware
The antivirus are particularly dumb and many of them hate polink.

jj2007

Quote from: Matthias Merkel on December 18, 2017, 04:49:33 PMThe huge issue with that way is that it's detected by a lot of antivirus vendors as malware

Yes indeed. Try the attached version, btw with progress indicator in the statusbar (Jotti:  2/18 scanners reported malware). Here is the source:GuiParas equ "Downloading a file is easy"
include \masm32\MasmBasic\Res\MbGui.asm
GuiControl Edit, "edit"
GuiControl Status, "statusbar"
Download "http://masm32.com/board/index.php?topic=6771.msg72451#msg72451", cb:MyCallback, msg:hWnd_
Event Message
  .if uMsg==WM_DOWNLOADFINISHED
SetWin$ hEdit="Download finished"+CrLf$+NoTag$(wParam)
MsgBox 0, "Save contents to test.html?", "Hi", MB_YESNOCANCEL
If_ eax==IDYES Then <mcs FileWrite "test.html", wParam : ShEx "test.html">
  .endif
EndOfEvents
  MyCallback:
  SetWin$ hStatus=Str$("%i bytes\ndownloaded - hold Shift to stop it", edx) ; currrent state in edx
  invoke GetKeyState, VK_SHIFT
  test ah, ah ; stop download if Sign? flag set
  retn
GuiEnd

avcaballero

Quote from: jj2007 on December 18, 2017, 07:21:25 PM
Quote from: Matthias Merkel on December 18, 2017, 04:49:33 PMThe huge issue with that way is that it's detected by a lot of antivirus vendors as malware

Yes indeed. Try the attached version, btw with progress indicator in the statusbar (Jotti:  2/18 scanners reported malware). Here is the source:GuiParas equ "Downloading a file is easy"
include \masm32\MasmBasic\Res\MbGui.asm
GuiControl Edit, "edit"
GuiControl Status, "statusbar"
Download "http://masm32.com/board/index.php?topic=6771.msg72451#msg72451", cb:MyCallback, msg:hWnd_
Event Message
  .if uMsg==WM_DOWNLOADFINISHED
SetWin$ hEdit="Download finished"+CrLf$+NoTag$(wParam)
MsgBox 0, "Save contents to test.html?", "Hi", MB_YESNOCANCEL
If_ eax==IDYES Then <mcs FileWrite "test.html", wParam : ShEx "test.html">
  .endif
EndOfEvents
  MyCallback:
  SetWin$ hStatus=Str$("%i bytes\ndownloaded - hold Shift to stop it", edx) ; currrent state in edx
  invoke GetKeyState, VK_SHIFT
  test ah, ah ; stop download if Sign? flag set
  retn
GuiEnd

Wow, it is a quite good example, where are the masm sources?  :biggrin: