[閒聊] Ping & EventLog

看板ASM (組合語言)作者 (zha0)時間17年前 (2007/06/05 02:26), 編輯推噓4(403)
留言7則, 4人參與, 最新討論串1/1
1~2 年沒寫組語了 XD 最近又在寫 XD Ping 一個 IP/Host 如果 Ping 不到觸發 EventLog 的小程式 XDXD http://student.ncit.edu.tw/~s19315050/event.rar 字串轉數字那裡不可以太大 XD 爆掉不管 XDXD 裡面錯誤處理都沒做 (懶得打了 XDXD) 亂玩會自爆 XD ; ######################################################################### .586 .model flat, stdcall option casemap :none ; case sensitive include \masm32\include\windows.inc include \masm32\include\kernel32.inc include \masm32\include\wsock32.inc include \masm32\include\advapi32.inc includelib \masm32\lib\kernel32.lib includelib \masm32\lib\ws2_32.lib includelib \masm32\lib\advapi32.lib ; ######################################################################### .data szICMPDLL db "ICMP.DLL", 0 szIcmpCreateFile db "IcmpCreateFile", 0 szIcmpCloseHandle db "IcmpCloseHandle", 0 szIcmpSendEcho db "IcmpSendEcho", 0 szPackageData db "!@#$%^&*()_+1234567890-='/.,[]\'", 0 ip_option_information STRUCT ucTtl db ? ucTos db ? ucFlags db ? ucOptionsSize db ? pucOptionsData dd ? ip_option_information ENDS ipoi ip_option_information <40h,0,0,0,0> szINIFileName db '.\ip.ini', 0 szSecIPSet db 'IP Setting', 0 sztarIP db 'TargetIP', 0 szSleep db 'Sleep', 0 szSecEvent db 'EventMsg', 0 szSrc db 'Source', 0 szEvent db 'EventId', 0 szDat db 'Data', 0 .data? hICMPDLL dd ? hICMP dd ? hEvent dd ? hIcmpCreateFile dd ? hIcmpCloseHandle dd ? hIcmpSendEcho dd ? dwSleep dd ? dwEvent dd ? dwIPAddr dd ? bFlags dd ? dwNum dd ? wsaData WSADATA <?> szBuffer db 1024 dup (?) szSource db 1024 dup (?) szData db 1024 dup (?) szEventID db 1024 dup (?) ; ######################################################################### .code start: invoke GetPrivateProfileString, addr szSecIPSet, addr sztarIP, NULL, addr szBuffer, 1024, addr szINIFileName or eax, eax jz Error1 ; no ip.ini files mov edi, offset szBuffer mov esi, edi call StrLen neChr: lodsb cmp al, '0' jl n1 cmp al, '9' jg n1 n3: loop neChr jmp is n1: cmp al, '.' jnz n2 jmp short n3 n2: or ecx, ecx jz is mov [bFlags], 0 jmp short qo is: mov [bFlags], 1 qo: invoke GetPrivateProfileString, addr szSecEvent, addr szSrc, NULL, addr szSource, 1024, addr szINIFileName invoke GetPrivateProfileString, addr szSecEvent, addr szDat, NULL, addr szData, 1024, addr szINIFileName invoke GetPrivateProfileString, addr szSecEvent, addr szEvent, NULL, addr szEventID, 8, addr szINIFileName mov esi, offset szEventID call StrToDec mov eax, dwNum mov [dwEvent], eax invoke GetPrivateProfileString, addr szSecIPSet, addr szSleep, NULL, addr szEventID, 8, addr szINIFileName mov esi, offset szEventID call StrToDec mov eax, dwNum mov [dwSleep], eax invoke WSAStartup, 202h, addr wsaData cmp dword ptr [bFlags], 1 jz short Get invoke gethostbyname, ADDR szBuffer or eax, eax jz Error1 ; if eax = 0 get host is error mov ebx, [eax+12] mov edx, [ebx] mov ebx, [edx] invoke inet_ntoa, ebx jmp short Convert Get: mov eax, offset szBuffer Convert: invoke inet_addr, eax ; only ip 32bit string mov [dwIPAddr], eax invoke WSACleanup invoke LoadLibrary, addr szICMPDLL mov [hICMPDLL], eax invoke GetProcAddress, hICMPDLL, addr szIcmpCreateFile mov [hIcmpCreateFile], eax invoke GetProcAddress, hICMPDLL, addr szIcmpCloseHandle mov [hIcmpCloseHandle], eax invoke GetProcAddress, hICMPDLL, addr szIcmpSendEcho mov [hIcmpSendEcho], eax mov eax, [hICMPDLL] or eax, eax jz Error1 and eax, [hIcmpCreateFile] and eax, [hIcmpCloseHandle] and eax, [hIcmpSendEcho] or eax, eax jz Error2 call [hIcmpCreateFile] mov [hICMP], eax Infinite: push 1000 push 2000 push offset szBuffer push offset ipoi push 20h push offset szPackageData push [dwIPAddr] push [hICMP] call [hIcmpSendEcho] or eax, eax jnz NoRecord ;; error invoke RegisterEventSource, NULL, addr szSource mov [hEvent], eax mov edi, offset szData call StrLen invoke ReportEvent, hEvent, 0, 0, dwEvent, NULL, 0, ecx, 0, addr szData invoke DeregisterEventSource, hEvent NoRecord: push [dwSleep] call Sleep jmp Infinite push [hICMP] call [hIcmpCloseHandle] Error2: invoke FreeLibrary, hICMP Error1: invoke ExitProcess, 0 ; 可以使用 GetPrivateProfileInt 取就可以不用轉,但我想自己寫 XD StrToDec: ; in : esi mov edi, esi call StrLen add esi, ecx dec esi std xor eax, eax mov dwNum, eax ntNum: mov ebx, eax mov eax, 10 mul ebx or al, al jnz sOne inc eax sOne: push eax mov ebx, eax lodsb sub al, '0' cbw cwd push ecx and eax, 0fh mov ecx, eax jecxz next ntSum: add [dwNum], ebx loop ntSum next: pop ecx pop eax loop ntNum cld ;; remove wii get bugs XDXD when call GetPrivateProfileString ret StrLen: ; in : edi ; out : ecx mov ecx, -1 xor eax, eax repnz scasb not ecx dec ecx ; ecx = string lenght ret end start -- -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 124.8.74.49

06/05 02:44, , 1F
看不懂,不過推 XD
06/05 02:44, 1F

06/05 03:48, , 2F
好懷念的 style 啊~ n年沒寫過pc的組語了, 不過還是推一下
06/05 03:48, 2F

06/05 03:48, , 3F
現在工作都是寫sparc和mips的, 不過也很少在寫組語了...
06/05 03:48, 3F

06/05 03:50, , 4F
連bootcode都95%以上C語言化了
06/05 03:50, 4F

06/05 03:51, , 5F
話說掃ping可是幹壞事最基本的呢~ 您該不會..... :p
06/05 03:51, 5F

06/05 09:45, , 6F
工作上需要,所以就寫寫小程式嘍 :p (有打算@#$%但沒時間XD)
06/05 09:45, 6F
※ 編輯: zha0 來自: 210.64.110.97 (06/06 11:54)

06/06 14:10, , 7F
看不懂+1,但高手該推一下~ <(_ _)>
06/06 14:10, 7F
文章代碼(AID): #16P5bGYV (ASM)
文章代碼(AID): #16P5bGYV (ASM)