
这样就实现了多个服务共享一个svchost进程。3. Svchost代码现在我们基本清楚svchost的原理了,但是要自己写一个DLL形式的服务,由svchost来启动,仅有上边的信息还有些问题不是很清楚。比如我们在导出的ServiceMain()函数中接收的参数是ANSI还是Unicode?我们是否需要调用RegisterServiceCtrlHandler和StartServiceCtrlDispatcher来注册服务控制及调度函数?这些问题要通过查看svchost代码获得。下边的代码是windows 2000+ service pack 4 的svchost反汇编片段,可以看出svchost程序还是很简单的。主函数首先调用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() 这个函数。
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-45729-2.html
这样他就有理由制裁在国际上摸黑我们了
美国提供了什么
饮料口味不错