;============================================================================================================================================= ; step_32.asm ;This program just shows all the active processes ; Algorithm ;A1: Get module handle ;A2: Create parent window ;A3: Create list box ;A4: Create button ;A5: Create terminate button ;A6: Start message loop ;A7: Clear the list ;A8: Get the processes and show them ;A9: Terminate selected process ;A10: Update list ;(C)I don't take any responsibility for the use of this program ; Zedr0n -- connection closed ;============================================================================================================================================= ;============================================================================================================================================= ; Options/Declarations ;============================================================================================================================================= .386 .model flat, stdcall option casemap:none include windows.inc include kernel32.inc include user32.inc include th32.inc includelib \masm32\lib\kernel32.lib includelib \masm32\lib\user32.lib ;============================================================================================================================================= ; Data segment ;============================================================================================================================================= .data WindowName_L db "List Box",0 WindowName db "Zedr0n's step #33",0 ClassName_L db "LISTBOX",0 ClassName db "Zedr0n's Class",0 ClassName_B db "BUTTON",0 WindowName_B db "Update",0 WindowName_BT db "Terminate",0 x equ 100 x_l equ x-100 y equ 100 y_l equ y-100 x_b equ x_l+win_width_l+10 y_b equ y_l y_bt equ y_l+50 win_width equ 600 win_width_l equ win_width-100 win_height equ 400 win_height_l equ win_height-50 win_width_b equ 80 win_height_b equ 30 Err_1 db "Error creating parent window",0 Err_2 db "Error creating a list box",0 Err_3 db "Error creating button",0 Err_4 db "Error making a snapshot",0 Err_5 db "Error receiving process",0 Err_6 db "Error sending message",0 Err_7 db "Select a process!",0 Err_8 db "Error getting text of an item",0 Err_9 db "Error getting handle",0 Caption db "Zedr0n's step #33",0 Start_program db "C:\WIN98SE\COMMAND\START.EXE",0 ;============================================================================================================================================ ; Variables segment ;============================================================================================================================================ .data? buffer db 256 dup(?) Message MSG <> hModule HANDLE ? hList HWND ? hParent HWND ? hButton HWND ? hButton_T HWND ? hProcess HANDLE ? hSnap HANDLE ? ident dd ? pe PROCESSENTRY32 <> pe_size equ $-pe wc WNDCLASSEX <> wc_size equ $-wc ;============================================================================================================================================= ; Code segment ;============================================================================================================================================= .code start: A1: invoke GetModuleHandle,NULL mov hModule,eax A2: mov wc.cbSize,wc_size mov wc.style,CS_HREDRAW OR CS_VREDRAW mov wc.lpfnWndProc,offset WndProc mov wc.hInstance,eax mov wc.lpszClassName,offset ClassName mov wc.cbClsExtra,NULL mov wc.cbWndExtra,NULL invoke LoadIcon,NULL,IDI_APPLICATION mov wc.hIcon,eax mov wc.hIconSm,eax invoke LoadCursor,NULL,IDC_ARROW mov wc.hCursor,eax mov wc.hbrBackground,COLOR_GRAYTEXT+1 mov wc.lpszMenuName,NULL invoke RegisterClassEx,addr wc invoke CreateWindowEx,NULL,offset ClassName,offset WindowName,WS_OVERLAPPEDWINDOW,x,y,win_width,win_height,NULL,NULL,hModule,NULL mov hParent,eax .if eax==NULL invoke MessageBox,NULL,offset Err_1,offset Caption,MB_OK invoke ExitProcess,NULL .endif invoke ShowWindow, hParent,SW_SHOWNORMAL invoke UpdateWindow, hParent A3: invoke CreateWindowEx,NULL,offset ClassName_L,offset WindowName_L,WS_CHILD OR WS_BORDER,x_l,y_l,win_width_l,win_height_l,hParent,NULL,hModule,NULL mov hList,eax .if eax==NULL invoke MessageBox,NULL,offset Err_2,offset Caption,MB_OK invoke ExitProcess,NULL .endif invoke ShowWindow,hList,SW_SHOWNORMAL invoke UpdateWindow,hList A4: invoke CreateWindowEx,NULL,offset ClassName_B,offset WindowName_B,WS_CHILD,x_b,y_b,win_width_b,win_height_b,hParent,NULL,hModule,NULL mov hButton,eax .if eax==NULL invoke MessageBox,NULL,offset Err_3,offset Caption,MB_OK invoke ExitProcess,NULL .endif invoke ShowWindow,hButton,SW_SHOWNORMAL invoke UpdateWindow,hButton invoke SendMessage,hParent,WM_COMMAND,NULL,hButton A5: invoke CreateWindowEx,NULL,offset ClassName_B,offset WindowName_BT,WS_CHILD,x_b,y_bt,win_width_b,win_height_b,hParent,NULL,hModule,NULL mov hButton_T,eax .if eax==NULL invoke MessageBox,NULL,offset Err_3,offset Caption,MB_OK invoke ExitProcess,NULL .endif invoke ShowWindow,hButton_T,SW_SHOWNORMAL invoke UpdateWindow,hButton_T A6: .WHILE TRUE invoke GetMessage, ADDR Message,NULL,0,0 .BREAK .IF (!eax) invoke TranslateMessage, ADDR Message invoke DispatchMessage, ADDR Message .ENDW Exit: invoke ExitProcess,NULL ;============================================================================================================================================ ; Procedures ;============================================================================================================================================ WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM .if uMsg==WM_DESTROY invoke PostQuitMessage,NULL .elseif uMsg==WM_COMMAND mov eax,lParam .if eax==hButton A7: invoke SendMessage,hList,LB_GETCOUNT,NULL,NULL .while eax>0 dec eax invoke SendMessage,hList,LB_DELETESTRING,eax,NULL .endw invoke CreateToolhelp32Snapshot,TH32CS_SNAPPROCESS,NULL mov hSnap,eax .if eax==NULL invoke MessageBox,NULL,offset Err_4,offset Caption,NULL invoke ExitProcess,NULL .endif A8: mov pe.dwSize,pe_size invoke Process32First,hSnap,offset pe .if eax==FALSE invoke MessageBox,NULL,offset Err_5,offset Caption,NULL invoke ExitProcess,NULL .endif mov eax,TRUE .while eax==TRUE invoke lstrcmp,offset buffer,offset pe.szExeFile .if eax==0 mov eax,pe.th32ProcessID mov ident,eax .endif invoke lstrcmp,offset Start_program,offset pe.szExeFile .if eax!=0 invoke SendMessage,hList,LB_ADDSTRING,NULL,offset pe.szExeFile .if eax==LB_ERR invoke MessageBox,NULL,offset Err_6,offset Caption,NULL invoke ExitProcess,NULL .endif .endif invoke Process32Next,hSnap,offset pe .endw .elseif eax==hButton_T A9: invoke SendMessage,hList,LB_GETCURSEL,NULL,NULL .if eax==LB_ERR invoke MessageBox,NULL,offset Err_7,offset Caption,NULL jmp A6 .endif invoke SendMessage,hList,LB_GETTEXT,eax,offset buffer .if eax==LB_ERR invoke MessageBox,NULL,offset Err_8,offset Caption,NULL invoke ExitProcess,NULL .endif invoke SendMessage,hParent,WM_COMMAND,NULL,hButton invoke OpenProcess,PROCESS_ALL_ACCESS,TRUE,ident mov hProcess,eax .if eax==NULL invoke MessageBox,NULL,offset Err_9,offset Caption,NULL invoke ExitProcess,NULL .endif invoke TerminateProcess,hProcess,NULL invoke CloseHandle,hProcess A10: invoke Sleep,2 invoke SendMessage,hParent,WM_COMMAND,NULL,hButton .endif .else invoke DefWindowProc,hWnd,uMsg,wParam,lParam ret .endif xor eax, eax ret WndProc endp end start