_drv.asm
来自「用win32asm写的防火墙...基本的功能实现了」· 汇编 代码 · 共 88 行
ASM
88 行
;---------------------------------------------------------------------------------------------------
; 驱动操作相关函数
; 安装并启动驱动
;---------------------------------------------------------------------------------------------------
_Install proc
local @hKey
local @pos:RECT
; 显示成设置模式的界面
invoke GetWindowRect,hDlgWnd,addr @pos
invoke MoveWindow,hDlgWnd,@pos.left,@pos.top,518,500,0
; 设置 IpFilterDriver 为自动启动
invoke RegCreateKey,HKEY_LOCAL_MACHINE,offset szRegKey,addr @hKey
.if eax == ERROR_SUCCESS
invoke RegSetValueEx,@hKey,offset szRegValue,NULL,\
REG_DWORD,offset szStr1,4
invoke RegCloseKey,@hKey
.endif
invoke WinExec,offset szCMD,SW_HIDE
ret
_Install endp
;---------------------------------------------------------------------------------------------------
; 停止并卸载驱动
;---------------------------------------------------------------------------------------------------
_StopDrv proc _Remove
local @hSCManager,@hService
local @SrvStat:SERVICE_STATUS
invoke OpenSCManager, NULL, NULL, SC_MANAGER_ALL_ACCESS
.if eax != NULL
mov @hSCManager,eax
invoke OpenService,@hSCManager,addr szDrvName,SERVICE_ALL_ACCESS
.if eax != NULL
mov @hService, eax
invoke ControlService,@hService, SERVICE_CONTROL_STOP,addr @SrvStat
.if _Remove == 1
invoke DeleteService, @hService
.endif
invoke CloseServiceHandle,@hService
.endif
invoke CloseServiceHandle,@hSCManager
.endif
.if _Remove == 1
; 卸载后删除文件
invoke ExpandEnvironmentStrings,offset szDrvFile,offset szFileName,sizeof szFileName
invoke DeleteFile,offset szFileName
.endif
ret
_StopDrv endp
;---------------------------------------------------------------------------------------------------
; 安装并启动驱动
;---------------------------------------------------------------------------------------------------
_InstallDrv proc
local @hRes,@lpDrv,@DrvSize
local @hSCManager,@hService
invoke ExpandEnvironmentStrings,offset szDrvFile,offset szFileName,sizeof szFileName
invoke CopyFile,offset szOldFile,offset szFileName,0
invoke OpenSCManager, NULL, NULL, SC_MANAGER_ALL_ACCESS
.if eax != NULL
mov @hSCManager,eax
invoke CreateService,eax,addr szDrvName,addr szDrvName, \
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_SYSTEM_START, \
SERVICE_ERROR_IGNORE, addr szFileName, NULL, NULL, NULL, NULL, NULL
.if eax != NULL
mov @hService, eax
invoke StartService,@hService, 0, NULL
invoke CloseServiceHandle,@hService
invoke CloseServiceHandle,@hSCManager
.else
invoke OpenService,@hSCManager,addr szDrvName,SERVICE_ALL_ACCESS
.if eax != NULL
mov @hService, eax
invoke StartService,@hService, 0, NULL
invoke CloseServiceHandle,@hService
invoke CloseServiceHandle,@hSCManager
.else
invoke CloseServiceHandle,@hSCManager
invoke ExitProcess,NULL
.endif
.endif
.endif
ret
_InstallDrv endp
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?