枚举系统服务出问题了
程序代码:
.386 .model flat,stdcall option casemap:none include windows.inc include user32.inc include kernel32.inc include advapi32.inc includelib Advapi32.lib includelib user32.lib includelib kernel32.lib IDD_DLG1 equ 1000 IDC_BTN1 equ 1002 IDC_BTN2 equ 1003 IDC_LST1 equ 1001 .data hModule dd ? szError db '出错',0 ScHandle dd ? dwNeed dd ? sr dd ? ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> .code SetDlgService proc hwnd:dword pushad invoke LocalAlloc,LMEM_FIXED and LMEM_ZEROINIT,1024*64 mov ebx,eax invoke OpenSCManager,NULL,NULL,SC_MANAGER_ALL_ACCESS mov ScHandle,eax .if !eax invoke MessageBox,NULL,offset szError,offset szError,MB_OK .endif invoke EnumServicesStatus,ScHandle,SERVICE_WIN32,SERVICE_STATE_ALL,ebx,1024*64,addr dwNeed,offset sr,NULL invoke GetLastError lea edi,[ebx] .while sr assume edi:ptr ENUM_SERVICE_STATUS invoke SendDlgItemMessage,hwnd,IDC_LST1,LB_ADDSTRING,0,[edi].lpServiceName add edi,sizeof ENUM_SERVICE_STATUS dec sr .endw popad ret SetDlgService endp DialogProc proc uses edi esi edx,hwnd,msg,wparam,lparam mov eax,msg .if eax == WM_CLOSE invoke ExitProcess,0 .elseif eax == WM_COMMAND mov eax,wparam .if eax == IDC_BTN1 push hwnd call SetDlgService .endif .endif mov eax,0 ret DialogProc endp start: invoke GetModuleHandle,0 mov hModule,eax invoke DialogBoxParam,hModule,IDD_DLG1,NULL,offset DialogProc,NULL invoke ExitProcess,0 end start ;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>程序枚举出来的系统服务数量没有错,但是服务名字有些不对,OD跟了一下是偏移弄错了,但是不知道汇编怎么枚举当前的服务的算法.希望版主帮忙.给段C的.
程序代码:
void main(int argc,char ** argv){ LPENUM_SERVICE_STATUS st; st=(LPENUM_SERVICE_STATUS)LocalAlloc(LPTR,64*1024); DWORD ret=0; DWORD size=0; HANDLE sc=OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS); EnumServicesStatus(sc,SERVICE_WIN32,SERVICE_STATE_ALL, (LPENUM_SERVICE_STATUS)st,1024*64,&size,&ret,NULL); for(int i=0;i<ret;i++){ printf("%-20s%-50s",st[i].lpServiceName,st[i].lpDisplayName); switch(st[i].ServiceStatus.dwCurrentState){ case(SERVICE_RUNNING): cout<<"running"<<endl; break; case(SERVICE_STOPPED): cout<<"stopped"<<endl; break; } } }