📄 zipdl.asm
字号:
invoke StrCpy,pMemory2,StrSub
invoke CharLower,pMemory1
invoke CharLower,pMemory2
invoke InString,pMemory1,pMemory2
push eax
invoke GlobalUnlock,pMemory1
invoke GlobalFree,hMemory1
invoke GlobalUnlock,pMemory2
invoke GlobalFree,hMemory2
pop eax
.endif
.endif
.endif
.endif
ret
InStringi ENDP
ShowSocketError PROC hWnd:DWORD,ErrCode:DWORD
LOCAL ErrorString[512]:BYTE
invoke TranslateErrorCode,ErrCode,addr ErrorString
invoke MessageBox,hWnd,addr ErrorString,addr AppName,MB_OK+MB_ICONERROR
invoke closesocket,sock
mov StateFlag,0
invoke SendMessage,hwndStatus,SB_SETTEXT,NULL,NULL
invoke SendDlgItemMessage,hWnd,IDC_NAMELIST,LVM_DELETEALLITEMS,NULL,NULL
invoke ToggleControls,hWnd
ret
ShowSocketError ENDP
RequestEOZ PROC hWnd:DWORD
LOCAL buffer[512]:BYTE
invoke wsprintf,addr buffer, addr EOZTemplate,addr RelativeURL,addr HostName,EOZSize
invoke SetStatusText,addr Connecting,addr HostName
invoke lstrlen,addr buffer
invoke send,sock,addr buffer,eax,0
.if eax==SOCKET_ERROR
invoke ShowErrorMessage,hWnd
invoke ToggleControls,hWnd
mov StateFlag,0
.else
invoke SetStatusText,addr Connected,addr HostName
mov HTTPIndex,0
mov MultipartIndex,0
mov EOZIndex,0
mov ActualBytesWritten,0
.endif
ret
RequestEOZ ENDP
ParseHeader PROC uses esi ecx edi hWnd:DWORD,Header:DWORD
LOCAL MyHeader[512]:BYTE
invoke lstrcpy,addr MyHeader,Header
invoke CharLower,addr MyHeader ; Convert the http header to lower case
invoke lstrlen,addr MyHeader
mov ecx,eax
lea edi,MyHeader
mov al," "
repne scasb
.if byte ptr [edi]==" "
repe scasb
dec edi
.endif
mov ecx,3
mov esi,edi
mov edi,offset StatusCode
rep movsb
invoke InStringi,addr MyHeader,addr Content
.if eax!=-1
mov edi,offset ContentString
lea ecx,MyHeader
add eax,ecx
add eax,15
.while byte ptr [eax]!=0 && byte ptr [eax]!=0Dh && byte ptr [eax]!=0Ah
.if byte ptr [eax]!=" "
mov cl,byte ptr [eax]
mov byte ptr [edi],cl
inc edi
.endif
inc eax
.endw
mov byte ptr [edi],0
invoke String2Dword,addr ContentString
mov ContentLength,eax
.else
mov ContentLength,0
.endif
mov eax,TRUE
ret
ParseHeader endp
ClearMessages PROC hWnd:DWORD,Message:DWORD
LOCAL MyMSG:MSG
mov eax,TRUE
.while eax==TRUE ; Since there may be WM_SOCKET messages left in the message queues,
; we must get rid of them before we create new socket.
invoke PeekMessage,addr MyMSG,hWnd,Message,Message,PM_REMOVE
.endw
ret
ClearMessages ENDP
GetHeader PROC uses edi esi hWnd:DWORD,mPointer:DWORD,lpDest:DWORD,lpDestIndex:DWORD
LOCAL FirstDataOffset:DWORD
mov edi,mPointer
mov ecx,sizetoread
mov al,0Ah
SearchForItAgain:
repne scasb
jcxz GoToEnd
jmp FoundIt
GoToEnd:
jmp EndOfHeaderNotFound
FoundIt:
cmp byte ptr [edi+1],0Ah
jne SearchForItAgain
inc StateFlag ; Marker that the HTTP header is parsed
push edi
dec edi
dec edi
sub edi,mPointer
mov ecx,edi
mov esi,mPointer
mov edi,offset HTTPHeader
add edi,HTTPIndex
rep movsb
mov byte ptr [edi],0
invoke ParseHeader,hWnd,addr HTTPHeader
pop edi
invoke CheckIfCanResume
.if eax==1 ; HTTP error
invoke closesocket,sock
invoke ClearMessages,hWnd,WM_SOCKET
invoke ToggleControls,hWnd
invoke SendMessage,hwndStatus,SB_SETTEXT,NULL,NULL
mov StateFlag,0
invoke String2Dword,addr StatusCode
.if eax==404
invoke MessageBox,hWnd,addr FileNotFound,addr AppName,MB_OK+MB_ICONERROR
.else
invoke MessageBox,hWnd,addr HTTPError,addr AppName,MB_OK+MB_ICONERROR
.endif
ret
.elseif eax==2 ; Cannot resume
invoke closesocket,sock
invoke ClearMessages,hWnd,WM_SOCKET
invoke ToggleControls,hWnd
invoke SendMessage,hwndStatus,SB_SETTEXT,NULL,NULL
mov StateFlag,0
invoke MessageBox,hWnd,addr CannotResume,addr AppName,MB_OK
ret
.endif
invoke InStringi,addr HTTPHeader,addr Multipart
.if eax==-1
inc edi
inc edi
push edi
mov ecx,sizetoread
sub edi,mPointer
sub ecx,edi
pop esi
.if StateFlag!=11
push ecx
mov edi,lpDest
rep movsb
pop ecx
mov eax,lpDestIndex
add [eax] ,ecx
.else
push ecx
invoke WriteFile,FileHandle,esi,ecx,addr BytesWritten,NULL
pop ecx
.endif
add ActualBytesWritten,ecx
invoke DisplayProgress
.else
mov CanResume,TRUE
inc edi
inc edi
mov FirstDataOffset,edi
sub edi,mPointer
mov eax,sizetoread
sub eax,edi
mov edi,FirstDataOffset
mov al,0Ah
SearchMultiAgain:
repne scasb
je FoundTheLineFeed
jmp EndOfMultiPartNotFound
FoundTheLineFeed:
cmp byte ptr [edi+1],0Ah
jne SearchMultiAgain
inc edi
inc edi
push edi
mov ecx,edi
sub ecx,FirstDataOffset
mov esi,FirstDataOffset
mov edi,offset MultipartHeader
add edi,MultipartIndex
push ecx
rep movsb
mov byte ptr [edi],0
pop ecx
add MultipartIndex,ecx
invoke ParseMultipartHeader
pop edi
push edi
sub edi,mPointer
mov ecx,sizetoread
sub ecx,edi
pop esi
.if ecx>ContentLength
mov ecx,ContentLength
.endif
add ActualBytesWritten,ecx
.if StateFlag!=11
push ecx
mov edi,lpDest
rep movsb
pop ecx
mov eax,lpDestIndex
add [eax],ecx
.else
invoke WriteFile,FileHandle,esi,ecx,addr BytesWritten,NULL
.endif
invoke DisplayProgress
ret
EndOfMultiPartNotFound:
mov esi,FirstDataOffset
mov edi,offset MultipartHeader
add edi,MultipartIndex
mov ecx,sizetoread
mov edx,FirstDataOffset
sub edx,mPointer
sub ecx,edx
push ecx
rep movsb
pop ecx
add MultipartIndex,ecx
inc StateFlag ; End of Multipart header is not found
.endif
ret
EndOfHeaderNotFound:
mov esi,mPointer
mov edi,offset HTTPHeader
mov ecx,sizetoread
rep movsb
mov eax,sizetoread
add HTTPIndex,eax
ret
GetHeader ENDP
FillTheData PROC uses edi esi mPointer:DWORD,lpDest:DWORD,lpDestIndex:DWORD
mov esi,mPointer
mov edi,lpDest
mov eax,lpDestIndex
add edi,[eax]
mov ecx,sizetoread
.if MultipartIndex!=0
mov edx,ActualBytesWritten
add edx,ecx
.if edx>ContentLength
mov ecx,ContentLength
sub ecx,ActualBytesWritten
.endif
.endif
add ActualBytesWritten,ecx
push ecx
rep movsb
pop ecx
mov eax,lpDestIndex
add [eax],ecx
invoke DisplayProgress
ret
FillTheData ENDP
ReadSocket PROC hWnd:DWORD
LOCAL mHandle:DWORD
LOCAL mPointer:DWORD
invoke ioctlsocket,sock,FIONREAD,addr sizetoread
.if eax!=SOCKET_ERROR
invoke GlobalAlloc,GHND,sizetoread
mov mHandle,eax
invoke GlobalLock,eax
mov mPointer,eax
invoke recv,sock,mPointer,sizetoread,0
.if eax!=SOCKET_ERROR
mov sizetoread,eax
.if StateFlag==1 ; HTTP header not yet parsed
invoke GetHeader,hWnd,mPointer,addr EndOfZip,addr EOZIndex
.elseif StateFlag==2 ; HTTP header parsed
invoke FillTheData,mPointer,addr EndOfZip,addr EOZIndex
.elseif StateFlag==3
invoke GetMultipartHeader,mPointer,addr EndOfZip,addr EOZIndex
.elseif StateFlag==4 ; Getting Central Dir
invoke GetHeader,hWnd,mPointer,pZipDir,addr CDIndex
.elseif StateFlag==5 ; HTTP header found, read the rest of the data
invoke FillTheData,mPointer,pZipDir,addr CDIndex
.elseif StateFlag==6
invoke GetMultipartHeader,mPointer,pZipDir,addr CDIndex
.elseif StateFlag==7 ; Getting local zip header
invoke GetHeader,hWnd,mPointer,addr LocalHeader, addr LocalIndex
.elseif StateFlag==8
invoke FillTheData,mPointer,addr LocalHeader,addr LocalIndex
.elseif StateFlag==9
invoke GetMultipartHeader,mPointer,addr LocalHeader,addr LocalIndex
.elseif StateFlag==10 ; Getting the actual zip data
invoke GetHeader,hWnd,mPointer,NULL,NULL
.elseif StateFlag==11
invoke FillActualData,mPointer
.elseif StateFlag==12
invoke GetMultipartHeader,mPointer,NULL,NULL
.endif
.else
invoke ShowErrorMessage,hWnd
invoke ToggleControls,hWnd
.endif
invoke GlobalUnlock,mPointer
invoke GlobalFree,mHandle
.else
invoke ShowErrorMessage,hWnd
invoke ToggleControls,hWnd
.endif
ret
ReadSocket ENDP
GetMultipartHeader PROC uses edi esi mPointer:DWORD,lpDest:DWORD,lpDestIndex:DWORD
mov edi,mPointer
mov ecx,sizetoread
mov al,0Ah
BackAndSearch:
repne scasb
je CheckIfLineFeed
jmp StillNotFound
CheckIfLineFeed:
.if byte ptr [edi+1]==0Ah
inc edi
inc edi
dec StateFlag
push edi
sub edi,mPointer
mov ecx,edi
mov esi,mPointer
mov edi,offset MultipartHeader
add edi,MultipartIndex
push ecx
rep movsb
pop ecx
add MultipartIndex,ecx
pop edi
push edi
sub edi,mPointer
mov ecx,sizetoread
sub ecx,edi
pop esi
mov edx,ActualBytesWritten
add edx,ecx
.if edx>ContentLength
mov ecx,ContentLength
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -