Dynamic loading of the driver

xiaoxiao2021-03-14  193

Dynamic loading of drivers: tubes uploaded on 2005-4-23 by Aogo compilation of the station

How to use it after the driver is made? According to Four-f, there are three ways: Service Control Manager (SCM).)

Service Control Program (SCP).) And Services (Service Program).

Below we use the Service Control Program (SCP) to implement the dynamic load of the driver, example program in KMDKit / Examples / Simple / Beeper

code show as below:

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

;

Scp.asm

;

Service Control Program for Beeper.sys Driver

;

Written by four-f (four-f@mail.ru)

;

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

.386

.Model flat, stdcall

Option CaseMAP: NONE

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

I n c l u d e f i l e s

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

INCLUDE /MASM32/INCLUDE/Windows.inc

INCLUDE /MASM32/INCLUDE / WANEL32.INC

INCLUDE /MASM32/INCLUDE/USER32.INC

Include /masm32/include/advapi32.inc

INCLUDELIB /MASM32/LIB/kernel32.lib

INCLUDELIB /MASM32/LIB/USER32.LIB

INCLUDELIB /MASM32/LIB/advapi32.lib

INCLUDE /MASM32/Macros/strings.mac

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

; C O d e

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

.code

START Proc

Local Hscmanager: Handle

Local HService: Handle

Local ACDRIVERPATH [MAX_PATH]: char

Open a Handle to the SC Manager Database

Invoke OpenScManager, NULL, NULL, SC_MANAGER_CREATE_SERVICE

.IF EAX! = NULL

Mov Hscmanager, EAX

Push EAX

Invoke getFullPathname, $ CTA0 ("Beeper.sys"), Sizeof ACDRIVERPATH, ADDR ACDRIVERPATH, ESPPOP 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, ADDR 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, HService

.lse

Invoke Messagebox, Null, $ CTA0 ("Can't Register Driver."), NULL, MB_ICONSTOP

.endif

Invoke CloseServiceHandle, HScManager

.lse

Invoke Messagebox, Null, $ CTA0 ("CAN't Connect To Service Control Manager."), /

NULL, MB_ICONSTOP

.endif

Invoke EXITPROCESS, 0

START ENDP

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

;

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

End Start

; ============= The following is the content of the driver source code beeper.bat ===========

@echo off

Goto Make

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

;

; beeper - kernel mode driver

Makes Beep Thorough Computer Speaker

;

Written by four-f (four-f@mail.ru)

;

Warning: TESTED W2000 & XP Only!

;

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

.386

.MODEL FLAT, STDCALLOPTION CASEMAP: NONE

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

I n c l u d e f i l e s

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

INCLUDE /MASM32/INCLUDE/W2k/ntstatus.inc

INCLUDE /MASM32/INCLUDE/W2K/NTDDK.inc

INCLUDE /MASM32/INCLUDE/W2k/hal.inc

INCLUDELIB /MASM32/LIB/W2k/hal.lib

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

; U s e r d e f i n e d e q u a t e s

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

Timer_frequency EQU 1193167; 1,193,167 HZ

Octave EQU 2

Pitch_a EQU 440; 440,00 Hz

Pitch_as EQU 446; 466, 16 Hz

Pitch_h EQU 494; 493, 88 HZ

PITCH_C EQU 523; 523, 25 Hz

PITCH_CS EQU 554; 554, 37 Hz

PITCH_D EQU 587; 587, 33 HZ

Pitch_ds EQU 622; 622, 25 Hz

PITCH_E EQU 659; 659, 25 HZ

PITCH_F EQU 698; 698, 46 Hz

PITCH_FS EQU 740; 739, 99 Hz

Pitch_G EQU 784; 783, 99 HZ

PITCH_GS EQU 831; 830, 61 Hz

PITCH_A EQU 880; 880,00 Hz

Pitch_as EQU 988; 987,77 HZ

Pitch_h EQU 1047; 1046, 50 Hz

WE Are Going to Play C-Major Chord

Tone_1 EQU Timer_Frequency / (PITCH_C * OCTAVE)

TONE_2 EQU Timer_Frequency / (Pitch_e * Octave)

Tone_3 EQU (Pitch_g * Octave); for halmakebeep

Delay EQU 1800000h; for my ~ 800MHz Machine

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

U S E R D E f I n e D m a c R o s

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

Do_delay macro

; Silly Method, But it works ;-)

Mov Eax, DELAY

.While EAX

Dec EAX

.endw

ENDM

;::::: :::::::::::::::::::::: ::::: :::::::::::::::::::::: Code

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

.code

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

Makebeep1

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

Makebeep1 Proc DWPITCH: DWORD

Direct Hardware Access

CLI

Mov Al, 10110110y

OUT 43H, Al; TIMER 8253-5 (at: 8254.2).

Mov Eax, DWPITCH

OUT 42H, Al

Mov Al, AH

OUT 42H, Al

Speaker ON

IN AL, 61H

OR Al, 11Y

OUT 61H, Al

STI

Do_DELAY

CLI

Speaker OFF

IN AL, 61H

And Al, 11111100Y

OUT 61H, Al

STI

RET

Makebeep1 ENDP

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

Makebeep2

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

Makebeep2 Proc DWPITCH: DWORD

Hardware Access Via Hal Using * _Port_uchar / * _ port_uchar functions

CLI

Invoke Write_Port_uchar, 43h, 10110110y

Mov Eax, DWPITCH

Invoke Write_Port_uchar, 42H, Al

Mov Eax, DWPITCH

Invoke Write_Port_uchar, 42h, AH

Speaker ON

Invoke Read_Port_uchar, 61H

OR Al, 11Y

Invoke Write_Port_uchar, 61h, Al

STI

Do_DELAY

CLI

Speaker OFF

Invoke Read_Port_uchar, 61H

And Al, 11111100Y

Invoke Write_Port_uchar, 61h, Al

STI

RET

Makebeep2 Endp

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

Driverentry

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

Driverentry Proc PDRIVEROBJECT: PDRIVER_OBJECT, PUSREGISTRYPATH: PUNICODE_STRINVOKE MAKEBEEP1, TONE_1

Invoke makebeep2, tone_2

Hardware Access Via Hal.dll Function Halmakebeep

Invoke Halmakebeep, Tone_3

Do_DELAY

Invoke Halmakebeep, 0

MOV EAX, Status_Device_configuration_error

RET

Driverentry Endp

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

;

;::::: :::::::::::::::::::::: ::::: ::::::::::::::::::::::

End Driverentry

: Make

SET DRV = BEEPER

/ MASM32 / BIN / mL / NOLOGO / C / COFF% DRV% .bat

/ MASM32 / BIN / LINK / NOLOGO / DRIVER / BASE: 0x10000 / align: 32 /out:%DRV%.sys / subsystem: native% DRV% .Obj

DEL% DRV% .Obj

echo.

PAUSE

Rem ============= or more is the content of the driver source beeper.bat ===========

We double-click Beeper.bat under KMDKit / Examples / Simple / Beeper / BEEPER.SYS, compile SCP.ASM like compiling a general Win32ASM program, generate scp.exe, double-click scp.exe, what did you hear? It is a sound emitted by the speaker on the motherboard. This is through direct control port, we have broken through Ring0 restrictions, is it happy?

转载请注明原文地址:https://www.9cbs.com/read-129308.html

New Post(0)