首发:变态VB之HookAPI(陈辉作品)

VB编程中钩子的实现及应用   Windows系统中钩子具有相当强大的功能,通过这种技术可以对几乎所有的Windows 系统中的消息进行拦截、监视、处理。这种技术可以广泛应用于各种软件,尤其是需要有监控、自动记录等对系统进行监测功能的软件。本文针对这个专题进行了探讨,希望可以为读者朋友们起到抛砖引玉的作用。  一、钩子的机制及类型  Windows的应用程序都是基于消息驱动的,应用程序的操作都依赖于它所得 阅读详情

(声明:魏滔序原创,转贴请注明出处。)
        标题的名字本身就变态,因为VB做HookAPI的确让人难以理解,没两把刷子的人也不敢轻易尝试。但陈辉兄弟写出了目前最简单的Hook代码,初步测试效果还不错。
       早期研究过憨豆豆(超级绿豆)的版本,也是一部惊世之作。现在,VB的Fans们又多了一项选择。
        这个HookAPI,在注入的目标为VB编译的EXE或Explorer可以正常工作,其他的exe会有问题,希望有高人能跟踪测试一下问题之所在,造福VB一方网民。 

HookAPI核心部分

项目文件:HookInfo.vbp
Type=Exe
Module=modHookMain; modHookMain.bas
Reference=*/G{00020430-0000-0000-C000-000000000046}#2.0#0#../../../../WINDOWS/system32/STDOLE2.TLB#OLE Automation
Form=frmMain.frm
Module=modHookInfo; modHookInfo.bas
Startup="Sub Main"
HelpFile=""
Title="HookInfo"
ExeName32="HookInfo.exe"
Command32=""
Name="HookInfo"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="Chenhui530"
CompilationType=-1
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1

[MS Transaction Server]
AutoRefresh=1

窗体文件:frmMain.frm (本窗体无任何操作,为了进程的生命期而存在。)
VERSION 5.00
Begin VB.Form frmMain
   Caption         =   "API拦截"
   ClientHeight    =   3090
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3090
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False

模块文件:modHookInfo.bas
Attribute VB_Name = "modHookInfo"
Private Declare Function MessageBoxA Lib "user32" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Private Declare Function MessageBoxW Lib "user32" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nSize As Long, lpNumberOfBytesWritten As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Private Const PROCESS_QUERY_INFORMATION As Long = (&H400)

Private Const STANDARD_RIGHTS_REQUIRED As Long = &HF0000

Private Const SYNCHRONIZE As Long = &H100000

Private Const PROCESS_ALL_ACCESS As Long = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)

Private mbytOldCode(5) As Byte
Private mbytNewCode(5) As Byte
Private mlngFunAddr As Long

Private mhProcess As Long

Public Function HookApi(ByVal strDllName As String, ByVal strFunName As String, ByVal lngFunAddr As Long, ByVal hProcess As Long) As Boolean
    Dim hModule As Long, dwJmpAddr As Long
    mhProcess = hProcess
    hModule = LoadLibrary(strDllName)
    If hModule = 0 Then
        HookApi = False
        Exit Function
    End If
    mlngFunAddr = GetProcAddress(hModule, strFunName)
    If mlngFunAddr = 0 Then
        HookApi = False
        Exit Function
    End If
    CopyMemory mbytOldCode(0), ByVal mlngFunAddr, 6
    Debug.Print mbytOldCode(0); mbytOldCode(1); mbytOldCode(2); mbytOldCode(3); mbytOldCode(4)
    mbytNewCode(0) = &HE9
    dwJmpAddr = lngFunAddr - mlngFunAddr - 5
    CopyMemory mbytNewCode(1), dwJmpAddr, 4
    Debug.Print mbytNewCode(0); mbytNewCode(1); mbytNewCode(2); mbytNewCode(3); mbytNewCode(4)
    HookStatus True
    HookApi = True
End Function

Public Function HookStatus(ByVal blnIsHook As Boolean) As Boolean
    If blnIsHook Then
       If WriteProcessMemory(mhProcess, ByVal mlngFunAddr, mbytNewCode(0), 5, 0) <> 0 Then HookStatus = False '拦截
    Else
        If WriteProcessMemory(mhProcess, ByVal mlngFunAddr, mbytOldCode(0), 5, 0) <> 0 Then HookStatus = False '恢复
    End If
End Function

Private Sub Class_Initialize()
'    mhProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, GetCurrentProcessId)
End Sub

Private Sub Class_Terminate()
    HookStatus False
'    CloseHandle mhProcess
End Sub

模块文件:modHookMain.bas
Attribute VB_Name = "modHookMain"

Option Explicit
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function VirtualAllocEx Lib "kernel32" (ByVal hProcess As Long, ByVal lpAddress As Long, ByVal dwnSize As Long, ByVal flAllocationType As Long, ByVal flProtect As Long) As Long
Private Declare Function VirtualFreeEx Lib "kernel32" (ByVal hProcess As Long, lpAddress As Any, ByVal dwnSize As Long, ByVal dwFreeType As Long) As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hhMod As Long, ByVal lpProcName As String) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long
Private Declare Function CreateRemoteThread Lib "kernel32" (ByVal hProcess As Long, lpThreadAttributes As Long, ByVal dwStacknSize As Long, lpStartAddress As Long, lpParameter As Any, ByVal dwCreationFlags As Long, lpthreadid As Long) As Long
Private Declare Function GetModuleHandleA Lib "kernel32" (ByVal ModName As Any) As Long
Private Declare Function WriteProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nnSize As Long, lpNumberOflngBytesWritten As Long) As Long
Private Declare Function ReadProcessMemory Lib "kernel32" (ByVal hProcess As Long, lpBaseAddress As Any, lpBuffer As Any, ByVal nnSize As Long, lpNumberOflngBytesWritten As Long) As Long
Private Declare Function LoadLibrary Lib "kernel32" Alias "LoadLibraryA" (ByVal lpLibFileName As String) As Long
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal Msg As Any, ByVal wParam As Any, ByVal lParam As Any) As Long
Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long
Private Declare Function DeleteFile Lib "kernel32" Alias "DeleteFileA" (ByVal lpFileName As String) As Long
Private Declare Function GetModuleFileName Lib "kernel32" Alias "GetModuleFileNameA" (ByVal hhMod As Integer, ByVal lpFileName As String, ByVal nnSize As Integer) As Integer
Private Declare Function GetCurrentProcessId Lib "kernel32" () As Long
Private Declare Sub ExitProcess Lib "kernel32" (ByVal dwExitCode As Long)
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)

Private Const MEM_COMMIT = &H1000
Private Const MEM_RESERVE = &H2000
Private Const MEM_RELEASE = &H8000
Private Const PAGE_EXECUTE_READWRITE = &H40&
Private Const IMAGE_NUMBEROF_DIRECTIRY_ENRIES = 16
Private Const STANDARD_RIGHTS_REQUIRED = &HF0000
Private Const SYNCHRONIZE = &H100000
Private Const PROCESS_ALL_ACCESS = (STANDARD_RIGHTS_REQUIRED Or SYNCHRONIZE Or &HFFF)

Private Type IMAGE_DATA_DIRECTORY
    VirtualAddress As Long
    Size As Long
End Type

Private Type IMAGE_FILE_HEADER
    Machine As Integer
    NumberOfSections As Integer
    TimeDataStamp As Long
    PointerToSymbolTable As Long
    NumberOfSymbols As Long
    SizeOfOptionalHeader As Integer
    Characteristics As Integer
End Type

Private Type IMAGE_OPTIONAL_HEADER32
    Magic As Integer
    MajorLinkerVersion As Byte
    MinorLinkerVersion As Byte
    SizeOfCode As Long
    SizeOfInitalizedData As Long
    SizeOfUninitalizedData As Long
    AddressOfEntryPoint As Long
    BaseOfCode As Long
    BaseOfData As Long
    ImageBase As Long
    SectionAlignment As Long
    FileAlignment As Long
    MajorOperatingSystemVersion As Integer
    MinorOperatingSystemVersion As Integer
    MajorImageVersion As Integer
    MinorImageVersion As Integer
    MajorSubsystemVersion As Integer
    MinorSubsystemVersion As Integer
    Reserved1 As Long
    SizeOfImage As Long
    SizeOfHeaders As Long
    CheckSum As Long
    Subsystem As Integer
    DllCharacteristics As Integer
    nSizeOfStackReserve As Long
    SizeOfStackCommit As Long
    SizeOfHeapReserve As Long
    SizeOfHeapCommit As Long
    LoaerFlags As Long
    NumberOfRvaAndnSizes As Long
    DataDirectory(IMAGE_NUMBEROF_DIRECTIRY_ENRIES - 1) As IMAGE_DATA_DIRECTORY
End Type

Private Type IMAGE_DOS_HEADER
    e_magic As Integer
    e_cblp As Integer
    e_cp As Integer
    e_crlc As Integer
    e_cparhdr As Integer
    e_minalloc As Integer
    e_maxalloc As Integer
    e_ss As Integer
    e_sp As Integer
    e_csum As Integer
    e_ip As Integer
    e_cs As Integer
    e_lfarlc As Integer
    e_onvo As Integer
    e_res(3) As Integer
    e_oemid As Integer
    e_oeminfo As Integer
    e_res2(9) As Integer
    e_lfanew As Long
End Type
Private Const szTarget As String = "ProgMan"
Private szFileName As String * 261

Private Type OBJECT_ATTRIBUTES
    Length As Long
    RootDirectory As Long
    ObjectName As Long
    Attributes As Long
    SecurityDescriptor As Long
    SecurityQualityOfService As Long
End Type

Private Type CLIENT_ID
    UniqueProcess As Long
    UniqueThread  As Long
End Type

Private Declare Function NtOpenProcess Lib "NTDLL.DLL" (ByRef hProcess As Long, ByVal AccessMask As Long, ByRef ObjectAttributes As OBJECT_ATTRIBUTES, ByRef CliendwThreadId As CLIENT_ID) As Long
Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As Long
Private Declare Function lstrcpyn Lib "kernel32" Alias "lstrcpynA" (ByVal lpString1 As String, ByVal lpString2 As String, ByVal iMaxLength As Long) As Long
Private mProcess As Long
Private mlnghWnd As Long
Private mdwProcessId As Long
Private Type MYTYPE
    strName As String * 260
    hwnd As Long
    dwProcessId As Long
End Type
Private pInfo As MYTYPE

Private Sub Main()
    ' Sub that will start when the program is run
    Dim dwProcessId As Long, hProcess As Long
    Dim nSize As Long, lngBytesWritten As Long, dwThreadId As Long, hMod As Long, hNewMod As Long
    Dim objPImageOptionalHeader As IMAGE_OPTIONAL_HEADER32, objPImageDosHeader As IMAGE_DOS_HEADER, objTImageFileHeader As IMAGE_FILE_HEADER
    Dim lngExeVariable As Long

    frmMain.Show
    ' Get the EXE name
    GetModuleFileName 0, szFileName, 261
    pInfo.hwnd = frmMain.hwnd
    pInfo.strName = szFileName
    pInfo.dwProcessId = GetCurrentProcessId
    ' Get the dwProcessId of the program. Note that it must be running in memory (open it)
    GetWindowThreadProcessId FindWindow(0&, "测试程序"), dwProcessId
    'GetWindowThreadProcessId FindWindow(szTarget, 0&), dwProcessId

    ' Open the process and give us full access, we need this to hijack it
    hProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, dwProcessId)
    If hProcess = 0 Then End
    ' Get the memory location of where our code starts in memory, this will correspond to the /BASE: switch that you put in the linker options using compile controller
    hMod = GetModuleHandleA(vbNullString)
    If hMod = 0 Then End
    ' Load the code's header into the DosHeader Type
    CopyMemory objPImageDosHeader, ByVal hMod, Len(objPImageDosHeader)
   
    ' e_lfanew is the starting address of the PE Header in memory. Add this value to the length of the fileheader as well as to the length of the optional header
    ' These headers are the founding blocks of any executable file, wether in memory or on disk.
    CopyMemory objPImageOptionalHeader, ByVal (hMod + objPImageDosHeader.e_lfanew + 4 + Len(objTImageFileHeader)), Len(objPImageOptionalHeader)
   
    ' After adding all those lengths, we will get the final nSize of the executable in memory, this is usually a bit more then the nSize on disk
    nSize = objPImageOptionalHeader.SizeOfImage
    If nSize = 0 Then End
    ' Just to make sure, free the memory in the program at the location of our exe
    VirtualFreeEx hProcess, hMod, 0, MEM_RELEASE
   
    ' Allocate the nSize of our exe in memory of the program, at the location of where our exe is in memory
    hNewMod = VirtualAllocEx(hProcess, hMod, nSize, MEM_RESERVE Or MEM_COMMIT, PAGE_EXECUTE_READWRITE)
    If hNewMod = 0 Then End
  
    ' Copy our exe into program's memory
    If WriteProcessMemory(hProcess, ByVal hNewMod, ByVal hMod, nSize, lngBytesWritten) = 0 Then End

    ' Copy the EXE name
    lngExeVariable = VirtualAllocEx(hProcess, 0, Len(pInfo), MEM_RESERVE Or MEM_COMMIT, PAGE_EXECUTE_READWRITE)
   
    'lngExeVariable = VirtualAllocEx(hProcess, 0, 261, MEM_RESERVE Or MEM_COMMIT, PAGE_EXECUTE_READWRITE)
    If lngExeVariable = 0 Then End
   
    If WriteProcessMemory(hProcess, ByVal lngExeVariable, pInfo, Len(pInfo), lngBytesWritten) = 0 Then End
    'If WriteProcessMemory(hProcess, ByVal lngExeVariable, szFileName, 261, lngBytesWritten) = 0 Then End
    '*************************************************************************
    ''这里要做下判断如果是注入非VB程序得拷贝VB库如果是VB程序则不需要下面代码
    ' Copy VB Runtime to EXE memory (same code as to copy our EXE, so I won't comment it again.
'    Dim hVBMod As Long, lngVBnSize As Long, hVBNewMod As Long
'    hVBMod = GetModuleHandleA("msvbvm60.dll")
'    If hVBMod = 0 Then End
'    CopyMemory objPImageDosHeader, ByVal hVBMod, Len(objPImageDosHeader)
'    CopyMemory objPImageOptionalHeader, ByVal (hVBMod + objPImageDosHeader.e_lfanew + 4 + Len(objTImageFileHeader)), Len(objPImageOptionalHeader)
'    lngVBnSize = objPImageOptionalHeader.SizeOfImage
'    hVBNewMod = VirtualAllocEx(hProcess, hVBMod, lngVBnSize, MEM_RESERVE Or MEM_COMMIT, PAGE_EXECUTE_READWRITE)
'    If hVBNewMod = 0 Then End
'    If WriteProcessMemory(hProcess, ByVal hVBNewMod, ByVal hVBMod, lngVBnSize, lngBytesWritten) = 0 Then End
    '**************************************************************************
    ' Create our remote thread
    If CreateRemoteThread(hProcess, ByVal 0, 0, ByVal GetFunAddr(AddressOf RemoteFunAdd), ByVal lngExeVariable, 0, dwThreadId) = 0 Then End
   
    'ExitProcess 0
End Sub

Public Function GetFunAddr(ByVal lngEntrypoint As Long) As Long
    GetFunAddr = lngEntrypoint
End Function

Public Function RemoteFunAdd(ByVal hAddr As Long) As Long ' Code that will run in the hijacked program - CANNOT USE MOST VB INTRISTIC FUNCTIONS -
    ' Call our hMod with full access to VB functions, any other code here needs to be extremly basic (not even left/mid etc)
    HookMain hAddr
End Function

Private Function HookMain(ByVal lngAgs As Long) As Long
    Dim szExename As String * 261, lnglngBytesWritten As Long
    'ReadProcessMemory OpenProcess(PROCESS_ALL_ACCESS, 0, GetCurrentProcessId), ByVal lngAgs, ByVal szExename, 261, ByVal lnglngBytesWritten
    'MessageBox 0, "成功HOOK", szExename, 0
    Dim mInfo As MYTYPE, nSize As Long
    CopyMemory mInfo, ByVal lngAgs, Len(mInfo)
    nSize = lstrlen(mInfo.strName)
    If nSize <> 0 Then
        nSize = nSize + 1
        Call lstrcpyn(szExename, mInfo.strName, nSize)
    Else
        szExename = mInfo.strName
    End If
    mdwProcessId = mInfo.dwProcessId
'    MessageBox 0, mInfo.hWnd, szExename, 0
    mProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, GetCurrentProcessId)
'    GetWindowThreadProcessId mInfo.hWnd, mdwProcessId
    MessageBox 0, szExename, mInfo.dwProcessId, 0
    HookApi "ntdll", "NtOpenProcess", GetFunAddr(AddressOf NtOpenProcessCallback), mProcess
End Function

Private Function NtOpenProcessCallback(ByRef hProcess As Long, ByVal AccessMask As Long, ByRef ObjectAttributes As OBJECT_ATTRIBUTES, ByRef ClientId As CLIENT_ID) As Long
    Dim lngReturn As Long
    HookStatus False
    lngReturn = NtOpenProcess(hProcess, AccessMask, ObjectAttributes, ClientId)
    HookStatus True
    If hProcess <> 0 Then
        If ClientId.UniqueProcess >= mdwProcessId And ClientId.UniqueProcess < mdwProcessId + 4 Then
            MessageBox 0, "被拦截了", "哈哈", 0
            hProcess = 0
        End If
    End If
    NtOpenProcessCallback = lngReturn
End Function

测试部分

项目文件:Test.vbp
Type=Exe
Form=frmMain.frm
Reference=*/G{00020430-0000-0000-C000-000000000046}#2.0#0#../../../../../WINDOWS/system32/STDOLE2.TLB#OLE Automation
Startup="frmMain"
ExeName32="Test.exe"
Command32=""
Name="Test"
HelpContextID="0"
CompatibleMode="0"
MajorVer=1
MinorVer=0
RevisionVer=0
AutoIncrementVer=0
ServerSupportFiles=0
VersionCompanyName="eabax"
CompilationType=0
OptimizationType=0
FavorPentiumPro(tm)=0
CodeViewDebugInfo=0
NoAliasing=0
BoundsCheck=0
OverflowCheck=0
FlPointCheck=0
FDIVCheck=0
UnroundedFP=0
StartMode=0
Unattended=0
Retained=0
ThreadPerObject=0
MaxNumberOfThreads=1

[MS Transaction Server]
AutoRefresh=1

窗体文件:frmMain.frm
VERSION 5.00
Begin VB.Form frmMain
   Caption         =   "测试程序"
   ClientHeight    =   3090
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   4680
   LinkTopic       =   "Form1"
   ScaleHeight     =   3090
   ScaleWidth      =   4680
   StartUpPosition =   3  '窗口缺省
   Begin VB.CommandButton cmdKill
      Caption         =   "结束进程"
      Height          =   525
      Left            =   1080
      TabIndex        =   0
      Top             =   1260
      Width           =   1695
   End
End
Attribute VB_Name = "frmMain"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hWnd As Long, lpdwProcessId As Long) As Long
Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long
Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub cmdKill_Click()
    Dim hWnd As Long, dwProcesdId As Long, hProcess As Long
    hWnd = FindWindow(vbNullString, "API拦截")
    GetWindowThreadProcessId hWnd, dwProcessId
    hProcess = OpenProcess(1, 0, dwProcessId)
    TerminateProcess hProcess, 0
End Sub

两个项目编译后,先打开Test.exe,然后再打开HookInfo.exe。
点击Test中窗体的按钮即可看到效果,祝你好运。

变速齿轮源码与Windows HOOK API实现 变速齿轮技术,也称为时间控制技术,是一种能够改变计算机内部时钟速度的技术。它通过精确控制CPU时间片的分配,使得运行在该系统中的程序运行速度加快或减慢,而不会影响到其它程序。这项技术在游戏作弊、性能测试和系统仿真中有着广泛的应用。Hook API技术是一种用于截获和修改系统、应用程序的行为的技术。它的工作原理是在系统或应用程序执行某些操作之前,拦截这些操作,并可以将它们重定向到新的代码中去执行。这种技术可以用于多种目的,例如调试、监控、扩展功能,以及改变应用程序的行为等。 阅读详情

相关推荐

告别以太网瓶颈:手把手教你为AI训练集群搭建InfiniBand网络(以NVIDIA DGX A100/H100为例)

本文详细指导如何为AI训练集群搭建InfiniBand网络,解决以太网瓶颈问题,特别针对NVIDIA DGX A100/H100系统。通过硬件选型、网络架构设计和性能调优,显著提升多机多卡训练效率,适用于大规模模型训练场景。

weixin_30336061的博客 315

vb Hook比较详细的讲解 ---> vb获取按键消息(钩子方式)

Windows系统中钩子具有相当强大的功能,通过这种技术可以对几乎所有的Windows 系统中的消息进行拦截、监视、处理。这种技术可以广泛应用于各种软件,尤其是需要有监控、自动记录等对系统进行监测功能的软件。本文针对这个专题进行了探讨,希望可以为读者朋友们起到抛砖引玉的作用。   一、钩子的机制及类型   Windows的应用程序都是基于消息驱动的,应用程序的操作都依赖于它所得到的消息

yuli1234147的博客 1万+

Cadence Allegro 17.4 保姆级教程:PCB位号重排与反标回原理图完整避坑指南

本文详细解析了Cadence Allegro 17.4中PCB位号重排与反标回原理图的全流程,包括安全工程准备、智能重排策略和反标黄金法则。特别针对芯片封装协同设计(Co-Design)场景,提供可追溯的版本管理和故障恢复方案,帮助工程师避免常见位号陷阱,确保设计文件一致性。

weixin_30613433的博客 445

我的Hook学习笔记

                                            关于Hook 一、基本概念:    钩子(Hook),是Windows消息处理机制的一个平台,应用程序可以在上面设置子程以监视指定窗口的某种消息,而且所监视的窗口可以是其他进程所创建的。当消息到达后,在目标窗口处理函数之前处理它。钩子机制允许应用程序截获处理window消息或特定事件。    钩子实际上

rivershan的专栏 2万+

常用的集成TTL门电路

本篇主要分析了常用的逻辑门电路与非门,详细分析了电源原理。值得收藏。

ManagerUser的博客 5101

ESXI 8.0.3 ubuntu 24.04 直通显卡P40

手把手,一步步教你直通GPU,ESXI 8.0.3 ubuntu 24.04 直通显卡P40

qq_36433118的博客 4689

vb底层开发之Hook(钩子)

原帖地址:http://hi.baidu.com/starwork/blog/item/6d989ed3b2cb2c35960a1638.htmlhook是WINDOWS提供的一种消息处理机制,它使得程序员可以使用子过程来监视系统消息,并在消息到达目标过程前得到处理。 下面将介绍WINNDOWS HOOKS并且说明如何在WINDOWS 程序中使用它。 关于HOOKS 使用HOOK 将会降低

VisionSpace的专栏 1398

PHY6252开发实战:从零构建BLE串口透传应用

本文详细介绍了PHY6252开发板在BLE串口透传应用中的实战经验,包括开发环境搭建、BLE串口透传例程解析、AT指令集实现与扩展、数据透传机制优化以及常见问题排查指南。通过智能家居遥控器项目案例,展示了PHY6252在低功耗物联网设备开发中的实际应用。

weixin_29183637的博客 321

VB Hook简介

文章作者:Jeffrey Richter Hook这个东西有时令人又爱又怕,Hook是用来拦截系统某些讯息之用,例如说,我们想让系统不管在什麽地方只要按个Ctl-B便执行NotePad,或许您会使用Form的KeyPreview,设定为True,但在其他Process中按Ctl-B呢?那就没有用,这是就得设一个Keyboard Hook来拦截所有Key in的键;再如:MouseMove的E

1271

新版MQL语言程序设计:用vscode编写编译调试mt4和mt5程序

使用VScode搭建MT4与MT5开发环境,实现编辑编译调试统一。

超哥量化的博客 6887

YOLO26涨点改进 | 独家创新,细节涨点改进篇 | CVPR 2025顶会 | YOLO26引入Mona即插即用模块, 含MoCAA和DyTMona二次创新改进,含多种创新改进高效发论文

本文给大家介绍Mona即插即用模块, 含MoCAA和DyTMona二次创新模块优化YOLO26模型。YOLO26引入 Mona通过引入多尺度视觉友好型卷积滤波器(如3x3、5x5、7x7深度卷积)和可伸缩归一化层来优化适配器设计,以更好地处理视觉信号并调节输入特征分布。YOLO26引入Mona即插即用模块, 含MoCAA和DyTMona二次创新改进,含多种创新改进高效发论文。适合目标检测、图像分割、图像分类等所有CV任务通用即插即用模块。

Ai缝合怪、助力小伙伴高效发论文 248

对《变态VB之HookAPI(陈辉作品) 》一文的补遗

(声明:魏滔序原创,转贴请注明出处。)原文地址:http://blog.csdn.net/Modest/archive/2007/09/18/1789758.aspx 该文中的HookInfo在编译的时候需要修改Base参数值为52000000才可以正常工作,本文附件中为vb的插件,可以在编译的过程中修改编译参数。http://dl2.csdn.net/down4/20070919/1

迈克揉索芙特 2988

中文核心:swin transformer 农作物病虫害识别 完整代码数据

中文核心:swin transformer 农作物病虫害识别

944

利用HOOKAPI拦截文件操作

先读下HookAPI 使用文档:功能简介HookAPI 是一个截获Windows 32位API函数的开发包,它可以在Windows调用某个API函数的时候,先调用自己编写的函数,从而实现特殊的功能。HookAPI同样也适用于截获用户自己编写的DLL文件中的输出函数。 1.5系统特点:1)自己编写的替代函数的参数形式和原API函数完全一样,方便了Delphi和VB用户的使用。2)实时截获所有新建立的...

bruce135lee的专栏 4108

文档:亲测可用解决vnc灰屏,黑屏,鼠标大黑叉情况

主要解决vnc-viewer灰屏,黑屏,鼠标大黑叉等现象,详细见文档。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Linux钩子拦截删除文件,利用HOOKAPI拦截文件操作

功能简介HookAPI 是一个截获Windows 32位API函数的开发包,它可以在Windows调用某个API函数的时候,先调用自己编写的函数,从而实现特殊的功能。HookAPI同样也适用于截获用户自己编写的DLL文件中的输出函数。1.5系统特点:1)自己编写的替代函数的参数形式和原API函数完全一样,方便了Delphi和VB用户的使用。2)实时截获所有新建立的进程,即进程建立后马上安装钩子,而...

weixin_39761880的博客 685

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

首次使用HOOKAPI暴力破解SQLITE3加密的数据库

怕原作者生气,在这就不放源代码了。 最近研究“给力大CI典”的时候,反汇编了一下,是用DELPHI写的,使用SQLITE3定制版本加密了一部分数据库,于是通过HOOKAPI到sqlite3_key,找到了密码,然后用VB6写了个解密SQLITE3的工具,把数据库都解密了。 这里就给出两个密钥: 1、shao8977545*S 用于zclb.db。 2、shao897754*Z 用于其余...

bihai.org 1万+

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

VB,你也想HOOK API吗?那跟我来!!

        本文不是介绍怎样用纯VB实现HOOK API的,如果您想了解细节那么您必须懂得一些vc和很少的汇编知识,并且参考我的其它文章,如果您是忠实VB使用者那么您完全可以不去了解内部的原理,因为那些是vc干的事情(不要不爱听,我没有种族歧视的倾向,因为我不知道怎样用VB实现它,我完全不会使用VB,为了本文才研究了几天,本文中涉及VB的代码也是非常非常的少,本文中涉及VB的代码都是前几天在C

liutaoxwl的专栏 4364

VB无DLLHook API

这篇程序让你实现VB HOOK 的实现,也让你做一些VC等其他语言才能做的事情.不过目前还不是很完善还有待修改,目前还只能注入到EXPLORER.EXE和VB写的程序中.什么原因目前还不知道.由于我不懂汇编,而且目前还在出差就没有多的时间来研究,这个问题就等高手来解决好造福广大VB爱好者吧!modHookInfo 模块 核心HOOK模块注意这个程序中不能使用类Attribute VB_Na

chenhui530的专栏 6075

VB6动态执行vb.net代码c#代码,python,内存加载OCX控件Activex-COM对象

我在研究内存动态编译运行.net源码。用.net开发一个dll,传入vb.net代码或者c#源码就可以自动运行,创建窗口或者直接返回计算结果。 把这个dll给易语言vc6,vb6,freebasic,delphi等语言调用。让一切编程语言都支持.net 简单说,熟悉一种开发语言,但有时找到其他语言的代码,只是需要运行简单算法函数,比如JavaScript代码计算MD5,VBS代码,python代...

896

划句号。

写这个游戏修改器已经很长时间了,今天决定短事件内不进行更新了。准备开始学D3D部分。公开这个游戏修改器的核心设计:1、搜索内存部分:分析进程内存块及各块属性修改不能读取的各内存块属性为可读,读进程内存到数组搜索数组内容——将要搜索的内容转换为BYTE数组并对照,保存得到的结果再次搜索时读上次结果内各个地址数据并保存本次结果,直至搜索完成2、 获取修改内存地址A的代码所在

zcsor的专栏 4万+

qq四国军旗2.1 beat03 builde018记牌器开发思路(四)

上文终于找到了行棋的起始位置和结束位置,这样就可以动态扫描的方式进行处理。这种方式是一种拉的方式,和使用HTTP协议非常相似。也就是说,你不知道游戏内存的数据什么时候,变成了什么。与之相似的处理方式,比如不停扫描数据库,看看是否记录增加等。因为对方不会通知,所以,需要主动去读,而缺点也显现出来了,与其它主动扫描一样有很多毛病。这里就不详细讲这个了,很多游戏外挂也是用的这样的思路,比如自动喝血喝蓝外...

weixin_34331102的博客 562

伤仲永?一个高中生的自学编程经历。看完能少走很多弯路!

我有很大的研究技术的热情,今年18。从初中开始,就已经种下了自由控制电脑这种欲望的种子。到了高一,我第一次从信息技术课本上看到编程二字,并且书上带走一个vb写的画二次函数图像的小例子,但是家里没有电脑,我也没大重视。从高一暑假开始,我拥有了一台电脑。我想学习编程,但是电脑没联网,于是我经常从别人家里下载资料软件,回家研究。 每次都下载一堆的东西,包括网上的教程,别人的经验,大学的课件,还有pdf格式的电子书等等。那时在网上搜编程资料,最多的就是vc vb,看到人家都说vb最简单,所以就选了vb,自己在家研究

MachineGunJoe666 923

班门弄斧一次VC++.NET 2008写的HOOK RECV代码

学习资料:   班门弄斧一次VC++.NET 2008写的HOOK RECV代码   确实是班门弄斧,因为我是学VB的,虽然VB6和.NET都算入门吧,可真正拿VC++写程序还是第一次。学B/C/D的就莫看了。 由于是用上两篇写的远线程调用,所以很多参数等等都是传入的,而不是直接获取的。   下面就一个用VB的人能理解为目标做简单说明和注释: 1、VC里面声明变量和VB不一样:类型

zbc_vc的专栏 1460

进程创建监控

上次讲了下进程保护原理,这次讲一下进程监控。监视进程创建,也就是监视EXE程序启动,就要hook掉创建进程的API,创建进程的API有ntdll!ZwCreateProcessEx、ZwCreateSection、ZwCreateThread等,kernel32里有CreateProcessA(W)和CreateProcessInternalA(W),hook ZW函数比较麻烦,因为那时进...

zzmzzff的博客 863

每周精选编程技术文章与资源_9月29日至10月05日

Hook API技术 对hook api感兴趣的可以看了,经常在群里有人问如何HOOK API,HOOK api为什么程序崩溃,程序卡死等现象。想知道答案么,看看这个吧 也许能帮助你。 http://www.panshy.com/articles/security-83.html 解决VC绘制窗体时闪烁与效率问题 很多开发人员在自绘窗体时常常出现窗体闪的问题,有的是偶

嬴政 780
上一篇: 绿软必备:ActiveXDLL免注册调用的方法(改良自阿国哥的源码)
下一篇: 对《变态VB之HookAPI(陈辉作品) 》一文的补遗
迈克揉索芙特
博客等级 码龄24年 865粉丝 71原创
评论 4
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址