减小字体
增大字体
主函数首先调用ProcCommandLine()对命令行进行分析,获得要启动的服务组,然后调用SvcHostOptions()查询该服务组的选项和服务组的所有服务,并使用一个数据结构 svcTable 来保存这些服务及其服务的DLL,然后调用PrepareSvcTable() 函数创建SERVICE_TABLE_ENTRY 结构,把所有处理函数SERVICE_MAIN_FUNCTION 指向自己的一个函数FuncServiceMain(),最后调用API StartServiceCtrlDispatcher() 注册这些服务的调度函数。
; =============================== Main Funcion ===========================================
.text:010010B8 public start .text:010010B8 start proc near .text:010010B8 pushesi .text:010010B9 pushedi .text:010010BA pushoffset sub_1001EBA ; lpTopLevelExceptionFilter .text:010010BF xor edi, edi .text:010010C1 callds:SetUnhandledExceptionFilter .text:010010C7 push1 ; uMode .text:010010C9 callds:SetErrorMode .text:010010CF callds:GetProcessHeap .text:010010D5 pusheax .text:010010D6 callsub_1001142 .text:010010DB mov eax, offset dword_1003018 .text:010010E0 pushoffset unk_1003000 ; lpCriticalSection .text:010010E5 mov dword_100301C, eax .text:010010EA mov dword_1003018, eax .text:010010EF callds:InitializeCriticalSection .text:010010F5 callds:GetCommandLineW .text:010010FB pusheax ; lpString .text:010010FC callProcCommandLine .text:01001101 mov esi, eax .text:01001103 testesi, esi .text:01001105 jzshort lab_doservice .text:01001107 pushesi .text:01001108 callSvcHostOptions .text:0100110D callPrepareSvcTable .text:01001112 mov edi, eax; SERVICE_TABLE_ENTRY returned .text:01001114 testedi, edi .text:01001116 jzshort loc_1001128 .text:01001118 mov eax, [esi+10h] .text:0100111B testeax, eax .text:0100111D jzshort loc_1001128 .text:0100111F pushdword ptr [esi+14h] ; dwCapabilities .text:01001122 pusheax ; int .text:01001123 callInitializeSecurity .text:01001128 .text:01001128 loc_1001128:; CODE XREF: start+5Ej .text:01001128 ; start+65j .text:01001128 pushesi ; lpMem .text:01001129 callHeapFreeMem .text:0100112E .text:0100112E lab_doservice:; CODE XREF: start+4Dj .text:0100112E testedi, edi .text:01001130 jzExitProgram .text:01001136 pushedi ; lpServiceStartTable .text:01001137 callds:StartServiceCtrlDispatcherW .text:0100113D jmp ExitProgram .text:0100113D start endp
; =============================== Main Funcion end =========================================== 由于svchost为该组的所有服务都注册了svchost中的一个处理函数,因此每次启动任何一个服务时,服务管理器SCM都会调用FuncServiceMain() 这个函数。这个函数使用 svcTable 查询要启动的服务使用的DLL,调用DLL导出的ServiceMain()函数来启动服务,然后返回。
; ============================== FuncServiceMain() =========================================== .text:01001504 FuncServiceMain proc near ; DATA XREF: PrepareSvcTable+44o .text:01001504 .text:01001504 arg_0 = dword ptr8 .text:01001504 arg_4 = dword ptr0Ch .text:01001504 .text:01001504 pushecx .text:01001505 mov eax, [esp+arg_4] .text:01001509 pushebx .text:0100150A pushebp .text:0100150B pushesi .text:0100150C mov ebx, offset unk_1003000 .text:01001511 pushedi .text:01001512 mov edi, [eax] .text:01001514 pushebx .text:01001515 xor ebp, ebp .text:01001517 callds:EnterCriticalSection .text:0100151D xor esi, esi .text:0100151F cmp dwGroupSize, esi .text:01001525 jbe short loc_1001566 .text:01001527 and [esp+10h], esi .text:0100152B .text:0100152B loc_100152B:; CODE XREF: FuncServiceMain+4Aj .text:0100152B mov eax, svcTable .text:01001530 mov ecx, [esp+10h] .text:01001534 pushdword ptr [eax+ecx] .text:01001537 pushedi .text:01001538 callds:lstrcmpiW .text:0100153E testeax, eax .text:01001540 jzshort StartThis .text:01001542 add dword ptr [esp+10h], 0Ch .text:01001547 inc esi .text:01001548 cmp esi, dwGroupSize .text:0100154E jbshort loc_100152B .text:01001550 jmp short loc_1001566 .text:01001552 ; ================================================= .text:01001552 .text:01001552 StartThis:; CODE XREF: FuncServiceMain+3Cj .text:01001552 mov ecx, svcTable .text:01001558 lea eax, [esi+esi*2] .text:0100155B lea eax, [ecx+eax*4] .text:0100155E pusheax .text:0100155F callGetDLLServiceMain .text:01001564 mov ebp, eax; dll ServiceMain Function address .text:01001566 .text:01001566 loc_1001566:; CODE XREF: FuncServiceMain+21j .text:01001566 ; FuncServiceMain+4Cj .text:01001566 pushebx .text:01001567 callds:LeaveCriticalSection .text:0100156D testebp, ebp .text:0100156F jzshort loc_100157B .text:01001571 push[esp+10h+arg_4] .text:01001575 push[esp+14h+arg_0] .text:01001579 callebp .text:0100157B .text:0100157B loc_100157B:; CODE XREF: FuncServiceMain+6Bj .text:0100157B pop edi .text:0100157C pop esi .text:0100157D pop ebp .text:0100157E pop ebx .text:0100157F pop ecx .text:01001580 retn8 .text:01001580 FuncServiceMain endp ; sp = -8 ; ============================== FuncServiceMain() end ========================================
|