因为自己要用,所以就有了以下代码,没做优化大家就将就着看吧!
把纯真IP数据库中的IP地址复制到文件中(注意要点右键全选复制)
.586
.model flat, stdcall
option casemap :none
;----------------------------------------------------------------
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
include comdlg32.inc
includelib comdlg32.lib
include wsock32.inc
includelib wsock32.lib
ICO_MAIN equ 1000
DLG_MAIN equ 100
.data
hInstance dd ?
szSeaveFile db 'Ipaddr.log',0
szFileName db MAX_PATH dup (?)
@stOF OPENFILENAME <?>
hFile dd ?
@hFile dd ?
@dwFileSize dd ?
@hMapFile dd ?
@lpFileMemory dd ?
@lpMemory dd ?
NumberIp2 dd ?
lpSize dd ?
Number2 dd ?
lpNumber dd ? ;写文件时返回的实际写入值
szBuffer db 51200 dup (?) ;50KB
szIp2 db 16 dup (?)
szIp3 db 16 dup (?)
szError01 db "创建线程失败",0
.code
_Thread proc uses ebx esi edi lParam
pushad
invoke RtlZeroMemory,addr @stOF,sizeof @stOF
mov @stOF.lStructSize,sizeof @stOF
mov @stOF.lpstrFile,offset szFileName
mov @stOF.nMaxFile,MAX_PATH
mov @stOF.Flags,OFN_EXPLORER+OFN_FILEMUSTEXIST+OFN_PATHMUSTEXIST
invoke GetOpenFileName,addr @stOF
;----------------------------------------------------------------------------------------------------------------------
invoke CreateFile,addr szFileName,GENERIC_READ,FILE_SHARE_READ or \
FILE_SHARE_WRITE,NULL,OPEN_EXISTING,FILE_ATTRIBUTE_ARCHIVE,\
NULL ;打开文件
mov @hFile,eax
invoke GetFileSize,eax,NULL ;获取文件大小
mov @dwFileSize,eax
invoke CreateFileMapping,@hFile,NULL,PAGE_READONLY,0,0,NULL
mov @hMapFile,eax
invoke MapViewOfFile,eax,FILE_MAP_READ,0,0,0
mov @lpFileMemory,eax ;内存文件视图
mov eax,@dwFileSize
invoke GlobalAlloc,GPTR,eax
mov @lpMemory,eax
;--------------------------------------------------------------------------------------------------------------------------------------
;处理数据
mov edi,eax
mov esi,@lpFileMemory
@04:
cmp byte ptr [esi],0dh
jz _Quit
mov al,byte ptr [esi]
cmp al,20h
jz @01
mov byte ptr [edi],al
inc esi
inc edi
jmp @04
@01:
mov byte ptr [edi],0
inc edi
@03:
inc esi
@05:
cmp byte ptr [esi],20h
jz @03
mov al,byte ptr [esi]
mov byte ptr [edi],al
inc esi
inc edi
cmp byte ptr [esi],20h
jz @06
jmp @05
@06:
mov word ptr [edi],0
add edi,2
@07:
inc esi
cmp byte ptr [esi],0ah
jnz @07
inc esi
jmp @04
_Quit:
invoke UnmapViewOfFile,@lpFileMemory ;关内存文件视图
invoke CloseHandle,@hMapFile ;关内存映射文件对象
invoke CloseHandle,@hFile ;关文件句柄
;@lpMemory 的内存结构为 IP地址 0 IP地址 00
;---------------------------------------------------------------------------------------
;对IP地址进行较
invoke lstrcat,offset szBuffer,@lpMemory
invoke lstrlen,offset szBuffer
mov lpSize,eax ;字符串大小
lea esi,szBuffer
add esi,eax
mov byte ptr [esi],20h
mov eax,@lpMemory
add eax,lpSize
inc eax
mov lpSize,eax
Re:
invoke RtlZeroMemory,offset szIp2,sizeof szIp2
invoke RtlZeroMemory,offset szIp3,sizeof szIp3
mov eax,lpSize
invoke lstrcpy,offset szIp2,eax
invoke lstrlen,offset szIp2
or eax,eax ;szIp2等于零说明以到结尾
jz _Exit
add eax,lpSize
add eax,2 ;IP后面有两个零
mov lpSize,eax
invoke lstrcpy,offset szIp3,eax
invoke lstrlen,offset szIp3
add eax,lpSize
inc eax ;IP后面有1个零
mov lpSize,eax
;----------------------------------------------------------------------------
invoke inet_addr,addr szIp2 ;把IP字符串转换成网络顺序
invoke ntohl,eax ;网络顺序转本机顺序
push eax
invoke inet_addr,addr szIp3
invoke ntohl,eax
pop ebx
sub eax,ebx
cmp eax,255
jl Re ;小于或不大于时转移
invoke lstrcat,offset szBuffer,offset szIp2
invoke lstrlen,offset szBuffer
lea esi,offset szBuffer
add esi,eax
mov dword ptr [esi],0a0dh ;插入换行符
invoke lstrcat,offset szBuffer,offset szIp3
invoke lstrlen,offset szBuffer
lea esi,offset szBuffer
add esi,eax
mov byte ptr [esi],20h ;IP地址之间插入空格
jmp Re
_Exit:
invoke GlobalFree,@lpMemory ;释放申请的内存
invoke CreateFile,offset szSeaveFile,GENERIC_WRITE,FILE_SHARE_READ,\
NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL
mov hFile,eax
invoke lstrlen,offset szBuffer
invoke WriteFile,hFile,offset szBuffer,eax,addr lpNumber,0
invoke CloseHandle,hFile
;invoke WinExec,offset szSeaveFile,0
popad
ret
_Thread endp
_ProcDlgMain proc uses ebx edi esi hWnd,wMsg,wParam,lParam
mov eax, wMsg
.if eax == WM_CLOSE
invoke EndDialog, hWnd, NULL
.elseif eax == WM_INITDIALOG
invoke LoadIcon, hInstance, ICO_MAIN
.elseif eax == WM_COMMAND
mov eax, wParam
.if ax == IDOK
invoke CreateThread,NULL,0,offset _Thread,\
NULL,0,addr lpNumber
.if !eax
invoke MessageBox,0,offset szError01,0,MB_OK
.endif
invoke CloseHandle,eax ;关闭线程句柄
.endif
.else
mov eax,FALSE
ret
.endif
mov eax,TRUE
ret
_ProcDlgMain endp
start:
invoke GetModuleHandle,NULL
mov hInstance,eax
invoke DialogBoxParam,hInstance,DLG_MAIN,NULL,offset _ProcDlgMain,NULL
invoke ExitProcess,NULL
end start
[招生]科锐逆向工程师培训(2024年11月15日实地,远程教学同时开班, 第51期)