程序代码:
;MASMPlus 代码模板 - 以对话框做为主窗口的程序
;*****************************************************************************************************************
;作者:zklhp
;Email:zklhp@
;QQ:493165744
;时间:2009.12.31
;版权所有 转载请保持完整
;*****************************************************************************************************************
.386
.Model Flat, StdCall
Option Casemap :None
Include windows.inc
Include user32.inc
Include kernel32.inc
Include gdi32.inc
include shell32.inc
include USkin.inc
Include WSock32.inc
include shlwapi.inc
;include libc.inc
includelib gdi32.lib
IncludeLib user32.lib
IncludeLib kernel32.lib
includelib shell32.lib
includelib USkin.lib
Includelib WSock32.Lib
includelib shlwapi.lib
includelib msvcrt.lib
include macro.asm
include _CmdLine.asm
;懒得自己写代码了 用了C的运行时库~
atoi proto C lpszString_IN:DWORD
strchr proto C lpszString_IN:DWORD,char_IN:DWORD
fgets proto C lpBuf_OUT:DWORD,size_IN:DWORD,hFile_IN:DWORD
sscanf proto C hFile_IN:DWORD,lpszFormat_IN:DWORD,var_OUT:VARARG
fopen PROTO C lpszFileName_IN:DWORD,lpszMode_IN:DWORD
fclose PROTO C hFile_IN:DWORD
fread proto C lpBuf_OUT:DWORD,size_IN:DWORD,count_IN:DWORD,hFile_IN:DWORD
ftell proto C hFile_IN:DWORD
_filelength proto C hFile_IN:DWORD
include rsrc.inc
_stPROXY struct
_dwIP dd ?
_dwPort dd ?
_stPROXY ends
DlgProc PROTO :DWORD,:DWORD,:DWORD,:DWORD
ID_TIMER equ 20
ID_WINS equ 10
ID_WINH equ 11
F_STOP equ 0FFFFFFFH
MAX_PROXY equ 512
.data
szAbout db 'HTTP代理发送器 v0.4',0dh,0ah,'By zklhp Email:zklhp@',0dh,0ah,'版权所有 转载请保持完整',0
x FLOAT 210.0f
y FLOAT 1.0f
szSend db 'GET http://www2.ouc. HTTP/1.1',0dh,0ah
db 'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*',0dh,0ah
db 'Accept-Language: zh-cn',0dh,0ah
db 'Accept-Encoding: gzip, deflate',0dh,0ah
db 'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)',0dh,0ah
db 'Host: www2.ouc.',0dh,0ah,0dh,0ah,0
.data?
IsAuto dd ? ;若加参数 auto 则为自动模式
hInstance dd ?
hWin dd ?
stProxy _stPROXY MAX_PROXY dup(<>)
stWSA WSADATA <?>
dwStop dd ?
dwTimeOut dd ?
szSendBuf db 40960 dup(?)
dwThreadID dd ?
.CODE
_SendProc proc uses ebx edi esi _Param:DWORD
local @szBuf[2048]:BYTE
local @stSin:sockaddr_in
local @hSocket:DWORD
assume esi:ptr _stPROXY
mov @stSin.sin_family,AF_INET
invoke Sleep,_Param ;这样把各个线程的发送错开 防止同一时间有很多链接
;每次循环检测停止标志位 若为F_STOP则线程停止
.while dwStop != F_STOP
lea esi,stProxy
.while [esi]._dwIP
@Begin:
mov eax,[esi]._dwPort
mov @stSin.sin_port,ax
mov eax,[esi]._dwIP
mov @stSin.sin_addr,eax
invoke socket,AF_INET,SOCK_STREAM,0
.if eax == INVALID_SOCKET
invoke WSAGetLastError
invoke wsprintf,addr @szBuf,CTXT('DeBug:socket fail WSAGetLastError:%x',0dh,0ah),eax
invoke SendDlgItemMessage,hWin,IDC_EDT3,EM_REPLACESEL,0,addr @szBuf
jmp @Next
.endif
mov @hSocket,eax
invoke connect,@hSocket,addr @stSin,sizeof @stSin
.if eax == SOCKET_ERROR
invoke WSAGetLastError
invoke wsprintf,addr @szBuf,CTXT('DeBug:connect fail WSAGetLastError:%x',0dh,0ah),eax
invoke SendDlgItemMessage,hWin,IDC_EDT3,EM_REPLACESEL,0,addr @szBuf
invoke closesocket,@hSocket
jmp @Next
.endif
invoke lstrlen,offset szSendBuf
invoke send,@hSocket,offset szSendBuf,eax,0
invoke closesocket,@hSocket
invoke Sleep,dwTimeOut
;若出错 一般是代理服务器被关了 这样其实是连接超时 所以再睡没意义 应减少无效链接占用的时间
@Next:
add esi,sizeof _stPROXY
.endw
.endw
assume esi:NOTHING
@ExitThread:
xor eax,eax
ret
_SendProc endp
START:
invoke USkinInit,NULL,NULL,CTXT("VistaPerfection.msstyles") ;初使化USkin
invoke USkinApplyColorTheme,x,y
;判断模式
invoke _argc
.if eax == 2
invoke _argv,1,offset szSendBuf,sizeof szSendBuf
invoke lstrcmpi,offset szSendBuf,CTXT('auto') ;自动模式
.if eax != 0 ;不为0 正常
mov IsAuto,FALSE
.else ;为0 自动模式
mov IsAuto,TRUE
.endif
.endif
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,IDD_DLG1,0,offset DlgProc,0
invoke USkinExit ;退出USkin
invoke ExitProcess,0
DlgProc proc hWnd,uMsg,wParam,lParam
local @hFile:DWORD
local @szBuf[256]:BYTE
.if uMsg==WM_INITDIALOG
invoke LoadIcon,hInstance,ICON_168
invoke SendMessage,hWnd,WM_SETICON,ICON_SMALL,eax
;限制文字个数
invoke SendDlgItemMessage,hWnd,IDC_EDT1,EM_LIMITTEXT,5,0
invoke SendDlgItemMessage,hWnd,IDC_EDT6,EM_LIMITTEXT,sizeof szSendBuf,0
;注册热键
invoke RegisterHotKey,hWnd,ID_WINS,MOD_WIN,VK_S
invoke RegisterHotKey,hWnd,ID_WINH,MOD_WIN,VK_H
push hWnd
pop hWin
invoke SendMessage,hWnd,WM_HOTKEY,ID_WINH,0
;输出信息
invoke SendDlgItemMessage,hWnd,IDC_EDT3,EM_REPLACESEL,0,CTXT('欢迎使用HTTP代理发送程序 请先阅读说明文件 注意程序的要求 否则出错~',0dh,0ah)
invoke SendDlgItemMessage,hWnd,IDC_EDT6,EM_REPLACESEL,0,offset szSend
invoke WSAStartup,0202h,offset stWSA
;初始化地址列表
assume esi:ptr _stPROXY
lea esi,stProxy
mov [esi]._dwIP,0
assume esi:NOTHING
.if IsAuto == TRUE
invoke SetTimer,hWnd,ID_TIMER,3000d,0
.endif
.elseif uMsg==WM_COMMAND
mov eax,wParam
and eax,0ffffh
.if eax==IDOK
invoke SendMessage,hWnd,WM_COMMAND,IDC_BTN1,0
.elseif eax==IDCANCEL
invoke SendMessage,hWnd,WM_CLOSE,0,0 ;按ESC退出
.elseif eax==IDC_CHK1
invoke IsDlgButtonChecked,hWnd,IDC_CHK1 ;看是否直接发送
.if eax == BST_CHECKED
;直接发送
invoke GetDlgItem,hWnd,IDC_EDT4
invoke EnableWindow,eax,TRUE
invoke GetDlgItem,hWnd,IDC_EDT7
invoke EnableWindow,eax,TRUE
assume esi:ptr _stPROXY
lea esi,stProxy
invoke GetDlgItemText,hWnd,IDC_EDT4,addr @szBuf,sizeof @szBuf
.if eax
invoke inet_addr,addr @szBuf
mov [esi]._dwIP,eax
invoke GetDlgItemInt,hWnd,IDC_EDT7,FALSE,FALSE
invoke htons,eax
mov [esi]._dwPort,eax
add esi,sizeof _stPROXY
mov [esi]._dwIP,0
.else
mov [esi]._dwIP,0
.endif
assume esi:NOTHING
.else
;使用代理列表
invoke GetDlgItem,hWnd,IDC_EDT4
invoke EnableWindow,eax,FALSE
invoke GetDlgItem,hWnd,IDC_EDT7
invoke EnableWindow,eax,FALSE
invoke SetDlgItemText,hWnd,IDC_EDT5,0 ;清空
;用了C函数
invoke fopen,CTXT('PROXY.txt'),CTXT('r')
.if eax == INVALID_HANDLE_VALUE
invoke SendDlgItemMessage,hWnd,IDC_EDT3,EM_REPLACESEL,0,CTXT('fail to open PROXY.txt',0dh,0ah)
jmp @F
.endif
mov @hFile,eax
assume esi:ptr _stPROXY
lea esi,stProxy
.while TRUE
invoke fgets,addr @szBuf,sizeof @szBuf,@hFile
invoke lstrlen,eax
mov edi,eax
.break .if edi < 2 ;若按照要求的格式最后有一个空行 则最后一次此处得到的长度为1 是换行
dec edi
lea ecx,@szBuf
add ecx,edi
mov BYTE ptr [ecx],0 ;除去换行
invoke SendDlgItemMessage,hWin,IDC_EDT5,EM_REPLACESEL,0,addr @szBuf
invoke SendDlgItemMessage,hWin,IDC_EDT5,EM_REPLACESEL,0,CTXT(0dh,0ah)
;找 : 之前为IP 之后为端口
xor eax,eax
mov al,':'
invoke strchr,addr @szBuf,eax
mov edi,eax
mov BYTE ptr [edi],0
invoke inet_addr,addr @szBuf
mov [esi]._dwIP,eax
inc edi
invoke atoi,edi
invoke htons,eax
mov [esi]._dwPort,eax
add esi,sizeof _stPROXY
.endw
mov [esi]._dwIP,0
@@:
invoke fclose,@hFile
assume esi:NOTHING
.endif
.elseif eax==IDC_BTN1
;发送
invoke GetDlgItemText,hWnd,IDC_EDT6,offset szSendBuf,sizeof szSendBuf
@@:
invoke GetDlgItemInt,hWnd,IDC_EDT2,FALSE,FALSE
.if eax
mov dwTimeOut,eax
invoke GetDlgItemInt,hWnd,IDC_EDT1,FALSE,FALSE
.if eax
mov dwStop,0
mov edi,eax
xor ebx,ebx
.while ebx < edi
mov eax,ebx
imul dwTimeOut
;这样把Sleep()放在线程函数开头比较好 避免界面没响应的现象
invoke CreateThread,0,0,offset _SendProc,eax,0,offset dwThreadID ;启动线程
invoke CloseHandle,eax
inc ebx
.endw
.endif
.endif
@@:
assume esi:NOTHING
.elseif eax==IDC_BTN2 ;取消
mov dwStop,F_STOP ;置标志位即可 线程会自动退出
.elseif eax==IDC_BTN3
invoke MessageBox,hWnd,offset szAbout,CTXT('关于'),0
.elseif eax==IDC_BTN4
invoke SendMessage,hWnd,WM_CLOSE,0,0
.endif
.elseif uMsg==WM_TIMER
;只执行一次 设置各参数 然后发送 不过没有一个办法让他停 这个就是方便新手 当然 也可以省点事啦~
;一定注意读取的格式
invoke fopen,CTXT('AUTO.txt'),CTXT('r')
.if eax == INVALID_HANDLE_VALUE
invoke SendDlgItemMessage,hWnd,IDC_EDT3,EM_REPLACESEL,0,CTXT('fail to open AUTO.txt',0dh,0ah)
invoke SendMessage,hWnd,WM_CLOSE,0,0 ;直接退出
.endif
mov @hFile,eax
;第一行 线程数
invoke fgets,addr @szBuf,sizeof @szBuf,@hFile
invoke SetDlgItemText,hWnd,IDC_EDT1,addr @szBuf
;第二行 发送间隔
invoke fgets,addr @szBuf,sizeof @szBuf,@hFile
invoke SetDlgItemText,hWnd,IDC_EDT2,addr @szBuf
;第三行开始 发送IP 这里不区分直接还是用代理 放什么就用什么发送
invoke SetDlgItemText,hWnd,IDC_EDT5,0 ;清空
assume esi:ptr _stPROXY
lea esi,stProxy
.while TRUE
invoke fgets,addr @szBuf,sizeof @szBuf,@hFile
invoke lstrlen,eax
mov edi,eax
.break .if edi < 2 ;若按照要求的格式最后有一个空行 则最后一次此处得到的长度为1 是换行
dec edi
lea ecx,@szBuf
add ecx,edi
mov BYTE ptr [ecx],0 ;除去换行
invoke SendDlgItemMessage,hWin,IDC_EDT5,EM_REPLACESEL,0,addr @szBuf
invoke SendDlgItemMessage,hWin,IDC_EDT5,EM_REPLACESEL,0,CTXT(0dh,0ah)
;找 : 之前为IP 之后为端口
xor eax,eax
mov al,':'
invoke strchr,addr @szBuf,eax
mov edi,eax
mov BYTE ptr [edi],0
invoke inet_addr,addr @szBuf
mov [esi]._dwIP,eax
inc edi
invoke atoi,edi
invoke htons,eax
mov [esi]._dwPort,eax
add esi,sizeof _stPROXY
.endw
mov [esi]._dwIP,0
assume esi:NOTHING
;最后 内容 缓冲区足够大了
invoke SetDlgItemText,hWnd,IDC_EDT6,0 ;清空
.while TRUE
invoke fgets,offset szSendBuf,sizeof szSendBuf,@hFile
invoke lstrlen,eax
mov edi,eax
.break .if edi < 2 ;若按照要求的格式最后有一个空行 则最后一次此处得到的长度为1 是换行
dec edi
lea ecx,szSendBuf
add ecx,edi
mov BYTE ptr [ecx],0
invoke SendDlgItemMessage,hWin,IDC_EDT6,EM_REPLACESEL,0,offset szSendBuf
invoke SendDlgItemMessage,hWin,IDC_EDT6,EM_REPLACESEL,0,CTXT(0dh,0ah)
.endw
invoke SendDlgItemMessage,hWin,IDC_EDT6,EM_REPLACESEL,0,CTXT(0dh,0ah)
invoke SendDlgItemMessage,hWin,IDC_EDT6,EM_REPLACESEL,0,CTXT(0dh,0ah)
invoke SendMessage,hWnd,WM_COMMAND,IDC_BTN1,0 ;相当于点发送
invoke KillTimer,hWnd,ID_TIMER
.elseif uMsg==WM_HOTKEY
.if wParam==ID_WINS
invoke ShowWindow,hWnd,SW_SHOW
.elseif wParam==ID_WINH
invoke AnimateWindow,hWnd,1000,AW_BLEND or AW_HIDE ;渐变退出
invoke ShowWindow,hWnd,SW_HIDE
.endif
.elseif uMsg==WM_CLOSE
invoke AnimateWindow,hWnd,1000,AW_BLEND or AW_HIDE ;渐变退出
;取消热键
invoke UnregisterHotKey,hWnd,ID_WINS
invoke UnregisterHotKey,hWnd,ID_WINH
invoke EndDialog,hWnd,wParam
invoke WSACleanup
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
DlgProc endp
END START
[
本帖最后由 zklhp 于 2010-2-11 20:32 编辑 ]