⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 http.asm

📁 一个用汇编做得下载软件
💻 ASM
📖 第 1 页 / 共 5 页
字号:
.386
.model flat,stdcall
include wsock32.inc
include comctl32.inc
include kernel32.inc
include user32.inc
include comdlg32.inc
includelib user32.lib
includelib comctl32.lib
includelib kernel32.lib
includelib wsock32.lib
includelib comdlg32.lib

WinMain PROTO :DWORD,:DWORD,:DWORD,:DWORD
EnableControls PROTO
DisableControls PROTO
StrCpy PROTO :DWORD, :DWORD
StrLen PROTO :DWORD
InString PROTO :DWORD,:DWORD
InStringi PROTO :DWORD,:DWORD
TranslateErrorCode PROTO :DWORD, :DWORD
ParseURL PROTO :DWORD
String2Dword PROTO :DWORD
ParseHeader PROTO :DWORD
ConnectSocket PROTO
GetFileName PROTO :DWORd
ManageInitialization PROTO
ReconnectIfPossible PROTO
ShowErrorMessage PROTO
ShowSocketError PROTO
ShowProgress PROTO :DWORD
GetErrorString PROTO :DWORD
WriteInitialData PROTO 
CreateNewFile PROTO
ShowDownloadSpeed PROTO
WriteOutputFile PROTO :DWORD,:DWORD
CloseSock PROTO
SendRequest PROTO
ClearMessages PROTO :DWORD,:DWORD
CreateOutputFile PROTO
FillMultipartHeader PROTO
SetStatusText PROTO :DWORD, :DWORD
ReadSocket PROTO
ParseAllHeaders PROTO
CloseTheSock PROTO
ActualClose PROTO
EXTRN wsprintfA:PROC

.data
ClassName db "WINSOCKDLG",0
AppName  db "Win32asm HTTP Download version 1.5",0
MenuName db "WinSock",0
URLDialogName db "URLDialog",0
MainDialog db "MAINDLG",0
IconName db "http",0
;********************************************************************
;                               Error Messages
;********************************************************************
NoContent db "Document doesn't have any content",0
BadRequest db "Bad Request: The request header is not understandable by the server",0
OpenError db "Cannot Open Output File for write",0
Unauthorized db "You're not authorized to get this resource",0
Forbidden db "You're forbidden to access this resource",0
NotFound db "404: Object not found",0
NotAcceptable db "No resource in the form acceptable by this program",0
Gone db "The resource is no longer in this server",0
Undefined db "Undefined HTTP error",0
ServerError db "Server error",0
NetworkNotReady db "No network connection",0
InvalidVersion db "No winsock 1.1 support by current winsock dll",0
ServerBusy db "The server is busy. Retry later",0
CreateError db "Cannot Create the output file",0
WriteError db "Cannot Write to output file",0

;*********************************************************************
;                               Templates for wsprintfA
;*********************************************************************
Downloading db "Currently Downloaded: %lu bytes",0
FilePrompt db "%s already exists. Resume the download?",0
OverwritePrompt db "%s already exists. Overwrite the file?",0
GetTemplate db "GET %s HTTP/1.0",0dh,0ah
            db "Host: %s",0Dh,0Ah
            db "Range: bytes=%lu-",0Dh,0Ah
            db "User-Agent: IczelionDownLoad",0Dh,0Ah
            db "Connection: Close",0Dh,0Ah
            db "Accept: text/*,image/*,application/*,*/*",0Dh,0Ah,0dh,0ah,0
SpeedTemplate db "%lu.%.2lu kb/s",0
WaitingForReply db "Host: %s contacted. Waiting for reply...",0             
ResolvingServer db "Resolving URL: %s",0
Connecting db "Connecting to : %s",0

;*****************************************************************
;                       Reference strings
;*****************************************************************
Multipart db "multipart/",00
ContentRange db "Content-Range:",0
AcceptRanges db "accept-ranges:",0
Location db "location:",0
FilterString db "All Files",0,"*.*",0
             db "Text Files",0,"*.txt",0   
             db "HTML files",0,"*.html",0
             db "Zip Archive",0,"*.zip",0,0
AboutMessage db "Win32asm HTTP Download version 1.5",0Dh,0Ah
             db "Written by Iczelion",0Dh,0Ah
             db "Web page: http://win32asm.cjb.net",0Dh,0Ah
             db "Special thanks: hutch (wonderful include files)",0
HTTP db "http://",0
Content db "content-length:",0

;*****************************************************************
;                       Miscellaneous
;*****************************************************************
StartingOffset dd 0             ; file offset of the remote file to start download from
PartWidth dd 250,-1             ; dimension of the status panels
CloseString db "The connection is closed",0
DefaultName db "index.html",0           ; Default document name
Dots db "...",0                 ; used in case url is too long to display on the window

.data?
;****************************************************************
;                               Structures
;****************************************************************
ofn   OPENFILENAME <>
wsadata WSAdata <>
SocketAddress sockaddr_in <>

;****************************************************************
;                               Buffers
;****************************************************************
HostName db 100 dup(?),0
RelativeURL db 400 dup(?),0     
CommandString db 512 dup(?),0   ; The buffer to store the command to send to the web server
FileName db 256 dup(?),0        ; The name of the file to be downloaded
URLString db 512 dup(?),0
PortString db 10 dup(?),0       ; the string indicating HTTP port in the url
StatusCode db 3 dup(?),0        ; HTTP response code
ContentString db 10 dup(?),0    ; String containing the length of the file
HTTPHeader db 512 dup(?),0      ; HTTP response header
MultipartHeader db 512 dup(?),0 ; Buffer to store the multipart http header
ErrorString db 512 dup(?),0     ; The buffer to receive the error message
;**********************************************************************
;                               Handles
;**********************************************************************
hInstance DWORD ?               ; Instance handle
sock DWORD ?                    ; socket handle
hwndStatus dd ?                 ; The handle to the status window
hwndConnectButton dd ?          ; The handle to the connect button
hMenu dd ?                      ; The handle to the menu
hwnd dd ?                       ; handle to the main window
mHandle dd ?                    ; Handle to the memory block to store data read in from the socket
buffer dd ?                     ; Address of the above memory block
FileHandle dd ?                 ; output file handle

;**********************************************************************
;                               Flags
;**********************************************************************
WaitingForName db ?             ; 1= Waiting for the user to input the output file name
CloseConnection db ?            ; 1= the connection is already closed
Redirection db ?                ; 1= redirection on
MultipartHeaderParsed db ?      ; TRUE=multipart header is parsed
CanResume db ?                  ; FALSE=The server cannot resume download
MultipartPresent db ?           ; TRUE=multipart header is present
HeaderParsed db ?               ; FALSE==Http header is not accounted for
Resuming db ?                   ; FALSE=This connection is not for resuming

;***********************************************************************
;                               Other variables
;***********************************************************************
TimerID dd ?                    ; ID of the timer
FirstDataOffset dd ?            ; Address of the first byte of actual data in the buffer (immediately after http header)
sizetoread dd ?                 ; size of data available for read from the socket
OriginalTickCount dd ?          ; Number of tick counts at the start of download
ActualDataRead dd ?             ; Current tick counts
HTTPPort dd ?                   ; the port that's used to connect to HTTP server
StatusValue dw ?                ; The numeric value of StatusCode
ContentLength dd ?              ; the size of the file
MultipartIndex dd ?             ; Index of the first unused byte in MultipartHeader
HeaderIndex dd ?                ; Index of the first unused byte in HTTPHeader
CurrentDataSize dd ?            ; The amount of data read from the socket
BytesWritten dd ?               ; numbers of bytes actually written to the output file


.CONST
IDM_CONNECT equ 1003
IDM_EXIT equ 1002
IDM_ABOUT equ 1004

IDC_CONNECT equ 1000
IDC_EXIT equ 1001
IDC_NAME equ 1004
IDC_EDIT1 equ 3000
IDC_OK equ 3001
IDC_CANCEL equ 3002
IDC_PROGRESS equ 3003
IDC_STATUS equ 3004

WM_SOCKET equ WM_USER+100h

.code                           
start:
        invoke GetModuleHandle, NULL
        mov    hInstance,eax
        invoke WinMain, hInstance,NULL,NULL, SW_SHOWDEFAULT
        invoke ExitProcess,eax

WinMain proc hInst:DWORD,hPrevInst:DWORD,CmdLine:DWORD,CmdShow:DWORD
        LOCAL wc:WNDCLASSEX
        LOCAL msg:MSG
        mov   wc.cbSize,SIZEOF WNDCLASSEX
        mov   wc.style, CS_HREDRAW or CS_VREDRAW
        mov   wc.lpfnWndProc, OFFSET WndProc
        mov   wc.cbClsExtra,NULL
        mov   wc.cbWndExtra,DLGWINDOWEXTRA
        push  hInstance
        pop   wc.hInstance
        mov   wc.hbrBackground,COLOR_BTNFACE+1
        mov   wc.lpszMenuName,OFFSET MenuName
        mov   wc.lpszClassName,OFFSET ClassName
        invoke LoadIcon,hInstance,addr IconName
        mov   wc.hIcon,eax
        mov   wc.hIconSm,0
        invoke LoadCursor,NULL,IDC_ARROW
        mov   wc.hCursor,eax
        invoke RegisterClassEx, addr wc
        invoke CreateDialogParam,hInstance,addr MainDialog,NULL,NULL,NULL
        mov   hwnd,eax
        INVOKE ShowWindow, hwnd,SW_SHOWNORMAL
        INVOKE UpdateWindow, hwnd
        invoke InitCommonControls
        invoke GetDlgItem,hwnd,IDC_CONNECT
        mov hwndConnectButton,eax
        invoke SetFocus,eax
        invoke GetMenu,hwnd
        mov hMenu,eax
        mov eax,1000
        shl eax,16
        invoke SendDlgItemMessage,hwnd,IDC_PROGRESS,PBM_SETRANGE,NULL,eax
        invoke SendDlgItemMessage,hwnd,IDC_PROGRESS,PBM_SETPOS,0,NULL
        invoke WSAStartup,101h,ADDR wsadata   ; Initialize the window socket dll
        .if eax==NULL
                .WHILE TRUE
                        INVOKE GetMessage, ADDR msg,NULL,0,0
                        .BREAK .IF (!eax)
                        invoke IsDialogMessage,hwnd,addr msg
                        .if eax==FALSE
                                INVOKE TranslateMessage, ADDR msg
                                INVOKE DispatchMessage, ADDR msg
                       .endif
                .ENDW
                mov eax,TRUE
                .while eax==TRUE
                        invoke WSACleanup
                        .if eax==SOCKET_ERROR
                                invoke GetErrorString,addr ErrorString
                                .if eax!=WSANOTINITIALISED
                                        invoke MessageBox,NULL,addr ErrorString,addr AppName,MB_OK
                                .endif
                                .break
                        .endif
                        mov eax,TRUE                
                .endw
        .else
                .if eax==WSASYSNOTREADY
                        invoke MessageBox,hwnd,addr NetworkNotReady,addr AppName,MB_OK+MB_ICONERROR
                .else
                        invoke MessageBox,hwnd,addr InvalidVersion,addr AppName,MB_OK+MB_ICONERROR
                .endif                                                  
        .endif
        mov     eax,msg.wParam
        ret
WinMain endp

WndProc proc hWnd:DWORD, uMsg:DWORD, wParam:DWORD, lParam:DWORD
        mov   eax,uMsg
        .IF eax==WM_DESTROY
                .if sock!=0         ; check if the socket was closed
                                    ; close it if it was not.
                        invoke CloseSock
                .endif
                invoke PostQuitMessage,NULL

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -