标题:枚举系统服务出问题了
只看楼主
djxh77710
Rank: 2
来 自:中国
等 级:论坛游民
帖 子:71
专家分:88
注 册:2008-10-20
结帖率:80%
 问题点数:0 回复次数:2 
枚举系统服务出问题了
程序代码:
.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;
            
        }
    }
    
}
搜索更多相关主题的帖子: 服务 枚举 系统 
2009-12-02 09:58
sll0807
Rank: 3Rank: 3
等 级:论坛游侠
威 望:5
帖 子:69
专家分:123
注 册:2009-3-2
得分:0 
程序代码:
.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

.Const
szError        db    '出错',0

.Code
Start    Proc
    Local    @dwRetNeed,@hSc,@dwSrvRet

    invoke    OpenSCManager,NULL,NULL,SC_MANAGER_ALL_ACCESS
    
    .if !eax
    
        invoke MessageBox,NULL,addr szError,addr szError,MB_OK
        ret
    
    .endif
    
    mov    @hSc,eax
    
    invoke    EnumServicesStatus,@hSc,SERVICE_WIN32,SERVICE_STATE_ALL,addr @dwRetNeed,sizeof DWORD,addr @dwRetNeed,addr @dwSrvRet,NULL

    invoke    LocalAlloc,LMEM_FIXED and LMEM_ZEROINIT,@dwRetNeed
    .if !eax
    
        invoke MessageBox,NULL,addr szError,addr szError,MB_OK
        ret
    
    .endif
    
    mov        ebx,eax
    
    invoke    EnumServicesStatus,@hSc,SERVICE_WIN32,SERVICE_STATE_ALL,ebx,@dwRetNeed,addr @dwRetNeed,addr @dwSrvRet,NULL
    mov        ecx,@dwSrvRet
    .While ecx
        
        mov        esi,DWORD ptr [ebx]
        mov        edi,DWORD ptr [ebx+4]
        invoke    MessageBox,0,edi,esi,0
        add        ebx,sizeof ENUM_SERVICE_STATUS
        dec        ecx
    .EndW
    invoke    CloseHandle,@hSc
    invoke    LocalFree,ebx
    ret

Start EndP

End Start
2009-12-02 16:22
djxh77710
Rank: 2
来 自:中国
等 级:论坛游民
帖 子:71
专家分:88
注 册:2008-10-20
得分:0 
回复 2楼 sll0807
万分感谢..

No Pains ,No Gains....
2009-12-02 22:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-293651-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.192300 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved