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

📄 zipdl.asm

📁 zip文件下载器的汇编语言源代码
💻 ASM
📖 第 1 页 / 共 5 页
字号:
                        mul ebx
                        dec esi
                .endw
                pop ebx
                add Result,eax
                pop eax
                inc edi
                dec eax
        .endw
        mov eax,Result
        ret
String2Dword endp

GetFileName proc URL:DWORD
        invoke RtlFillMemory,addr FileName,256,0
        invoke lstrlen,URL
        std               ; We will search for "/" in reverse direction
        mov edi,URL
        add edi,eax
        dec edi
        mov ecx,eax
        mov al,"/"
        repne scasb
        cld
        jne No_name
        cmp byte ptr [edi],"/"
        je  No_name
        inc edi
        inc edi
        invoke lstrcpy,addr FileName,edi
No_name:
        ret
GetFileName endp

ParseURL PROC uses esi edi URL:DWORD
        LOCAL MyURL[512]:BYTE
        LOCAL URLLength:DWORD
        invoke GetFileName,URL
        invoke lstrlen,URL
        mov URLLength,eax
        mov ecx,eax             ; Trim the spaces at the start of the url string, if any
        mov edi,URL
        mov al,20h
        repe scasb
        dec edi
        invoke lstrcpy,addr MyURL,edi           ; We don't want to modify the original url string since we have to modify the cases of the url
        invoke lstrcpy,URL,addr MyURL
        invoke lstrlen,URL
        mov URLLength,eax
        invoke RtlFillMemory,addr HostName,501,0   ; fill HostName and RelativeURL with zeroes
        invoke CharLower,addr MyURL             ; change to lower case for ease of comparison
        lea edi,MyURL
        mov esi,offset HTTP             ; check if the url starts with "http://"
        mov ecx,7
        repe cmpsb
        jne No_HTTP
        mov eax,URLLength       ; if it is, substract the length of url string by 7 to
        sub eax,7               ; account for the length of "http://" string
        mov URLLength,eax
        jmp Common_parse
No_HTTP:
        lea edi,MyURL
Common_parse:
        push edi
        invoke lstrcpy,addr MyURL,URL
        pop edi
        xor ecx,ecx
        mov esi,offset HostName
        mov HTTPPort,80         ; Default port =80
        .while ecx < URLLength
                .if byte ptr [edi]=="/"         ; if "/" is found, it denotes the end of the host name string
                        invoke lstrcpy,addr RelativeURL,edi     ; and the start of the relative url string
                        .break
                .elseif byte ptr [edi]==":"     ; if ":" is found, it means an HTTP port is specified in the url
                        inc ecx
                        inc edi
                        invoke RtlFillMemory,addr PortString,10,0
                        mov eax,offset PortString
                        .while (byte ptr [edi]!="/") && (byte ptr [edi]!=0)
                                mov dl,byte ptr [edi]
                                mov byte ptr [eax],dl
                                inc eax
                                inc ecx
                                inc edi
                        .endw
                        invoke String2Dword,addr PortString
                        mov HTTPPort,eax
                .else
                        mov al,byte ptr [edi]
                        mov byte ptr [esi],al
                        inc edi
                        inc esi
                        inc ecx
                .endif
        .endw
        .if ecx==URLLength      ; if there's no relative URL , we must add "/" to it.
                mov byte ptr [RelativeURL],"/"
        .endif
        ret
ParseURL endp

ToggleControls PROC hWnd:DWORD
        invoke IsWindowEnabled,hwndURL
        .if eax==TRUE
                invoke EnableWindow,hwndURL,FALSE
                invoke EnableWindow,hwndURLOK,FALSE
                invoke EnableWindow,hwndCancelURL,FALSE
                invoke EnableWindow,hwndList,TRUE
                invoke EnableWindow,hwndOK,TRUE
                invoke EnableWindow,hwndCancel,TRUE
        .else
                invoke EnableWindow,hwndURL,TRUE
                invoke EnableWindow,hwndURLOK,TRUE
                invoke EnableWindow,hwndCancelURL,TRUE
                invoke EnableWindow,hwndList,FALSE
                invoke EnableWindow,hwndOK,FALSE
                invoke EnableWindow,hwndCancel,FALSE
        .endif
        ret
ToggleControls ENDP

GetHandlesOfChildWindows PROC hWnd:DWORD
        invoke GetDlgItem,hWnd,IDC_URL
        mov hwndURL,eax
        invoke GetDlgItem,hWnd,IDC_URLOK
        mov hwndURLOK,eax
        invoke GetDlgItem,hWnd,IDC_CANCELURL
        mov hwndCancelURL,eax
        invoke GetDlgItem,hWnd,IDC_NAMELIST
        mov hwndList,eax
        invoke GetDlgItem,hWnd,IDC_OK
        mov hwndOK,eax
        invoke GetDlgItem,hWnd,IDC_CANCEL
        mov hwndCancel,eax
        ret
GetHandlesOfChildWindows ENDP

TranslateErrorCode proc ErrCode:DWORD, pErrString:DWORD
        invoke LoadString,hInstance,ErrCode,pErrString,512
        .if eax==0
                invoke LoadString,hInstance,1,pErrString,512
        .endif
        ret
TranslateErrorCode endp

GetErrorString proc pErrString:DWORD
        invoke WSAGetLastError
        push eax
        invoke TranslateErrorCode,eax,pErrString
        pop eax
        ret
GetErrorString endp

ShowErrorMessage PROC hWnd:DWORD
        LOCAL Buffer[512]:BYTE
        invoke GetErrorString,addr Buffer
        invoke SendMessage,hwndStatus,SB_SETTEXT,NULL,NULL
        invoke MessageBox,NULL,addr Buffer,addr AppName,MB_OK+MB_ICONERROR
        invoke closesocket,sock
        mov StateFlag,0
        ret
ShowErrorMessage ENDP

SetStatusText PROC Text:DWORD, Text1:DWORD
        LOCAL Buffer[200]:BYTE
		  invoke wsprintf,addr Buffer,Text,Text1
        invoke SetWindowText,hwndStatus,addr Buffer
        ret
SetStatusText ENDP

;========================================================================
;                               MakeConnection
;========================================================================
; Create a socket , parse the URL string and connect to the host
; Return true if all operations are successful, FALSE otherwise
;========================================================================
MakeConnection PROC hWnd:DWORD
        invoke socket,PF_INET,SOCK_STREAM,0
        .if eax!=SOCKET_ERROR
                mov sock,eax
                .if StateFlag==1
                        invoke ParseURL,addr URLString
                        invoke SetStatusText,addr Resolving,addr HostName
                        invoke inet_addr,addr HostName
                        .if eax==INADDR_NONE
                                invoke gethostbyname,addr HostName     ; Use this function to get the host ip address from host name.
                                .if eax==NULL
                                        invoke ShowErrorMessage,hWnd
                                        mov eax,FALSE
                                        ret
                                .endif
                                mov eax,[eax+12]
                                mov eax,[eax]
                                mov eax,[eax]
                                mov SocketAddress.sin_addr,eax
                        .else
                                mov SocketAddress.sin_addr,eax
                        .endif
                        mov SocketAddress.sin_family,AF_INET
                        invoke htons,HTTPPort   ; We must convert host byte order to network byte order
                        mov SocketAddress.sin_port,ax
                .endif
                invoke WSAAsyncSelect,sock,hWnd,WM_SOCKET,\     ; We choose to receive notification about successful connection,
                        FD_CONNECT or FD_READ or FD_CLOSE ; incoming data, and when the socket is closed
                .if eax==NULL
                        invoke SetStatusText,addr Connecting,addr HostName
                        invoke connect,sock,addr SocketAddress,sizeof SocketAddress     ; Make a connection with the remote host
                                                                        ; Since we operate in non-blocking mode, we wait for the window socket to call us when
                                                                        ; the events we are interested in occur.
                        .if eax==SOCKET_ERROR
                                invoke WSAGetLastError
                                .if eax!=WSAEWOULDBLOCK
                                        invoke ShowErrorMessage,hWnd
                                .else
                                        mov eax,TRUE
                                        ret
                                .endif
                        .endif
                .else
                        invoke ShowErrorMessage,hWnd
                .endif
        .else
                invoke ShowErrorMessage,hWnd
        .endif
        mov eax,FALSE                
        ret
MakeConnection ENDP

;=====================================================================
;                               StrLen
;=====================================================================
; This procedure takes an address of a string as its parameter and
; returns the length of the string in eax
;=====================================================================
StrLen PROC uses edi String:DWORD
        mov edi,String
        mov al,0
        mov ecx,0FFFFFFFFh
        repne scasb
        sub ecx,0FFFFFFFFh
        neg ecx
        dec ecx
        mov eax,ecx
        ret
StrLen ENDP
;=====================================================================
;                               StrCpy
;=====================================================================
; This procedure copies a string into a buffer. If the buffer is smaller
; than the string to copy, it returns 0.
;=====================================================================
StrCpy PROC uses edi esi StrBuffer:DWORD,String:DWORD
        invoke StrLen,String
        mov ecx,eax
        mov edi,StrBuffer
        mov esi,String
        rep movsb
        ret
StrCpy ENDP
;=========================================================================
;                               InString
;=========================================================================
; Search for a substring in one string. Case Sensitive
; Return Value: -1 if substring not found, offset of the first byte
; of the substring if successful
;=========================================================================
InString PROC uses ebx edi esi StrMain:DWORD, StrSub:DWORD
        invoke StrLen,StrMain
        mov ecx,eax
        push ecx
        invoke StrLen,StrSub
        pop ecx
        mov ebx,eax
        .if ecx<eax
                mov eax,FALSE
        .elseif ecx==eax
                mov esi,StrMain
                mov edi,StrSub
                repe cmpsb
                je Equal
                mov eax,FALSE
                jmp GetOut
Equal:
                xor eax,eax
GetOut:                
        .else
                sub ecx,eax
                inc ecx
                mov eax,ecx
                xor edx,edx
                push eax                
                .while eax!=0
                        mov edi,StrMain
                        add edi,edx
                        mov esi,StrSub
                        mov ecx,ebx
                        repe cmpsb
                        je Found
                        jmp DontFind
Found:
                        .break        
DontFind:
                        inc edx
                        dec eax
                .endw
                pop ecx
                .if eax!=0
                        sub ecx,eax
                        mov eax,ecx 
                .else
                        mov eax,-1
                .endif
        .endif
        ret
InString ENDP
;=====================================================================
;                               InStringi
;=====================================================================
; Search for a substring in one string. Case insensitive
; Return Value: -1 if substring not found, offset of the first byte
; of the substring if successful
;=========================================================================
InStringi PROC StrMain:DWORD,StrSub:DWORD
        LOCAL hMemory1:DWORD
        LOCAL pMemory1:DWORD
        LOCAL hMemory2:DWORD
        LOCAL pMemory2:DWORD
        invoke StrLen,StrMain
        inc eax
        invoke GlobalAlloc,GHND,eax
        .if eax==NULL
                mov eax,-1
        .else
                mov hMemory1,eax
                invoke GlobalLock,eax
                .if eax==NULL
                        invoke GlobalFree,hMemory1
                        mov eax,-1
                .else
                        mov pMemory1,eax
                        invoke StrLen,StrSub
                        inc eax
                        invoke GlobalAlloc,GHND,eax
                        .if eax==NULL
                                invoke GlobalUnlock,pMemory1
                                invoke GlobalFree,hMemory1
                                mov eax,-1
                        .else
                                mov hMemory2,eax
                                invoke GlobalLock,eax
                                .if eax==NULL
                                        invoke GlobalUnlock,pMemory1
                                        invoke GlobalFree,hMemory1
                                        invoke GlobalFree,hMemory2
                                        mov eax,-1
                                .else
                                        mov pMemory2,eax
                                        invoke StrCpy,pMemory1,StrMain

⌨️ 快捷键说明

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