驱动程序的动态加载_第1页
驱动程序的动态加载_第2页
驱动程序的动态加载_第3页
驱动程序的动态加载_第4页
驱动程序的动态加载_第5页
已阅读5页,还剩1页未读, 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、驱动程序的动态加载驱动程序做出来后,怎么用呢?根据Four-F的说法,有三种方式:服务控制管理器(Servi ce Control Manager (SCM).)服务控制程序(Service Control Program (SCP).)和服务程序(service program).下面我们就用服务控制程序(SCP)来实现驱动程序的动态加载,例子程序在KmdKitexampl essimpleBeeper代码如下:;:; scp.asm;Service Control Program for beeper.sys driver;Written by Four-F ( HYPERLINK mai

2、lto:four-fmail.ru four-fmail.ru);:.386.model flat, stdcall option casemap:noneI N C L U D E F I L E S include masm32includewindows.incinclude masm32includekernel32.incinclude masm32includeuser32.incinclude masm32includeadvapi32.incincludelib masm32libkernel32.libincludelib masm32libuser32.lib includ

3、elib masm32libadvapi32.libinclude masm32MacrosStrings.mac.codestart proclocal hSCManager:HANDLE local hService:HANDLE local acDriverPathMAX_PATH:CHAR;Open a handle to the SC Manager database invoke OpenSCManager, NULL, NULL, SC_MANAGER_CREATE_SERVICE .if eax != NULLmov hSCManager, eaxpush eax invoke

4、 GetFullPathName, $CTA0(beeper.sys), sizeof acDriverPath, addr acDriver Path, esp pop eax; Register driver in SCM active database invoke CreateService, hSCManager, $CTA0(beeper), $CTA0(Nice Melody Beeper ),SERVICE_START + DELETE, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START, SERVICE_ERROR_IGNORE, add

5、r acDriverPath, NULL, NULL, NULL, NULL, NULL .if eax != NULL mov hService, eax invoke StartService, hService, 0, NULL; Here driver beeper.sys plays its nice melody ; and reports error to be removed from memory ; Remove driver from SCM database invoke DeleteService, hService invoke CloseServiceHandle

6、, hService .elseinvoke MessageBox, NULL, $CTA0(Cant register driver.), NULL, MB_ICONSTOP .endifinvoke CloseServiceHandle, hSCManager .elseinvoke MessageBox, NULL, $CTA0(Cant connect to Service Control Manager.), NULL, MB_ICONSTOP .endif invoke ExitProcess, 0start endp end start;=以下是驱动程序源码beeper.bat的

7、内容=;echo off;goto makeJ;beeper - Kernel Mode Driver;Makes beep thorough computer speaker;Written by Four-F ( HYPERLINK mailto:four-fmail.ru four-fmail.ru);WARNING: Tested W2000 & XP only!;:.386.model flat, stdcall option casemap:none;I N C L U D E F I L E S;:include masm32includew2kntstatus.incinclu

8、de masm32includew2kntddk.incinclude masm32includew2khal.incincludelib masm32libw2khal.lib;:U S E R D E F I N E D E Q U A T E STIMER_FREQUENCY equ 1193167 ; 1,193,167 HzOCTAVE equ 2;PITCH_A equ 440 ; 440,00 Hz;PITCH_As equ 446 ; 466,16 Hz;PITCH_H equ 494 ; 493,88 HzPITCH_C equ 523 ; 523,25 HzPITCH_Cs

9、 equ 554 ; 554,37 HzPITCH_D equ 587 ; 587,33 HzPITCH_Ds equ 622 ; 622,25 HzPITCH_E equ 659 ; 659,25 HzPITCH_F equ 698 ; 698,46 HzPITCH_Fs equ 740 ; 739,99 HzPITCH_G equ 784 ; 783,99 HzPITCH_Gs equ 831 ; 830,61 HzPITCH_A equ 880 ; 880,00 HzPITCH_As equ 988 ; 987,77 Hz PITCH_H equ 1047 ; 1046,50 Hz;We

10、 are going to play c-major chordTONE_1 equ TIMER_FREQUENCY/(PITCH_C*OCTAVE)TONE_2 equ TIMER_FREQUENCY/(PITCH_E*OCTAVE)TONE_3 equ (PITCH_G*OCTAVE); for HalMakeBeepDELAY equ 1800000h ; for my 800mHz machineU S E R D E F I N E D M A C R O SDO_DELAY MACRO;Silly method, but it works ;-) mov eax, DELAY .w

11、hile eax dec eax .endwENDMJ:;C O D E;: :.code;: :;MakeBeepl;: :MakeBeepl proc dwPitch:DWORD;Direct hardware accessclimov al, 10110110yout 43h, al ; Timer 8253-5 (AT: 8254.2).mov eax, dwPitch out 42h, almov al, ah out 42h, al;speaker ON in al, 61h or al, 11y out 61h, alstiDO_DELAYcli;speaker OFF in a

12、l, 61h and al, 11111100y out 61h, al stiretMakeBeepl endp;: :;MakeBeep2;: :MakeBeep2 proc dwPitch:DWORD;Hardware access via HAL using *_PORT_UCHAR/*_PORT_UCHAR functionscliinvoke WRITE_PORT_UCHAR, 43h, 10110110ymov eax, dwPitch invoke WRITE_PORT_UCHAR, 42h, al mov eax, dwPitchinvoke WRITE_PORT_UCHAR

13、, 42h, ah;speaker ON invoke READ_PORT_UCHAR, 61h or al, 11yinvoke WRITE_PORT_UCHAR, 61h, alstiDO_DELAYcli;speaker OFF invoke READ_PORT_UCHAR, 61h and al, 11111100yinvoke WRITE_PORT_UCHAR, 61h, alsti retMakeBeep2 endp;DriverEntry;:DriverEntry proc pDriverObject:PDRIVER_OBJECT, pusRegistryPath:PUNICOD

14、E_STRINGinvoke MakeBeep1, TONE_1 invoke MakeBeep2, TONE_2;Hardware access via hal.dll function HalMakeBeep invoke HalMakeBeep, TONE_3 DO_DELAYinvoke HalMakeBeep, 0mov eax, STATUS_DEVICE_CONFIGURATION_ERROR retDriverEntry endp end DriverEntry:makeset drv=beepermasm32binml /nologo /c /coff %drv%.batmasm32binlink /nologo /driver /base:0 x10000 /align:32 /out:%drv%.sys /subsys tem:native %drv%.o

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论