;============================================================================================================================================= ; 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: Start message loop ;(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 #32",0 ClassName_L db "LISTBOX",0 ClassName db "Zedr0n's Class",0 ClassName_B db "BUTTON",0 WindowName_B db "Update",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 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 Caption db "Zedr0n's step #32",0 ;============================================================================================================================================ ; Variables segment ;============================================================================================================================================ .data? Message MSG <> hModule HANDLE ? hList HWND ? hParent HWND ? hButton HWND ? hSnap HANDLE ? 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 A5: .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 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 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 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 invoke Process32Next,hSnap,offset pe .endw .endif .else invoke DefWindowProc,hWnd,uMsg,wParam,lParam ret .endif xor eax, eax ret WndProc endp end start